Skip to content

Commit 11fce56

Browse files
committed
Standardize AppKitBackend CI rendering env's dpi and color space
Credit goes to pointfreeco/swift-snapshot-testing#533
1 parent 1f66029 commit 11fce56

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

.github/workflows/swift-macos.yml

-6
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,3 @@ jobs:
3838
swift build --target GtkExample
3939
- name: Test
4040
run: swift test --test-product swift-cross-uiPackageTests
41-
- name: Upload snapshot
42-
uses: actions/upload-artifact@v4
43-
if: always()
44-
with:
45-
name: snapshot
46-
path: snapshot.tiff

Sources/AppKitBackend/AppKitBackend.swift

+10
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,16 @@ class NSSplitViewResizingDelegate: NSObject, NSSplitViewDelegate {
14021402
public class NSCustomWindow: NSWindow {
14031403
var resizeDelegate = ResizeDelegate()
14041404

1405+
/// Allows the backing scale factor to be overridden. Useful for keeping
1406+
/// UI tests consistent across devices.
1407+
///
1408+
/// Idea from https://github.com/pointfreeco/swift-snapshot-testing/pull/533
1409+
public var backingScaleFactorOverride: CGFloat?
1410+
1411+
public override var backingScaleFactor: CGFloat {
1412+
backingScaleFactorOverride ?? super.backingScaleFactor
1413+
}
1414+
14051415
class ResizeDelegate: NSObject, NSWindowDelegate {
14061416
var resizeHandler: ((SIMD2<Int>) -> Void)?
14071417

Tests/SwiftCrossUITests/SwiftCrossUITests.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ final class SwiftCrossUITests: XCTestCase {
6868
func testBasicLayout() throws {
6969
let backend = AppKitBackend()
7070
let window = backend.createWindow(withDefaultSize: SIMD2(200, 200))
71+
72+
// Idea taken from https://github.com/pointfreeco/swift-snapshot-testing/pull/533
73+
// and implemented in AppKitBackend.
74+
window.backingScaleFactorOverride = 1
75+
window.colorSpace = .genericRGB
76+
7177
let environment = EnvironmentValues(backend: backend)
7278
.with(\.window, window)
7379
let viewGraph = ViewGraph(
@@ -86,11 +92,9 @@ final class SwiftCrossUITests: XCTestCase {
8692
backend.setSize(of: view, to: result.size.size)
8793
backend.setSize(ofWindow: window, to: result.size.size)
8894

89-
try Self.snapshotView(view).write(to: URL(fileURLWithPath: "snapshot.tiff"))
90-
9195
XCTAssertEqual(
9296
result.size,
93-
ViewSize(fixedSize: SIMD2(94, 95)),
97+
ViewSize(fixedSize: SIMD2(88, 95)),
9498
"View update result mismatch"
9599
)
96100

0 commit comments

Comments
 (0)