-
-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
enhancementNew feature or requestNew feature or request
Description
🚀 Feature Proposal
Currently if you have custom snapshot files these will be considered obsolete if the related Match function is not called during the test, such as because you're using -run or there is an error beforehand.
It could be useful if we can explicitly provide a list of snapshot files for snaps.Clean to not consider obsolete.
For example over in osv.dev we're adding a bunch of snapshot-based tests that run on input files that I'm having go to multiple snapshot files to break things up - this means we can determine the snapshot files that will be used i.e.
func listCassetteSnapshotFiles() ([]string, error) {
files, err := os.ReadDir("./testdata/cassettes")
if err != nil {
return nil, err
}
snapshots := []string{}
for _, file := range files {
if file.IsDir() {
continue
}
name, _, _ := strings.Cut(file.Name(), ".")
snapshots = append(snapshots, "./__snapshots_/cassette_"+name+".snap")
}
return snapshots, nil
}
func TestMain(m *testing.M) {
err := vcr.CleanCassettes()
if err != nil {
fmt.Println("Error cleaning cassettes:", err)
os.Exit(1)
}
m.Run()
extraSnapshotFiles, err := listCassetteSnapshotFiles()
if err != nil {
fmt.Println("Error cleaning cassettes:", err)
os.Exit(1)
}
dirty, err := snaps.Clean(m, snaps.CleanOpts{
Sort: true,
ExtraSnapshotFiles: extraSnapshotFiles,
})
if err != nil {
fmt.Println("Error cleaning snaps:", err)
os.Exit(1)
}
if dirty {
fmt.Println("Some snapshots were outdated.")
os.Exit(1)
}
}Motivation
No response
Example
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request