Skip to content
Closed
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);
}

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