Skip to content

Vitest removes toMatchFileSnapshot snapshots if the filename matches one from toMatchSnapshot #8655

Description

@solita-jaakkoha2

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions