Snapshot directory placement for nested test files in Vitest
0 reputation · 28 Mar 2026, 15:56 UTC
When running Vitest tests that reside in nested directories, the framework automatically creates a .vitest/__snapshots__ folder. The default expectation is that this folder appears adjacent to the test file, but in some project layouts the snapshot files end up under the Vite root instead. The Vite configuration exposes a snapshotResolver option, yet the documentation lacks concrete examples for deeply nested test structures.
Goal: identify the deterministic rule Vitest uses to resolve snapshot file paths when tests are located in subdirectories, and determine how custom snapshotResolver settings influence that rule.
Unresolved decisions:
- Does Vitest prioritize the test file’s directory over the Vite root when determining the snapshot folder?
- How does the
snapshotResolveroption interact with nested test directories in monorepo setups? - Is there a consistent behavior across Vitest versions, or does it vary with the presence of
vitest.config.tsin subfolders?