Binary snapshots (in-memory)#610
Conversation
This is the somewhat simplified version of mitsuhiko#489 where we keep the full files in-memory during the assert and when reviewing.
…snapshots This merge is far from compiling. I just picked the side of each conflict that makes more sense to build upon.
…snapshots Still WIP like the previous merge.
This fixes the failing tests.
max-sixty
left a comment
There was a problem hiding this comment.
It's in impressive effort! And thank you for redoing on top of the new master.
It does add lots more data structures & some complications to the code. I'm going to think about how much we could simplify (I've already simplified the existing code somewhat..). If you have ideas, that would be great too.
FWIW I think the ontology is quite an interesting case — The proposed structure seems reasonable (as above I'd like to see if we can reduce the number of data structures a bit, but I don't think there are any easy large clean-ups) |
|
To sketch out what I think we need to do to merge:
|
|
Let's add a couple of examples to the docs and then hit the big button. Thank you very much for all your persistence here, I know it was a long road. It's a great feature for insta! |
|
The deleting of unreferenced snapshots does not work for binary snapshots yet. I'm working on fixing that now. |
Previously it only deleted the .snap file, but not the binary file next to it.
|
Now it works, but I'm not quite sure what the best error handling strategy there is. It needs to load the snapshot now to know whether it's binary and to get the extension. It still ignores errors when deleting the files like before. So I think it should probably also ignore errors when loading the snapshot and just skip it and maybe print a log message. |
The message "snapshots are matching" was previously printed when replacing a binary snapshot with an empty string text snapshot.
I meant to reply to this earlier but forgot: |
|
I've started adding a section for the website: https://github.com/mitsuhiko/insta-website/compare/main...lasernoises:insta-website:binary-snapshots?expand=1. I think I'll wait with opening a PR until this is merged. |
Yes v good point. Would be great to add the comment (but no need to slow down this PR ofc) |
|
@lasernoises anything else? Or we merge? :) |
|
I think from my point of view we can merge. |
|
🎉🎉🎉 Thank you so much for your patience and the many reviews/comments! |
|
Thank you!! |
This PR migrates us to insta's binary snapshots. These snapshots were added via - #1563 - mitsuhiko/insta#610 <details><summary>previous blockers</summary> <p> <del>Currently, this PR is not mergable as the binary snapshots don't actually work. I encountered these two bugs:</del> - [x] <del>the binary snapshots get created as `FILENAME.snap.new.png`. This naming is inconsistent with how other snapshots are created.</del> - [x] <del>Re-running the tests creates different metadata files which contain different data:</del> ```diff --- source: martin/src/sprites/mod.rs - assertion_line: 273 expression: png - extension: png - snapshot_kind: binary --- + ``` <del> Yes, I looked if I am using the same versions of insta, I am. `cargo test` and `cargo insta` still provide really weird results </del> <del> => to be mergable, this PR would need work upstream. I am going to try to write this up during the christmas holidays and provide a fix upstream.</del> </p> </details> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
The biggest difference to the previous attempt in #489 is that the snapshot contents are now kept in-memory instead of being written into a temporary file directly.
For
SnapshotContentsI decided to make it an enum with two variants like in the previous attempt. I first attempted to change it to three variants so it would also replace theSnapshotKindenum but I realized that a lot of logic is still shared between inline and file text snapshots. That approach would definitely also work though and it's perhaps also a question of how much the logic between the two is expected to diverge in the future.In
runtime::assert_snapshotI replaced the combination of therefvalandnew_snapshot_valuewith an enum. In that case it is a three variant enum and someFromimpls for two value tuples for the macros. Maybe it would be better to make it a two variant enum there too for consistency and keep theReferenceValueenum for the text case. That might be a bit weird because both binary and non-inline text snapshot have a name and that would then be in two different enums.I should probably also add some tests in
cargo-insta. I'll do that as soon as possible, but I need to figure out how the testing there works.