insta icon indicating copy to clipboard operation
insta copied to clipboard

Snapshots have to be accepted twice.

Open buildwithzephyr opened this issue 5 months ago • 1 comments

What happened?

Accepting snapshots doesn't take the first time. You have to do it twice.

I'm not sure when this started, but I did recently update my rust toolchain from 1.84.

Reproduction steps

  1. Change or create a new snapshot using insta::assert_snapshot!(expr)
  2. cargo test. The test fails as expected.
  3. cargo insta accept.
  4. cargo test. The test still fails.
  5. cargo insta accept again.
  6. cargo test. Now the tests pass.

Same behavior if accepting tests using cargo insta review.

rustc Version

rustc 1.87.0 (17067e9ac 2025-05-09)

insta Version

1.43.1

cargo insta --version output

cargo-insta 1.43.1

What did you expect?

cargo insta accept should make the next cargo test pass.

buildwithzephyr avatar Jun 26 '25 03:06 buildwithzephyr

please you could you do one more check that the insta version in Cargo.toml and cargo insta --version are the same, both 1.43.1?

it's ofc not impossible, but this seems like too big a bug that it affects all insta installs — 1.43.1 has been out for two months with no reports

unless others also experience this bug we'd need a reproducible example — a mini-repo with the commands to run, since it's very likely a corner case with a non-traditional setup.

...I hope that's reasonable, obv if we can show there's a bug then I'm enthusiastic to fix, but worry I'd be chasing a ghost without the repro

max-sixty avatar Jun 27 '25 20:06 max-sixty

This turned out to be my own ignorance about how to set up integration tests in Rust.

I had multiple test files under /tests, but I was also adding each test file to /tests/main.rs with a mod statement. For example, here's a minimal project that displays the issue: https://github.com/buildwithzephyr/insta-issue-718. You can see that tests/snapshots ends up with two snapshots, one for the test in the module file, and the other with main__ appended to the front.

I'm not sure why insta shows one failure on each of two subsequent runs, rather than showing both failures at once, but at any rate I don't need to include all of my tests into a main file like this, and once I stop doing that, the issue goes away.

buildwithzephyr avatar Jul 11 '25 03:07 buildwithzephyr