Skip to content

Commit

Permalink
fix: clean snapshots should only delete .snap files (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkampitakis authored May 20, 2023
1 parent 6c41cd3 commit 6a7fc6c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion snaps/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func examineFiles(

for _, content := range dirContents {
// this is a sanity check shouldn't have dirs inside the snapshot dirs
if content.IsDir() {
// and only delete any `.snap` files
if content.IsDir() || filepath.Ext(content.Name()) != snapsExt {
continue
}

Expand Down
4 changes: 4 additions & 0 deletions snaps/clean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func setupTempExamineFiles(t *testing.T) (map[string]map[string]int, string, str
name: filepath.FromSlash(dir2 + "/obsolete2.snap"),
data: []byte{},
},
{
name: filepath.FromSlash(dir2 + "/should_not_delete.txt"),
data: []byte{},
},
}

for _, file := range files {
Expand Down
5 changes: 2 additions & 3 deletions snaps/skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func isFileSkipped(dir, filename, runOnly string) bool {
}

testFilePath := path.Join(dir, "..", strings.TrimSuffix(filename, snapsExt)+".go")
isSkipped := true

fset := token.NewFileSet()
file, err := parser.ParseFile(fset, testFilePath, nil, parser.ParseComments)
Expand All @@ -105,9 +104,9 @@ func isFileSkipped(dir, filename, runOnly string) bool {
// If the TestFunction is inside the file then it's not skipped
matched, _ := regexp.MatchString(runOnly, funcDecl.Name.String())
if matched {
isSkipped = false
return false
}
}

return isSkipped
return true
}

0 comments on commit 6a7fc6c

Please sign in to comment.