gkampitakis / go-snaps

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

[Bug]: Invalid json snapshot #111

Open KoNekoD opened 2 days ago

KoNekoD commented 2 days ago

Description

image

Steps to Reproduce

Create json snappshot

Expected Behavior

Without invalid characters, only json file

KoNekoD commented 2 days ago

Just

{
...
}
gkampitakis commented 2 days ago

Hi, thanks for opening this issue. This is expected behaviour, of how go-snaps works and not a bug. It's similar to how jest is storing multiple snapshots in a file.

If you want to save your snapshot in a single file as a json you could do

snaps.WithConfig(snaps.Ext(".json")).
    MatchStandaloneSnapshot(t, "{}")

This will create a single file with json extension with your data.

KoNekoD commented 1 day ago

@gkampitakis Could you please make a short hook for this?

KoNekoD commented 1 day ago

I want to be able to immediately structure this method to read

KoNekoD commented 1 day ago

Everything in your library would be perfect if you didn't have those fucking square brackets that turn the file red. I tried to refactor it, but the code overcomplicated.

gkampitakis commented 1 day ago

You could do it on your tests instead of creating a short name for every simple configuration option.

jsonSnapshot := snaps.WithConfig(snaps.Ext(".json")).MatchStandaloneSnapshot

....

jsonSnapshot(t, "{}")

and then reuse it wherver you want.

gkampitakis commented 1 day ago

Everything in your library would be perfect if you didn't have those fucking square brackets that turn the file red. I tried to refactor it, but the code overcomplicated.

Sorry for this but this library might not be for you then. You can use https://github.com/bradleyjkemp/cupaloy that does this by default.