Skip to content
Latchkey

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.

Vitest output
❯ 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

  1. Mock network and timer-dependent code so it resolves deterministically.
  2. When using fake timers, advance them so pending callbacks run.
  3. Await the assertion so Vitest knows the test finished.
api.test.ts
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.

slow.test.ts
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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →