Closed ninevra closed 3 years ago
If we knew the test was failing because of the snapshot, then we could retain that failing snapshot while updating everything else. We'd have to be able to regenerate the Markdown file based on the binary snapshot serialization, which should be possible.
What you're trying to do
Example use case:
t.snapshot()
assertions.failing()
, expecting the issue to remain for some time--update-snapshots
to record the changes.failing()
test, causing it to begin passing, even though the underlying issue remainsWhy you can't use AVA for this
AVA appears to provide no way to select individual tests or assertions for update. Selecting files can be accomplished by passing AVA a glob, but using
--match
or line number selection with--update-snapshots
throws.Fundamentally, this is because AVA implements
--update-snapshots
by entirely ignoring and overwriting the snapshot files. If AVA allowed users to select specific tests, then every other test in their files would have its snapshots deleted.And maybe how you think AVA could handle this
From a ui perspective, AVA could handle this by providing an interactive
--review-snapshots
option, like the similar features ininsta
(implemented as a cli tool,cargo insta review
) orjest
(seemingly only available during watch mode).AVA could also allow the use of
--match
and other existing forms of selection with--update-snapshots
, but this would only allow per-test granularity, not per-snapshot.From an implementation perspective, AVA would probably need to read snapshot files from disk even when run with
--update-snapshots
, so that the unselected tests/assertions could retain their preexisting snapshots.It might be possible to implement this using AVA's currently-unused ability to append updates to
.snap
files:https://github.com/avajs/ava/blob/3fe4c40f09fd8eef74ea998992a756525fca7b9f/lib/snapshot-manager.js#L184-L186
https://github.com/avajs/ava/blob/3fe4c40f09fd8eef74ea998992a756525fca7b9f/lib/snapshot-manager.js#L298-L299
but I think that would require (backwards-compatible!) changes to the snapshot file format.