zachallaun
Mneme - Snapshot testing tool for the busy programmer
I’d like to announce Mneme, a snapshot testing tool I’ve been working on.
I’ll keep this post short for now. This has been a lot of fun to work on and I hope that others find it useful! Please feel free to post any comments/feedback here, or issues on GitHub.
Most Liked
zachallaun
Getting closer to the next sizable update to Mneme and wanted to share! After noticing that it can sometimes be difficult to visually parse what changed when an auto-generated value updates, I started working on semantic diffing, using the amazing Difftastic as reference and inspiration.
This has proved more of a rabbit hole than I initially thought, but is still relatively easy thanks to Elixir’s general awesomeness. Today I reached the point where my semantic diff development branch can start using semantic diffs to work on semantic diffs!
For instance, here’s what an update might look like using the latest release:
Here’s the same update using semantic diffs:
There’s still a ways to go before this lands, but I’m hoping that being able to use semantic diffs in development will help expose edge-cases/etc. before I ship the feature.
zachallaun
v0.2 released
Note: Mneme now requires Elixir v1.14 or later.
defp deps do
[
{:mneme, "~> 0.2.1", only: :test}
]
end
Semantic diffs
In addition to some quality-of-life changes when things go wrong, the big feature that v0.2 brings is a custom diff engine that produces dramatically more readable diffs when auto-assertions are updated. I’m really excited about this and it’s made Mneme much more pleasant to use, at least for me.
I expect there to be some formatting bugs – please report them on GitHub if you encounter anything weird! If you desire the old behavior, you can configure Mneme to continue using textual diffs as before.
Example 1. New assertions highlight only the new value
Text
Semantic
Example 2. Changed assertions highlight deleted/added nodes
Text
Semantic
Example 3. Slightly changed strings call out the changed portion
Text
Semantic
Future work
- Diff quality: These diffs could still be improved. For instance, example 2 highlighted a suboptimal set of square brackets.
- Performance: For large expressions, semantic diffs will take too long and it will fall back to text diffs. I’m sure there’s still some low-hanging fruit for improving performance, however.
- Formatting: I’d like to add side-by-side formatting to decrease the vertical real-estate needed. I’d also like to explore replacing very large, unchanged nodes with
...or something in the same way thatinspectdoes at a certain point.
zachallaun
I’ve released a new version (v0.2.2) that disables an optimization that was causing a poor diff in example 2 above, increasing the likelihood that subtrees would become “misaligned”.
v0.2.1
v0.2.2
The new diff does a much better job of reflecting the actual change: the nil is being replaced with a new subtree, and the second subtree is being modified.
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance


















