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

Only delete unreferenced snapshots after a successful test run #440

Merged
merged 1 commit into from
Feb 19, 2024
Merged
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
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
Loading