Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: Prevent lots of empty inline snapshots with --force-update-snapshots without --accept #573

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions insta/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,23 @@ pub fn assert_snapshot(
if pass {
ctx.cleanup_passing()?;

if tool_config.force_update_snapshots() {
ctx.update_snapshot(new_snapshot)?;
if dbg!(tool_config.force_update_snapshots()) {
// Inline snapshots currently create lots of files even when they
// match. So we don't update them if they fully match.
//
// Note that there's a check down the stack on whether the files
// match for file snapshots; probably we should combine that check
// with `matches_fully` and then use a single check for whether we
// force update snapshots. Currently the bad user experience is for
// inline snapshots only, so that's the check we do here.
let matches_fully = dbg!(&ctx.old_snapshot)
.as_ref()
.map(|x| x.matches_fully(dbg!(&new_snapshot)))
.unwrap_or(false);
let inline = ctx.snapshot_file.is_none();
if !dbg!(matches_fully) || !dbg!(inline) {
ctx.update_snapshot(new_snapshot)?;
}
}
// otherwise print information and update snapshots.
} else {
Expand Down
7 changes: 6 additions & 1 deletion insta/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ impl MetaData {
// snapshot. But we don't know that from here (notably
// `self.input_file.is_none()` is not a correct approach). Given that
// `--require-full-match` is experimental and we're working on making
// inline & file snapshots more coherent, I'm leaving this as is for now.
// inline & file snapshots more coherent, I'm leaving this as is for
// now.
//
// FIXME: for the current issue around `matches_fully` not passing
// correctly for inline snapshots, we need to figure that out here and
// remove metadata if so.
if self.assertion_line.is_some() {
let mut rv = self.clone();
rv.assertion_line = None;
Expand Down
Loading