-
Notifications
You must be signed in to change notification settings - Fork 31k
/
Copy pathtest-runner-misc.js
33 lines (30 loc) · 1.04 KB
/
test-runner-misc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
const common = require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
const { setTimeout } = require('timers/promises');
if (process.argv[2] === 'child') {
const test = require('node:test');
if (process.argv[3] === 'abortSignal') {
assert.throws(() => test({ signal: {} }), {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
});
let testSignal;
test({ timeout: 10 }, common.mustCall(async ({ signal }) => {
assert.strictEqual(signal.aborted, false);
testSignal = signal;
await setTimeout(50);
})).then(() => {
test(() => assert.strictEqual(testSignal.aborted, true));
});
} else assert.fail('unreachable');
} else {
const child = spawnSync(process.execPath, [__filename, 'child', 'abortSignal']);
const stdout = child.stdout.toString();
assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.match(stdout, /# pass 1/);
assert.match(stdout, /# fail 0/);
assert.match(stdout, /# cancelled 1/);
}