From 4b0f81d9e8ed4d06468c612c803d1e0dd22a547f Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 5 Mar 2023 12:46:14 -0500 Subject: [PATCH] test_runner: track bootstrapping process This commit updates the test harness and root test to track when bootstrapping has completed. PR-URL: https://github.com/nodejs/node/pull/46962 Reviewed-By: Moshe Atlow Reviewed-By: Yagiz Nizipli --- lib/internal/test_runner/harness.js | 3 ++- lib/internal/test_runner/runner.js | 15 +++++++++------ lib/internal/test_runner/utils.js | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/internal/test_runner/harness.js b/lib/internal/test_runner/harness.js index 84205d43ac78f9..3d4fc3b49674c5 100644 --- a/lib/internal/test_runner/harness.js +++ b/lib/internal/test_runner/harness.js @@ -178,13 +178,14 @@ function getGlobalRoot() { globalRoot.reporter.once('test:fail', () => { process.exitCode = kGenericUserError; }); - reportersSetup = setupTestReporters(globalRoot.reporter); + reportersSetup = setupTestReporters(globalRoot); } return globalRoot; } async function startSubtest(subtest) { await reportersSetup; + getGlobalRoot().harness.bootstrapComplete = true; await subtest.start(); } diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 5108fc3283f63b..5b772251be981e 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -387,13 +387,16 @@ function run(options) { filesWatcher = watchFiles(testFiles, root, inspectPort); postRun = undefined; } - const runFiles = () => SafePromiseAllSettledReturnVoid(testFiles, (path) => { - const subtest = runTestFile(path, root, inspectPort, filesWatcher); - runningSubtests.set(path, subtest); - return subtest; - }); + const runFiles = () => { + root.harness.bootstrapComplete = true; + return SafePromiseAllSettledReturnVoid(testFiles, (path) => { + const subtest = runTestFile(path, root, inspectPort, filesWatcher); + runningSubtests.set(path, subtest); + return subtest; + }); + }; - PromisePrototypeThen(PromisePrototypeThen(PromiseResolve(setup?.(root.reporter)), runFiles), postRun); + PromisePrototypeThen(PromisePrototypeThen(PromiseResolve(setup?.(root)), runFiles), postRun); return root.reporter; } diff --git a/lib/internal/test_runner/utils.js b/lib/internal/test_runner/utils.js index 72270e464248a5..e4fd23c8e8cb60 100644 --- a/lib/internal/test_runner/utils.js +++ b/lib/internal/test_runner/utils.js @@ -150,13 +150,13 @@ async function getReportersMap(reporters, destinations) { } -async function setupTestReporters(testsStream) { +async function setupTestReporters(rootTest) { try { const { reporters, destinations } = parseCommandLine(); const reportersMap = await getReportersMap(reporters, destinations); for (let i = 0; i < reportersMap.length; i++) { const { reporter, destination } = reportersMap[i]; - compose(testsStream, reporter).pipe(destination); + compose(rootTest.reporter, reporter).pipe(destination); } } catch (err) { throw new ERR_TEST_FAILURE(err, kAsyncBootstrapFailure);