Skip to content

Commit

Permalink
Define which interface style the test should be run on from launch ar…
Browse files Browse the repository at this point in the history
…guments (#8)
  • Loading branch information
materik authored Sep 11, 2024
1 parent 786078a commit 629e1c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/SnapshotTestCase/Models/LaunchEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum LaunchEnvironment {
static let tolerance: String = "snapshotTolerance"
static let renderOffsetY: String = "snapshotRenderOffsetY"
static let renderScale: String = "snapshotRenderScale"
static let interfaceStyle: String = "snapshotInterfaceStyle"
static let recordMode: String = "-RecordingSnapshot"
}

Expand Down Expand Up @@ -42,4 +43,11 @@ enum LaunchEnvironment {
}
return Double(renderScale) ?? 1
}

static var interfaceStyle: InterfaceStyle? {
guard let rawValue = ProcessInfo.processInfo.environment[Key.interfaceStyle] else {
return nil
}
return InterfaceStyle(rawValue: rawValue)
}
}
5 changes: 5 additions & 0 deletions Sources/SnapshotTestCase/Snapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ public class Snapshot {
let failurePath: String
let recordMode: Bool
let tolerance: Double
let interfaceStyle: InterfaceStyle?

init() {
self.referencePath = LaunchEnvironment.referencePath
self.failurePath = LaunchEnvironment.failurePath
self.recordMode = LaunchEnvironment.recordMode
self.tolerance = LaunchEnvironment.tolerance
self.interfaceStyle = LaunchEnvironment.interfaceStyle
}

func verify(testCase: TestCase, with config: SnapshotConfig) async throws {
Expand All @@ -52,6 +54,9 @@ public class Snapshot {
}

func verify(testCase: TestCase, with config: SnapshotConfig.Config) async throws {
if let interfaceStyle, interfaceStyle != config.interfaceStyle {
return
}
if recordMode {
return try await record(testCase: testCase, with: config)
}
Expand Down

0 comments on commit 629e1c9

Please sign in to comment.