Skip to content

Commit

Permalink
Add test for reporting correct number of snapshots (#595)
Browse files Browse the repository at this point in the history
This was fixed in 1.40, added a test out of #593 to confirm
  • Loading branch information
max-sixty authored Sep 11, 2024
1 parent 99ed3b1 commit d1f6e7e
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions cargo-insta/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ impl TestProject {
// Turn off CI flag so that cargo insta test behaves as we expect
// under normal operation
command.env("CI", "0");
// And any others that can affect the output
command.env_remove("CARGO_TERM_COLOR");
command.env_remove("CLICOLOR_FORCE");
command.env_remove("RUSTDOCFLAGS");

command.current_dir(self.workspace_dir.as_path());
// Use the same target directory as other tests, consistent across test
Expand Down Expand Up @@ -484,11 +488,12 @@ fn test_root() {
}

/// Check that in a workspace with a default root crate, running `cargo insta
/// test --workspace` will update snapsnots in both the root crate and the
/// test --workspace --accept` will update snapsnots in both the root crate and the
/// member crate.
#[test]
fn test_root_crate_all() {
let test_project = workspace_with_root_crate("root-crate-all".to_string()).create_project();
fn test_root_crate_workspace_accept() {
let test_project =
workspace_with_root_crate("root-crate-workspace-accept".to_string()).create_project();

let output = test_project
.cmd()
Expand All @@ -510,16 +515,38 @@ fn test_root_crate_all() {
member/src
member/src/lib.rs
+ member/src/snapshots
+ member/src/snapshots/root_crate_all_member__member.snap
+ member/src/snapshots/root_crate_workspace_accept_member__member.snap
src
src/main.rs
+ src/snapshots
+ src/snapshots/root_crate_all__root.snap
+ src/snapshots/root_crate_workspace_accept__root.snap
"### );
}

/// Check that in a workspace with a default root crate, running `cargo insta
/// test` will only update snapsnots in the root crate
/// test --workspace` will correctly report the number of pending snapshots
#[test]
fn test_root_crate_workspace() {
let test_project =
workspace_with_root_crate("root-crate-workspace".to_string()).create_project();

let output = test_project
.cmd()
// Need to disable colors to assert the output below
.args(["test", "--workspace", "--color=never"])
.output()
.unwrap();

// 1.39 had a bug where it would claim there were 3 snapshots here
assert!(
String::from_utf8_lossy(&output.stderr).contains("info: 2 snapshots to review"),
"{}",
String::from_utf8_lossy(&output.stderr)
);
}

/// Check that in a workspace with a default root crate, running `cargo insta
/// test --accept` will only update snapsnots in the root crate
#[test]
fn test_root_crate_no_all() {
let test_project = workspace_with_root_crate("root-crate-no-all".to_string()).create_project();
Expand Down Expand Up @@ -619,8 +646,8 @@ fn test_member_2() {
)
}

/// Check that in a workspace with a virtual manifest, running `cargo insta test --workspace`
/// will update snapshots in all member crates.
/// Check that in a workspace with a virtual manifest, running `cargo insta test
/// --workspace --accept` updates snapshots in all member crates.
#[test]
fn test_virtual_manifest_all() {
let test_project =
Expand Down Expand Up @@ -656,8 +683,8 @@ fn test_virtual_manifest_all() {
"### );
}

/// Check that in a workspace with a virtual manifest, running `cargo insta test`
/// updates snapshots in all member crates.
/// Check that in a workspace with a virtual manifest, running `cargo insta test
/// --accept` updates snapshots in all member crates.
#[test]
fn test_virtual_manifest_default() {
let test_project =
Expand Down

0 comments on commit d1f6e7e

Please sign in to comment.