gkampitakis/go-snaps

[Feature Request ]: Add env variable to error if .snap is missing

giulio-opal opened this issue ยท 3 comments

๐Ÿš€ Feature Proposal

We want to make sure that .snaps files are always committed alongside each test. In case a test that relies on a snapshot, in CI, instead of creating the .snap file upon run, fail automatically.

Motivation

No response

Example

In CI we want to set an env variable FAIL_ON_MISSING_SNAP=true and if a .snap is missing when snaps.MatchJSON (or similar), instead of creating/updating the .snap file, the test fails.

Hey ๐Ÿ‘‹ . Thanks a lot for opening this issue. Apart from the ENV var, go-snaps already works like this. It tries to detect if it's running on CI and if that's the case it doesn't create that snap file but fails preventing tests running as successful.

Here if the previous snapshot can't be located and the CI is detected it will fail https://github.com/gkampitakis/go-snaps/blob/main/snaps/matchJSON.go#L98-L103.

Do you have a case where this is not working as expected ?

Ah! Thank you so much for getting back to me so quickly!

It should work as expected then, I didn't find that in your documentation, and this is much neater than an env variable. Closing this :)

Also thank you for maintaining this library!

Happy to help. Indeed i missed documenting this behaviour, I will add it ๐Ÿ˜„