From ece842f4565e008f481f6bab11b944d38848299d Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Sat, 5 Apr 2025 16:13:22 +0900 Subject: [PATCH 1/2] fix(runner): provide stacktrace for test timeout error --- packages/runner/src/suite.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/runner/src/suite.ts b/packages/runner/src/suite.ts index 2b53016623f0..ef4117199a64 100644 --- a/packages/runner/src/suite.ts +++ b/packages/runner/src/suite.ts @@ -342,22 +342,26 @@ function createSuiteCollector( }) setTestFixture(context, options.fixtures) + // custom can be called from any place, let's assume the limit is 15 stacks + const limit = Error.stackTraceLimit + Error.stackTraceLimit = 15 + const stackTraceError = new Error('STACK_TRACE_ERROR') + Error.stackTraceLimit = limit + if (handler) { setFn( task, withTimeout( withAwaitAsyncAssertions(withFixtures(handler, context), task), timeout, + false, + stackTraceError, ), ) } if (runner.config.includeTaskLocation) { - const limit = Error.stackTraceLimit - // custom can be called from any place, let's assume the limit is 15 stacks - Error.stackTraceLimit = 15 - const error = new Error('stacktrace').stack! - Error.stackTraceLimit = limit + const error = stackTraceError.stack! const stack = findTestFileStackTrace(error, task.each ?? false) if (stack) { task.location = stack From 4dfa16767ca57d1012e4e499fa6a1871fbbd9e84 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Sat, 5 Apr 2025 16:25:01 +0900 Subject: [PATCH 2/2] test: add test --- .../fixtures/hook-timeout/basic.test.ts | 2 ++ .../__snapshots__/hook-timeout.test.ts.snap | 32 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/test/config/fixtures/hook-timeout/basic.test.ts b/test/config/fixtures/hook-timeout/basic.test.ts index 0278a6f578e4..a3a381071f52 100644 --- a/test/config/fixtures/hook-timeout/basic.test.ts +++ b/test/config/fixtures/hook-timeout/basic.test.ts @@ -48,3 +48,5 @@ describe('onFinished', () => { ctx.onTestFinished(() => new Promise(() => {}), 80) }) }) + +it("test timeout", () => new Promise(() => {}), 123) diff --git a/test/config/test/__snapshots__/hook-timeout.test.ts.snap b/test/config/test/__snapshots__/hook-timeout.test.ts.snap index 29b6fffe2533..1d86134a1b58 100644 --- a/test/config/test/__snapshots__/hook-timeout.test.ts.snap +++ b/test/config/test/__snapshots__/hook-timeout.test.ts.snap @@ -15,7 +15,7 @@ If this is a long-running hook, pass a timeout value as the last argument or con 5| 6| it('ok', () => {}) -⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/9]⎯ +⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/10]⎯ FAIL basic.test.ts > afterAll 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 17| 18| it('ok', () => {}) -⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/9]⎯ +⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/10]⎯ FAIL basic.test.ts > cleanup-beforeAll 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 29| 30| it('ok', () => {}) -⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/9]⎯ +⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/10]⎯ -⎯⎯⎯⎯⎯⎯⎯ Failed Tests 5 ⎯⎯⎯⎯⎯⎯⎯ +⎯⎯⎯⎯⎯⎯⎯ Failed Tests 6 ⎯⎯⎯⎯⎯⎯⎯ FAIL basic.test.ts > beforeEach > ok 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 11| 12| it('ok', () => {}) -⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[4/9]⎯ +⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[4/10]⎯ FAIL basic.test.ts > afterEach > ok 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 23| 24| it('ok', () => {}) -⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[5/9]⎯ +⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[5/10]⎯ FAIL basic.test.ts > cleanup-beforeEach > ok 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 35| 36| it('ok', () => {}) -⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[6/9]⎯ +⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[6/10]⎯ FAIL basic.test.ts > onFailed > fail Error: fail @@ -95,7 +95,7 @@ Error: fail 43| }) 44| }) -⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[7/9]⎯ +⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[7/10]⎯ FAIL basic.test.ts > onFailed > fail 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 42| throw new Error('fail') 43| }) -⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[8/9]⎯ +⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[8/10]⎯ FAIL basic.test.ts > onFinished > ok 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 49| }) 50| }) -⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[9/9]⎯ +⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[9/10]⎯ + + FAIL basic.test.ts > test timeout +Error: Test timed out in 123ms. +If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout". + ❯ basic.test.ts:52:1 + 50| }) + 51| + 52| it("test timeout", () => new Promise(() => {}), 123) + | ^ + 53| + +⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[10/10]⎯ " `;