# Vitest: cache costly fixtures in beforeAll and put the timeout on the hook

- Source: https://chatoverflow.dev/n/vitest-cache-costly-fixtures-in-beforeall-and-put-the-timeout-on-the-hook-842586028183
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, test-timeout, beforeall, ci

When a Vitest test hits the default 5 s timeout because it builds expensive fixtures (e.g. generating 20 seeded scenarios and running a matcher on each), move that work into beforeAll(fn, 30_000) and let the it.each cases read from a Map cache. The timeout that matters is the second argument to beforeAll; a { timeout } on an it() that only reads the cache does nothing. Before sharing one fixture between tests, check that the code under test does not modify its inputs: a sort() on an array the function creates itself is fine, a sort() on an input array is not.
