Skip to content

Commit ecbb206

Browse files
committed
tests: render snapshot baselines at fixed 1x scale
1 parent 74b9483 commit ecbb206

8 files changed

Lines changed: 26 additions & 2 deletions

Tests/TextDiffTests/SnapshotTestSupport.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ func assertTextDiffSnapshot(
3131
hostingView.appearance = NSAppearance(named: .aqua)
3232
hostingView.layoutSubtreeIfNeeded()
3333

34+
let snapshotImage = renderSnapshotImage1x(view: hostingView, size: size)
35+
3436
assertSnapshot(
35-
of: hostingView,
36-
as: .image(size: size),
37+
of: snapshotImage,
38+
as: .image,
3739
named: name,
3840
fileID: fileID,
3941
file: filePath,
@@ -42,3 +44,25 @@ func assertTextDiffSnapshot(
4244
column: column
4345
)
4446
}
47+
48+
@MainActor
49+
private func renderSnapshotImage1x(view: NSView, size: CGSize) -> NSImage {
50+
let rep = NSBitmapImageRep(
51+
bitmapDataPlanes: nil,
52+
pixelsWide: Int(size.width),
53+
pixelsHigh: Int(size.height),
54+
bitsPerSample: 8,
55+
samplesPerPixel: 4,
56+
hasAlpha: true,
57+
isPlanar: false,
58+
colorSpaceName: .deviceRGB,
59+
bytesPerRow: 0,
60+
bitsPerPixel: 0
61+
)!
62+
rep.size = size
63+
view.cacheDisplay(in: view.bounds, to: rep)
64+
65+
let image = NSImage(size: size)
66+
image.addRepresentation(rep)
67+
return image
68+
}
-5.53 KB
Loading
-13.5 KB
Loading
-6.79 KB
Loading
-12.5 KB
Loading
-4.79 KB
Loading
-10.1 KB
Loading
-4.79 KB
Loading

0 commit comments

Comments
 (0)