Skip to content

Commit 0f50d2a

Browse files
committed
test_runner: refactor build Promise in Suite()
This commit refactors the buildSuite Promise logic in the Suite constructor to use an async function instead of creating an awkward primordial-based Promise chain.
1 parent 1d0738a commit 0f50d2a

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

lib/internal/test_runner/test.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const {
2424
SafeMap,
2525
SafePromiseAll,
2626
SafePromiseAllReturnVoid,
27-
SafePromisePrototypeFinally,
2827
SafePromiseRace,
2928
SafeSet,
3029
StringPrototypeStartsWith,
@@ -1259,27 +1258,20 @@ class Suite extends Test {
12591258
this.skipped = false;
12601259
}
12611260

1261+
this.buildSuite = this.createBuild();
1262+
this.fn = noop;
1263+
}
1264+
1265+
async createBuild() {
12621266
try {
12631267
const { ctx, args } = this.getRunArgs();
12641268
const runArgs = [this.fn, ctx];
12651269
ArrayPrototypePushApply(runArgs, args);
1266-
this.buildSuite = SafePromisePrototypeFinally(
1267-
PromisePrototypeThen(
1268-
PromiseResolve(ReflectApply(this.runInAsyncScope, this, runArgs)),
1269-
undefined,
1270-
(err) => {
1271-
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
1272-
}),
1273-
() => this.postBuild(),
1274-
);
1270+
await ReflectApply(this.runInAsyncScope, this, runArgs);
12751271
} catch (err) {
12761272
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
1277-
this.postBuild();
12781273
}
1279-
this.fn = noop;
1280-
}
12811274

1282-
postBuild() {
12831275
this.buildPhaseFinished = true;
12841276
}
12851277

0 commit comments

Comments
 (0)