Skip to content

Releases: pointfreeco/swift-snapshot-testing

1.16.0

05 Apr 20:46
Compare
Choose a tag to compare

What's Changed

  • Added: Inline snapshots can now be removed programmatically (#844).
  • Fixed: Test observer is now forced to register on the main queue (thanks @MarkVillacampa, #834).

New Contributors

Full Changelog: 1.15.4...1.16.0

1.15.4

04 Mar 21:41
5b0c434
Compare
Choose a tag to compare

What's Changed

  • Fixed: Bump swift-syntax requirements to support 5.10.0 (#836).

Full Changelog: 1.15.3...1.15.4

1.15.3

01 Feb 22:29
e7b7722
Compare
Choose a tag to compare

What's Changed

  • Fixed: Inline snapshots in test files containing a leading, whitespace-only line will no longer include this newline as leading trivia in the recording.

Full Changelog: 1.15.2...1.15.3

1.15.2

08 Jan 19:43
8e68404
Compare
Choose a tag to compare

What's Changed

  • Fixed: Support perceptual comparisons on platforms that do not support metal (thanks @ejensen, #666).
  • Fixed: Better support for WKWebView in Xcode 14 and Xcode 15 (thanks @teameh, #692).

Full Changelog: 1.15.1...1.15.2

1.15.1

27 Nov 19:02
59b663f
Compare
Choose a tag to compare

What's Changed

  • Improve the speed of comparing memory buffers by @ejensen in #664

Full Changelog: 1.15.0...1.15.1

1.15.0

14 Nov 23:06
4862d48
Compare
Choose a tag to compare

What's Changed

  • Added: assertInlineSnapshot now has record mode (#809).
  • Fixed: assertInlineSnapshot's failure difference now reads more correctly as the patch that would be applied were record mode to be on (#809).

Full Changelog: 1.14.2...1.15.0

1.14.2

13 Oct 18:14
bb0ea08
Compare
Choose a tag to compare

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

06 Oct 20:51
Compare
Choose a tag to compare

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

02 Oct 22:01
Compare
Choose a tag to compare

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

Full Changelog: 1.13.0...1.14.0

1.13.0

12 Sep 21:19
Compare
Choose a tag to compare

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:

    inline-snapshot

    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 called assertRequest, 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 and InlineSnapshotTesting 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