Skip to content

Commit 6dbf708

Browse files
authored
test_runner: fix suite timeout
PR-URL: #59853 Reviewed-By: Chemi Atlow <[email protected]>
1 parent 535efea commit 6dbf708

File tree

4 files changed

+57
-15
lines changed

4 files changed

+57
-15
lines changed

lib/internal/test_runner/test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,9 @@ class Suite extends Test {
14551455
reportedType = 'suite';
14561456
constructor(options) {
14571457
super(options);
1458-
this.timeout = null;
1458+
if (options.timeout == null) {
1459+
this.timeout = null;
1460+
}
14591461

14601462
if (this.config.testNamePatterns !== null &&
14611463
this.config.testSkipPatterns !== null &&

test/fixtures/test-runner/output/test-timeout-flag.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
const { describe, it, after } = require('node:test');
33
const { setTimeout } = require('node:timers');
44

5-
const timeoutRefs = [];
5+
describe('--test-timeout is set to 100ms', () => {
6+
const timeoutRefs = [];
67

7-
describe('--test-timeout is set to 20ms', () => {
8-
it('should timeout after 20ms', async () => {
8+
it('should timeout after 100ms', async () => {
99
const { promise, resolve } = Promise.withResolvers();
1010
timeoutRefs.push(setTimeout(() => {
1111
resolve();
@@ -37,3 +37,22 @@ describe('--test-timeout is set to 20ms', () => {
3737
}
3838
});
3939
});
40+
41+
42+
describe('should inherit timeout options to children', { timeout: 1 }, () => {
43+
const timeoutRefs = [];
44+
45+
after(() => {
46+
for (const timeoutRef of timeoutRefs) {
47+
clearTimeout(timeoutRef);
48+
}
49+
});
50+
51+
it('should timeout after 1ms', async () => {
52+
const { promise, resolve } = Promise.withResolvers();
53+
timeoutRefs.push(setTimeout(() => {
54+
resolve();
55+
}, 20000));
56+
await promise;
57+
});
58+
});

test/fixtures/test-runner/output/test-timeout-flag.snapshot

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
TAP version 13
2-
# Subtest: --test-timeout is set to 20ms
3-
# Subtest: should timeout after 20ms
4-
not ok 1 - should timeout after 20ms
2+
# Subtest: --test-timeout is set to 100ms
3+
# Subtest: should timeout after 100ms
4+
not ok 1 - should timeout after 100ms
55
---
66
duration_ms: *
77
type: 'test'
88
location: '/test/fixtures/test-runner/output/test-timeout-flag.js:(LINE):3'
99
failureType: 'testTimeoutFailure'
10-
error: 'test timed out after 20ms'
10+
error: 'test timed out after 100ms'
1111
code: 'ERR_TEST_FAILURE'
1212
stack: |-
1313
async Promise.all (index 0)
@@ -35,7 +35,7 @@ TAP version 13
3535
type: 'test'
3636
...
3737
1..4
38-
not ok 1 - --test-timeout is set to 20ms
38+
not ok 1 - --test-timeout is set to 100ms
3939
---
4040
duration_ms: *
4141
type: 'suite'
@@ -44,12 +44,33 @@ not ok 1 - --test-timeout is set to 20ms
4444
error: '2 subtests failed'
4545
code: 'ERR_TEST_FAILURE'
4646
...
47-
1..1
48-
# tests 4
49-
# suites 1
47+
# Subtest: should inherit timeout options to children
48+
# Subtest: should timeout after 1ms
49+
not ok 1 - should timeout after 1ms
50+
---
51+
duration_ms: *
52+
type: 'test'
53+
location: '/test/fixtures/test-runner/output/test-timeout-flag.js:(LINE):3'
54+
failureType: 'cancelledByParent'
55+
error: 'test did not finish before its parent and was cancelled'
56+
code: 'ERR_TEST_FAILURE'
57+
...
58+
1..1
59+
not ok 2 - should inherit timeout options to children
60+
---
61+
duration_ms: *
62+
type: 'suite'
63+
location: '/test/fixtures/test-runner/output/test-timeout-flag.js:(LINE):1'
64+
failureType: 'testTimeoutFailure'
65+
error: 'test timed out after 1ms'
66+
code: 'ERR_TEST_FAILURE'
67+
...
68+
1..2
69+
# tests 5
70+
# suites 2
5071
# pass 2
5172
# fail 0
52-
# cancelled 2
73+
# cancelled 3
5374
# skipped 0
5475
# todo 0
5576
# duration_ms *

test/parallel/test-runner-output.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ const tests = [
137137
name: 'test-runner/output/test-timeout-flag.js',
138138
flags: [
139139
'--test-reporter=tap',
140-
'--test-timeout=20',
140+
'--test-timeout=100',
141141
],
142142
},
143143
// --test-timeout should work with or without --test flag
144144
{
145145
name: 'test-runner/output/test-timeout-flag.js',
146146
flags: [
147147
'--test-reporter=tap',
148-
'--test-timeout=20',
148+
'--test-timeout=100',
149149
'--test',
150150
],
151151
},

0 commit comments

Comments
 (0)