Skip to content

Commit

Permalink
test_runner: refactor Promise chain in run()
Browse files Browse the repository at this point in the history
This commit refactors the chain of functions in run() to use an
async function instead of creating an awkward primordial-based
Promise chain.

PR-URL: #55958
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Pietro Marchini <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
  • Loading branch information
cjihrig authored and nodejs-github-bot committed Nov 25, 2024
1 parent 216fd20 commit 3c35188
Showing 1 changed file with 10 additions and 3 deletions.
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

0 comments on commit 3c35188

Please sign in to comment.