-
Notifications
You must be signed in to change notification settings - Fork 30.3k
/
Copy pathtest_runner_abort.js
47 lines (42 loc) · 1.71 KB
/
test_runner_abort.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Flags: --no-warnings
'use strict';
require('../common');
const test = require('node:test');
test('promise timeout signal', { signal: AbortSignal.timeout(1) }, async (t) => {
await Promise.all([
t.test('ok 1', async () => {}),
t.test('ok 2', () => {}),
t.test('ok 3', { signal: t.signal }, async () => {}),
t.test('ok 4', { signal: t.signal }, () => {}),
t.test('not ok 1', () => new Promise(() => {})),
t.test('not ok 2', (t, done) => {}),
t.test('not ok 3', { signal: t.signal }, () => new Promise(() => {})),
t.test('not ok 4', { signal: t.signal }, (t, done) => {}),
t.test('not ok 5', { signal: t.signal }, (t, done) => {
t.signal.addEventListener('abort', done);
}),
]);
});
test('promise abort signal', { signal: AbortSignal.abort() }, async (t) => {
await t.test('should not appear', () => {});
});
test('callback timeout signal', { signal: AbortSignal.timeout(1) }, (t, done) => {
t.test('ok 1', async () => {});
t.test('ok 2', () => {});
t.test('ok 3', { signal: t.signal }, async () => {});
t.test('ok 4', { signal: t.signal }, () => {});
t.test('not ok 1', () => new Promise(() => {}));
t.test('not ok 2', (t, done) => {});
t.test('not ok 3', { signal: t.signal }, () => new Promise(() => {}));
t.test('not ok 4', { signal: t.signal }, (t, done) => {});
t.test('not ok 5', { signal: t.signal }, (t, done) => {
t.signal.addEventListener('abort', done);
});
});
test('callback abort signal', { signal: AbortSignal.abort() }, (t, done) => {
t.test('should not appear', done);
});
// AbortSignal.timeout(1) doesn't prevent process from closing
// thus we have to keep the process open to prevent cancelation
// of the entire test tree
setTimeout(() => {}, 1000);