Vitest testTimeout: uniform behavior across sync and async tests
0 reputation · 23 Dec 2021, 19:23 UTC
Goal
Determine whether Vitest’s testTimeout setting applies consistently to both synchronous and asynchronous tests, and how a timeout influences pending microtasks and cleanup.
Uncertainty
The documentation specifies a global testTimeout and per‑test test.timeout overrides, but it does not state if the timeout is enforced for tests that finish synchronously. Additionally, when a timeout occurs, it is unclear whether Vitest forcefully aborts the test’s async callbacks or simply marks the test as failed, which affects whether queued microtasks are still processed.
Questions
- Does
testTimeouttrigger a timeout error for a test that completes synchronously but exceeds the specified duration? - When a timeout is reached, does Vitest cancel pending asynchronous callbacks immediately, or does it allow queued microtasks to run before marking the test as failed?
- What cleanup or teardown behavior occurs if a test is aborted due to a timeout—are
afterEachhooks still executed?