Vitest "Test timed out in 5000ms" in CI
The test ran longer than Vitest's default 5000 ms test timeout and was failed. The usual cause is an awaited promise that never settles, or fake timers that were never advanced.
What this error means
A test fails with "Error: Test timed out in 5000ms. If this is a long-running test, pass a timeout value as the last argument." It is often more frequent in CI, where the runner is slower.
❯ src/api.test.ts > loads data
Error: Test timed out in 5000ms.
If this is a long-running test, pass a timeout value as the last argument or
configure it globally with "testTimeout".Common causes
An awaited promise never resolves
A network call, unmocked dependency, or blocked resource hangs in CI so the test never completes within the timeout.
Fake timers without advancing them
The test enables fake timers but never calls vi.advanceTimersByTime, so a pending timer never fires and the awaited work stalls.
How to fix it
Mock slow I/O and advance fake timers
- Mock network and timer-dependent code so it resolves deterministically.
- When using fake timers, advance them so pending callbacks run.
- Await the assertion so Vitest knows the test finished.
vi.useFakeTimers();
const p = doDelayed();
await vi.advanceTimersByTimeAsync(1000);
await expect(p).resolves.toBe('done');Raise the timeout for legitimate work
For a genuinely long test, pass a per-test timeout or set testTimeout in config.
test('slow', async () => {
// ...
}, 20000);How to prevent it
- Mock external services so tests do not depend on real latency.
- Advance fake timers whenever you enable them.
- Set explicit timeouts for known-slow integration tests.