Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

test_runner: refactor primordial-based Promise chains #55958

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Expand Up @@ -17,7 +17,6 @@ const {
ArrayPrototypeSort,
ObjectAssign,
PromisePrototypeThen,
PromiseResolve,
PromiseWithResolvers,
SafeMap,
SafePromiseAll,
Expand Down Expand Up @@ -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);
}
cjihrig marked this conversation as resolved.
Show resolved Hide resolved

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

runChain();
return root.reporter;
}

Expand Down
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
Loading