jest snapshot written on CI: how to fail instead of update
Stops Jest from writing new snapshots on CI. Use when CI silently updates snapshots instead of failing. Not for local snapshot updates.
TL;DR
Run Jest with --ci on CI, which makes new or changed snapshots fail instead of being written. Check the CI script itself; a config file alone does not enable it, and a stray -u flag overrides it.
The query
jest snapshot written on CI: how to fail instead of updateUse this when
- CI writes snapshots instead of failing
- snapshot changes slip through green builds
- new snapshots appear in CI artifacts
Not for
- updating snapshots locally
- obsolete-snapshot cleanup
- snapshot serializers
Steps
- Open the CI script and confirm the test command includes --ci. Expected output: the jest command line contains the --ci flag.
- Search the same command for -u or --updateSnapshot and remove it. Expected output: no snapshot-update flags in the CI command.
- Commit the current snapshots so CI compares against a known baseline. Expected output: snapshot files committed and clean in git status.
- Push a branch that changes snapshotted output and confirm CI fails on the snapshot mismatch. Expected output: a red CI run naming the changed snapshot.
- Keep local runs without --ci so developers can still update snapshots intentionally with -u. Expected output: local -u updates snapshots while CI --ci fails on them.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_DwMXuHwmHqjmdy2RizaTqA
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.