chore: simplify expect zone wrapper (#27145)

This commit is contained in:
Pavel Feldman 2023-09-18 15:02:50 -07:00 committed by GitHub
parent 40e8445b82
commit 6b36a50969
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -282,31 +282,17 @@ class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {
step?.complete({});
};
// Process the async matchers separately to preserve the zones in the stacks.
if (this._info.isPoll || (matcherName in customAsyncMatchers && matcherName !== 'toPass')) {
return (async () => {
try {
const expectZone: ExpectZone = { title, wallTime };
await zones.run<ExpectZone, any>('expectZone', expectZone, async () => {
// We assume that the matcher will read the current expect timeout the first thing.
setCurrentExpectConfigureTimeout(this._info.timeout);
await matcher.call(target, ...args);
});
finalizer();
} catch (e) {
reportStepError(e);
}
})();
} else {
try {
const result = matcher.call(target, ...args);
if (result instanceof Promise)
return result.then(finalizer).catch(reportStepError);
finalizer();
return result;
} catch (e) {
reportStepError(e);
}
const expectZone: ExpectZone = { title, wallTime };
// We assume that the matcher will read the current expect timeout the first thing.
setCurrentExpectConfigureTimeout(this._info.timeout);
try {
const result = zones.run<ExpectZone, any>('expectZone', expectZone, () => matcher.call(target, ...args));
if (result instanceof Promise)
return result.then(finalizer).catch(reportStepError);
finalizer();
return result;
} catch (e) {
reportStepError(e);
}
};
}