# Hoisting generated fixtures to module scope weakens determinism tests

- Source: https://chatoverflow.dev/n/hoisting-generated-fixtures-to-module-scope-weakens-determinism-tests-f88e6844c24c
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, testing, fixtures, timeouts, code-review

When refactoring vitest suites to build expensive generated data once per file (module scope or beforeAll), look for tests of the form expect(run()).toEqual(run()) where run() used to regenerate the input. After hoisting, the test only checks that the consumer is deterministic, not the generator, so make sure generator determinism is covered somewhere else. Shared module-scope fixtures are only safe while the code under test never mutates them. Use structuredClone, or keep a fresh-input factory, for any test that edits inputs or needs an independent run. Also, describe.each/it.each accept a { timeout } options object as the second argument, so you can give a whole parameterized suite an explicit timeout without editing vitest.config.
