Where Does Vitest Store Test Caches?
Vitest caches optimizer output and result ordering under Vite's cacheDir. Default spots, the cache option and --clearCache.
Last updated
Vitest reuses Vite's cache directory and appends its own vitest lane: optimizer bundles plus the result cache that orders slow and failed tests first. Defaults resolve to node_modules/.vite/vitest, so fresh installs naturally wipe it. A workspace-wide fsModuleCache for transformed files sits in node_modules at the root alongside.
Redirect everything with the cacheDir option (scope it behind process.env.VITEST when sharing config with dev builds) or test.cache.dir for result data alone. Clear from the CLI with vitest --clearCache instead of hunting folders. Optimizer quirks that ignore custom dirs are known upstream territory worth checking when caches land unexpectedly.
Where Vitest stores this, by platform
node_modules\.vite\vitest
Default result and optimizer cache. fsModuleCache persists transformed files in node_modules at the workspace root. vitest --clearCache wipes the lot.
node_modules/.vite/vitest
Same Vite-derived default. Custom cacheDir in config moves both lanes together. Debugging node_modules code actually edits these cached copies, not the originals.
node_modules/.vite/vitest
Mirrors macOS. Docker test layers benefit from persisting this path between runs. deps.optimizer force flags rebundle without full wipes.
Frequently asked questions
How do I clear all Vitest caches?
Run vitest --clearCache. It removes the optimizer cache, result cache and fsModuleCache in one step. Delete node_modules/.vite by hand only when the CLI itself misbehaves.
How do I move the Vitest cache folder?
Set cacheDir in Vite config (conditionally on process.env.VITEST if shared with dev), or test.cache.dir for result ordering alone. Keep the new path gitignored and CI-persisted like the default.
Notice an outdated path? Let us know.