From 95e8c4ef6c31bb155d6014947c15b86e964482dc Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 22 Nov 2024 15:41:35 -0500 Subject: [PATCH] test_runner: refactor build Promise in Suite() This commit refactors the buildSuite Promise logic in the Suite constructor 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/test.js | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 1ba113dbdc1a49..6a92ec335ddf34 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -23,7 +23,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; }