Skip to content

test_runner: refactor primordial-based Promise chains #55958

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@ const {
ArrayPrototypeSort,
ObjectAssign,
PromisePrototypeThen,
PromiseResolve,
PromiseWithResolvers,
SafeMap,
SafePromiseAll,
@@ -801,9 +800,17 @@ function run(options = kEmptyObject) {
}
}

const setupPromise = PromiseResolve(setup?.(root.reporter));
PromisePrototypeThen(PromisePrototypeThen(PromisePrototypeThen(setupPromise, runFiles), postRun), teardown);
const runChain = async () => {
if (typeof setup === 'function') {
await setup(root.reporter);
}

await runFiles();
postRun?.();
teardown?.();
};

runChain();
return root.reporter;
}

20 changes: 6 additions & 14 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ const {
SafeMap,
SafePromiseAll,
SafePromiseAllReturnVoid,
SafePromisePrototypeFinally,
SafePromiseRace,
SafeSet,
StringPrototypeStartsWith,
@@ -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;
}

Loading