• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --no-warnings
2'use strict';
3require('../../../common');
4const test = require('node:test');
5
6test('promise timeout signal', { signal: AbortSignal.timeout(1) }, async (t) => {
7  await Promise.all([
8    t.test('ok 1', async () => {}),
9    t.test('ok 2', () => {}),
10    t.test('ok 3', { signal: t.signal }, async () => {}),
11    t.test('ok 4', { signal: t.signal }, () => {}),
12    t.test('not ok 1', () => new Promise(() => {})),
13    t.test('not ok 2', (t, done) => {}),
14    t.test('not ok 3', { signal: t.signal }, () => new Promise(() => {})),
15    t.test('not ok 4', { signal: t.signal }, (t, done) => {}),
16    t.test('not ok 5', { signal: t.signal }, (t, done) => {
17      t.signal.addEventListener('abort', done);
18    }),
19  ]);
20});
21
22test('promise abort signal', { signal: AbortSignal.abort() }, async (t) => {
23  await t.test('should not appear', () => {});
24});
25
26test('callback timeout signal', { signal: AbortSignal.timeout(1) }, (t, done) => {
27  t.test('ok 1', async () => {});
28  t.test('ok 2', () => {});
29  t.test('ok 3', { signal: t.signal }, async () => {});
30  t.test('ok 4', { signal: t.signal }, () => {});
31  t.test('not ok 1', () => new Promise(() => {}));
32  t.test('not ok 2', (t, done) => {});
33  t.test('not ok 3', { signal: t.signal }, () => new Promise(() => {}));
34  t.test('not ok 4', { signal: t.signal }, (t, done) => {});
35  t.test('not ok 5', { signal: t.signal }, (t, done) => {
36    t.signal.addEventListener('abort', done);
37  });
38});
39
40test('callback abort signal', { signal: AbortSignal.abort() }, (t, done) => {
41  t.test('should not appear', done);
42});
43
44// AbortSignal.timeout(1) doesn't prevent process from closing
45// thus we have to keep the process open to prevent cancelation
46// of the entire test tree
47setTimeout(() => {}, 1000);
48