PhxDemo.Drift (phx_demo v0.1.1)

Copy Markdown View Source

Visual drift checks. Warns, never fails.

While recording, the end state of each scene is screenshotted to <demo dir>/screens/NN-<scene>.png. mix demo.record then compares each screenshot with a baseline by the share of pixels that changed noticeably (a per-pixel difference above 24/255). Whole-image SSIM was too forgiving: a changed heading on a mostly blank page still scored 0.994.

  • baselines live in test/demos/__baselines__/<os>/<module>/<demo>/ (config :phx_demo, :baseline_dir, ... to change the root). They're per OS because fonts render differently on macOS and Linux.
  • more than the threshold (default 0.1% of pixels, set with config :phx_demo, :drift_threshold, 0.5) is reported as drift, with a diff image written next to the screenshot (NN-<scene>.diff.png)
  • on GitHub Actions, drift becomes a ::warning annotation
  • mix demo.record --update-baselines copies the new screenshots over

Missing baselines are reported, not treated as drift.

Summary

Functions

Baseline directory for a rendered demo directory. Baselines are kept per OS (darwin, linux, …) because font rendering differs between platforms.

Screenshots the page into <dir>/screens/ as the next numbered file.

Percentage of pixels whose difference exceeds 24/255. The candidate is scaled to the baseline's size in case the viewport changed.

Compares a demo's screenshots with its baselines. Returns a list of {:ok | :drift | :new, screenshot, details}.

Copies a demo's screenshots into its baseline directory.

Functions

baseline_dir(demo_dir)

Baseline directory for a rendered demo directory. Baselines are kept per OS (darwin, linux, …) because font rendering differs between platforms.

capture(conn, dir, label)

Screenshots the page into <dir>/screens/ as the next numbered file.

changed_percent!(baseline, shot)

Percentage of pixels whose difference exceeds 24/255. The candidate is scaled to the baseline's size in case the viewport changed.

compare(demo_dir, opts \\ [])

Compares a demo's screenshots with its baselines. Returns a list of {:ok | :drift | :new, screenshot, details}.

update_baselines(demo_dir)

Copies a demo's screenshots into its baseline directory.