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

Add test for reporting correct number of snapshots #595

Merged
merged 4 commits into from
Sep 11, 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
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
Loading