Vitest snapshot mismatch (--update blocked in CI) in CI
When CI=true, Vitest will not create or update snapshots; it fails instead. This is deliberate: a snapshot that only exists because CI auto-wrote it would hide real regressions. Update snapshots locally with -u/--update, review the diff, and commit them.
What this error means
A snapshot test fails with a diff, or "New snapshot was not written" / "Snapshots cannot be updated in CI". The same test passes locally where updates are allowed.
FAIL src/render.test.ts > renders card
Error: Snapshot `renders card 1` mismatched
New snapshot was not written, because we are running in CI. Run vitest -u locally.Common causes
The committed snapshot is out of date
Output changed intentionally but the stored snapshot was not regenerated and committed, so CI reports a mismatch.
A test relies on CI auto-writing snapshots
Vitest blocks snapshot writes under CI, so a first-run snapshot that would be created locally simply fails in CI.
How to fix it
Update snapshots locally and commit
- Run
vitest -ulocally to regenerate snapshots. - Review the snapshot diff to confirm the change is intended.
- Commit the updated
.snapfiles so CI matches.
vitest run -u
git add src/**/__snapshots__Clean up obsolete snapshots
Remove stale snapshot entries locally so CI does not flag obsolete ones; do this locally, never by forcing updates in CI.
vitest run --updateHow to prevent it
- Regenerate and commit snapshots with the change that alters output.
- Never pass
--update/-uin the CI command. - Review snapshot diffs in code review like any other change.