From ab5b3185f1fa161e063e1e000cec1784808248b6 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 874f1c253e110b..a00320a6b0d2d2 100644 --- a/lib/internal/test_runner/harness.js +++ b/lib/internal/test_runner/harness.js @@ -176,13 +176,14 @@ function getGlobalRoot() { globalRoot.reporter.once('test:fail', () => { process.exitCode = 1; }); - 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 82017d69722598..68468277b2b782 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -386,13 +386,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 6d0b58c5325f67..d4564b063f3bbd 100644 --- a/lib/internal/test_runner/utils.js +++ b/lib/internal/test_runner/utils.js @@ -151,13 +151,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);