Skip to content

Commit 9378be9

Browse files
committed
refactor: remove the need for testIdLabelMappings when examining snaps
1 parent ca7dbde commit 9378be9

File tree

2 files changed

+119
-94
lines changed

2 files changed

+119
-94
lines changed

snaps/clean.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,11 @@ func Clean(m *testing.M, opts ...CleanOpts) (bool, error) {
110110
shouldClean,
111111
)
112112
obsoleteTests, snapsDirty, err := examineSnaps(
113-
testsRegistry.cleanup,
113+
testsRegistry.labeled,
114114
usedFiles,
115115
runOnly,
116-
count,
117116
shouldClean,
118117
opt.Sort,
119-
testsRegistry.labeled,
120118
)
121119
if err != nil {
122120
return snapsDirty || filesDirty, err
@@ -240,13 +238,11 @@ func examineFiles(
240238
}
241239

242240
func examineSnaps(
243-
registry map[string]map[string]int,
241+
testIdLabelMappings map[string]string,
244242
used []string,
245243
runOnly string,
246-
count int,
247244
shouldUpdate,
248245
sort bool,
249-
testIdLabelMappings map[string]string,
250246
) ([]string, bool, error) {
251247
obsoleteTests := []string{}
252248
tests := map[string]string{}
@@ -262,7 +258,6 @@ func examineSnaps(
262258

263259
var needsUpdating bool
264260

265-
registeredTests := occurrences(registry[snapPath], count, snapshotOccurrenceFMT)
266261
s := snapshotScanner(f)
267262

268263
for s.Scan() {
@@ -277,19 +272,18 @@ func examineSnaps(
277272
// resolve the current full test snapshot id, based on the "old" one
278273
currentTestIdWithLabel, ok := testIdLabelMappings[oldTestIDWithoutLabel]
279274

280-
// remove the old test snapshot if the label has been changed
281-
if ok && currentTestIdWithLabel != oldTestIDWithLabel {
282-
obsoleteTests = append(obsoleteTests, oldTestIDWithLabel)
275+
// remove any test snapshots whose test no longer exists
276+
if !ok && !testSkipped(oldTestIDWithoutLabel, runOnly) {
277+
obsoleteTests = append(obsoleteTests, oldTestIDWithoutLabel)
283278
needsUpdating = true
284279

285280
removeSnapshot(s)
286281
continue
287282
}
288283

289-
// remove any test snapshots whose test no longer exists
290-
if !registeredTests.Has(oldTestIDWithoutLabel) &&
291-
!testSkipped(oldTestIDWithoutLabel, runOnly) {
292-
obsoleteTests = append(obsoleteTests, oldTestIDWithoutLabel)
284+
// remove the old test snapshot if the label has been changed
285+
if ok && currentTestIdWithLabel != oldTestIDWithLabel {
286+
obsoleteTests = append(obsoleteTests, oldTestIDWithLabel)
293287
needsUpdating = true
294288

295289
removeSnapshot(s)

0 commit comments

Comments
 (0)