forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-timeout-flag.js
More file actions
58 lines (48 loc) · 1.37 KB
/
test-timeout-flag.js
File metadata and controls
58 lines (48 loc) · 1.37 KB
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
48
49
50
51
52
53
54
55
56
57
58
'use strict';
const { describe, it, after } = require('node:test');
const { setTimeout } = require('node:timers');
describe('--test-timeout is set to 100ms', () => {
const timeoutRefs = [];
it('should timeout after 100ms', async () => {
const { promise, resolve } = Promise.withResolvers();
timeoutRefs.push(setTimeout(() => {
resolve();
}, 20000));
await promise;
});
it('should timeout after 5ms', { timeout: 5 }, async () => {
const { promise, resolve } = Promise.withResolvers();
timeoutRefs.push(setTimeout(() => {
resolve();
}, 20000));
await promise;
});
it('should not timeout', { timeout: 50000 }, async () => {
const { promise, resolve } = Promise.withResolvers();
timeoutRefs.push(setTimeout(() => {
resolve();
}, 1));
await promise;
});
it('should pass', async () => {});
after(() => {
for (const timeoutRef of timeoutRefs) {
clearTimeout(timeoutRef);
}
});
});
describe('should inherit timeout options to children', { timeout: 1 }, () => {
const timeoutRefs = [];
after(() => {
for (const timeoutRef of timeoutRefs) {
clearTimeout(timeoutRef);
}
});
it('should timeout after 1ms', async () => {
const { promise, resolve } = Promise.withResolvers();
timeoutRefs.push(setTimeout(() => {
resolve();
}, 20000));
await promise;
});
});