Skip to content

Commit df33bba

Browse files
authored
fix(runner): show stacktrace on test timeout error (#7799)
1 parent a7e773b commit df33bba

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

packages/runner/src/suite.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,22 +343,26 @@ function createSuiteCollector(
343343
})
344344
setTestFixture(context, options.fixtures)
345345

346+
// custom can be called from any place, let's assume the limit is 15 stacks
347+
const limit = Error.stackTraceLimit
348+
Error.stackTraceLimit = 15
349+
const stackTraceError = new Error('STACK_TRACE_ERROR')
350+
Error.stackTraceLimit = limit
351+
346352
if (handler) {
347353
setFn(
348354
task,
349355
withTimeout(
350356
withAwaitAsyncAssertions(withFixtures(handler, context), task),
351357
timeout,
358+
false,
359+
stackTraceError,
352360
),
353361
)
354362
}
355363

356364
if (runner.config.includeTaskLocation) {
357-
const limit = Error.stackTraceLimit
358-
// custom can be called from any place, let's assume the limit is 15 stacks
359-
Error.stackTraceLimit = 15
360-
const error = new Error('stacktrace').stack!
361-
Error.stackTraceLimit = limit
365+
const error = stackTraceError.stack!
362366
const stack = findTestFileStackTrace(error, task.each ?? false)
363367
if (stack) {
364368
task.location = stack

test/config/fixtures/hook-timeout/basic.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ describe('onFinished', () => {
4848
ctx.onTestFinished(() => new Promise(() => {}), 80)
4949
})
5050
})
51+
52+
it("test timeout", () => new Promise(() => {}), 123)

test/config/test/__snapshots__/hook-timeout.test.ts.snap

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If this is a long-running hook, pass a timeout value as the last argument or con
1515
5|
1616
6| it('ok', () => {})
1717
18-
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/9]⎯
18+
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/10]⎯
1919
2020
FAIL basic.test.ts > afterAll
2121
Error: Hook timed out in 30ms.
@@ -28,7 +28,7 @@ If this is a long-running hook, pass a timeout value as the last argument or con
2828
17|
2929
18| it('ok', () => {})
3030
31-
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/9]⎯
31+
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/10]⎯
3232
3333
FAIL basic.test.ts > cleanup-beforeAll
3434
Error: Hook timed out in 50ms.
@@ -41,10 +41,10 @@ If this is a long-running hook, pass a timeout value as the last argument or con
4141
29|
4242
30| it('ok', () => {})
4343
44-
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/9]⎯
44+
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/10]⎯
4545
4646
47-
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 5 ⎯⎯⎯⎯⎯⎯⎯
47+
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 6 ⎯⎯⎯⎯⎯⎯⎯
4848
4949
FAIL basic.test.ts > beforeEach > ok
5050
Error: Hook timed out in 20ms.
@@ -57,7 +57,7 @@ If this is a long-running hook, pass a timeout value as the last argument or con
5757
11|
5858
12| it('ok', () => {})
5959
60-
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[4/9]⎯
60+
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[4/10]⎯
6161
6262
FAIL basic.test.ts > afterEach > ok
6363
Error: Hook timed out in 40ms.
@@ -70,7 +70,7 @@ If this is a long-running hook, pass a timeout value as the last argument or con
7070
23|
7171
24| it('ok', () => {})
7272
73-
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[5/9]⎯
73+
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[5/10]⎯
7474
7575
FAIL basic.test.ts > cleanup-beforeEach > ok
7676
Error: Hook timed out in 60ms.
@@ -83,7 +83,7 @@ If this is a long-running hook, pass a timeout value as the last argument or con
8383
35|
8484
36| it('ok', () => {})
8585
86-
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[6/9]⎯
86+
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[6/10]⎯
8787
8888
FAIL basic.test.ts > onFailed > fail
8989
Error: fail
@@ -95,7 +95,7 @@ Error: fail
9595
43| })
9696
44| })
9797
98-
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[7/9]⎯
98+
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[7/10]⎯
9999
100100
FAIL basic.test.ts > onFailed > fail
101101
Error: Hook timed out in 70ms.
@@ -108,7 +108,7 @@ If this is a long-running hook, pass a timeout value as the last argument or con
108108
42| throw new Error('fail')
109109
43| })
110110
111-
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[8/9]⎯
111+
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[8/10]⎯
112112
113113
FAIL basic.test.ts > onFinished > ok
114114
Error: Hook timed out in 80ms.
@@ -121,7 +121,19 @@ If this is a long-running hook, pass a timeout value as the last argument or con
121121
49| })
122122
50| })
123123
124-
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[9/9]⎯
124+
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[9/10]⎯
125+
126+
FAIL basic.test.ts > test timeout
127+
Error: Test timed out in 123ms.
128+
If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".
129+
basic.test.ts:52:1
130+
50| })
131+
51|
132+
52| it("test timeout", () => new Promise(() => {}), 123)
133+
| ^
134+
53|
135+
136+
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[10/10]⎯
125137
126138
"
127139
`;

0 commit comments

Comments
 (0)