-
Notifications
You must be signed in to change notification settings - Fork 627
Added Snapshotting.json
for Any
value
#552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Snapshotting.json
for Any
value
#552
Conversation
Currently the only way to snapshot `Any` value is using `dump`. However, the format isn't always as readable as it can be. For data that can be encoded in JSON, this new overload provides a much more readable output.
The library ships with a And we have some tests to show how it works: swift-snapshot-testing/Tests/SnapshotTestingTests/SnapshotTestingTests.swift Lines 171 to 179 in 6bc120b
Does this cover your use case? |
In the test that I added I'm using an The specific use case I'm covering here is this: I have a type from an old Swift implementation that does "manual" JSON encoding into a |
Ah yes, I see now. Two things then: 1.) I think the strategy needs to be public, and 2.) could you update the test to use something that is not encodable, such as a |
`.sortedKeys` is only available from `macOS 10.13`.
Oh yes my bad, changed to As for the test, it's already using |
Ah ok, I breezed past that. We can leave it as-is. |
Anything else I can do? :) |
For #1045. Snapshot testing is a more maintainable and readable way to ensure that the output format doesn't change. In this case, I'm using it to test `ProductInfo.asDictionary()`, as a way to ensure that #1107 doesn't introduce changes. We can use this to check other types in the future, like `SubscriberAttribute`, `ETagAndResponseWrapper`, etc. This uses [`swift-snapshot-testing`](https://github.com/pointfreeco/swift-snapshot-testing). The simple line `try assertSnapshot(matching: productInfo.asDictionary(), as: .json)` automatically checks against a stored file (`PurchasesTests/Purchasing/__Snapshots__/ProductInfoTests/testEncoding.1.json`). If the output changes, the test error is very readable: <img width="228" alt="Screen Shot 2021-12-21 at 15 27 57" src="https://user-images.githubusercontent.com/685609/147010663-88eddc69-b106-46f5-a8b5-0ee927882282.png"> I've added the snapshot folder as a reference folder in Xcode, which makes looking at the expected output much easier than a bunch of Swift lines checking each value in a dictionary: <img width="178" alt="Screen Shot 2021-12-21 at 15 26 31" src="https://user-images.githubusercontent.com/685609/147010570-dd68f1ec-b0b0-4570-b59f-8451dcaf05e2.png"> I've also submitted a PR (pointfreeco/swift-snapshot-testing#552) based on the small extension added here.
Sorry for the delay. Thanks for this! |
Any chance we can get a release including this? |
* Added `Snapshotting.json` for `Any` value Currently the only way to snapshot `Any` value is using `dump`. However, the format isn't always as readable as it can be. For data that can be encoded in JSON, this new overload provides a much more readable output. * Fixed macOS build `.sortedKeys` is only available from `macOS 10.13`. * Public extension
Currently the only way to snapshot
Any
value is usingdump
. However, the format isn't always as readable as it could be.For data that can be encoded in JSON, this new overload provides a much more readable output.