gkampitakis / go-snaps

Jest-like snapshot testing in Golang 📸
https://pkg.go.dev/github.com/gkampitakis/go-snaps
MIT License
146 stars 6 forks source link

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

Closed giulio-opal closed 12 months ago

giulio-opal commented 12 months ago

🚀 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.

gkampitakis commented 12 months ago

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 ?

giulio-opal commented 12 months ago

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!

gkampitakis commented 12 months ago

Happy to help. Indeed i missed documenting this behaviour, I will add it 😄