Skip to main content
Version: v1.2.0

CLI Reference

Status: Stable

The design-tests binary runs the suite, promotes screenshots into the baseline, compares two runs, validates the configuration, and builds the report. Every command except compare-runs and review takes -c, --config <path>, which defaults to .designTests.js, then .designTests.ts, resolved against the working directory. Run it through your package manager so the local install is used:

pnpm exec design-tests --version
pnpm exec design-tests <command> --help

run​

Capture every test of the selected projects, compare them against the baseline, and write the report.

pnpm exec design-tests run --config .designTests.js --all
OptionDescription
-c, --config <path>Path to the configuration file. Defaults to .designTests.js, then .designTests.ts.
-p, --project <key>Project key to test. The PROJECT or DESIGN_TESTS_PROJECT environment variable sets the same value.
--allRun every project in the configuration.
--workers <number>Number of parallel browser workers. Overrides playwright.workers (default 1).
--set <key.path>=<value>Override any configuration value. Repeatable.
--debugHeaded browser and verbose logs.
--fail-on-changesExit 1 on visual differences and 2 on capture failures. Without it the command exits 0 whenever the run completes.

Select one project or all of them — a run with neither --project nor --all has nothing to do.

# One project, eight workers, headed
pnpm exec design-tests run --config .designTests.js --project portal --workers 8 --debug

# Project by environment variable
PROJECT=contracts pnpm exec design-tests run --config .designTests.js

# Override configuration values
pnpm exec design-tests run --config .designTests.js --all \
--set projects.cms.url=http://localhost:3000 \
--set playwright.workers=4

A run writes screenshots to actualDir, diff images to diffDir, and reg.json, index.html, manifest.json and CURRENT.json to reportDir. It never writes into baselineDir: a test without a baseline is reported as NEW, and its screenshot stays in actualDir until baseline-update promotes it.

The console shows one 📸 line per test (OK, DIFF, FAIL, NEW!), the capture platform (🖥️ Capture platform: linux-x64, Chromium 112.0.5615.29, Playwright 1.32.3, Node v24.0.0), a warning when BASELINE.json records a different platform, the Tests complete: summary, the 🔗 Non-Passed Test URLs list (every capture that differs from its baseline, including a capture whose dimensions changed, which shows its size change in place of the diff percentage), and a final 🚪 Exit line naming the exit code and the mode.

Exit codes​

CodeWithout --fail-on-changesWith --fail-on-changes
0The run completed and the report was written, with or without differences.Every test passed.
1—At least one visual difference, and no capture failures.
2The run could not complete: a crash, a configuration error, or no tests.A capture failure, or no tests.

Use the default for local work, where the report is the output. A pipeline that reads reg.json or manifest.json for the build status runs without the flag. A pipeline that wants the exit code to carry the verdict passes it.

baseline-update​

Promote the last run's new and changed screenshots into the baseline, and write BASELINE.json when an image changes.

pnpm exec design-tests baseline-update --config .designTests.js --dry-run
pnpm exec design-tests baseline-update --config .designTests.js
pnpm exec design-tests baseline-update --config .designTests.js --project cms
pnpm exec design-tests baseline-update --config .designTests.js --prune
OptionDescription
-c, --config <path>Path to the configuration file. Defaults to .designTests.js, then .designTests.ts.
-p, --project <key>Promote only this project's items.
--pruneDelete the baseline images the run reported as deleted. Use it only after an --all run, because a partial run reports every uncovered project as deleted.
--allow-platform-changeAccept a run whose capture platform differs from the one BASELINE.json records.
--dry-runPrint the plan and write nothing.

The command reads reportDir/manifest.json and copies each new and failed item from actualDir to baselineDir. It never copies errors items: those are tests where no screenshot of the page could be taken, and their slot may hold an error screenshot. It also declines a failed item with attemptsDiffer: true (two attempts of this run captured different bytes, so the capture is unstable): the output counts the declined items and lists each image path, with the path of its second attempt in the report directory when the item has one. The baseline file of a declined item stays unchanged, the exit code does not change, and no option overrides the decline. Items with attemptsDiffer: false or without the field are copied as before. When the command copies or removes at least one image, BASELINE.json receives the run's CURRENT.json content — deployment reference, os, arch, browserVersion and playwrightVersion — plus updatedAt; reference stays the app version the baseline was captured from. When the run recorded a CI build number, build holds the CI build (buildNumber, buildUrl, jobName, the shape of ci in manifest.json). RUN.json receives the run's metadata and the items that did not pass, on every update: see Run record. When the command copies and removes no image (every changed item declined, every actual screenshot missing, or nothing to promote), it leaves BASELINE.json byte-identical (or writes none where none exists), still writes RUN.json and prints that nothing changed; a dry run prints the same line.

The command exits 2 and writes nothing when no manifest exists, or when the run was captured on another platform or browser than the baseline and --allow-platform-change is absent. The refusal names each differing field.

baseline-update does not run git. A pipeline runs baseline-update, then commits and pushes baselineDir itself.

compare-runs​

Measure each capture of a second run against the same capture of a first run. The command answers one question: how many captures have the same pixels in both runs, and by how much do the others differ. Use it to see the effect of one change, such as an app version, a browser version or a setting, on every capture at once.

It reads two completed runs and writes nothing. It does not launch a browser, read the baseline, read the config file, or run git.

# 1. First run. Keep its manifest.json and its actual images: the second run overwrites both.
pnpm exec design-tests run --config .designTests.js --all
cp -R design-tests/report /tmp/before-report
cp -R design-tests/actual-images /tmp/before-actual

# 2. Change one thing, then run again.
pnpm exec design-tests run --config .designTests.js --all

# 3. Compare.
pnpm exec design-tests compare-runs \
--before-manifest /tmp/before-report --before-images /tmp/before-actual \
--after-manifest design-tests/report --after-images design-tests/actual-images

Instead of copying the first run, give the second run its own directories: --set actualDir=design-tests/after-actual --set reportDir=design-tests/after-report.

OptionDescription
--before-manifest <path>The first run's manifest.json, or the report directory that holds it. Required.
--before-images <dir>The directory that holds the first run's actual images. Required.
--after-manifest <path>The second run's manifest.json, or the report directory that holds it. Required.
--after-images <dir>The directory that holds the second run's actual images. Required.
--jsonPrint the same data as JSON, with one row per pair.

Pairs​

The paths to compare come from the two manifests, never from a scan of the image directories. run does not empty actualDir, so a directory can hold images of stories that left the suite; the command ignores them.

Manifest itemTreatment
A passed, failed or new item in both runsA pair. The command measures it.
A passed, failed or new item in one run onlyCounted as onlyBefore or onlyAfter. Not measured.
An errors item in either runListed apart with the run that failed (before, after or both). Never measured, also when an error screenshot exists.
A deleted itemIgnored. It has no actual image.

A pair whose image is missing, is not a PNG, or lies outside its image directory (a path with .., or a symbolic link that leads out) is listed as unreadable, with the side and the reason, and does not count as compared. Any unreadable pair makes the command exit 2 (see the exit codes below). A manifest that lists one path twice is an error.

The command decodes one pair at a time and compares the decoded pixels, every channel exactly. It does not compare file bytes, and it does not use pixelmatch or any per-pixel tolerance: the same pixels in another PNG encoding are identical, and a difference of 1 in one channel of one pixel is differs.

ClassMeaning
identicalBoth images have the same size and the same pixels.
differsBoth images have the same size and at least one pixel differs. The row holds diffPx, diffPercent (two decimals), maxDelta (the largest difference of one channel, 1 to 255), the bounding box of the differing pixels and the row bands.
sizeChangedThe sizes differ. The row holds both sizes and no percentage, because the area that one image lacks has no meaning as a difference.

Distribution​

The output holds:

  • The count of each class, and the share of the compared pairs that are not identical (differs plus sizeChanged), in percent with two decimals.
  • Two histograms over the pairs that differ. A sizeChanged pair is in neither.
  • The same counts for each project and viewport. A group holds the pair classes and the paths that exist in one run only. Errors and unreadable pairs appear in the totals and in their own lists.

The bucket edges are fixed. A bucket includes its lower edge and excludes its upper edge.

HistogramBuckets
diffPercent, in percent of the pixels<0.01, 0.01-<0.1, 0.1-<1, 1-<10, >=10
maxDelta1, 2-3, 4-7, 8-15, 16-31, 32-63, 64-127, 128-255

diffPercent is rounded to two decimals before it is placed, so a pair with fewer than 0.005 % differing pixels falls in <0.01.

The two runs​

The command reports two facts about the pair of runs. Neither fact stops the comparison.

  • App version. same, differs or unknown. The version of a run is current.gitHash of its manifest, else the first part of current.reference (<gitHash>|<branch>|<date>; the date moves between runs of one version). A run that gives no version, because it has no gitHash and its reference is empty, unknown or the generated unknown|unknown|<time>, makes the result unknown. unknown is not same.
  • Capture platform. same, differs or unknown, with one entry for each of os, arch, browserVersion and playwrightVersion (the fields that change pixels; nodeVersion does not). A field that one run does not record is unknown, and a platform with one unknown field and no differing field is unknown.

A manifest's current holds the metadata of the first project of the run. In a suite with several projects, the app version is that of the first project.

Output and exit codes​

The default output is a short text summary: the counts, the two facts, both histograms, the table of project and viewport, and the first five paths of each list (size changed, only in one run, errors, unreadable). --json prints everything, with every list in full and the rows in pairs sorted by path. The same pair of runs gives byte-equal JSON, whatever the order of the items in the manifests.

CodeMeaning
0Every pair was compared. Differences never change the exit code: the command measures and does not judge.
2An input is wrong: a missing, unknown or incomplete option, an extra argument, a missing manifest, a manifest without an errors bucket (schema before 1.2.0), a manifest that is not JSON, an image directory that does not exist, both runs given as the same manifest or the same image directory, or a manifest that lists a path twice. Also 2 when a run holds no items, when no story path appears in both runs (another suite, the wrong directory, a full rename), and when any pair is unreadable.

The last three cases of code 2 print the summary to stdout first, so the counts stay readable, and then the cause to stderr:

  • No shared path. The message says "no story path appears in both runs" and gives the item count of each run. A run that holds no items names that run.
  • Unreadable pair. A pair is unreadable when the manifest lists an image that is missing from its image directory or that cannot be decoded (a truncated file, or a file that is not a PNG). The message gives the number of unreadable pairs and the first five paths, sorted. A run directory needs every image of the items it lists. A CI archive that keeps only the failed images cannot be compared until the images of the other items are present.

Limits​

  • It sets no threshold and gives no verdict. It does not label a difference as drift, a flake or an outlier. A person or a script reads the numbers.
  • It does not refuse a comparison when the app versions or the capture platforms differ. It reports the difference.
  • It does not read the baseline, promote an image, or change a file.
  • It does not capture a run twice. It measures the two runs it is given; it does not tell whether either run is repeatable.

config​

Validate the configuration and print what it resolves to, without launching a browser.

pnpm exec design-tests config --config .designTests.js
pnpm exec design-tests config --config .designTests.js --set playwright.workers=4
DESIGN_TESTS__PROJECTS__CMS__URL=http://localhost:3000 pnpm exec design-tests config --config .designTests.js --json | jq .projects.cms.url
OptionDescription
-c, --config <path>Path to the configuration file. Defaults to .designTests.js, then .designTests.ts.
--set <key.path>=<value>Apply an override, as run would. Repeatable.
--jsonPrint only the effective configuration.

The default output names the projects, viewports and worker count, and lists every DESIGN_TESTS__* variable and --set flag with the path and value it set. It warns about variables that start with DESIGN_TESTS_ but reach nothing, then prints the configuration as JSON with functions rendered as [Function name]. A validation error exits 2, with the overrides still listed.

report​

Generate reg.json and the HTML diff report from the images already on disk. run writes the report itself; this command rebuilds it without capturing.

pnpm exec design-tests report --config .designTests.js
OptionDescription
-c, --config <path>Path to the configuration file. Defaults to .designTests.js, then .designTests.ts.
-p, --project <key>Project key, used to resolve directories.
-o, --output <path>Output directory. Defaults to reportDir from the configuration.
--url-prefix <prefix>Prefix prepended to image URLs in the report. Defaults to jenkins.baseUrl. Needed when the report is served from a path that differs from where it was written — see Jenkins Resource Root URL.

Report options​

OptionDescription
report.baselineLinkURL template that links a passed item without an image in the archive to its baseline file, with the placeholders {commit} and {path}. Unset by default: no link. See Baseline link.
report.layoutLayout of the changed items in the HTML report. Unset by default: the card of a changed item shows one image, the diff, as reg-cli draws it. "three-up" shows the baseline, the diff and the actual image in a row. See Three-up layout.

Three-up layout​

report.layout: "three-up" shows the card of a changed item as the baseline, the diff and the actual image in a row, so a reader compares the images without opening the item. Passed, new and deleted items, manifest.json and RUN.json stay as they are.

Set it in the configuration file, with --set report.layout=three-up on run, or with DESIGN_TESTS__REPORT__LAYOUT=three-up. The report command has no --set: it reads the configuration file and the environment variable. Check the value with design-tests config.

The library does this after reg-cli has written index.html. It replaces the report UI that reg-cli embeds (report.js and style.css) with the build in vendor/reg-cli-report-ui/ of the package and sets threeUpLayout in the report data. SOURCE.md in that folder names the fork, its commit and the checksum of each file. If index.html does not hold the report UI of the pinned reg-cli and the report data exactly once each, the report keeps the layout of reg-cli and the run prints one warning that names report.layout.

Each cell is 260 px high and clips what is larger. An image keeps its aspect ratio and is never drawn larger than its own size. The width of its cell limits it. A cell is a third of the card. A card is at least 600 px wide, 900 px wide at a viewport of 1200 and 1280 px, and grows with the viewport: 1020 px at 1400 px, 1220 px at 1600 px, 1540 px at 1920 px. Measured in Chromium:

ViewportCellCapture of 1280 × 800 pxFull-page capture of 1878 × 15031 px
1280 px300 × 260 px299 × 187 px, whole299 × 2393 px, a window of 260 px (11 %)
1920 px513 × 260 px512 × 320 px, a window of 260 px512 × 4101 px, a window of 260 px (6 %)

A full-page capture does not shrink to a strip: the cell shows a window of it, so a window shows 11 % of the capture at 1280 px and 6 % at 1920 px. Open the item for the whole image. The item viewer is unchanged and keeps its 2up mode, which shows the baseline and the actual image side by side at full size.

Position of the window​

The window does not show the top of the image. The library compares the baseline and the actual image of each changed item, as review measure does, and writes the changed rows into the report data as focus on the item in failedItems: { "top": 8200, "bottom": 8459, "height": 15031 }. All three values are image pixels: top is the first and bottom the last row that differs, both included, and height is the height of the larger image. The report UI centres the window of all three cells on the middle of those rows, clamped to the image, so the three cells show the same rows. When the changed rows are higher than the window, the window starts at top. The title of each cell names the visible rows, for example rows 8200–8460 of 15031.

Measured in Chromium with a 60-row change at the bottom of a 1878 × 15031 px capture (rows 14200 to 14259): at 1280 px the window shows rows 13397 to 15031 and the change lies at 128 to 137 px from the top of the cell; at 1920 px the window shows rows 13753 to 14707 and the change lies at 124 to 141 px. Without the position, the cell shows rows 0 to 1633 at 1280 px, and the change is not visible.

An item whose images the library cannot read (missing, no PNG, or no difference between them) has no focus, and its cells show the top of the image. The library writes focus only with report.layout; a report without the option holds no focus and stays as reg-cli wrote it.

The card also changes the length of the changed section. From a viewport of 1600 px, the layout of reg-cli shows two cards per row (590 px wide at 1600 px, 750 px wide at 1920 px) and three-up shows one card per row, so the section is longer.

A cell narrower than 240 px clips the placeholder of an image that the archive does not hold. The placeholder is 240 px wide. A viewport below about 1100 px gives a narrower cell: 223 px at 1050 px, 207 px at 1000 px and 200 px at 800 px and below. The clip is at most 40 px.

debug​

Registered but not implemented. It prints a notice and exits 0. Use run --debug instead, which opens a headed browser and turns on verbose logging.

Configuration overrides​

Every configuration value is overridable from outside the file, in this precedence:

  1. --set flags
  2. DESIGN_TESTS__* environment variables
  3. The configuration file
  4. Built-in defaults

Environment variables use __ to separate path segments and are case-insensitive. A single _ inside a key marks a camelCase boundary, so STABILITY__WAIT_BEFORE_SCREENSHOT sets stability.waitBeforeScreenshot:

DESIGN_TESTS__PLAYWRIGHT__WORKERS=8 pnpm exec design-tests run --config .designTests.js --all
DESIGN_TESTS__PROJECTS__CMS__URL="http://localhost:3000" pnpm exec design-tests run --config .designTests.js --project cms

Values are coerced to the type the schema expects and then validated, so a bad type or an invalid URL fails immediately with a message naming the key. design-tests config shows which overrides applied.

Set environment variables inline on the command rather than exporting them. An inline assignment keeps the command reproducible and scoped to that one run.

Environment variables​

VariableRead byEffect
DESIGN_TESTS__<PATH>__<KEY>run, report, config, baseline-updateOverride a configuration value, as described above.
PROJECT, DESIGN_TESTS_PROJECTrunProject key when --project is absent.
DESIGN_TESTS_FORCE_HEADLESS=truerunHeadless even with --debug, for containers without a display.
DESIGN_TESTS_DIAGNOSTICS=truerunWrite a .diag.json sidecar beside each screenshot with the page's state at capture time; see Diagnostics sidecar.
CURRENT_REFERENCE, CURRENT_REFERENCE_LINKrunDeployment reference when /git-metadata.json is not served. The Storybook addon serves it.
ENABLE_NETWORK_CACHE=true, NETWORK_CACHE_DIRrunExperimental network cache; see Network Cache.
DEBUG=capture:fs,comparison:fs,report:fsallTrace file operations through the debug package.

design-tests config lists the variables that are set and read, and names those that are set but read by nothing.

Request rewrites​

requestRewrites sends the page's requests for one URL prefix to another. It fixes a page that calls an absolute https:// URL of a host that the suite reaches over http://. Set it in the global config or in a project. A project's list replaces the global list, and requestRewrites: [] in a project switches the global rules off. Without the option, nothing changes.

FieldContent
fromAbsolute http(s) URL prefix ending in /. A request whose URL starts with it is rewritten. The trailing / keeps https://www-test.example/ from matching https://www-test.example.evil/.
toAbsolute http(s) URL prefix ending in /. The new URL is to plus the rest of the URL after from, with query and hash. Must differ from from.
headersOptional. Set on the rewritten request; a header of the same name (case-insensitive) replaces the page's.

The first matching rule wins. There is no regular expression. The config check names the index of an invalid rule. A rewritten request bypasses the network cache. If the request for the new URL fails, the original request continues. DEBUG=capture:rewrite logs the first rewrite per host and every failure. See the playbook case.

Ready signals​

stability.ready (experimental) makes every capture under it wait for the page's ready participants: components that register on window.__designTestsReady and report ready(), busy(), fail(reason) or dispose(). Set it in the global stability block or in a project's; a project's ready object replaces the global one as a whole. Without the option, nothing changes.

FieldContent
timeoutMilliseconds the capture may spend in ready waits: the wait after the scroll steps and the re-checks before the shots together. Default maxWaitTime, then 10000.
settleMilliseconds every live participant must stay ready before the page counts as ready. Default 250.

--set projects.<key>.stability.ready.timeout=15000 and DESIGN_TESTS__PROJECTS__<KEY>__STABILITY__READY__TIMEOUT=15000 set a field of one project (the key uppercased; DESIGN_TESTS__PROJECTS__CMS__STABILITY__READY__TIMEOUT addresses projects.cms). ready in the global block, also through --set stability.ready.timeout=… or DESIGN_TESTS__STABILITY__READY__TIMEOUT, opts every project in, and the loader logs a warning that names them; a project's own ready object shadows the global one as a whole; an object without fields, ready: {}, turns the option on with the defaults. No participant within the timeout, a page not ready within it, or a participant that called fail() makes the attempt a capture failure (the registry exists in the top frame only, so a participant inside an iframe is not seen), which the runner retries and then reports as an error item. Each item of a capture under the option carries a ready object in manifest.json, and the run prints one summary line. DEBUG=capture:ready logs each outcome that is not ready, and DEBUG=capture:requests a request record that could not attach. The playbook section describes the protocol, the outcomes and a map participant.

Diagnostics sidecar​

With DESIGN_TESTS_DIAGNOSTICS=true, run writes <screenshot>.diag.json beside each screenshot in the actual directory. Each attempt reads the page after the stability waits, immediately before its screenshot. The probe only reads the page, so it changes no pixels, and a probe that fails does not fail the capture.

FieldContent
runStartedAt, testId, url, viewportThe run and the test the sidecar belongs to.
attemptThe attempt that the top-level fields below describe: the last one that read the page.
rootFontSize, htmlClass, innerWidth, clientWidthThe computed html font size, the html classes, and the window and layout widths.
gridsFor each match of diagnostics.gridSelectors, the laid-out column count.
imagesHow many images the page holds, how many have no intrinsic size yet, and how many lack width or height attributes.
mediaQueriesEach query of diagnostics.mediaQueries with its matchMedia result.
classesFor each selector of diagnostics.classSelectors, the tag and the classes of its first 10 matches. The lookup includes open shadow roots.
capturemethod names the screenshot taken: root (#storybook-root), viewport (a root with no area), body or page. rootBoxAtLoad is the root's box that decided the method, measured after the first network-idle wait; rootBox is its box at capture time.
requestRewritesPresent when rules apply: rules lists every configured rule with its own rewritten count, 0 included, so a typo in a host shows; rewritten and failed count the attempt's requests.
requestErrorsThe attempt's failed requests and responses with status 400 or more: total, byHost with a count per host, and entries with the URL, the status or the failure text, and at, milliseconds since the capture started; the first 100. The record only listens.
readyUnder stability.ready: the attempt's ready record, as in the manifest item, also for an attempt the signal failed.
attemptsOne entry per attempt of the current run, ordered by attempt, each with the fields above. An attempt that threw during the capture has an error field. An attempt that captured and then differed from its baseline has the fields only. A retry follows only an attempt that did not pass, so every entry before the last belongs to such an attempt.

Configure the probes in the global diagnostics block or in a project's; a project's list replaces the global one:

diagnostics: {
mediaQueries: ["(min-width: 900px) and (hover: hover) and (pointer: fine)"],
classSelectors: ["header.navbar", ".card-slider"],
},

A sidecar left in the actual directory by an earlier run is replaced, not extended: an attempt joins attempts only when the sidecar's runStartedAt is that of the current run. baseline-update promotes no sidecar.