| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent be2feec commit a2881b7
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,9 +13,10 @@ const { | |||
| 13 | 13 | ERR_TEST_FAILURE, | |
| 14 | 14 | }, | |
| 15 | 15 | } = require('internal/errors'); | |
| 16 | + const { getOptionValue } = require('internal/options'); | ||
| 16 | 17 | const { Test, ItTest, Suite } = require('internal/test_runner/test'); | |
| 17 | 18 | ||
| 18 | - | ||
| 19 | + const isTestRunner = getOptionValue('--test'); | ||
| 19 | 20 | const testResources = new SafeMap(); | |
| 20 | 21 | const root = new Test({ __proto__: null, name: '<root>' }); | |
| 21 | 22 | let wasRootSetup = false; | |
@@ -134,8 +135,11 @@ function setup(root) { | |||
| 134 | 135 | process.on('uncaughtException', exceptionHandler); | |
| 135 | 136 | process.on('unhandledRejection', rejectionHandler); | |
| 136 | 137 | process.on('beforeExit', exitHandler); | |
| 137 | - process.on('SIGINT', terminationHandler); | ||
| 138 | - process.on('SIGTERM', terminationHandler); | ||
| 138 | + // TODO(MoLow): Make it configurable to hook when isTestRunner === false. | ||
| 139 | + if (isTestRunner) { | ||
| 140 | + process.on('SIGINT', terminationHandler); | ||
| 141 | + process.on('SIGTERM', terminationHandler); | ||
| 142 | + } | ||
| 139 | 143 | ||
| 140 | 144 | root.reporter.pipe(process.stdout); | |
| 141 | 145 | root.reporter.version(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + const test = require('node:test'); | ||
| 2 | + const { setTimeout } = require('timers/promises'); | ||
| 3 | + | ||
| 4 | + // We are using a very large timeout value to ensure that the parent process | ||
| 5 | + // will have time to send a SIGINT signal to cancel the test. | ||
| 6 | + test('never ending test', () => setTimeout(100_000_000)); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + const test = require('node:test'); | ||
| 2 | + | ||
| 3 | + test('never ending test', () => { | ||
| 4 | + while (true); | ||
| 5 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,8 +2,29 @@ | |||
| 2 | 2 | const common = require('../common'); | |
| 3 | 3 | const fixtures = require('../common/fixtures'); | |
| 4 | 4 | const assert = require('assert'); | |
| 5 | - const { spawnSync } = require('child_process'); | ||
| 6 | - const { setTimeout } = require('timers/promises'); | ||
| 5 | + const { spawnSync, spawn } = require('child_process'); | ||
| 6 | + const { once } = require('events'); | ||
| 7 | + const { finished } = require('stream/promises'); | ||
| 8 | + | ||
| 9 | + async function runAndKill(file) { | ||
| 10 | + if (common.isWindows) { | ||
| 11 | + common.printSkipMessage(`signals are not supported in windows, skipping ${file}`); | ||
| 12 | + return; | ||
| 13 | + } | ||
| 14 | + let stdout = ''; | ||
| 15 | + const child = spawn(process.execPath, ['--test', file]); | ||
| 16 | + child.stdout.setEncoding('utf8'); | ||
| 17 | + child.stdout.on('data', (chunk) => { | ||
| 18 | + if (!stdout.length) child.kill('SIGINT'); | ||
| 19 | + stdout += chunk; | ||
| 20 | + }); | ||
| 21 | + const [code, signal] = await once(child, 'exit'); | ||
| 22 | + await finished(child.stdout); | ||
| 23 | + assert.match(stdout, /not ok 1/); | ||
| 24 | + assert.match(stdout, /# cancelled 1\n/); | ||
| 25 | + assert.strictEqual(signal, null); | ||
| 26 | + assert.strictEqual(code, 1); | ||
| 27 | + } | ||
| 7 | 28 | ||
| 8 | 29 | if (process.argv[2] === 'child') { | |
| 9 | 30 | const test = require('node:test'); | |
@@ -17,12 +38,6 @@ if (process.argv[2] === 'child') { | |||
| 17 | 38 | test('failing test', () => { | |
| 18 | 39 | assert.strictEqual(true, false); | |
| 19 | 40 | }); | |
| 20 | - } else if (process.argv[3] === 'never_ends') { | ||
| 21 | - assert.strictEqual(process.argv[3], 'never_ends'); | ||
| 22 | - test('never ending test', () => { | ||
| 23 | - return setTimeout(100_000_000); | ||
| 24 | - }); | ||
| 25 | - process.kill(process.pid, 'SIGINT'); | ||
| 26 | 41 | } else assert.fail('unreachable'); | |
| 27 | 42 | } else { | |
| 28 | 43 | let child = spawnSync(process.execPath, [__filename, 'child', 'pass']); | |
@@ -37,14 +52,6 @@ if (process.argv[2] === 'child') { | |||
| 37 | 52 | assert.strictEqual(child.status, 1); | |
| 38 | 53 | assert.strictEqual(child.signal, null); | |
| 39 | 54 | ||
| 40 | - child = spawnSync(process.execPath, [__filename, 'child', 'never_ends']); | ||
| 41 | - assert.strictEqual(child.status, 1); | ||
| 42 | - assert.strictEqual(child.signal, null); | ||
| 43 | - if (common.isWindows) { | ||
| 44 | - common.printSkipMessage('signals are not supported in windows'); | ||
| 45 | - } else { | ||
| 46 | - const stdout = child.stdout.toString(); | ||
| 47 | - assert.match(stdout, /not ok 1 - never ending test/); | ||
| 48 | - assert.match(stdout, /# cancelled 1/); | ||
| 49 | - } | ||
| 55 | + runAndKill(fixtures.path('test-runner', 'never_ending_sync.js')).then(common.mustCall()); | ||
| 56 | + runAndKill(fixtures.path('test-runner', 'never_ending_async.js')).then(common.mustCall()); | ||
| 50 | 57 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments