zachallaun

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

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

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 that inspect does at a certain point.
zachallaun

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.

zachallaun

zachallaun

v0.6.0 is now available

This release primarily includes some small fixes to play nicely with the Lexical language server.

Additionally, the restart behavior enabled by using Mneme.start(restart: true) is now always there. @mindreframer, one less thing for you to remember. :smile:

Finally, if you’re using VS Code, I’ve rewritten the VS Code Setup guide to be more supportive of running tests regardless if which language server you’re using.

zachallaun

zachallaun

v0.9.0 is now available

After a few months of dogfooding and smoothing some rough edges, I’m confident enough in mix mneme.watch to ditch the “alpha” moniker in this release.

Give it a try!

Where Next?

Popular in Libraries Top

josevalim
Hi everyone, We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
mhanberg
I just released the first version of Temple: an HTML DSL for Elixir and Phoenix! You can read this blog post or the docs for more info...
New
tmbb
I’ve been working on two packages (not on hex.pm yet) to build admin interfaces for phoenix apps: bureaucrat - which contains a bunch ...
New
OvermindDL1
Been making an MLElixir thing (not released yet…) for fun in spare time in the past day. I’m just trying to see how much I can get an ML...
132 13487 106
New
archan937
It is a well-know topic within the Elixir community: “To mock or not to mock? :)” Every alchemist probably has his / her own opinion con...
New
Crowdhailer
I have been updating a library that allows you to pipe between functions that use the erlang result tuple convention. Assuming you have...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 18262 141
New
wmnnd
Hi there, for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
OvermindDL1
I created a new library (rather I pulled out a couple files from my big project), it manages an operating system PID file for the BEAM. ...
New
Qqwy
While not as prevalent as in imperative languages, arrays (collections with efficient random element access) are still very useful in Eli...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

Sub Categories:

We're in Beta

About us Mission Statement