Skip to content

feat(snapshot): add --no-snapshot-create to fail on a missing snapshot - #910

Merged
Chemaclass merged 1 commit into
mainfrom
feat/901-no-snapshot-create
Jul 27, 2026
Merged

feat(snapshot): add --no-snapshot-create to fail on a missing snapshot#910
Chemaclass merged 1 commit into
mainfrom
feat/901-no-snapshot-create

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #901

A missing snapshot is recorded on the fly and the run exits 0. So a snapshot that was never committed — gitignored, lost or forgotten — gets re-created by CI, and the green run asserted nothing. Nothing let a caller make that state fail.

💡 Changes

  • Add --no-snapshot-create / BASHUNIT_SNAPSHOT_CREATE=false: a missing snapshot fails the test and the message names the resolved path (which is derived, not visible in the test source). Default behaviour is unchanged.
  • Applies to both assert_match_snapshot and assert_match_snapshot_ignore_colors; the tail they share is now one function rather than two copies.
  • Documented as the recommended CI setting in the snapshots, command-line and configuration pages.

Kept as a separate flag rather than folded into --strict, which means set -euo pipefail for test bodies — a different axis, as the issue notes. It pairs with --snapshot-update: one records deliberately, the other forbids recording by accident.

A missing snapshot is written and counted as a snapshot assertion, and the run
exits 0. So a snapshot that was never committed — gitignored, lost, or simply
forgotten — is re-created by CI on the fly, and the green run asserted nothing.
Nothing let a caller make that state fail.

Add --no-snapshot-create / BASHUNIT_SNAPSHOT_CREATE=false: a missing snapshot
fails the test, and the failure names the resolved path, which is derived from
the test file and function name and so cannot be guessed from the source.
Default behaviour is unchanged.

A separate flag rather than folding it into --strict, which means
`set -euo pipefail` for test bodies — a different axis, as the issue notes. It
pairs with --snapshot-update: one records deliberately, the other forbids
recording by accident.

The tail shared by both snapshot assertions is now one function instead of two
copies, since this is the second branch to be added to it.

Closes #901
@Chemaclass Chemaclass added the enhancement New feature or request label Jul 27, 2026
@Chemaclass Chemaclass self-assigned this Jul 27, 2026
@Chemaclass
Chemaclass merged commit 1c3fef6 into main Jul 27, 2026
37 checks passed
@Chemaclass
Chemaclass deleted the feat/901-no-snapshot-create branch July 27, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant