From a66803a3aedd80c48bc7ed3157f3b83d41504240 Mon Sep 17 00:00:00 2001 From: David Furman Date: Fri, 14 Jul 2023 21:08:06 -0700 Subject: [PATCH] Added a global var that allows users to disable the counter suffix in unnamed tests --- Sources/SnapshotTesting/AssertSnapshot.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sources/SnapshotTesting/AssertSnapshot.swift b/Sources/SnapshotTesting/AssertSnapshot.swift index 6f7099294..a0b930555 100644 --- a/Sources/SnapshotTesting/AssertSnapshot.swift +++ b/Sources/SnapshotTesting/AssertSnapshot.swift @@ -5,6 +5,9 @@ import XCTest /// diffTool = "ksdiff" public var diffTool: String? = nil +/// Whether or not to have snapshot tests add a counter suffix when the `named` parameter in `assertSnapshot()` is `nil`. +public var addsCounterSuffixToEmptyTestName = true + /// Whether or not to record all new references. public var isRecording = false @@ -199,8 +202,15 @@ public func verifySnapshot( } let testName = sanitizePathComponent(testName) + let pathComponent: String + if addsCounterSuffixToEmptyTestName && name == nil { + pathComponent = "\(testName).\(identifier)" + } else { + pathComponent = testName + } + let snapshotFileUrl = snapshotDirectoryUrl - .appendingPathComponent("\(testName).\(identifier)") + .appendingPathComponent(pathComponent) .appendingPathExtension(snapshotting.pathExtension ?? "") let fileManager = FileManager.default try fileManager.createDirectory(at: snapshotDirectoryUrl, withIntermediateDirectories: true)