Skip to content

Commit e2ae436

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 77e2bf0 commit e2ae436

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
@@ -26,6 +26,7 @@ const {
2626
setupTestReporters,
2727
shouldColorizeTestFiles,
2828
} = require('internal/test_runner/utils');
29+
const { queueMicrotask } = require('internal/process/task_queues');
2930
const { bigint: hrtime } = process.hrtime;
3031

3132
const testResources = new SafeMap();
@@ -189,6 +190,7 @@ function setup(root) {
189190

190191
root.harness = {
191192
__proto__: null,
193+
allowTestsToRun: false,
192194
bootstrapComplete: false,
193195
watching: false,
194196
coverage: FunctionPrototypeBind(collectCoverage, null, root, coverage),
@@ -232,7 +234,16 @@ function getGlobalRoot() {
232234

233235
async function startSubtest(subtest) {
234236
await reportersSetup;
235-
getGlobalRoot().harness.bootstrapComplete = true;
237+
238+
const root = getGlobalRoot();
239+
if (!root.harness.bootstrapComplete) {
240+
root.harness.bootstrapComplete = true;
241+
queueMicrotask(() => {
242+
root.harness.allowTestsToRun = true;
243+
root.processPendingSubtests();
244+
});
245+
}
246+
236247
await subtest.start();
237248
}
238249

lib/internal/test_runner/runner.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ function run(options) {
590590
}
591591
const runFiles = () => {
592592
root.harness.bootstrapComplete = true;
593+
root.harness.allowTestsToRun = true;
593594
return SafePromiseAllSettledReturnVoid(testFiles, (path) => {
594595
const subtest = runTestFile(path, filesWatcher, opts);
595596
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
@@ -584,7 +584,7 @@ class Test extends AsyncResource {
584584
// it. Otherwise, return a Promise to the caller and mark the test as
585585
// pending for later execution.
586586
this.reporter.enqueue(this.nesting, this.loc, this.name);
587-
if (!this.parent.hasConcurrency()) {
587+
if (!this.root.harness.allowTestsToRun || !this.parent.hasConcurrency()) {
588588
const deferred = createDeferredPromise();
589589

590590
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)