Skip to content

Commit 9810df4

Browse files
committed
wip
1 parent 9d2c475 commit 9810df4

File tree

3 files changed

+59
-14
lines changed

3 files changed

+59
-14
lines changed

Sources/SnapshotTesting/AssertSnapshot.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ public func verifySnapshot<Value, Format>(
278278

279279
guard
280280
record != .all,
281-
record != .missing
282-
|| fileManager.fileExists(atPath: snapshotFileUrl.path)
281+
record != .missing || fileManager.fileExists(atPath: snapshotFileUrl.path)
283282
else {
284283
try snapshotting.diffing.toData(diffable).write(to: snapshotFileUrl)
285284
#if !os(Linux) && !os(Windows)

Sources/SnapshotTesting/Documentation.docc/Articles/IntegratingWithTestFrameworks.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct FeatureTests {
8181
}
8282
```
8383

84-
> Note: You must import SnapshotTesting with the `@_spi(Experimental)` attribute to get access to
85-
this functionality because Swift Testing's own `CustomExecutionTrait` is hidden behind the same
84+
> Important: You must import SnapshotTesting with the `@_spi(Experimental)` attribute to get access
85+
to this functionality because Swift Testing's own `CustomExecutionTrait` is hidden behind the same
8686
SPI flag. This means this API is subject to change in the future, but hopefully Apple will
8787
publicize this tool soon.

Sources/SnapshotTesting/Documentation.docc/Articles/MigrationGuides/MigratingTo1.17.md

+56-10
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,66 @@ allows you to customize how the `assertSnapshot` tool behaves for a well-defined
4343
Rather than overriding `isRecording` or `diffTool` directly in your tests, you can wrap your test in
4444
`withSnapshotTesting`:
4545

46-
```swift
47-
withSnapshotTesting(diffTool: .ksdiff, record: .all) {
48-
// Assertions in here
46+
@Row {
47+
@Column {
48+
```swift
49+
// Before
50+
51+
func testFeature() {
52+
isRecording = true
53+
diffTool = "ksdiff"
54+
assertSnapshot(…)
55+
}
56+
```
57+
}
58+
@Column {
59+
```swift
60+
// After
61+
62+
func testFeature() {
63+
withSnapshotTesting(record: .all, diffTool: .ksdiff) {
64+
assertSnapshot(…)
65+
}
66+
}
67+
```
68+
}
4969
}
50-
```
5170

5271
If you want to override the options for an entire test class, you can override the `invokeTest`
5372
method of `XCTestCase`:
5473

55-
```swift
56-
class FeatureTests: XCTestCase {
57-
override func invokeTest() {
58-
withSnapshotTesting(diffTool: .ksdiff, record: .all) {
59-
super.invokeTest()
74+
@Row {
75+
@Column {
76+
```swift
77+
// Before
78+
79+
class FeatureTests: XCTestCase {
80+
override func invokeTest() {
81+
isRecording = true
82+
diffTool = "ksdiff"
83+
defer {
84+
isRecording = false
85+
diffTool = nil
86+
}
87+
super.invokeTest()
88+
}
89+
}
90+
```
91+
}
92+
@Column {
93+
```swift
94+
// After
95+
96+
class FeatureTests: XCTestCase {
97+
override func invokeTest() {
98+
withSnapshotTesting(diffTool: .ksdiff, record: .all) {
99+
super.invokeTest()
100+
}
101+
}
60102
}
103+
```
61104
}
62105
}
63-
```
64106

65107
And if you want to override these settings for _all_ tests, then you can implement a base
66108
`XCTestCase` subclass and have your tests inherit from it.
@@ -117,3 +159,7 @@ struct FeatureTests {
117159
```
118160

119161
That will override the `diffTool` and `record` options for the entire `FeatureTests` suite.
162+
163+
> Important: As evident by the usage of `@_spi(Experimental)` this API is subject to change. As
164+
soon as the Swift Testing library finalizes its API for `CustomExecutionTrait` we will update
165+
the library accordingly and remove the `@_spi` annotation.

0 commit comments

Comments
 (0)