Skip to main content

Module snapshot

Module snapshot 

Source
Available on crate feature snapshot only.
Expand description

Perceptual snapshot assertions.

A snapshot is named, and where its bytes come from depends on where the test runs. Natively they are read from the asset submodule beside the test file, so a mismatch can be re-stored in place with SNAPSHOT_UPDATE=1. In a browser there is no filesystem to read or write, so snapshot! embeds the baseline into the wasm binary at the call site instead β€” and the comparison itself, a real SSIMULACRA2 score, runs there unchanged.

Both paths decode the same WebP and score it the same way; only the origin of the bytes differs.

Re-exportsΒ§

use image::ImageEncoder; πŸ”’
use ssimulacra2::ColorPrimaries; πŸ”’
use ssimulacra2::Rgb; πŸ”’
use ssimulacra2::TransferCharacteristic; πŸ”’
use ssimulacra2::compute_frame_ssimulacra2; πŸ”’

StructsΒ§

Comparison πŸ”’
What comparing a frame against its baseline found.
Snapshot
A snapshot baseline, and where its bytes come from.
Tolerance
How closely a frame must match its snapshot.

EnumsΒ§

SnapshotError
What went wrong storing or comparing a snapshot.

ConstantsΒ§

DEFAULT_MIN_SCORE
The perceptual score a frame must reach to match its snapshot.
DEFAULT_MISMATCH_DIRNon-WebAssembly
Where mismatched frames are written when MISMATCH_DIR_ENV is unset.
DEFAULT_TOLERANCE
The tolerance a snapshot gets when it names none: the perceptual floor DEFAULT_MIN_SCORE, with no bound on how many pixels may stand out.
MISMATCH_DIR_ENVNon-WebAssembly
The environment variable that collects mismatched frames on the host.
SNAPSHOT_DIR πŸ”’ Non-WebAssembly
Where Snapshot::on_disk looks a snapshot up by name, relative to the process’s working directory β€” which for a test is its package root.

FunctionsΒ§

assert_image_snapshot
Assert that rgba matches snapshot within DEFAULT_TOLERANCE.
assert_image_snapshot_with_tolerance
Assert that rgba matches snapshot within tolerance.
check_frame_size πŸ”’
Reject a frame whose bytes do not describe width x height RGBA pixels.
compare πŸ”’ Non-WebAssembly
Measure a frame against its baseline, storing one where none exists yet.
compare_frame_bytes πŸ”’
Measure rgba against a WebP baseline held in memory.
compare_frame_webp πŸ”’ Non-WebAssembly
Measure the frame rgba against the snapshot at path.
encode_frame_webp
Encode rgba as a lossless WebP.
outlier_fraction πŸ”’
The fraction of pixels whose largest per-channel difference from the baseline exceeds channel_delta.
rgb_frame πŸ”’
Turn an RGBA8 frame into the RGB the metric reads.
score_frame_webpNon-WebAssembly
Score the frame rgba against the snapshot at path, on SSIMULACRA2’s 0–100 scale where higher is closer.
snapshot_pathNon-WebAssembly
Where a snapshot named name lives, under the snapshots directory.
store_frame_webpNon-WebAssembly
Write rgba to path as a lossless WebP, creating its directory.
store_mismatch πŸ”’ Non-WebAssembly
Keep a frame that did not match, so a failing run leaves it behind.