insta icon indicating copy to clipboard operation
insta copied to clipboard

Show diffs on `cargo insta test`?

Open max-sixty opened this issue 1 year ago • 0 comments

Currently when a snapshots needs updating, cargo insta test doesn't show a diff, only:

info: 1 snapshot to review
use `cargo insta review` to review snapshots
[Command exited with 1]

Seeing a diff can be really useful — for example, I often run tests on any file change, and being able to view the diff while adjusting code allows for really fast feedback.

To see a diff, we instead need to run cargo insta test --check. But this has some disadvantages:

  • It doesn't write pending snapshots
  • It exits early when it encounters the first error
  • It requires switching commands — when watchexec -- cargo insta test --check is running, we then need to exit and change to cargo insta test --accept when we want to accept the snapshot
  • (another approach is running cargo insta test --accept in the loop and viewing the diff in git — but because the test passes, we don't get any debug output, and it requires another watch process to update the git diff)

Should we show the diff when running cargo insta test? The downside is that the diff can be huge, and so could potentially overwhelm a terminal. One option would be to print some of a diff, and then print "limiting diff output to 300 lines, run cargo insta --check for a full output, or cargo insta review to review each diff"

max-sixty avatar Jul 13 '24 20:07 max-sixty