-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Clear and concise description of the problem
Currently when the hook times out, Vitest only shows the fact that the run failed with Hook time out.
FAIL test/basic.test.ts [ test/basic.test.ts ]
Error: Hook timed out in 1000ms.
If this is a long-running hook, pass a timeout value as the last argument or configure it globally with "hookTimeout".
Example fail: https://stackblitz.com/edit/vitest-dev-vitest-qgnj5ff5?file=test%2Fbasic.test.ts&initialPath=__vitest__/
With this error, it is difficult to know which hook timed out.
Suggested solution
Improve the error message to show the place where the hook exists like when the test failed.
FAIL test/basic.test.ts
Error: Hook timed out in 1000ms.
If this is a long-running hook, pass a timeout value as the last argument or configure it globally with "hookTimeout".
❯ test/basic.test.ts:10:1
9|
10| beforeAll(() => {
| ^
11| return new Promise((resolve) => {});
12| });
13|
I guess this is possible by adding new Error().stack / Error.captureStackTrace() here and passing that information to withTimeout.
vitest/packages/runner/src/hooks.ts
Line 39 in 926ca95
| assertTypes(fn, '"beforeAll" callback', ['function']) |
Although, creating stacktrace for every hook might affect performance.
Alternative
Show the function name passed to the hook in the error message.
beforeAll(function myHook () {
return new Promise((resolve) => {});
})For the code above, the error message will be:
FAIL test/basic.test.ts [ test/basic.test.ts ]
Error: Hook "myHook" timed out in 1000ms.
If this is a long-running hook, pass a timeout value as the last argument or configure it globally with "hookTimeout".
This is possible by passing fn.name to makeTimeoutMsg here.
vitest/packages/runner/src/context.ts
Line 50 in 926ca95
| reject(new Error(makeTimeoutMsg(isHook, timeout))) |
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status