Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tests executed repeatedly #585

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Sources/SnapshotTesting/AssertSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public func verifySnapshot<Value, Format>(
)
-> String? {

CleanCounterBetweenTestCases.registerIfNeeded()
let recording = recording || isRecording

do {
Expand Down Expand Up @@ -328,3 +329,24 @@ func sanitizePathComponent(_ string: String) -> String {
.replacingOccurrences(of: "\\W+", with: "-", options: .regularExpression)
.replacingOccurrences(of: "^-|-$", with: "", options: .regularExpression)
}

// We need to clean counter between tests executions in order to support test-iterations.
private class CleanCounterBetweenTestCases: NSObject, XCTestObservation {
private static var registered = false
private static var registerQueue = DispatchQueue(label: "co.pointfree.SnapshotTesting.testObserver")

static func registerIfNeeded() {
registerQueue.sync {
if !registered {
registered = true
XCTestObservationCenter.shared.addTestObserver(CleanCounterBetweenTestCases())
}
}
}

func testCaseDidFinish(_ testCase: XCTestCase) {
counterQueue.sync {
counterMap = [:]
krzysztofpawski marked this conversation as resolved.
Show resolved Hide resolved
}
}
}