Cargo Insta

Cargo Insta is the companion command line tool to assist with snapshot reviewing. It's not necessary for working with regular snapshots but it's required when working with inline snapshots.

Installation

Cargo Insta can be installed with curl to bash or powershell if you haven't yet.

On Unix (Linux and macOS):

curl -LsSf https://insta.rs/install.sh | sh

On Windows:

powershell -c "irm https://insta.rs/install.ps1 | iex"

Alternatively you can also manually install it with cargo install:

cargo install cargo-insta

You can also update it this way. After installation it becomes available as cargo insta.

Configuration

cargo-insta will load the insta.yaml config file from the workspace which can be used to influence its behavior. For more information on this have a look at the settings configuration.

Commands

Cargo Insta comes with a few different commands.

Common Options

review

Review is the most important command as it can be used to review all pending snapshots. Pending snapshots are snapshots that changed from the stored reference during a test run.

It scans for all non ignored snapshots (optionally filtered down to individual snapshots with --snapshot) and then walks you through all of them. For each snapshot change a diff is shown. To accept a snapshot change press a, to reject r and to skip for now use s. Diffs can be turned on and off with d and auxiliary information can be shown or hidden with i.

screenshot of cargo-insta review

When you skip the new snapshot file will be left behind.

accept

This operates exactly like review but instead of an interactive review all snapshot changes will be accepted.

reject

This operates exactly like review but instead of an interactive review all snapshot changes will be rejected.

pending-snapshots

This command returns a list of all snapshots that need reviewing. This is useful when you want to provide editor integrations for insta. For instance this is how the VS Code extension shows the list of pending snapshots.

When JSON output is used the old and new contents of inline snapshots are also returned.

Options:

test

The test command lets you execute all tests (similar to cargo test) but forces all snapshot tests to pass so that they are collected. It accepts the same arguments as the normal cargo test command.

Additionally extra comments can be passed to cargo test when separated with --.

Options:

Some other options are directly mirrored from cargo test.

Found an issue? You can edit this page on GitHub.