Skip to content

Commit

Permalink
Only delete unreferenced snapshots after a successful test run (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty authored Feb 19, 2024
1 parent 0974fe8 commit 1f9ee0f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ struct TestCommand {
/// Update all snapshots even if they are still matching.
#[structopt(long)]
force_update_snapshots: bool,
/// Controls what happens with unreferenced snapshots.
/// Handle unreferenced snapshots after a successful test run.
#[structopt(long, default_value="ignore", possible_values=&["ignore", "warn", "reject", "delete", "auto"])]
unreferenced: String,
/// Delete unreferenced snapshots after the test run.
/// Delete unreferenced snapshots after a successful test run.
#[structopt(long, hidden = true)]
delete_unreferenced_snapshots: bool,
/// Filters to apply to the insta glob feature.
Expand Down Expand Up @@ -641,9 +641,12 @@ fn test_run(mut cmd: TestCommand, color: &str) -> Result<(), Box<dyn Error>> {
return Err(QuietExit(1).into());
}

// handle unreferenced snapshots if we were instructed to do so
if let Some(ref path) = snapshot_ref_file {
handle_unreferenced_snapshots(path.borrow(), &loc, unreferenced, &cmd.package[..])?;
// handle unreferenced snapshots if we were instructed to do so and the
// tests ran successfully
if success {
if let Some(ref path) = snapshot_ref_file {
handle_unreferenced_snapshots(path.borrow(), &loc, unreferenced, &cmd.package[..])?;
}
}

if cmd.review || cmd.accept {
Expand Down

0 comments on commit 1f9ee0f

Please sign in to comment.