diff --git a/Nimble_Snapshots/DynamicSize/DynamicSizeSnapshot.swift b/Nimble_Snapshots/DynamicSize/DynamicSizeSnapshot.swift index 7a4fb9d..8afbe9c 100644 --- a/Nimble_Snapshots/DynamicSize/DynamicSizeSnapshot.swift +++ b/Nimble_Snapshots/DynamicSize/DynamicSizeSnapshot.swift @@ -152,7 +152,8 @@ public func haveValidDynamicSizeSnapshot(named name: String? = nil, usesDrawRect: Bool = false, pixelTolerance: CGFloat? = nil, tolerance: CGFloat? = nil, - resizeMode: ResizeMode = .frame) -> Predicate { + resizeMode: ResizeMode = .frame, + shouldIgnoreScale: Bool = false) -> Predicate { return Predicate { actualExpression in return performDynamicSizeSnapshotTest(name, identifier: identifier, @@ -163,7 +164,8 @@ public func haveValidDynamicSizeSnapshot(named name: String? = nil, tolerance: tolerance, pixelTolerance: pixelTolerance, isRecord: false, - resizeMode: resizeMode) + resizeMode: resizeMode, + shouldIgnoreScale: shouldIgnoreScale) } } @@ -176,7 +178,8 @@ func performDynamicSizeSnapshotTest(_ name: String?, tolerance: CGFloat? = nil, pixelTolerance: CGFloat? = nil, isRecord: Bool, - resizeMode: ResizeMode) -> PredicateResult { + resizeMode: ResizeMode, + shouldIgnoreScale: Bool = false) -> PredicateResult { // swiftlint:disable:next force_try force_unwrapping let instance = try! actualExpression.evaluate()! let testFileLocation = actualExpression.location.file @@ -204,7 +207,8 @@ func performDynamicSizeSnapshotTest(_ name: String?, snapshot: finalSnapshotName, record: isRecord, referenceDirectory: referenceImageDirectory, tolerance: tolerance, perPixelTolerance: pixelTolerance, - filename: actualExpression.location.file, identifier: nil) + filename: actualExpression.location.file, identifier: nil, + shouldIgnoreScale: shouldIgnoreScale) } if isRecord { @@ -243,7 +247,8 @@ public func recordDynamicSizeSnapshot(named name: String? = nil, sizes: [String: CGSize], isDeviceAgnostic: Bool = false, usesDrawRect: Bool = false, - resizeMode: ResizeMode = .frame) -> Predicate { + resizeMode: ResizeMode = .frame, + shouldIgnoreScale: Bool = false) -> Predicate { return Predicate { actualExpression in return performDynamicSizeSnapshotTest(name, identifier: identifier, @@ -252,7 +257,8 @@ public func recordDynamicSizeSnapshot(named name: String? = nil, usesDrawRect: usesDrawRect, actualExpression: actualExpression, isRecord: true, - resizeMode: resizeMode) + resizeMode: resizeMode, + shouldIgnoreScale: shouldIgnoreScale) } } diff --git a/Nimble_Snapshots/HaveValidSnapshot.swift b/Nimble_Snapshots/HaveValidSnapshot.swift index b8d94df..0e7d32d 100644 --- a/Nimble_Snapshots/HaveValidSnapshot.swift +++ b/Nimble_Snapshots/HaveValidSnapshot.swift @@ -45,13 +45,16 @@ public class FBSnapshotTest: NSObject { tolerance: CGFloat, perPixelTolerance: CGFloat, filename: String, - identifier: String? = nil) -> Bool { + identifier: String? = nil, + shouldIgnoreScale: Bool = false) -> Bool { let testName = parseFilename(filename: filename) let snapshotController: FBSnapshotTestController = FBSnapshotTestController(test: self) snapshotController.folderName = testName if isDeviceAgnostic { snapshotController.fileNameOptions = [.device, .OS, .screenSize, .screenScale] + } else if shouldIgnoreScale { + snapshotController.fileNameOptions = .none } else { snapshotController.fileNameOptions = .screenScale } @@ -199,7 +202,8 @@ private func performSnapshotTest(_ name: String?, usesDrawRect: Bool = false, actualExpression: Expression, pixelTolerance: CGFloat? = nil, - tolerance: CGFloat?) -> PredicateResult { + tolerance: CGFloat?, + shouldIgnoreScale: Bool) -> PredicateResult { // swiftlint:disable:next force_try force_unwrapping let instance = try! actualExpression.evaluate()! let testFileLocation = actualExpression.location.file @@ -212,7 +216,7 @@ private func performSnapshotTest(_ name: String?, usesDrawRect: usesDrawRect, snapshot: snapshotName, record: false, referenceDirectory: referenceImageDirectory, tolerance: tolerance, perPixelTolerance: pixelTolerance, - filename: actualExpression.location.file, identifier: identifier) + filename: actualExpression.location.file, identifier: identifier, shouldIgnoreScale: shouldIgnoreScale) return PredicateResult(status: PredicateStatus(bool: result), message: .fail("expected a matching snapshot in \(snapshotName)")) @@ -222,7 +226,8 @@ private func recordSnapshot(_ name: String?, identifier: String? = nil, isDeviceAgnostic: Bool = false, usesDrawRect: Bool = false, - actualExpression: Expression) -> PredicateResult { + actualExpression: Expression, + shouldIgnoreScale: Bool) -> PredicateResult { // swiftlint:disable:next force_try force_unwrapping let instance = try! actualExpression.evaluate()! let testFileLocation = actualExpression.location.file @@ -241,7 +246,8 @@ private func recordSnapshot(_ name: String?, tolerance: tolerance, perPixelTolerance: pixelTolerance, filename: actualExpression.location.file, - identifier: identifier) { + identifier: identifier, + shouldIgnoreScale: shouldIgnoreScale) { let name = name ?? snapshotName message = "snapshot \(name) successfully recorded, replace recordSnapshot with a check" } else if let name = name { @@ -264,14 +270,16 @@ public func haveValidSnapshot(named name: String? = nil, identifier: String? = nil, usesDrawRect: Bool = false, pixelTolerance: CGFloat? = nil, - tolerance: CGFloat? = nil) -> Predicate { + tolerance: CGFloat? = nil, + shouldIgnoreScale: Bool = false) -> Predicate { return Predicate { actualExpression in if switchChecksWithRecords { return recordSnapshot(name, identifier: identifier, usesDrawRect: usesDrawRect, - actualExpression: actualExpression) + actualExpression: actualExpression, + shouldIgnoreScale: shouldIgnoreScale) } return performSnapshotTest(name, @@ -279,7 +287,8 @@ public func haveValidSnapshot(named name: String? = nil, usesDrawRect: usesDrawRect, actualExpression: actualExpression, pixelTolerance: pixelTolerance, - tolerance: tolerance) + tolerance: tolerance, + shouldIgnoreScale: shouldIgnoreScale) } } @@ -287,7 +296,8 @@ public func haveValidDeviceAgnosticSnapshot(named name: String? = nil, identifier: String? = nil, usesDrawRect: Bool = false, pixelTolerance: CGFloat? = nil, - tolerance: CGFloat? = nil) -> Predicate { + tolerance: CGFloat? = nil, + shouldIgnoreScale: Bool = false) -> Predicate { return Predicate { actualExpression in if switchChecksWithRecords { @@ -295,7 +305,8 @@ public func haveValidDeviceAgnosticSnapshot(named name: String? = nil, identifier: identifier, isDeviceAgnostic: true, usesDrawRect: usesDrawRect, - actualExpression: actualExpression) + actualExpression: actualExpression, + shouldIgnoreScale: shouldIgnoreScale) } return performSnapshotTest(name, @@ -304,26 +315,31 @@ public func haveValidDeviceAgnosticSnapshot(named name: String? = nil, usesDrawRect: usesDrawRect, actualExpression: actualExpression, pixelTolerance: pixelTolerance, - tolerance: tolerance) + tolerance: tolerance, + shouldIgnoreScale: shouldIgnoreScale) } } public func recordSnapshot(named name: String? = nil, identifier: String? = nil, - usesDrawRect: Bool = false) -> Predicate { + usesDrawRect: Bool = false, + shouldIgnoreScale: Bool = false) -> Predicate { return Predicate { actualExpression in return recordSnapshot(name, identifier: identifier, usesDrawRect: usesDrawRect, - actualExpression: actualExpression) + actualExpression: actualExpression, + shouldIgnoreScale: shouldIgnoreScale) } } public func recordDeviceAgnosticSnapshot(named name: String? = nil, identifier: String? = nil, - usesDrawRect: Bool = false) -> Predicate { + usesDrawRect: Bool = false, + shouldIgnoreScale: Bool = false) -> Predicate { return Predicate { actualExpression in return recordSnapshot(name, identifier: identifier, isDeviceAgnostic: true, usesDrawRect: usesDrawRect, - actualExpression: actualExpression) + actualExpression: actualExpression, + shouldIgnoreScale: shouldIgnoreScale) } }