Skip to content

Commit

Permalink
feat: drop snaps.update flag
Browse files Browse the repository at this point in the history
  • Loading branch information
gkampitakis committed Apr 8, 2022
1 parent 4684f22 commit 7959dbf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,9 @@ name is the test file name with extension `.snap`.
So for example if your test is called `add_test.go` when you run your tests at the same
directory a new folder will be created `./__snapshots__/add_test.snaps`.

Finally you can update your failing snapshots with the cli flag `-snaps.update=true`
or by setting `UPDATE_SNAPS` env variable to true.
Finally you can update your failing snapshots by setting `UPDATE_SNAPS` env variable to true.

```bash
go test ./... -snaps.update=true
# or
UPDATE_SNAPS=true go test ./...
```

Expand Down
15 changes: 1 addition & 14 deletions snaps/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package snaps

import (
"errors"
"flag"
"fmt"
"regexp"
"runtime"
"sync"
"testing"

"github.com/gkampitakis/ciinfo"
"github.com/kr/pretty"
Expand All @@ -21,13 +19,13 @@ var (
snapsDir = "__snapshots__"
snapsExt = ".snap"
isCI = ciinfo.IsCI
shouldUpdate bool
// Matches [ Test ... ] testIDs
testIDRegexp = regexp.MustCompile(`^\[([Test].+)]$`)
spacesRegexp = regexp.MustCompile(`^\s+$`)
endCharRegexp = regexp.MustCompile(`(?m)(^---$)`)
endCharEcscapedRegexp = regexp.MustCompile(`(?m)(^/-/-/-/$)`)
dmp = diffmatchpatch.New()
shouldUpdate = getEnvBool("UPDATE_SNAPS", false) && !isCI
)

const (
Expand All @@ -42,17 +40,6 @@ const (
bulletPoint = "• "
)

// Register snap flags
func init() {
testing.Init()

updateFlag := flag.Bool("snaps.update", false, "update snapshots/remove obsolete tests")

flag.Parse()

shouldUpdate = *updateFlag || getEnvBool("UPDATE_SNAPS", false) && !isCI
}

type set map[string]struct{}
type testingT interface {
Helper()
Expand Down

0 comments on commit 7959dbf

Please sign in to comment.