Skip to content

Commit 5bc3728

Browse files
Add parameter to make accessibilityImage run in host application optional. (#232)
Co-authored-by: Alex Odawa <[email protected]>
1 parent da453d2 commit 5bc3728

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Sources/AccessibilitySnapshot/SnapshotTesting/SnapshotTesting+Accessibility.swift

+8-4
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ extension Snapshotting where Value == UIView, Format == UIImage {
4444
/// - parameter markerColors: The array of colors which will be chosen from when creating the overlays.
4545
/// - parameter showUserInputLabels: Controls when to show elements' accessibility user input labels (used by Voice
4646
/// Control).
47+
/// - parameter shouldRunInHostApplication: Controls whether a host application is required to run the test or not.
4748
public static func accessibilityImage(
4849
showActivationPoints activationPointDisplayMode: ActivationPointDisplayMode = .whenOverridden,
4950
useMonochromeSnapshot: Bool = true,
5051
drawHierarchyInKeyWindow: Bool = false,
5152
markerColors: [UIColor] = [],
52-
showUserInputLabels: Bool = true
53+
showUserInputLabels: Bool = true,
54+
shouldRunInHostApplication: Bool = true
5355
) -> Snapshotting {
54-
guard isRunningInHostApplication else {
56+
guard !shouldRunInHostApplication || isRunningInHostApplication else {
5557
fatalError("Accessibility snapshot tests cannot be run in a test target without a host application")
5658
}
5759

@@ -257,15 +259,17 @@ extension Snapshotting where Value == UIViewController, Format == UIImage {
257259
useMonochromeSnapshot: Bool = true,
258260
drawHierarchyInKeyWindow: Bool = false,
259261
markerColors: [UIColor] = [],
260-
showUserInputLabels: Bool = true
262+
showUserInputLabels: Bool = true,
263+
shouldRunInHostApplication: Bool = true
261264
) -> Snapshotting {
262265
return Snapshotting<UIView, UIImage>
263266
.accessibilityImage(
264267
showActivationPoints: activationPointDisplayMode,
265268
useMonochromeSnapshot: useMonochromeSnapshot,
266269
drawHierarchyInKeyWindow: drawHierarchyInKeyWindow,
267270
markerColors: markerColors,
268-
showUserInputLabels: showUserInputLabels
271+
showUserInputLabels: showUserInputLabels,
272+
shouldRunInHostApplication: shouldRunInHostApplication
269273
)
270274
.pullback { viewController in
271275
viewController.view

Sources/AccessibilitySnapshot/SnapshotTesting/SnapshotTesting+SwiftUI.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,17 @@ extension Snapshotting where Value: SwiftUI.View, Format == UIImage {
5353
useMonochromeSnapshot: Bool = true,
5454
drawHierarchyInKeyWindow: Bool = false,
5555
markerColors: [UIColor] = [],
56-
showUserInputLabels: Bool = true
56+
showUserInputLabels: Bool = true,
57+
shouldRunInHostApplication: Bool = true
5758
) -> Snapshotting {
5859
return Snapshotting<UIViewController, UIImage>
5960
.accessibilityImage(
6061
showActivationPoints: activationPointDisplayMode,
6162
useMonochromeSnapshot: useMonochromeSnapshot,
6263
drawHierarchyInKeyWindow: drawHierarchyInKeyWindow,
6364
markerColors: markerColors,
64-
showUserInputLabels: showUserInputLabels
65+
showUserInputLabels: showUserInputLabels,
66+
shouldRunInHostApplication: shouldRunInHostApplication
6567
)
6668
.pullback { (view: Value) in
6769
let hostingController = UIHostingController(rootView: view)

0 commit comments

Comments
 (0)