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: https://github.com/nodejs/node/pull/52092
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
Colin Ihrig authored and Marco Ippolito committed 2024-05-23 13:12:56 +02:00
1 parent 77e2bf029a
commit e2ae4367f4
4 files changed
+17 -2

No files matched your search

+12 -1
View File
@@ -26,6 +26,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();
@@ -189,6 +190,7 @@ function setup(root) {
root.harness = {
__proto__: null,
allowTestsToRun: false,
bootstrapComplete: false,
watching: false,
coverage: FunctionPrototypeBind(collectCoverage, null, root, coverage),
@@ -232,7 +234,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();
}
+1
View File
@@ -590,6 +590,7 @@ function run(options) {
}
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);
+1 -1
View File
@@ -584,7 +584,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;
@@ -21,6 +21,9 @@ not ok 1 - fails
*
*
*
*
*
*
...
1..1
# tests 1