Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: run top level tests in a microtask #52092

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -181,6 +182,7 @@ function setup(root) {

root.harness = {
__proto__: null,
allowTestsToRun: false,
bootstrapComplete: false,
coverage: FunctionPrototypeBind(collectCoverage, null, root, coverage),
counters: {
Expand Down Expand Up @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ not ok 1 - fails
*
*
*
*
*
*
...
1..1
# tests 1
Expand Down
Loading