Skip to content

Snapshot Comparison ​

Snapshot testing utility for regression detection with integrated diff output.

Overview ​

Snapshot Comparison (snapcmp) catches regressions by comparing current output against stored "golden" snapshots. It integrates with output-diffing-utility for rich, semantic diffs of text, JSON, and binary data.

First Tool Using Library Composition

This is the first Tuulbelt tool to use another Tuulbelt tool as a library dependency (not CLI). It imports output-diffing-utility via Cargo path dependency, demonstrating PRINCIPLES.md Exception 2: Tuulbelt tools can compose while maintaining zero external dependencies.

Status: Production Ready (v0.1.0)

Language: Rust

Repository: tuulbelt/snapshot-comparison

Features ​

Snapshot Testing ​

Store expected output and automatically detect regressions. Create, check, and update snapshots with simple commands.

Integrated Semantic Diffs ​

Uses output-diffing-utility for intelligent comparisons:

  • Text: Unified diff with context lines
  • JSON: Semantic comparison showing field changes
  • Binary: Hex dump with byte-level differences

CLI-First Design ​

Works with any language via stdin/stdout. Pipe output from any program for snapshot testing.

CLI & Library ​

Use as a command-line tool for shell scripts or integrate as a Rust library.

Zero Runtime Dependencies ​

Uses only Rust standard library plus output-diffing-utility (another zero-dep Tuulbelt tool).

Quick Start ​

bash
# Clone the repository
git clone https://github.com/tuulbelt/snapshot-comparison.git
cd snapshot-comparison

# Build
cargo build --release

# Install globally
cargo install --path .

# Create a snapshot
my-program | snapcmp create my-test

# Check against snapshot
my-program | snapcmp check my-test

Demo ​

See the tool in action:

Snapshot Comparison Demo

▶ View interactive recording on asciinema.org

Try it online:Open in StackBlitz

Use Cases ​

API Response Testing ​

bash
curl -s https://api.example.com/users | snapcmp create users-api
curl -s https://api.example.com/users | snapcmp check users-api

Build Verification ​

bash
./build.sh | snapcmp create build-output
./build.sh | snapcmp check build-output

Configuration Validation ​

bash
cat config.json | snapcmp create -t json valid-config
cat config.json | snapcmp check valid-config

Why Snapshot Comparison? ​

Unlike Jest snapshots or insta:

  1. Zero dependencies - Pure Rust, no runtime dependencies
  2. Integrated diffs - Rich semantic diffs included
  3. Format-aware - Understands text, JSON, and binary
  4. CLI-first - Works with any language

Documentation ​

Released under the MIT License.