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

feat: support configurable snapshot dir and filename #60

Closed gkampitakis closed 1 year ago

gkampitakis commented 1 year ago

This pull request adds back support for allowing configurable snapshot filename and directory name. [ pr tha dropped config ]

Action Items:

closes #58

Example usage of current api

t.Run("should allow setting filename", func(t *testing.T) {
    snaps.WithConfig(snaps.Filename("my_custom_name")).MatchSnapshot(t, "Hello Word")
    snaps.WithConfig(snaps.Dir("my_dir")).MatchSnapshot(t, 10, 20, 30)

    snaps.WithConfig(snaps.Filename("my_custom_name")).MatchSnapshot(t, "Hello Word")
    snaps.WithConfig(snaps.Dir("my_dir")).MatchSnapshot(t, 10, 20, 30)

    snaps.WithConfig(snaps.Dir("my_dir"), snaps.Filename("json_file")).MatchJSON(t, `{"hello":"world"}`)
    snaps.WithConfig(snaps.Dir("json_dir"), snaps.Filename("blue_file")).MatchJSON(t, `{"hello":"world"}`)
})