diff --git a/lib/internal/test_runner/harness.js b/lib/internal/test_runner/harness.js index b13ca112e5cc27..504cc1e93acd7a 100644 --- a/lib/internal/test_runner/harness.js +++ b/lib/internal/test_runner/harness.js @@ -25,6 +25,7 @@ const { setupTestReporters, shouldColorizeTestFiles, } = require('internal/test_runner/utils'); +const { queueMicrotask } = require('internal/process/task_queues'); const { bigint: hrtime } = process.hrtime; const testResources = new SafeMap(); @@ -181,6 +182,7 @@ function setup(root) { root.harness = { __proto__: null, + allowTestsToRun: false, bootstrapComplete: false, coverage: FunctionPrototypeBind(collectCoverage, null, root, coverage), counters: { @@ -219,7 +221,16 @@ function getGlobalRoot() { async function startSubtest(subtest) { await reportersSetup; - getGlobalRoot().harness.bootstrapComplete = true; + + const root = getGlobalRoot(); + if (!root.harness.bootstrapComplete) { + root.harness.bootstrapComplete = true; + queueMicrotask(() => { + root.harness.allowTestsToRun = true; + root.processPendingSubtests(); + }); + } + await subtest.start(); } diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index b7ac5756dad195..41fbfdab931392 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -538,6 +538,7 @@ function run(options = kEmptyObject) { } const runFiles = () => { root.harness.bootstrapComplete = true; + root.harness.allowTestsToRun = true; return SafePromiseAllSettledReturnVoid(testFiles, (path) => { const subtest = runTestFile(path, filesWatcher, opts); filesWatcher?.runningSubtests.set(path, subtest); diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 1642cfdd15e3c6..0bb714a617c09c 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -603,7 +603,7 @@ class Test extends AsyncResource { // it. Otherwise, return a Promise to the caller and mark the test as // pending for later execution. this.reporter.enqueue(this.nesting, this.loc, this.name); - if (!this.parent.hasConcurrency()) { + if (!this.root.harness.allowTestsToRun || !this.parent.hasConcurrency()) { const deferred = createDeferredPromise(); deferred.test = this; diff --git a/test/fixtures/test-runner/output/source_mapped_locations.snapshot b/test/fixtures/test-runner/output/source_mapped_locations.snapshot index 24c3ee8d113446..29b70fd0d08378 100644 --- a/test/fixtures/test-runner/output/source_mapped_locations.snapshot +++ b/test/fixtures/test-runner/output/source_mapped_locations.snapshot @@ -21,6 +21,9 @@ not ok 1 - fails * * * + * + * + * ... 1..1 # tests 1