1.13.0 #770
stephencelis
started this conversation in
General
1.13.0
#770
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What's Changed
Added: Inline Snapshot Testing (Formalize 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 (Inline Snapshot Testing #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: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:After this assertion runs, the test source code is updated in place:
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.
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:
And when we first run the test, it will automatically expand:
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 (DocC + swift-format #765). The
SnapshotTesting
andInlineSnapshotTesting
are fully documented using DocC.Infrastructure: swift-format support (DocC + swift-format #765). The library is now auto-formatted using swift-format.
Full Changelog: 1.12.0...1.13.0
This discussion was created from the release 1.13.0.
Beta Was this translation helpful? Give feedback.
All reactions