Skip to content

Commit

Permalink
test_runner: refactor build Promise in Suite()
Browse files Browse the repository at this point in the history
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.

PR-URL: #55958
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
  • Loading branch information
cjihrig authored and aduh95 committed Nov 26, 2024
1 parent 30f26ba commit 95e8c4e
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const {
SafeMap,
SafePromiseAll,
SafePromiseAllReturnVoid,
SafePromisePrototypeFinally,
SafePromiseRace,
SafeSet,
StringPrototypeStartsWith,
Expand Down Expand Up @@ -1259,27 +1258,20 @@ class Suite extends Test {
this.skipped = false;
}

this.buildSuite = this.createBuild();
this.fn = noop;
}

async createBuild() {
try {
const { ctx, args } = this.getRunArgs();
const runArgs = [this.fn, ctx];
ArrayPrototypePushApply(runArgs, args);
this.buildSuite = SafePromisePrototypeFinally(
PromisePrototypeThen(
PromiseResolve(ReflectApply(this.runInAsyncScope, this, runArgs)),
undefined,
(err) => {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
}),
() => this.postBuild(),
);
await ReflectApply(this.runInAsyncScope, this, runArgs);
} catch (err) {
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
this.postBuild();
}
this.fn = noop;
}

postBuild() {
this.buildPhaseFinished = true;
}

Expand Down

0 comments on commit 95e8c4e

Please sign in to comment.