Skip to content

Commit f29e201

Browse files
Add support for execution tests repeatedly (#585)
1 parent e408bf9 commit f29e201

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Sources/SnapshotTesting/AssertSnapshot.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public func verifySnapshot<Value, Format>(
173173
)
174174
-> String? {
175175

176+
CleanCounterBetweenTestCases.registerIfNeeded()
176177
let recording = recording || isRecording
177178

178179
do {
@@ -339,3 +340,24 @@ func sanitizePathComponent(_ string: String) -> String {
339340
.replacingOccurrences(of: "\\W+", with: "-", options: .regularExpression)
340341
.replacingOccurrences(of: "^-|-$", with: "", options: .regularExpression)
341342
}
343+
344+
// We need to clean counter between tests executions in order to support test-iterations.
345+
private class CleanCounterBetweenTestCases: NSObject, XCTestObservation {
346+
private static var registered = false
347+
private static var registerQueue = DispatchQueue(label: "co.pointfree.SnapshotTesting.testObserver")
348+
349+
static func registerIfNeeded() {
350+
registerQueue.sync {
351+
if !registered {
352+
registered = true
353+
XCTestObservationCenter.shared.addTestObserver(CleanCounterBetweenTestCases())
354+
}
355+
}
356+
}
357+
358+
func testCaseDidFinish(_ testCase: XCTestCase) {
359+
counterQueue.sync {
360+
counterMap = [:]
361+
}
362+
}
363+
}

0 commit comments

Comments
 (0)