From 41566005eda668c0e5dd476dc1e9d6e0cd0c456a Mon Sep 17 00:00:00 2001 From: Aleksei Kakoulin Date: Tue, 18 Jan 2022 09:25:29 +0300 Subject: [PATCH] Dell SnapshottingHEIC --- .../SnapshottingHEIC.swift | 133 ------------------ 1 file changed, 133 deletions(-) delete mode 100644 Sources/SnapshotTestingStitch/SnapshottingHEIC.swift diff --git a/Sources/SnapshotTestingStitch/SnapshottingHEIC.swift b/Sources/SnapshotTestingStitch/SnapshottingHEIC.swift deleted file mode 100644 index a791352..0000000 --- a/Sources/SnapshotTestingStitch/SnapshottingHEIC.swift +++ /dev/null @@ -1,133 +0,0 @@ -import UIKit -import SnapshotTesting -import SnapshotTestingHEIC - -public extension Snapshotting where Format == UIImage { - /// Stitches multiple visual snapshot strategies into a single image asset. - /// - /// - Parameters: - /// - tasks: The unnamed tasks which should be carried out, in the order that they should be displayed. - /// Any strategy can be used as long as the output format is UIImage. - /// - style: The style configuration which allows for you to customise the appearance of the output image, - /// including but not limited to the item spacing, and optional image borders. - /// - precision: The percentage of pixels that must match in the final comparison - /// in order for the test to successfully pass. - /// - compressionQuality: The desired compression quality to use when writing to an image destination. - static func stitchHEIC( - strategies tasks: [Snapshotting], - style: StitchStyle = .init(), - precision: Float = 1, - compressionQuality: CompressionQuality = .lossless - ) -> Snapshotting { - // Default to an empty string, if they choose not to provide one. - stitchHEIC( - strategies: tasks.map { .init(name: nil, strategy: $0, configure: nil) }, - style: style, - precision: precision, - compressionQuality: compressionQuality - ) - } - - /// Stitches multiple visual snapshot strategies into a single image asset. - /// - /// - Parameters: - /// - tasks: The named tasks which should be carried out, in the order that they should be displayed. - /// Titles will be displayed above their respectful image, allowing for easier identification. - /// Any strategy can be used as long as the output format is UIImage. - /// - style: The style configuration which allows for you to customise the appearance of the output image, - /// including but not limited to the item spacing, and optional image borders. - /// - precision: The percentage of pixels that must match in the final comparison - /// in order for the test to successfully pass. - /// - compressionQuality: The desired compression quality to use when writing to an image destination. - static func stitchHEIC( - strategies tasks: [(name: String, strategy: Snapshotting)], - style: StitchStyle = .init(), - precision: Float = 1, - compressionQuality: CompressionQuality = .lossless - ) -> Snapshotting { - stitchHEIC( - strategies: tasks.map { .init(name: $0.name, strategy: $0.strategy, configure: nil) }, - style: style, - precision: precision, - compressionQuality: compressionQuality - ) - } - - /// Stitches multiple visual snapshot strategies into a single image asset. - /// - /// - Parameters: - /// - tasks: The tasks which should be carried out, in the order that they should be displayed. - /// Tasks can include a title which will be displayed above their respectful image, - /// allowing for easier identification. Any strategy can be used as long as the output format is UIImage. - /// Tasks can can also contain a configuration block which allows for you to modify - /// the value just before it's snapshot is taken. - /// - style: The style configuration which allows for you to customise the appearance of the output image, - /// including but not limited to the item spacing, and optional image borders. - /// - precision: The percentage of pixels that must match in the final comparison - /// in order for the test to successfully pass. - /// - compressionQuality: The desired compression quality to use when writing to an image destination. - static func stitchHEIC( - strategies tasks: [StitchTask], - style: StitchStyle = .init(), - precision: Float = 1, - compressionQuality: CompressionQuality = .lossless - ) -> Snapshotting { - let internalStrategy: Snapshotting = .imageHEIC( - precision: precision, - compressionQuality: compressionQuality - ) - - return Snapshotting( - pathExtension: internalStrategy.pathExtension, - diffing: internalStrategy.diffing - ) { value in - Async { callback in - // Fail fast: Ensure we have tasks to complete, otherwise return an empty image. - // - // An empty image will render an error as part of the SnapshotTesting flow. - guard tasks.isEmpty == false else { - callback(UIImage()) - return - } - - // Create a dispatch group to keep track of the remaining tasks - let dispatchGroup = DispatchGroup() - - // Create an array to store the final outputs to be stitched - var values = [(index: Int, title: String?, output: UIImage)]() - - // Loop over each of the user-provided strategies, snapshot them, - // store the output, and update the dispatch group. - tasks.enumerated().forEach { index, task in - dispatchGroup.enter() - - var mutableValue = value - task.configure?(&mutableValue) - - task.strategy.snapshot(mutableValue).run { output in - values.append((index, task.name, output)) - dispatchGroup.leave() - } - } - - // Once all strategies have been completed... - dispatchGroup.notify(queue: .main) { - // Sort values based on input order - let sortedValues: [(String?, UIImage)] = values - .sorted(by: { lhs, rhs in lhs.index < rhs.index }) - .map { result in (result.title, result.output) } - - // Check to ensure all tasks have been returned - assert( - sortedValues.count == tasks.count, - "Inconsistant number of outputted values in comparison to inputted strategies" - ) - - // Stitch them together, and callback to the snapshot testing library. - let image = ImageStitcher(inputs: sortedValues).stitch(style: style) - callback(image) - } - } - } - } -}