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