Describe the bug
If I have a file src/snapshot.test.ts, which calls .toMatchFileSnapshot("__snapshots__/snapshot.test.ts.snap"), vitest will remove the snapshot file when called with --update if the snapshot doesn't have any changes.
Reproduction
Here is a minimal example repository which triggers the bug:
https://github.com/solita-jaakkoha2/vitest-removes-snapshots
When npm run test -- -u is called, every second run the file src/__snapshots__/snapshot.test.ts.snap will be deleted, and every second run it will exist.
System Info
System:
OS: Linux 6.14 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
CPU: (16) x64 AMD Ryzen 7 PRO 8840U w/ Radeon 780M Graphics
Memory: 15.83 GB / 30.01 GB
Container: Yes
Shell: 5.9 - /usr/bin/zsh
Binaries:
Node: 22.18.0 - ~/.nvm/versions/node/v22.18.0/bin/node
npm: 10.9.3 - ~/.nvm/versions/node/v22.18.0/bin/npm
pnpm: 10.14.0 - ~/.nvm/versions/node/v22.18.0/bin/pnpm
npmPackages:
vitest: ^3.2.4 => 3.2
Used Package Manager
npm
Validations
Describe the bug
If I have a file
src/snapshot.test.ts, which calls.toMatchFileSnapshot("__snapshots__/snapshot.test.ts.snap"), vitest will remove the snapshot file when called with--updateif the snapshot doesn't have any changes.Reproduction
Here is a minimal example repository which triggers the bug:
https://github.com/solita-jaakkoha2/vitest-removes-snapshots
When
npm run test -- -uis called, every second run the filesrc/__snapshots__/snapshot.test.ts.snapwill be deleted, and every second run it will exist.System Info
System: OS: Linux 6.14 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat) CPU: (16) x64 AMD Ryzen 7 PRO 8840U w/ Radeon 780M Graphics Memory: 15.83 GB / 30.01 GB Container: Yes Shell: 5.9 - /usr/bin/zsh Binaries: Node: 22.18.0 - ~/.nvm/versions/node/v22.18.0/bin/node npm: 10.9.3 - ~/.nvm/versions/node/v22.18.0/bin/npm pnpm: 10.14.0 - ~/.nvm/versions/node/v22.18.0/bin/pnpm npmPackages: vitest: ^3.2.4 => 3.2Used Package Manager
npm
Validations