| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f1f32d8 commit 433bd1b
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -519,6 +519,8 @@ function run(options = kEmptyObject) { | |||
| 519 | 519 | root.harness.shouldColorizeTestFiles ||= shouldColorizeTestFiles(root); | |
| 520 | 520 | ||
| 521 | 521 | if (process.env.NODE_TEST_CONTEXT !== undefined) { | |
| 522 | + process.emitWarning('node:test run() is being called recursively within a test file. skipping running files.'); | ||
| 523 | + root.postRun(); | ||
| 522 | 524 | return root.reporter; | |
| 523 | 525 | } | |
| 524 | 526 | let testFiles = files ?? createTestFileList(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,7 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const { test, run } = require('node:test'); | ||
| 4 | + | ||
| 5 | + test('recursive run() calls', async () => { | ||
| 6 | + for await (const event of run({ files: [__filename] })); | ||
| 7 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -522,6 +522,18 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { | |||
| 522 | 522 | // eslint-disable-next-line no-unused-vars | |
| 523 | 523 | for await (const _ of stream); | |
| 524 | 524 | }); | |
| 525 | + | ||
| 526 | + it('should avoid running recursively', async () => { | ||
| 527 | + const stream = run({ files: [join(testFixtures, 'recursive_run.js')] }); | ||
| 528 | + let stderr = ''; | ||
| 529 | + stream.on('test:fail', common.mustNotCall()); | ||
| 530 | + stream.on('test:pass', common.mustCall(1)); | ||
| 531 | + stream.on('test:stderr', (c) => { stderr += c.message; }); | ||
| 532 | + | ||
| 533 | + // eslint-disable-next-line no-unused-vars | ||
| 534 | + for await (const _ of stream); | ||
| 535 | + assert.match(stderr, /Warning: node:test run\(\) is being called recursively/); | ||
| 536 | + }); | ||
| 525 | 537 | }); | |
| 526 | 538 | ||
| 527 | 539 | describe('forceExit', () => { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments