Releases: pointfreeco/swift-snapshot-testing
1.14.2
What's Changed
- Fixed: Inline snapshots are now prepared before emitting an XCTest failure, ensuring the artifact is written (#787).
- Fixed:
assertCustomInline()
no longer leaves empty parens hanging around when expanded (#788). - Fixed: The
swift-syntax
dependency has widened to support 508.0.1..<510.0.0, allowing the library to be depended on even when another package depends on 508.0.1 (#795). - Infrastructure: Updated SPI configuration for watchOS (thanks @finestructure, #789).
Full Changelog: 1.14.1...1.14.2
1.14.1
What's Changed
- Fixed: Avoid inline snapshot trailing closure index crash (#786).
- Infrastructure: Update .spi.yml to show watchOS support (thanks @finestructure, #785).
Full Changelog: 1.14.0...1.14.1
1.14.0
What's Changed
- Added: Support for inline snapshot API migrations (#779)
- Updated: Pinned SwiftSyntax to 509.0.0 (#774).
- Fixed: Escape carriage returns explicitly in inline snapshots (#772).
- Infrastructure: CONTRIBUTING.md fixes (thanks @soo941226, #773).
New Contributors
- @soo941226 made their first contribution in #773
Full Changelog: 1.13.0...1.14.0
1.13.0
What's Changed
-
Added: Inline Snapshot Testing (#764). This allows your text-based snapshots to live right in the test source code, rather than in an external file:
While the library has had experimental support for this feature since 1.5.0 thanks to @rjchatfield (#199), we've finally put the finishing touches to it:
-
Inline snapshot testing is available in a separate
InlineSnapshotTesting
module. To use inline snapshot testing, add a dependency on this module and update your existing imports:-import SnapshotTesting +import InlineSnapshotTesting
The feature has been rewritten to use SwiftSyntax. While a heavyweight dependency, it is a more reasonable tool for generating Swift code than string substitution, and will be an increasingly common dependency as the de facto tool for writing Swift macros.
The main
SnapshotTesting
module does not depend on SwiftSyntax, so existing snapshot tests will not incur cost of compiling SwiftSyntax. -
The API now follows the same structure as
assertSnapshot
, except it uses a trailing closure to capture the inline snapshot. This makes it easy to update an existing snapshot test to use inline snapshots:-assertSnapshot(of: user, as: .json) +assertInlineSnapshot(of: user, as .json)
After this assertion runs, the test source code is updated in place:
assertInlineSnapshot(of: user, as: .json) { """ { "id" : 42, "isAdmin" : true, "name" : "Blob" } """ }
These trailing closures are easy to select in Xcode in order to delete and re-record a snapshot: simply double-click one of the braces to highlight the closure, delete, and run the test.
-
Inline snapshotting's
assertInlineSnapshot
testing tool is fully customizable so that you can build your own testing helpers on top of it without your users even knowing they are using snapshot testing. In fact, we do this to create a testing tool that helps us test the Swift code that powers Point-Free. It's calledassertRequest
, and it allows you to simultaneously assert the request being made to the server (including URL, query parameters, headers, POST body) as well as the response from the server (including status code and headers).For example, to test that when a request is made for a user to join a team subscription, we can write the following:
await assertRequest( connection( from: request( to: .teamInviteCode(.join(code: subscription.teamInviteCode, email: nil)), session: .loggedIn(as: currentUser) ) ) )
And when we first run the test it will automatically expand:
await assertRequest( connection( from: request( to: .teamInviteCode(.join(code: subscription.teamInviteCode, email: nil)), session: .loggedIn(as: currentUser) ) ) ) { """ POST http://localhost:8080/join/subscriptions-team_invite_code3 Cookie: pf_session={"userId":"00000000-0000-0000-0000-000000000001"} """ } response: { """ 302 Found Location: /account Referrer-Policy: strict-origin-when-cross-origin Set-Cookie: pf_session={"flash":{"message":"You now have access to Point-Free!","priority":"notice"},"userId":"00000000-0000-0000-0000-000000000001"}; Expires=Sat, 29 Jan 2028 00:00:00 GMT; Path=/ X-Content-Type-Options: nosniff X-Download-Options: noopen X-Frame-Options: SAMEORIGIN X-Permitted-Cross-Domain-Policies: none X-XSS-Protection: 1; mode=block """ }
This shows that the response redirects the use back to their account page and shows them the flash message that they now have full access to Point-Free. This makes writing complex and nuanced tests incredibly easy, and so there is no reason to not write lots of tests for all the subtle edge cases of your application's logic.
-
-
Added: DocC documentation (#765). The
SnapshotTesting
andInlineSnapshotTesting
are fully documented using DocC. -
Infrastructure: swift-format support (#765). The library is now auto-formatted using swift-format.
Full Changelog: 1.12.0...0.13.0
1.12.0
What's Changed
- Added:
assertSnapshot(of:)
is now the default interface for snapshot assertions (#762).assertSnapshot(matching:)
will remain in 1.x as a soft-deprecated alias. - Infrastructure: Add to README plug-ins (thanks @BarredEwe, #746; @tahirmt, #763).
- Infrastructure: Don't ignore Package.resolved (#649).
New Contributors
- @BarredEwe made their first contribution in #746
Full Changelog: 1.11.1...1.12.0
1.11.1
What's Changed
- Fixed: Xcode 15 support (thanks @finestructure, #737).
- Infrastructure: Add PreviewSnapshots to README "Plug-ins" (thanks @jflan-dd, #696)
Full Changelog: 1.11.0...1.11.1
1.11.0
What's Changed
- Added: Image paths in Xcode XCTest output are now clickable (thanks @RufusMall, #675).
- Fixed: Silenced SPM warnings by excluding snapshots and fixtures in Package manifest (thanks @valeriyvan, #684).
- Fixed: 1.10.0 erroneously bumped platform requirements. This release reverts compatibility to align with previous versions (#698).
- Infrastructure: Fixed Ubuntu CI by locking version (#685).
New Contributors
- @RufusMall made their first contribution in #675
Full Changelog: 1.10.0...1.11.0
1.10.0
Changes that may affect your build requirements
- The package name has been changed from
SnapshotTesting
toswift-snapshot-testing
, to better reflect community naming conventions (#555). This may require you to update anyPackage.swift
files that depend on Snapshot Testing. - Support for CocoaPods and Carthage has been obsoleted. No new releases will be available on those platforms, starting with 1.10.0. Please use the Swift Package Manager to depend on Snapshot Testing.
- Snapshot Testing now requires Swift 5.5+, as well at iOS 13+, macOS 10.15+, tvOS 13+, and watchOS 6+.
Changes that may affect snapshot format/output
Warning: The following updates change how a strategy may output a snapshot, causing existing snapshot suites to fail. When upgrading, please rerecord your failing snapshots and audit the changes.
- Fixed: A UIViewController strategy was not passing along the correct trait collection (thanks @arnopoulos, #554).
- Fixed: iPhone XS Max portrait configuration was not applying base traits (thanks @imvm, #417)
- Fixed: URLRequest strategy now sorts query items for more consistent diffing (thanks @mihai8804858, #491).
- Removed: GLKView is no longer supported (thanks @jpsim, #507).
Everything else
- Added: Image-based strategies have a new
perceptualPrecision
option, which can be used to support snapshot tests across Intel and M1 devices. Along for the ride is a 90+% speed improvement to the strategies (thanks @ejensen, #628). - Added: Windows support, CI (thanks @MaxDesiatov, #532).
- Added: Failure messages now include the snapshot name, if given (thanks @calda, #547).
- Added: iPhone 13 configs (thanks @luispadron, #603).
- Added: iPad 9.7" and iPad 10.2" configs (thanks @skols85, #405).
- Added: iPhone 12 and iPhone 12 Pro Max configs(thanks @imvm, #418).
- Added:
Snapshotting.json
forAny
value (thanks @NachoSoto, #552). - Added: Newly-recorded snapshots are now attached to the test run (thanks @marcelofabri, #586).
- Fixed: the UIImage strategy was using the device scale instead of the scale of the given images (thanks @codeman9, #472).
- Fixed: the UIImage strategy now compares image contexts using the same colorspace (thanks @dflems, #446).
- Fixed: the WebView strategy no longer overrides the delegate (thanks @teameh in #443).
- Fixed: Patched a leak when running tests in a host application (thanks @llinardos, #511).
- Fixed: False positive when asserting reference image with empty image (thanks @nuno-vieira, #453).
- Fixed: watchOS compilation (thanks @aydegee, #579).
- Fixed: Support for repeatedly running tests (thanks @krzysztofpawski, #585).
- Infrastructure: Add
swift-snapshot-testing-stitch
to plugins list (thanks @Sherlouk, #483) - Infrastructure: Document diff tool configuration.
- Infrastructure: README updates (thanks @MaatheusGois, @gohanlon), documentation fixes (thanks @heckj, @valeriyvan).
- Infrastructure: Added GitHub issue templates (#556).
- Infrastructure: Add SnapshotTestingHEIC to plugins list (thanks @alexey1312, #561).
New Contributors
- @arietis made their first contribution in #468
- @codeman9 made their first contribution in #472
- @Nikoloutsos made their first contribution in #482
- @mihai8804858 made their first contribution in #491
- @dflems made their first contribution in #446
- @skols85 made their first contribution in #405
- @imvm made their first contribution in #418
- @teameh made their first contribution in #443
- @MaatheusGois made their first contribution in #496
- @calda made their first contribution in #547
- @MaxDesiatov made their first contribution in #532
- @jpsim made their first contribution in #507
- @arnopoulos made their first contribution in #554
- @llinardos made their first contribution in #511
- @heckj made their first contribution in #601
- @aydegee made their first contribution in #579
- @valeriyvan made their first contribution in #630
- @ejensen made their first contribution in #628
- @luispadron made their first contribution in #603
- @alexey1312 made their first contribution in #561
- @gohanlon made their first contribution in #592
- @marcelofabri made their first contribution in #586
- @nuno-vieira made their first contribution in #453
- @krzysztofpawski made their first contribution in #585
Full Changelog: 1.9.0...1.10.0
1.9.0
- Added: publicized
data
snapshotting strategy (thanks @regexident). - Speed up
NSImage
comparison (thanks @finestructure, @JaapWijnen). - Fixed: enabled testing search paths (thanks @thedavidharris).
- Infrastructure: links for AccessibilitySnapshot and AccessibilitySnapshotColorBlindness (thanks @Sherlouk).
1.8.2
- Rename
SnapshotTesting.record
toSnapshotTesting.isRecording
to avoid clash with XCTestCase's newrecord
method (thanks @xavierLowmiller). - Fix UIApplication selector to return the application as expected (thanks @mstultz).
- Fix key window warning (thanks @tinder-maxwellelliott)