Skip to content

Commit a1a0da7

Browse files
committed
test_runner: fix infinite loop when files are undefined in test runner
1 parent 37ba7a3 commit a1a0da7

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/internal/test_runner/runner.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ function run(options = kEmptyObject) {
487487
}
488488

489489
const root = createTestTree({ __proto__: null, concurrency, timeout, signal });
490+
if (process.env.NODE_TEST_CONTEXT !== undefined) {
491+
return root.reporter;
492+
}
490493
let testFiles = files ?? createTestFileList();
491494

492495
if (shard) {

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)