Skip to content

Named snapshots#237

Open
dylanbr wants to merge 4 commits intospatie:mainfrom
dylanbr:dylanbr/named-snapshots
Open

Named snapshots#237
dylanbr wants to merge 4 commits intospatie:mainfrom
dylanbr:dylanbr/named-snapshots

Conversation

@dylanbr
Copy link

@dylanbr dylanbr commented Jan 22, 2026

As per the issue I previously already, here is an implementation of named snapshots, option 2.

Having the option to use explicitly named IDs for snapshots allows one to avoid needing read confusing diffs when a test is refactored (see the issue for an example).

This PR implements the following changes:

  • Moves the incrementor functionality to the SnapshotIdAware concern. It makes sense to have it here, rather than in MatchesSnapshots, so getting an ID and incrementing are all a single operation.
  • Added an optional $id argument to all the assertions. The retains backwards compatibility, while allowing explicit IDs to be used when required.
  • When the optional $id is populated, this is used to name the snapshot, instead of the next incrementor value. It is also prefixed with s- to avoid the possibility of conflicts with incrementor values.
  • Adds additional tests for all the assertions with the optional $id argument set.

@freekmurze
Copy link
Member

Could you rebase with main?

@dylanbr dylanbr force-pushed the dylanbr/named-snapshots branch from a96bfb9 to 2629561 Compare January 23, 2026 12:42
@dylanbr
Copy link
Author

dylanbr commented Jan 23, 2026

Rebased with the latest main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants