You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: CODE_OF_CONDUCT.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ This Code of Conduct applies both within project spaces and in public spaces whe
34
34
35
35
## Enforcement
36
36
37
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at mbw234@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
37
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at support@pointfree.co. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
38
39
39
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
Copy file name to clipboardexpand all lines: CONTRIBUTING.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -2,4 +2,4 @@
2
2
3
3
## Code of Conduct
4
4
5
-
This project and everyone participating in it is governed by its [Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to mbw234@gmail.com.
5
+
This project and everyone participating in it is governed by its [Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to support@pointfree.co.

9
+
-->
10
+
11
+
## Usage
8
12
9
-
Once the library [is installed](#installation), no additional configuration is required. You can import the `SnapshotTesting` module into a test and pass a value to the `assertSnapshot` function.
13
+
Once [installed](#installation), _no additional configuration is required_. You can import the `SnapshotTesting` module and call the `assertSnapshot` function.
10
14
11
15
```swift
12
16
importSnapshotTesting
@@ -21,15 +25,15 @@ class MyViewControllerTests: XCTestCase {
21
25
}
22
26
```
23
27
24
-
When the test first runs, a snapshot is recorded automatically to disk and the test will fail and print out the file path of the reference.
28
+
When an assertion first runs, a snapshot is automatically recorded to disk and the test will fail, printing out the file path of any newly-recorded reference.
Repeat test runs will load this reference for comparison. If the images don't match, the test will fail and print out the file path of each image for further inspection.
34
+
Repeat test runs will load this reference and compare it with the runtime value. If they don't match, the test will fail and describe the difference.
31
35
32
-
You can record a new reference by setting `record` mode to `true` on the assertion or globally.
36
+
You can record a new reference by setting the `record` mode to `true` on the assertion or globally.
While most snapshot testing libraries in the Swift community are limited to `UIView`s and `UIImage`s, SnapshotTesting can work with _any_ value and _any_ format on _any_ Swift platform!
50
+
51
+
The `assertSnapshot` function accepts a value and any snapshot strategy that value supports. This means that a [view](Documentation/Available-Snapshot-Strategies.md#uiview) or [view controller](Documentation/Available-Snapshot-Strategies.md#uiviewcontroller) can be tested against an image representation _and_ against a textual representation of its properties and subview hierarchy.
View testing is [highly configurable](Documentation/Available-Snapshot-Strategies.md#uiviewcontroller). You can override trait collections (for specific size classes and content size categories) and generate device-agnostic snapshots, all from a single simulator.
Better yet, SnapshotTesting isn't limited to views and view controllers! There are [a number of available snapshot strategies](Documentation/Available-Snapshot-Strategies.md) to choose from.
68
+
69
+
For example, you can snapshot test URL requests (_e.g._, those that your API client prepares).
70
+
71
+
```swift
72
+
assertSnapshot(matching: urlRequest, as: .raw)
73
+
// POST http://localhost:8080/account
74
+
// Cookie: pf_session={"userId":"1"}
75
+
//
76
+
// email=blob%40pointfree.co&name=Blob
77
+
```
78
+
79
+
And you can snapshot test `Encodable` values against their JSON _and_ property list representations.
80
+
81
+
```swift
82
+
assertSnapshot(matching: user, as: .json)
83
+
// {
84
+
// "bio" : "Blobbed around the world.",
85
+
// "id" : 1,
86
+
// "name" : "Blobby"
87
+
// }
88
+
89
+
assertSnapshot(matching: user, as: .plist)
90
+
// <?xml version="1.0" encoding="UTF-8"?>
91
+
// <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
92
+
// <plist version="1.0">
93
+
// <dict>
94
+
// <key>bio</key>
95
+
// <string>Blobbed around the world.</string>
96
+
// <key>id</key>
97
+
// <integer>1</integer>
98
+
// <key>name</key>
99
+
// <string>Blobby</string>
100
+
// </dict>
101
+
// </plist>
102
+
```
103
+
104
+
In fact, _[any](Documentation/Available-Snapshot-Strategies.md#any)_ value can be snapshot-tested by default using its [mirror](https://developer.apple.com/documentation/swift/mirror)!
105
+
106
+
```swift
107
+
assertSnapshot(matching: user, as: .dump)
108
+
// ▿ User
109
+
// - bio: "Blobbed around the world."
110
+
// - id: 1
111
+
// - name: "Blobby"
112
+
```
113
+
114
+
If your data can be represented as an image, text, or data, you can write a snapshot test for it! Check out [all of the snapshot strategies](Documentation/Available-Snapshot-Strategies.md) that ship with SnapshotTesting and [learn how to define your own custom strategies](Documentation/Defining-Custom-Snapshot-Strategies.md).
48
115
49
116
## Installation
50
117
@@ -53,7 +120,7 @@ TODO
53
120
If you use [Carthage](https://github.com/Carthage/Carthage), you can add the following dependency to your `Cartfile`:
Renderable data will write as an image. This includes `UIImage`s and `NSImage`s, but also data that is typically viewed visually, like `UIView`s and `NSView`s.
128
-
129
-
Given a view:
130
-
131
-
```swift
132
-
importSnapshotTesting
133
-
importXCTest
134
-
135
-
classHomepageTests: XCTestCase {
136
-
functestRender() {
137
-
let size =CGSize(width: 800, height: 600)
138
-
let webView =UIWebView(frame: .init(origin: .zero, size: size))
139
-
webView.loadHTMLString(renderHomepage())
140
-
141
-
assertSnapshot(matching: webView)
142
-
}
143
-
}
144
-
```
146
+
## Features
145
147
146
-
The above will write to an image on disk. If that image ever renders differently in the future, the assertion will fail and produce a diff for inspection.
148
+
-[**Dozens of snapshot strategies**](Documentation/Available-Snapshot-Strategies.md). Snapshot testing isn't just for `UIView`s and `CALayer`s. Write snapshots against _any_ value.
149
+
-[**Write your own snapshot strategies**](Documentation/Defining-Custom-Snapshot-Strategies.md). If you can convert it to an image, string, data, or your own diffable format, you can snapshot test it! Build your own snapshot strategies from scratch or transform existing ones.
150
+
-**No configuration required.** Don't fuss with scheme settings and environment variables. Snapshots are automatically saved alongside your tests.
151
+
-**More hands-off.** New snapshots are recorded whether `record` mode is `true` or not.
152
+
-**Subclass-free.** Assert from any XCTest case or Quick spec.
153
+
-**Device-agnostic snapshots.** Render views and view controllers for specific devices and trait collections from a single simulator.
154
+
-**First-class Xcode support.** Image differences are captured as XCTest attachments. Text differences are rendered in inline error messages.
155
+
-**Supports any platform that supports Swift.** Write snapshot tests for iOS, Linux, macOS, and tvOS.
156
+
-**SceneKit, SpriteKit, and WebKit support.** Most snapshot testing libraries don't support these view subclasses.
157
+
-**`Codable` support**. Snapshot encodable data structures into their [JSON](Documentation/Available-Snapshot-Strategies.md#json) and [property list](Documentation/Available-Snapshot-Strategies.md#plist) representations.
SnapshotTesting was designed with [witness-oriented programming](https://www.pointfree.co/episodes/ep39-witness-oriented-library-design).
150
163
151
-
## Related Tools
164
+
This concept (and more) are explored thoroughly in a series of episodes on [Point-Free](https://www.pointfree.co), a video series exploring functional programming and Swift hosted by [Brandon Williams](https://github.com/mbrandonw) and [Stephen Celis](https://github.com/stephencelis).
152
165
153
-
-[`FBSnapshotTestCase`](https://github.com/facebook/ios-snapshot-test-case) helped introduce screen shot testing to a broad audience in the iOS community. Experience with it inspired the creation of this library.
166
+
Witness-oriented programming was explored in the following episodes:
154
167
155
-
-[`Jest`](http://facebook.github.io/jest/) brought generalized snapshot testing to the front-end with a polished user experience. Several features of this library (diffing, tracking outdated snapshots) were directly influenced.
168
+
-[Episode 33](https://www.pointfree.co/episodes/ep33-protocol-witnesses-part-1): Protocol Witnesses: Part 1
169
+
-[Episode 34](https://www.pointfree.co/episodes/ep34-protocol-witnesses-part-1): Protocol Witnesses: Part 2
170
+
-[Episode 35](https://www.pointfree.co/episodes/ep35-advanced-protocol-witnesses-part-1): Advanced Protocol Witnesses: Part 1
171
+
-[Episode 36](https://www.pointfree.co/episodes/ep36-advanced-protocol-witnesses-part-2): Advanced Protocol Witnesses: Part 2
172
+
-[Episode 37](https://www.pointfree.co/episodes/ep37-protocol-oriented-library-design-part-1): Protocol-Oriented Library Design: Part 1
173
+
-[Episode 38](https://www.pointfree.co/episodes/ep38-protocol-oriented-library-design-part-2): Protocol-Oriented Library Design: Part 2
0 commit comments