slint-snapshot
Headless software rendering and visual regression testing for compiled Slint components. Frames are available as RGBA8 pixels, in-memory PNG data, or PNG files.
Rendering
use ComponentHandle;
use SnapshotRuntime;
slint!
RenderedFrame also provides rgba8() and encode_png().
Visual regression tests
[]
= { = "0.1", = ["testing"] }
use ;
The default mode is Verify and never changes a baseline.
| Mode | Behavior |
|---|---|
Verify |
Compare with an existing baseline |
CreateMissing |
Create only a missing baseline |
Accept |
Create or replace the baseline |
Tests that use SnapshotMode::from_env() can accept reviewed output with:
SLINT_SNAPSHOT_MODE=accept
Baselines and failure artifacts are kept separate:
tests/snapshots/settings/default.zh-CN.light.png
target/slint-snapshots/settings/default.zh-CN.light/
├── expected.png
├── actual.png
└── diff.png
Exact RGBA comparison is the default. Use
ComparisonPolicy::PixelTolerance only when explicit renderer tolerance is
required. Structured mismatch statistics and artifact paths are available
through SnapshotTestError::mismatch(). Its artifacts() method returns a
Result<_, &SnapshotWriteError>: artifact write failures preserve the comparison
statistics. MissingBaseline similarly retains its primary cause, with
actual_artifact: Result<PathBuf, SnapshotWriteError> recording the artifact outcome.
Baseline and artifact roots must not be equal or nested.
Deterministic output
Use a manual clock for timers and animations:
use ;
let runtime = builder
.clock_mode
.build?;
runtime.advance_time?;
# Ok::
Also fix the logical size, scale factor, fonts, and embedded resources. The default build does not use host fonts or link Fontconfig. Consumers should compile resources for the software renderer:
let config = new
.embed_resources;
compile_with_config?;
# Ok::
[]
= "1.19.0"
Enable host fonts with the system-fonts feature. On Linux this requires
Fontconfig development files. With Slint 1.19 it also enables software
rendering for Path elements; the default Fontconfig-free configuration does
not render Path elements.
Constraints
- Slint permits one platform per process; reuse one
SnapshotRuntime. - Components have independent windows and renderers. Inject events through
component.window(); the runtime shares only configuration and the clock. - Keep runtime operations on one thread; the runtime is neither
SendnorSync. - Frames are limited to 16,777,216 physical pixels by default. Configure
trusted larger canvases with
SnapshotRuntime::builder().max_pixels(...). - Give concurrently running tests unique snapshot names.