Skip to content

Commit d457e85

Browse files
committed
test-runner: fix suite timeout
1 parent f1b56d6 commit d457e85

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,14 @@ describe('--test-timeout is set to 20ms', () => {
3737
}
3838
});
3939
});
40+
41+
42+
describe('should inherit timeout options to children', { timeout: 5 }, () => {
43+
it('should timeout after 5ms', async () => {
44+
const { promise, resolve } = Promise.withResolvers();
45+
timeoutRefs.push(setTimeout(() => {
46+
resolve();
47+
}, 20000));
48+
await promise;
49+
});
50+
});

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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 5ms
49+
not ok 1 - should timeout after 5ms
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 5ms'
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 *

0 commit comments

Comments
 (0)