From 4d456a82972414e0ae7278e15b46399b74b7f31a Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 22 Nov 2024 15:54:03 -0500 Subject: [PATCH] test_runner: refactor Promise chain in run() 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: https://github.com/nodejs/node/pull/55958 Reviewed-By: Yagiz Nizipli Reviewed-By: Benjamin Gruenbaum Reviewed-By: Matteo Collina Reviewed-By: Pietro Marchini Reviewed-By: Jacob Smith Reviewed-By: James M Snell Reviewed-By: Chemi Atlow --- lib/internal/test_runner/runner.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 9fd10dbb5f4b1e..de30789ba4b79f 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -17,7 +17,6 @@ const { ArrayPrototypeSort, ObjectAssign, PromisePrototypeThen, - PromiseResolve, PromiseWithResolvers, SafeMap, SafePromiseAll, @@ -798,9 +797,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; }