From b8f0ea6f60a77e6f3f1539ee0b2e7b52c7154660 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta Date: Sun, 10 Dec 2023 15:05:22 +0530 Subject: [PATCH] test_runner: fix infinite loop when files are undefined in test runner PR-URL: https://github.com/nodejs/node/pull/51047 Fixes: https://github.com/nodejs/node/issues/48823 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Moshe Atlow Reviewed-By: James M Snell --- 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 d6976c56082f72..68f5cda30bffac 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -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) { diff --git a/test/parallel/test-runner-run.mjs b/test/parallel/test-runner-run.mjs index 35dbf359d36690..74d6d91937678c 100644 --- a/test/parallel/test-runner-run.mjs +++ b/test/parallel/test-runner-run.mjs @@ -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); + }); });