Snapshot testing for Nix based on [haumea]
bash
nix flake init -t github:nix-community/namaka
nix develop # add namaka to the environment
namaka check # run checks
namaka review # review pending snapshots
Namaka follows semantic versioning. Breaking changes can happen in main branch at any time, so it is recommended to pin namaka to a specific tag. A list of available versions can be found on the releases page.
```
Usage: namaka [OPTIONS]
Commands:
check Wrapper around nix flake check
to prepare snapshots for failed tests [aliases: c]
review Review pending snapshots and selectively accept or reject them [aliases: r]
help Print this message or the help of the given subcommand(s)
Options:
-c, --cmd nix flake check
-h, --help Print help (see more with '--help')
-V, --version Print version
```
load
Type: { ... } -> { }
Wrapper around [haumea.load
] to loads snapshot tests from a directory.
It throws an error if any tests fail, otherwise it will always return { }
.
load { src = ./tests; }
will load tests from the tests
directory,
which should be structured like this:
tests
├─ foo/
│ ├─ expr.nix
├─ bar/
│ ├─ expr.nix
│ └─ format.nix (optional)
expr.nix
contains the Nix expression you want to test.
format.nix
contains a Nix string specifying how the expression should be serialized.
Here are the possible values:
"json"
serializes the expression using builtins.toJSON
(default)"pretty"
serializes the expression using lib.generators.toPretty { }
"string"
serializes the string as isSee the tests directory or one of the templates for an example.
Ignore the _snapshots
directory, as it is automatically generated by namaka.
The rest of the available options are documented in [haumea.load
],
as they will function exactly the same.
Snapshot testing is a strategy that allows you to write tests without manually writing reference values.
Instead of assert foo == bar;
, you only need to have foo
,
and namaka will store bar
in a snapshot file and ask you to update it with namaka review
.
To start, you can follow the Quick Start guide, or refer to load for more detailed documentation.