Skip to content

Commit

Permalink
test_runner: fix recursive run
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Apr 3, 2024
1 parent 74343a7 commit fe3fca7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ function run(options = kEmptyObject) {
root.harness.shouldColorizeTestFiles ||= shouldColorizeTestFiles(root);

if (process.env.NODE_TEST_CONTEXT !== undefined) {
process.emitWarning('node:test run() is being called recursively within a test file. skipping running files.');
root.postRun();
return root.reporter;
}
let testFiles = files ?? createTestFileList();
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/test-runner/recursive_run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const { test, run } = require('node:test');

test('recursive run() calls', async () => {
for await (const event of run({ files: [__filename] }));
});
12 changes: 12 additions & 0 deletions test/parallel/test-runner-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,18 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});

it('should avoid running recursively', async () => {
const stream = run({ files: [join(testFixtures, 'recursive_run.js')] });
let stderr = '';
stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall(1));
stream.on('test:stderr', (c) => { stderr += c.message; });

// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
assert.match(stderr, /Warning: run\(\) is being called recursively/);

Check failure on line 535 in test/parallel/test-runner-run.mjs

View workflow job for this annotation

GitHub Actions / test-linux

--- stderr --- (node:138141) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 uncaughtException listeners added to [process]. Use emitter.setMaxListeners() to increase limit (Use `node --trace-warnings ...` to show where the warning was created) (node:138141) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unhandledRejection listeners added to [process]. Use emitter.setMaxListeners() to increase limit (node:138141) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 beforeExit listeners added to [process]. Use emitter.setMaxListeners() to increase limit --- stdout --- β–Ά require('node:test').run βœ” should run with no tests (1037.069814ms) ::debug::starting to run require('node:test').run ::debug::starting to run should run with no tests ::debug::completed running should run with no tests βœ” should fail with non existing file (1309.026138ms) ::debug::starting to run should fail with non existing file ::debug::completed running should fail with non existing file βœ” should succeed with a file (1283.893742ms) ::debug::starting to run should succeed with a file ::debug::completed running should succeed with a file βœ” should run same file twice (1755.638913ms) βœ” should run a failed test (1293.479004ms) βœ” should support timeout (1426.331023ms) βœ” should be piped with dot (1293.228758ms) β–Ά should be piped with spec reporter βœ” new spec (895.891521ms) βœ” spec() (896.185529ms) βœ” spec (908.807105ms) ::debug::starting to run should run same file twice ::debug::completed running should run same file twice ::debug::starting to run should run a failed test ::debug::completed running should run a failed test ::debug::starting to run should support timeout ::debug::completed running should support timeout ::debug::starting to run should be piped with dot ::debug::completed running should be piped with dot ::debug::starting to run should be piped with spec reporter ::debug::starting to run new spec ::debug::completed running new spec ::debug::starting to run spec() ::debug::completed running spec() ::debug::starting to run spec ::debug::completed running spec β–Ά should be piped with spec reporter (1066.990538ms) βœ” should be piped with tap (1294.950934ms) βœ” should skip tests not matching testNamePatterns - RegExp (1291.302109ms) βœ” should skip tests not matching testNamePatterns - string (1274.970504ms) βœ” should pass only to children (1286.106804ms) βœ” should emit "test:watch:drained" event on watch mode (895.391256ms) β–Ά AbortSignal βœ” should accept a signal (646.054573ms) ::debug::completed running should be piped with spec reporter ::debug::starting to run should be piped with tap ::debug::completed running should be piped with tap ::debug::starting to run should skip tests not matching testNamePatterns - RegExp ::debug::completed running should skip tests not matching testNamePatterns - RegExp ::debug::starting to run should skip tests not matching testNamePatterns - string ::debug::completed running should skip tests not matching testNamePatterns - string ::debug::starting to run should pass only to children ::debug::completed running should pass only to children ::debug::starting to run should emit "test:watch:drained" event on watch mode ::debug::completed running should emit "test:watch:drained" event on watch mode ::debug::starting to run AbortSignal ::debug::starting to run should accept a signal ::debug::completed running should accept a signal ::debug::starting to run should stop watch mode when abortSignal aborts βœ” should stop watch mode when abortSignal aborts (1090.814359ms) βœ” should abort when test succeeded (987.983209ms) βœ” should abort when test failed (995.464844ms) β–Ά AbortSignal (1153.788049ms) ::debug::completed running should stop watch mode when abortSignal aborts ::debug::starting to run should abort when test succeeded ::debug::completed running should abort when test succeeded ::debug::starting to run should abort when test failed ::debug::completed running should abort when test failed ::d

Check failure on line 535 in test/parallel/test-runner-run.mjs

View workflow job for this annotation

GitHub Actions / test-macOS

--- stderr --- (node:41407) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 uncaughtException listeners added to [process]. Use emitter.setMaxListeners() to increase limit (Use `node --trace-warnings ...` to show where the warning was created) (node:41407) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unhandledRejection listeners added to [process]. Use emitter.setMaxListeners() to increase limit (node:41407) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 beforeExit listeners added to [process]. Use emitter.setMaxListeners() to increase limit --- stdout --- β–Ά require('node:test').run βœ” should run with no tests (584.032292ms) ::debug::starting to run require('node:test').run ::debug::starting to run should run with no tests ::debug::completed running should run with no tests βœ” should fail with non existing file (684.209125ms) ::debug::starting to run should fail with non existing file ::debug::completed running should fail with non existing file βœ” should succeed with a file (695.856667ms) ::debug::starting to run should succeed with a file ::debug::completed running should succeed with a file βœ” should run same file twice (876.386458ms) βœ” should run a failed test (683.591083ms) βœ” should support timeout (685.820208ms) βœ” should be piped with dot (705.4885ms) β–Ά should be piped with spec reporter βœ” new spec (697.478459ms) βœ” spec() (697.545875ms) βœ” spec (697.7025ms) ::debug::starting to run should run same file twice ::debug::completed running should run same file twice ::debug::starting to run should run a failed test ::debug::completed running should run a failed test ::debug::starting to run should support timeout ::debug::completed running should support timeout ::debug::starting to run should be piped with dot ::debug::completed running should be piped with dot ::debug::starting to run should be piped with spec reporter ::debug::starting to run new spec ::debug::completed running new spec ::debug::starting to run spec() ::debug::completed running spec() ::debug::starting to run spec ::debug::completed running spec β–Ά should be piped with spec reporter (723.748167ms) βœ” should be piped with tap (740.6435ms) βœ” should skip tests not matching testNamePatterns - RegExp (740.742375ms) βœ” should skip tests not matching testNamePatterns - string (740.931417ms) βœ” should pass only to children (740.879542ms) βœ” should emit "test:watch:drained" event on watch mode (462.682167ms) β–Ά AbortSignal βœ” should accept a signal (543.610292ms) ::debug::completed running should be piped with spec reporter ::debug::starting to run should be piped with tap ::debug::completed running should be piped with tap ::debug::starting to run should skip tests not matching testNamePatterns - RegExp ::debug::completed running should skip tests not matching testNamePatterns - RegExp ::debug::starting to run should skip tests not matching testNamePatterns - string ::debug::completed running should skip tests not matching testNamePatterns - string ::debug::starting to run should pass only to children ::debug::completed running should pass only to children ::debug::starting to run should emit "test:watch:drained" event on watch mode ::debug::completed running should emit "test:watch:drained" event on watch mode ::debug::starting to run AbortSignal ::debug::starting to run should accept a signal ::debug::completed running should accept a signal ::debug::starting to run should stop watch mode when abortSignal aborts βœ” should stop watch mode when abortSignal aborts (699.329959ms) βœ” should abort when test succeeded (699.418334ms) βœ” should abort when test failed (699.593792ms) β–Ά AbortSignal (712.682125ms) ::debug::completed running should stop watch mode when abortSignal aborts ::debug::starting to run should abort when test succeeded ::debug::completed running should abort when test succeeded ::debug::starting to run should abort when test failed ::debug::completed running should abort when test failed ::debug::completed running

Check failure on line 535 in test/parallel/test-runner-run.mjs

View workflow job for this annotation

GitHub Actions / test-asan

--- stderr --- (node:136168) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 uncaughtException listeners added to [process]. Use emitter.setMaxListeners() to increase limit (Use `node --trace-warnings ...` to show where the warning was created) (node:136168) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unhandledRejection listeners added to [process]. Use emitter.setMaxListeners() to increase limit (node:136168) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 beforeExit listeners added to [process]. Use emitter.setMaxListeners() to increase limit --- stdout --- β–Ά require('node:test').run βœ” should run with no tests (2525.478014ms) ::debug::starting to run require('node:test').run ::debug::starting to run should run with no tests ::debug::completed running should run with no tests βœ” should fail with non existing file (3037.998779ms) ::debug::starting to run should fail with non existing file ::debug::completed running should fail with non existing file βœ” should succeed with a file (3032.883763ms) ::debug::starting to run should succeed with a file ::debug::completed running should succeed with a file βœ” should run same file twice (4818.296324ms) βœ” should run a failed test (3109.273575ms) βœ” should support timeout (3337.055921ms) βœ” should be piped with dot (3115.074596ms) β–Ά should be piped with spec reporter βœ” new spec (2552.053635ms) βœ” spec() (2552.908479ms) βœ” spec (2570.772279ms) ::debug::starting to run should run same file twice ::debug::completed running should run same file twice ::debug::starting to run should run a failed test ::debug::completed running should run a failed test ::debug::starting to run should support timeout ::debug::completed running should support timeout ::debug::starting to run should be piped with dot ::debug::completed running should be piped with dot ::debug::starting to run should be piped with spec reporter ::debug::starting to run new spec ::debug::completed running new spec ::debug::starting to run spec() ::debug::completed running spec() ::debug::starting to run spec ::debug::completed running spec β–Ά should be piped with spec reporter (2985.866232ms) βœ” should be piped with tap (3143.667621ms) βœ” should skip tests not matching testNamePatterns - RegExp (3143.341419ms) βœ” should skip tests not matching testNamePatterns - string (3163.279599ms) βœ” should pass only to children (3192.752363ms) βœ” should emit "test:watch:drained" event on watch mode (2312.135988ms) β–Ά AbortSignal βœ” should accept a signal (2054.458214ms) ::debug::completed running should be piped with spec reporter ::debug::starting to run should be piped with tap ::debug::completed running should be piped with tap ::debug::starting to run should skip tests not matching testNamePatterns - RegExp ::debug::completed running should skip tests not matching testNamePatterns - RegExp ::debug::starting to run should skip tests not matching testNamePatterns - string ::debug::completed running should skip tests not matching testNamePatterns - string ::debug::starting to run should pass only to children ::debug::completed running should pass only to children ::debug::starting to run should emit "test:watch:drained" event on watch mode ::debug::completed running should emit "test:watch:drained" event on watch mode ::debug::starting to run AbortSignal ::debug::starting to run should accept a signal ::debug::completed running should accept a signal ::debug::starting to run should stop watch mode when abortSignal aborts βœ” should stop watch mode when abortSignal aborts (2587.568344ms) βœ” should abort when test succeeded (2633.334766ms) βœ” should abort when test failed (2634.255142ms) β–Ά AbortSignal (2825.115256ms) ::debug::completed running should stop watch mode when abortSignal aborts ::debug::starting to run should abort when test succeeded ::debug::completed running should abort when test succeeded ::debug::starting to run should abort when test failed ::debug::completed running should abort when test fai
});
});

describe('forceExit', () => {
Expand Down

0 comments on commit fe3fca7

Please sign in to comment.