From a1a0da74f1e32a6b0de9081fb72fa5f9cb6787ef Mon Sep 17 00:00:00 2001 From: pulkit-30 Date: Sun, 10 Dec 2023 11:53:13 +0530 Subject: [PATCH] test_runner: fix infinite loop when files are undefined in test runner --- lib/internal/test_runner/runner.js | 3 +++ test/parallel/test-runner-run.mjs | 33 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index c4194923cc0f44..34100213ebd935 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -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) { diff --git a/test/parallel/test-runner-run.mjs b/test/parallel/test-runner-run.mjs index 911f115e5fb6a4..c712f500153b42 100644 --- a/test/parallel/test-runner-run.mjs +++ b/test/parallel/test-runner-run.mjs @@ -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); + }); });