Skip to content

Commit 41a775c

Browse files
cjihrigmarco-ippolito
authored andcommitted
test_runner: run top level tests in a microtask
This commit updates the test harness to prevent top level tests from executing immediately. This allows certain config data, such as filtering options, to be discovered before running the tests. PR-URL: #52092 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
1 parent 76eba06 commit 41a775c

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

lib/internal/test_runner/harness.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const {
2525
setupTestReporters,
2626
shouldColorizeTestFiles,
2727
} = require('internal/test_runner/utils');
28+
const { queueMicrotask } = require('internal/process/task_queues');
2829
const { bigint: hrtime } = process.hrtime;
2930

3031
const testResources = new SafeMap();
@@ -181,6 +182,7 @@ function setup(root) {
181182

182183
root.harness = {
183184
__proto__: null,
185+
allowTestsToRun: false,
184186
bootstrapComplete: false,
185187
coverage: FunctionPrototypeBind(collectCoverage, null, root, coverage),
186188
counters: {
@@ -219,7 +221,16 @@ function getGlobalRoot() {
219221

220222
async function startSubtest(subtest) {
221223
await reportersSetup;
222-
getGlobalRoot().harness.bootstrapComplete = true;
224+
225+
const root = getGlobalRoot();
226+
if (!root.harness.bootstrapComplete) {
227+
root.harness.bootstrapComplete = true;
228+
queueMicrotask(() => {
229+
root.harness.allowTestsToRun = true;
230+
root.processPendingSubtests();
231+
});
232+
}
233+
223234
await subtest.start();
224235
}
225236

lib/internal/test_runner/runner.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ function run(options) {
582582
}
583583
const runFiles = () => {
584584
root.harness.bootstrapComplete = true;
585+
root.harness.allowTestsToRun = true;
585586
return SafePromiseAllSettledReturnVoid(testFiles, (path) => {
586587
const subtest = runTestFile(path, filesWatcher, opts);
587588
filesWatcher?.runningSubtests.set(path, subtest);

lib/internal/test_runner/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ class Test extends AsyncResource {
571571
// it. Otherwise, return a Promise to the caller and mark the test as
572572
// pending for later execution.
573573
this.reporter.enqueue(this.nesting, this.loc, this.name);
574-
if (!this.parent.hasConcurrency()) {
574+
if (!this.root.harness.allowTestsToRun || !this.parent.hasConcurrency()) {
575575
const deferred = createDeferredPromise();
576576

577577
deferred.test = this;

test/fixtures/test-runner/output/source_mapped_locations.snapshot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ not ok 1 - fails
2121
*
2222
*
2323
*
24+
*
25+
*
26+
*
2427
...
2528
1..1
2629
# tests 1

0 commit comments

Comments
 (0)