Git Product home page Git Product logo

namaka's Introduction

namaka

release version deps license ci

Snapshot testing for Nix based on haumea

Quick Start

nix flake init -t github:nix-community/namaka
nix develop # add namaka to the environment
namaka check # run checks
namaka review # review pending snapshots

Versioning

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

Usage: namaka [OPTIONS] [DIR] <COMMAND>

Commands:
  check   Wrapper around `nix flake check` to prepare snapshots for failed tests [aliases: c]
  clean   Remove unused and pending snapshots [aliases: cl]
  review  Review pending snapshots and selectively accept or reject them [aliases: r]
  help    Print this message or the help of the given subcommand(s)

Arguments:
  [DIR]  Change to this working directory

Options:
  -c, --cmd <CMD>...  Command to run instead of `nix flake check`
  -h, --help          Print help (see more with '--help')
  -V, --version       Print version

Type: { ... } -> { }

Wrapper around haumea.load to load snapshot tests from a directory.

It throws an error if any of the tests fail, otherwise it always returns { }. 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 is

See 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.

Configuration

namaka will try to read namaka.toml in the working directory. Here is an example configuration file (all fields are optional):

# namaka.toml

# change the working directory
# this stacks with the command line option
#`namaka check bar` will read `bar/namaka.toml` and change the working directory to `bar/foo`
dir = "foo"

[check]
# the command to run with `namaka check`
# defaults to `nix flake check --extra-experimental-features "flakes nix-command"`
cmd = ["nix", "eval", "./dev#checks"]

[eval]
# the command to run with `namaka review` and `namaka clean`
# defaults to `nix eval ./checks --extra-experimental-features "flakes nix-command"`
cmd = ["nix", "flake", "check"]

Snapshot Testing

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.

Related Tools

  • Namaka is largely inspired by insta, a snapshot testing library for Rust.
  • Namaka is based on haumea, which also has some testing functionalities.

namaka's People

Contributors

dependabot[bot] avatar figsoda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

namaka's Issues

[UX] Potential check and review flow improvments

I want to open a conversation about improving the UX when writing/fixing tests.

Basically while setting up tests I found myself running namaka check || namaka review as part of my feedback loop just to get a diff. That could easily be twice as fast by avoiding either evaluation.
Also since I was just wanting to see diffs, not update the snapshots, I had to do Ctrl-C in addition to "up + return" every time. And this isn't something I'm looking to improve here, but exiting in the middle of a prompt partially breaks the terminal because of console-rs/dialoguer#248, which adds a bit of frustration to that flow.

The first solution that comes to mind is adding something like check --verbose/--show-diffs or review --check.
But I'd even say both commands could be merged. You might have a flow in mind that I don't but based on my current understanding, having check print the diff by default seems to only have upsides.
And from there maybe also make check prompt by default if isatty(stdin), with a way to opt-out via something like --no-prompt/--non-interactive.
Then since check also has review's functionality review could be removed/made an alias, and the complexity surrounding .pending can be removed.

Again, thanks for the tool, I like it and this is coming from a positive place: trying make the UX even better :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.