mirror of
https://github.com/nodejs/node.git
synced 2025-12-28 07:50:41 +00:00
test_runner: simplify code and make it more consistent
PR-URL: https://github.com/nodejs/node/pull/60777 Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Ilyas Shabi <ilyasshabi94@gmail.com>
This commit is contained in:
parent
0771137972
commit
5e6ac7ede6
@ -13,7 +13,6 @@ const {
|
||||
MathMax,
|
||||
Number,
|
||||
NumberPrototypeToFixed,
|
||||
ObjectDefineProperty,
|
||||
ObjectSeal,
|
||||
Promise,
|
||||
PromisePrototypeThen,
|
||||
@ -55,6 +54,7 @@ const {
|
||||
const {
|
||||
kEmptyObject,
|
||||
once: runOnce,
|
||||
setOwnProperty,
|
||||
} = require('internal/util');
|
||||
const { isPromise } = require('internal/util/types');
|
||||
const {
|
||||
@ -133,20 +133,14 @@ function stopTest(timeout, signal) {
|
||||
if (timeout === kDefaultTimeout) {
|
||||
disposeFunction = abortListener[SymbolDispose];
|
||||
} else {
|
||||
timer = setTimeout(() => deferred.resolve(), timeout);
|
||||
timer = setTimeout(deferred.resolve, timeout);
|
||||
timer.unref();
|
||||
|
||||
ObjectDefineProperty(deferred, 'promise', {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: PromisePrototypeThen(deferred.promise, () => {
|
||||
throw new ERR_TEST_FAILURE(
|
||||
`test timed out after ${timeout}ms`,
|
||||
kTestTimeoutFailure,
|
||||
);
|
||||
}),
|
||||
});
|
||||
setOwnProperty(deferred, 'promise', PromisePrototypeThen(deferred.promise, () => {
|
||||
throw new ERR_TEST_FAILURE(
|
||||
`test timed out after ${timeout}ms`,
|
||||
kTestTimeoutFailure,
|
||||
);
|
||||
}));
|
||||
|
||||
disposeFunction = () => {
|
||||
abortListener[SymbolDispose]();
|
||||
@ -154,12 +148,7 @@ function stopTest(timeout, signal) {
|
||||
};
|
||||
}
|
||||
|
||||
ObjectDefineProperty(deferred.promise, SymbolDispose, {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: disposeFunction,
|
||||
});
|
||||
setOwnProperty(deferred.promise, SymbolDispose, disposeFunction);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
@ -994,7 +983,7 @@ class Test extends AsyncResource {
|
||||
if (this.root.harness.buildPromise || !this.parent.hasConcurrency()) {
|
||||
const deferred = PromiseWithResolvers();
|
||||
|
||||
deferred.test = this;
|
||||
setOwnProperty(deferred, 'test', this);
|
||||
this.parent.addPendingSubtest(deferred);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user