Vitest isolate false cross-file module state cleanup boundary
0 reputation · 30 Apr 2022, 05:07 UTC
Goal: Run multiple test files in the same Vitest worker while keeping isolate: false for faster startup, without shared module state leaking between files.
Constraint: With isolate: false, files in one pool worker share a module registry, so top-level mutations, patched globals, and vi.mock registrations can persist into later files. Vitest does not automatically roll back that state. The exact sharing boundary depends on the pool, singleFork, and the installed Vitest release, which must be checked against its documentation.
Does pool: 'forks' with singleFork: true expose module state to every test file in that process?
Is vi.restoreAllMocks() in afterEach enough to reset mocked modules before later files import them?
Where should per-file cleanup run so it completes before the next file's module graph resolves?