Skip to content

Commit 929ddde

Browse files
committed
test_runner: infinite loop when files are undefined in run()
1 parent 7b3eb31 commit 929ddde

File tree

2 files changed

+55
-20
lines changed

2 files changed

+55
-20
lines changed

lib/internal/test_runner/runner.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -487,29 +487,31 @@ function run(options = kEmptyObject) {
487487
}
488488

489489
const root = createTestTree({ __proto__: null, concurrency, timeout, signal });
490-
let testFiles = files ?? createTestFileList();
490+
if (process.env.NODE_TEST_CONTEXT === undefined) {
491+
let testFiles = files ?? createTestFileList();
491492

492-
if (shard) {
493-
testFiles = ArrayPrototypeFilter(testFiles, (_, index) => index % shard.total === shard.index - 1);
494-
}
493+
if (shard) {
494+
testFiles = ArrayPrototypeFilter(testFiles, (_, index) => index % shard.total === shard.index - 1);
495+
}
495496

496-
let postRun = () => root.postRun();
497-
let filesWatcher;
498-
const opts = { __proto__: null, root, signal, inspectPort, testNamePatterns, only };
499-
if (watch) {
500-
filesWatcher = watchFiles(testFiles, opts);
501-
postRun = undefined;
502-
}
503-
const runFiles = () => {
504-
root.harness.bootstrapComplete = true;
505-
return SafePromiseAllSettledReturnVoid(testFiles, (path) => {
506-
const subtest = runTestFile(path, filesWatcher, opts);
507-
filesWatcher?.runningSubtests.set(path, subtest);
508-
return subtest;
509-
});
510-
};
497+
let postRun = () => root.postRun();
498+
let filesWatcher;
499+
const opts = { __proto__: null, root, signal, inspectPort, testNamePatterns, only };
500+
if (watch) {
501+
filesWatcher = watchFiles(testFiles, opts);
502+
postRun = undefined;
503+
}
504+
const runFiles = () => {
505+
root.harness.bootstrapComplete = true;
506+
return SafePromiseAllSettledReturnVoid(testFiles, (path) => {
507+
const subtest = runTestFile(path, filesWatcher, opts);
508+
filesWatcher?.runningSubtests.set(path, subtest);
509+
return subtest;
510+
});
511+
};
511512

512-
PromisePrototypeThen(PromisePrototypeThen(PromiseResolve(setup?.(root)), runFiles), postRun);
513+
PromisePrototypeThen(PromisePrototypeThen(PromiseResolve(setup?.(root)), runFiles), postRun);
514+
}
513515

514516
return root.reporter;
515517
}

test/parallel/test-runner-run.mjs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,4 +466,37 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
466466
}));
467467
});
468468
});
469+
470+
it('should run with no files', async () => {
471+
const stream = run({
472+
files: undefined
473+
}).compose(tap);
474+
stream.on('test:fail', common.mustNotCall());
475+
stream.on('test:pass', common.mustNotCall());
476+
477+
// eslint-disable-next-line no-unused-vars
478+
for await (const _ of stream);
479+
});
480+
481+
it('should run with no files and use spec reporter', async () => {
482+
const stream = run({
483+
files: undefined
484+
}).compose(spec);
485+
stream.on('test:fail', common.mustNotCall());
486+
stream.on('test:pass', common.mustNotCall());
487+
488+
// eslint-disable-next-line no-unused-vars
489+
for await (const _ of stream);
490+
});
491+
492+
it('should run with no files and use dot reporter', async () => {
493+
const stream = run({
494+
files: undefined
495+
}).compose(dot);
496+
stream.on('test:fail', common.mustNotCall());
497+
stream.on('test:pass', common.mustNotCall());
498+
499+
// eslint-disable-next-line no-unused-vars
500+
for await (const _ of stream);
501+
});
469502
});

0 commit comments

Comments
 (0)