Open wuggen opened 1 month ago
Thanks for the issue. We're more "advanced" about looking up the snapshots for each target now, including the paths that each target specifies — previously we would miss something outside the root (e.g. https://github.com/mitsuhiko/insta/issues/625)
Unfortunately that doesn't work so well here, because the file could belong to the root or to the tests target, and so insta is counting it as both.
I think probably the solution is to dedup when we're presenting the number of snapshots etc, though I'll think about whether there's some way of defining the file as belonging to only the tests target.
If you need a workaround in the short-term, passing --tests
should work (lmk if it doesn't, would mean my understanding is wrong)
Hm, doesn't seem to work. cargo insta test --tests
yields the same behavior with the same setup.
OK thanks a lot @wuggen , I can reproduce, and my --tests
suggestion wasn't correct. I will look into it shortly.
What happened?
When insta is used in tests located in the package root (specified via the
[[test]]
Cargo.toml key), the CLI will find each generated snapshot twice, even though only one file is generated per snapshot.Reproduction steps
The following is a minimal workspace setup to reproduce the issue:
Cargo.toml
:test.rs
:cargo insta test
yields the following output and resulting workspace state:Running
cargo insta review
at this point will present the same snapshot twice.cargo insta pending-snapshots
will list the same snap.new file twice. Runningcargo insta accept
will complain (once) about the snap.new file having been removed by another process, presumably upon failing to find it again after accepting and removing it the first time.Insta Version
1.41.0
rustc Version
1.82.0
What did you expect?
I would have expected the snapshot to be found by the CLI only once; only reported as one snapshot from
insta test
andinsta pending-snapshots
, only presented once byinsta review
, only removed once byinsta accept
, etc.Prior versions of insta display the expected behavior; setting the insta dependency version to
=1.40.0
and installingcargo-insta@1.40.0
yields the expected behavior.As far as I've been able to tell, this behavior only occurs when the test is in the package root directory. For instance, it does not occur (i.e. the expected behavior occurs) if
test.rs
is in the defaulttests
directory, or if it's in a different subdirectory specified via the[[test]]
key. However, changing the snapshot directory viawith_settings!
(or manually viaSettings::bind
) does not affect the behavior; it seems to depend only on the location of the test itself.