Vitest "Test timed out in 5000ms" (testTimeout) in CI
Vitest fails a test that does not finish within testTimeout (5000ms by default). In CI, slower runners or a promise that never resolves push tests over the limit. Raise the timeout for genuinely slow work, or fix the unresolved async.
What this error means
A test fails with "Test timed out in 5000ms. If this is a long-running test, pass a timeout value as the last argument." more often on CI than locally.
Error: Test timed out in 5000ms.
If this is a long-running test, pass a timeout value as the last argument.
❯ src/fetch.test.ts:14:3Common causes
A promise that never resolves
An awaited call hangs (an unmocked network request, an unfired fake timer), so the test cannot complete before the timeout.
A genuinely slow test on a slower runner
CI runners can be slower than a dev machine, so a borderline test that just fit locally exceeds the default limit.
How to fix it
Fix the hang or raise the timeout
- Confirm every awaited promise resolves (mock network, advance fake timers).
- For legitimately slow tests, raise
testTimeoutglobally or per test. - Re-run to confirm the test completes.
export default defineConfig({
test: { testTimeout: 15000 },
})Set a per-test timeout
Give one slow test more time without loosening the global default.
it('imports a large dataset', async () => {
// ...
}, 20000)How to prevent it
- Mock external I/O so tests do not wait on the network.
- Advance fake timers instead of awaiting real delays.
- Set a realistic
testTimeoutfor the slowest legitimate tests.