Skip to content

Commit

Permalink
test_runner: fix infinite loop when files are undefined in test runner
Browse files Browse the repository at this point in the history
PR-URL: #51047
Fixes: #48823
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
pulkit-30 authored and richardlau committed Mar 25, 2024
1 parent 03b19cb commit b8f0ea6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ function run(options) {
}

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

if (shard) {
Expand Down
33 changes: 33 additions & 0 deletions test/parallel/test-runner-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,37 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
assert.deepStrictEqual(executedTestFiles.sort(), [...shardsTestsFiles].sort());
});
});

it('should run with no files', async () => {
const stream = run({
files: undefined
}).compose(tap);
stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustNotCall());

// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});

it('should run with no files and use spec reporter', async () => {
const stream = run({
files: undefined
}).compose(spec);
stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustNotCall());

// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});

it('should run with no files and use dot reporter', async () => {
const stream = run({
files: undefined
}).compose(dot);
stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustNotCall());

// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});
});

0 comments on commit b8f0ea6

Please sign in to comment.