Skip to content

Commit 5e6ac7e

Browse files
authored
test_runner: simplify code and make it more consistent
PR-URL: #60777 Reviewed-By: Pietro Marchini <[email protected]> Reviewed-By: Xuguang Mei <[email protected]> Reviewed-By: Ilyas Shabi <[email protected]>
1 parent 0771137 commit 5e6ac7e

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

lib/internal/test_runner/test.js

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const {
1313
MathMax,
1414
Number,
1515
NumberPrototypeToFixed,
16-
ObjectDefineProperty,
1716
ObjectSeal,
1817
Promise,
1918
PromisePrototypeThen,
@@ -55,6 +54,7 @@ const {
5554
const {
5655
kEmptyObject,
5756
once: runOnce,
57+
setOwnProperty,
5858
} = require('internal/util');
5959
const { isPromise } = require('internal/util/types');
6060
const {
@@ -133,33 +133,22 @@ function stopTest(timeout, signal) {
133133
if (timeout === kDefaultTimeout) {
134134
disposeFunction = abortListener[SymbolDispose];
135135
} else {
136-
timer = setTimeout(() => deferred.resolve(), timeout);
136+
timer = setTimeout(deferred.resolve, timeout);
137137
timer.unref();
138-
139-
ObjectDefineProperty(deferred, 'promise', {
140-
__proto__: null,
141-
configurable: true,
142-
writable: true,
143-
value: PromisePrototypeThen(deferred.promise, () => {
144-
throw new ERR_TEST_FAILURE(
145-
`test timed out after ${timeout}ms`,
146-
kTestTimeoutFailure,
147-
);
148-
}),
149-
});
138+
setOwnProperty(deferred, 'promise', PromisePrototypeThen(deferred.promise, () => {
139+
throw new ERR_TEST_FAILURE(
140+
`test timed out after ${timeout}ms`,
141+
kTestTimeoutFailure,
142+
);
143+
}));
150144

151145
disposeFunction = () => {
152146
abortListener[SymbolDispose]();
153147
timer[SymbolDispose]();
154148
};
155149
}
156150

157-
ObjectDefineProperty(deferred.promise, SymbolDispose, {
158-
__proto__: null,
159-
configurable: true,
160-
writable: true,
161-
value: disposeFunction,
162-
});
151+
setOwnProperty(deferred.promise, SymbolDispose, disposeFunction);
163152
return deferred.promise;
164153
}
165154

@@ -994,7 +983,7 @@ class Test extends AsyncResource {
994983
if (this.root.harness.buildPromise || !this.parent.hasConcurrency()) {
995984
const deferred = PromiseWithResolvers();
996985

997-
deferred.test = this;
986+
setOwnProperty(deferred, 'test', this);
998987
this.parent.addPendingSubtest(deferred);
999988
return deferred.promise;
1000989
}

0 commit comments

Comments
 (0)