[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(runner): show stacktrace on test timeout error (#7799)

authored by

Hiroshi Ogawa and committed by
GitHub
(Apr 9, 2025, 10:55 AM +0200) df33bba7 a7e773bd

+33 -15
+9 -5
packages/runner/src/suite.ts
··· 343 343 }) 344 344 setTestFixture(context, options.fixtures) 345 345 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 + 346 352 if (handler) { 347 353 setFn( 348 354 task, 349 355 withTimeout( 350 356 withAwaitAsyncAssertions(withFixtures(handler, context), task), 351 357 timeout, 358 + false, 359 + stackTraceError, 352 360 ), 353 361 ) 354 362 } 355 363 356 364 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! 362 366 const stack = findTestFileStackTrace(error, task.each ?? false) 363 367 if (stack) { 364 368 task.location = stack
+2
test/config/fixtures/hook-timeout/basic.test.ts
··· 48 48 ctx.onTestFinished(() => new Promise(() => {}), 80) 49 49 }) 50 50 }) 51 + 52 + it("test timeout", () => new Promise(() => {}), 123)
+22 -10
test/config/test/__snapshots__/hook-timeout.test.ts.snap
··· 15 15 5| 16 16 6| it('ok', () => {}) 17 17 18 - ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/9]⎯ 18 + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/10]⎯ 19 19 20 20 FAIL basic.test.ts > afterAll 21 21 Error: Hook timed out in 30ms. ··· 28 28 17| 29 29 18| it('ok', () => {}) 30 30 31 - ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/9]⎯ 31 + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/10]⎯ 32 32 33 33 FAIL basic.test.ts > cleanup-beforeAll 34 34 Error: Hook timed out in 50ms. ··· 41 41 29| 42 42 30| it('ok', () => {}) 43 43 44 - ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/9]⎯ 44 + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/10]⎯ 45 45 46 46 47 - ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 5 ⎯⎯⎯⎯⎯⎯⎯ 47 + ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 6 ⎯⎯⎯⎯⎯⎯⎯ 48 48 49 49 FAIL basic.test.ts > beforeEach > ok 50 50 Error: Hook timed out in 20ms. ··· 57 57 11| 58 58 12| it('ok', () => {}) 59 59 60 - ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[4/9]⎯ 60 + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[4/10]⎯ 61 61 62 62 FAIL basic.test.ts > afterEach > ok 63 63 Error: Hook timed out in 40ms. ··· 70 70 23| 71 71 24| it('ok', () => {}) 72 72 73 - ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[5/9]⎯ 73 + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[5/10]⎯ 74 74 75 75 FAIL basic.test.ts > cleanup-beforeEach > ok 76 76 Error: Hook timed out in 60ms. ··· 83 83 35| 84 84 36| it('ok', () => {}) 85 85 86 - ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[6/9]⎯ 86 + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[6/10]⎯ 87 87 88 88 FAIL basic.test.ts > onFailed > fail 89 89 Error: fail ··· 95 95 43| }) 96 96 44| }) 97 97 98 - ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[7/9]⎯ 98 + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[7/10]⎯ 99 99 100 100 FAIL basic.test.ts > onFailed > fail 101 101 Error: Hook timed out in 70ms. ··· 108 108 42| throw new Error('fail') 109 109 43| }) 110 110 111 - ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[8/9]⎯ 111 + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[8/10]⎯ 112 112 113 113 FAIL basic.test.ts > onFinished > ok 114 114 Error: Hook timed out in 80ms. ··· 121 121 49| }) 122 122 50| }) 123 123 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]⎯ 125 137 126 138 " 127 139 `;