|
| 1 | +// https://github.com/nodejs/node/blob/2e682f10b6104373fded64b0e364984b85ae2243/test/parallel/test-runner-misc.js |
| 2 | + |
| 3 | +'use strict' |
| 4 | +const common = require('../common') |
| 5 | +const assert = require('assert') |
| 6 | +const { spawnSync } = require('child_process') |
| 7 | +const { setTimeout } = require('timers/promises') |
| 8 | + |
| 9 | +if (process.argv[2] === 'child') { |
| 10 | + const test = require('node:test') |
| 11 | + |
| 12 | + if (process.argv[3] === 'abortSignal') { |
| 13 | + assert.throws(() => test({ signal: {} }), { |
| 14 | + code: 'ERR_INVALID_ARG_TYPE', |
| 15 | + name: 'TypeError' |
| 16 | + }) |
| 17 | + |
| 18 | + let testSignal |
| 19 | + test({ timeout: 10 }, common.mustCall(async ({ signal }) => { |
| 20 | + assert.strictEqual(signal.aborted, false) |
| 21 | + testSignal = signal |
| 22 | + await setTimeout(50) |
| 23 | + })).finally(common.mustCall(() => { |
| 24 | + test(() => assert.strictEqual(testSignal.aborted, true)) |
| 25 | + })) |
| 26 | + } else assert.fail('unreachable') |
| 27 | +} else { |
| 28 | + const child = spawnSync(process.execPath, [__filename, 'child', 'abortSignal']) |
| 29 | + const stdout = child.stdout.toString() |
| 30 | + assert.match(stdout, /^# pass 1$/m) |
| 31 | + assert.match(stdout, /^# fail 0$/m) |
| 32 | + assert.match(stdout, /^# cancelled 1$/m) |
| 33 | + assert.strictEqual(child.status, 1) |
| 34 | + assert.strictEqual(child.signal, null) |
| 35 | +} |
0 commit comments