Skip to content

Commit b8f0ea6

Browse files
pulkit-30richardlau
authored andcommitted
test_runner: fix infinite loop when files are undefined in test runner
PR-URL: #51047 Fixes: #48823 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 03b19cb commit b8f0ea6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/internal/test_runner/runner.js

+3
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ function run(options) {
531531
}
532532

533533
const root = createTestTree({ __proto__: null, concurrency, timeout, signal });
534+
if (process.env.NODE_TEST_CONTEXT !== undefined) {
535+
return root.reporter;
536+
}
534537
let testFiles = files ?? createTestFileList();
535538

536539
if (shard) {

test/parallel/test-runner-run.mjs

+33
Original file line numberDiff line numberDiff line change
@@ -458,4 +458,37 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
458458
assert.deepStrictEqual(executedTestFiles.sort(), [...shardsTestsFiles].sort());
459459
});
460460
});
461+
462+
it('should run with no files', async () => {
463+
const stream = run({
464+
files: undefined
465+
}).compose(tap);
466+
stream.on('test:fail', common.mustNotCall());
467+
stream.on('test:pass', common.mustNotCall());
468+
469+
// eslint-disable-next-line no-unused-vars
470+
for await (const _ of stream);
471+
});
472+
473+
it('should run with no files and use spec reporter', async () => {
474+
const stream = run({
475+
files: undefined
476+
}).compose(spec);
477+
stream.on('test:fail', common.mustNotCall());
478+
stream.on('test:pass', common.mustNotCall());
479+
480+
// eslint-disable-next-line no-unused-vars
481+
for await (const _ of stream);
482+
});
483+
484+
it('should run with no files and use dot reporter', async () => {
485+
const stream = run({
486+
files: undefined
487+
}).compose(dot);
488+
stream.on('test:fail', common.mustNotCall());
489+
stream.on('test:pass', common.mustNotCall());
490+
491+
// eslint-disable-next-line no-unused-vars
492+
for await (const _ of stream);
493+
});
461494
});

0 commit comments

Comments
 (0)