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 RafaelGSS committed Dec 15, 2023
1 parent 2581fce commit d5c9adf
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 @@ -487,6 +487,9 @@ function run(options = kEmptyObject) {
}

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 @@ -466,4 +466,37 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
}));
});
});

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 d5c9adf

Please sign in to comment.