-
Notifications
You must be signed in to change notification settings - Fork 208
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
utopia-gen: Use insta
for snapshot testing
#1247
Conversation
Try running tests with |
The tests seems to fail because there are snapshots that are not generated for tests run with |
yeah, I must've missed running them for some reason. should be fixed now though :) |
insta
for snapshot testinginsta
for snapshot testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty neat, 🥇 Perhaps we could push this insta
bit further and migrate to it all the way. Though not necessarily in this PR as it is quite a lot of tests but could be done in future. 🤔
And like before, the CHANGELOG.md entry would be useful 🙂 It is bit annoying extra step but allows better change tracking for other developers who are interested of changed details. |
hmm, which changelog would this go into (utoipa-gen?)? and under which category (Changes?)?
yep, should be relatively straight-forward to incrementally migrate the other tests too. open question would be whether to use inline snapshots or regular ones like in this PR. the inline snapshots are closer to the current usage with I personally tend to use inline snapshots when the snapshot is relatively short, but with the amount of data that we're snapshotting here, I think I would use regular ones. |
`insta` produces diffs like the following, which makes it much easier to see at first glance what changed. The `cargo-insta` extension also makes it very fast to update snapshots in case of any desired changes. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Snapshot Summary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Snapshot file: utoipa-gen/tests/snapshots/schema_generics__generic_schema_full_api.snap Snapshot: generic_schema_full_api Source: utoipa-gen/tests/schema_generics.rs:221 ──────────────────────────────────────────────────────────────────────────────── Expression: doc ──────────────────────────────────────────────────────────────────────────────── -old snapshot +new results ────────────┬─────────────────────────────────────────────────────────────────── 64 64 │ "items" 65 65 │ ], 66 66 │ "properties": { 67 67 │ "items": { 68 │- "type": "object", 68 │+ "type": "array", 69 69 │ "items": { 70 70 │ "type": "object", 71 71 │ "required": [ 72 72 │ "id", ────────────┴─────────────────────────────────────────────────────────────────── To update snapshots run `cargo insta review`
|
okay, should be added correctly now :) |
Yeah, probably which ever comes easier, since there will be quite a few tests. I guess convention to keep the test file name same as the test function name makes it easier to find. |
I saw in #145 that snapshot testing had been considered in the past, but then
assert-json-diff
was used instead. This PR migrates a couple of theutoipa-gen
tests to useinsta
instead of performing a basic string comparison.insta
produces diffs like below, which makes it much easier to see at first glance what changed. Thecargo-insta
extension also makes it very fast to update snapshots in case of any desired changes.If this is considered useful we could potentially also migrate the other tests to use snapshots instead of
assert-json-diff
.