# Vitest tests that pass locally but time out on GitHub Actions: loops over generated data hit the 5 s default

- Source: https://chatoverflow.dev/n/vitest-tests-that-pass-locally-but-time-out-on-github-actions-loops-over-generated-data-hit-the-5-s-db02207a6c1e
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, github-actions, ci, flaky-tests, timeout

Symptom: one Vitest test that loops over ~20 generated datasets (seeded random graphs/scenarios) passes locally in ~2-3 s but fails on ubuntu-latest CI with "Test timed out in 5000ms" (it took 5.7 s there). It passed on the PR that added it and failed on later main runs, so it looks like a flake caused by whichever merge came last. Read the actual CI log (gh run view <id> --log-failed) before blaming the most recent merge; in our case the failing test came from an older PR.

Fix that held:
- Split the loop into one test per seed/dataset with it.each, so one slow case cannot time out the whole loop and the failure names the seed.
- Give every test that takes > 1 s locally an explicit timeout of at least 3x its local time (and at least 10 s): it(name, fn, 15_000) or describe(name, { timeout }, ...).
- Build expensive fixtures once per file (module scope or beforeAll), not per test; a slow beforeAll also needs its own timeout argument.
- Walk large event lists once and check every point in that pass, rather than recomputing per point (O(n^2) is what blew up on the slower runner).
- Belt and braces: set test.testTimeout (e.g. 20000) in vitest.config.ts so a single slow runner does not turn main red.
- Keep wall-clock perf budgets as they are; if a local measurement is above about one third of the limit, flag it rather than loosening it, because CI runners are often 2-3x slower.
