@@ -6,6 +6,19 @@ import TextDiff
66private let snapshotPrecision : Float = 0.995
77private let snapshotPerceptualPrecision : Float = 0.98
88
9+ func snapshotRecordMode(
10+ default defaultMode: SnapshotTestingConfiguration . Record = . missing
11+ ) -> SnapshotTestingConfiguration . Record {
12+ guard
13+ let rawValue = ProcessInfo . processInfo. environment [ " SNAPSHOT_TESTING_RECORD " ] ,
14+ let recordMode = SnapshotTestingConfiguration . Record ( rawValue: rawValue)
15+ else {
16+ return defaultMode
17+ }
18+
19+ return recordMode
20+ }
21+
922@MainActor
1023func assertTextDiffSnapshot(
1124 original: String ,
@@ -21,11 +34,12 @@ func assertTextDiffSnapshot(
2134 column: UInt = #column
2235) {
2336 configureSnapshotArtifactsDirectory ( filePath: filePath)
37+ let snapshotStyle = stableSnapshotStyle ( from: style)
2438
2539 let rootView = TextDiffView (
2640 original: original,
2741 updated: updated,
28- style: style ,
42+ style: snapshotStyle ,
2943 mode: mode
3044 )
3145 . frame ( width: size. width, height: size. height, alignment: . topLeading)
@@ -71,11 +85,12 @@ func assertNSTextDiffSnapshot(
7185 column: UInt = #column
7286) {
7387 configureSnapshotArtifactsDirectory ( filePath: filePath)
88+ let snapshotStyle = stableSnapshotStyle ( from: style)
7489
7590 let diffView = NSTextDiffView (
7691 original: original,
7792 updated: updated,
78- style: style ,
93+ style: snapshotStyle ,
7994 mode: mode
8095 )
8196
@@ -124,6 +139,41 @@ private func configureSnapshotArtifactsDirectory(filePath: StaticString) {
124139 setenv ( " SNAPSHOT_ARTIFACTS " , artifactsPath, 1 )
125140}
126141
142+ private func stableSnapshotStyle( from base: TextDiffStyle ) -> TextDiffStyle {
143+ var style = base
144+
145+ style. additionsStyle = stableSnapshotChangeStyle (
146+ from: base. additionsStyle,
147+ fillColor: NSColor (
148+ srgbRed: 0.29 ,
149+ green: 0.73 ,
150+ blue: 0.37 ,
151+ alpha: 1
152+ )
153+ )
154+ style. removalsStyle = stableSnapshotChangeStyle (
155+ from: base. removalsStyle,
156+ fillColor: NSColor (
157+ srgbRed: 0.96 ,
158+ green: 0.42 ,
159+ blue: 0.42 ,
160+ alpha: 1
161+ )
162+ )
163+
164+ return style
165+ }
166+
167+ private func stableSnapshotChangeStyle(
168+ from base: TextDiffChangeStyle ,
169+ fillColor: NSColor
170+ ) -> TextDiffChangeStyle {
171+ var style = base
172+ style. fillColor = fillColor
173+ style. strokeColor = fillColor
174+ return style
175+ }
176+
127177@MainActor
128178private func renderSnapshotImage1x( view: NSView , size: CGSize ) -> NSImage {
129179 let rep = NSBitmapImageRep (
0 commit comments