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.
  • Loading branch information
cjihrig committed Nov 24, 2024
1 parent 1d0738a commit 0f50d2a
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 @@ -24,7 +24,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 0f50d2a

Please sign in to comment.