Retries
Status: Stable
A test that does not pass is captured and compared again. The runner opens a fresh page, captures the story, and compares the new capture with the baseline; it never compares the same two images twice, because pixelmatch is deterministic and returns the same answer. A result is final when it passes. A dimension mismatch, a capture failure, an HTTP error and a page crash are captured again. A comparison that completed and differs is captured again only when retries.onDiff is on.
The loop stops as soon as two attempts write the same bytes. The two captures reproduce, so the difference is a real change and the remaining attempts return the same answer. A deterministic difference therefore costs one extra capture, not retries.default of them.
Configuration
// .designTests.js
module.exports = {
retries: {
default: 2, // retries after the first attempt; 0 switches retries off
delay: 0, // milliseconds to wait before each retry
onDiff: false, // capture again after a comparison that differs
// onDiffLimit: 100, // items per run that onDiff captures again; no cap when unset
},
};
retries.default is 2 and retries.onDiff is false when the block is absent. retries.onDiffLimit has no default in 1.x: without it, retries.onDiff takes every differing item again and no cap applies. The default becomes 100 in 2.0; set the option to keep a cap or to lift it explicitly. retries.onDiffLimit takes an integer of 0 or more and has an effect only with retries.onDiff on. A manual page sets its own count beside expectStatus:
pages: [{ name: "Home/Homepage DE", path: "/de/", retries: 0 }];
A Storybook story declares parameters.designTests.retries for the same purpose. The Storybook index carries no parameters, so the runner does not read this value from a Storybook today.
playwright.retries is rejected with a message naming retries.default. The library does not use Playwright Test, and the key named a count the parallel runner never read.
Cost
A run in which every test passes takes one capture per test, because the loop returns after the first attempt. A retry costs one capture, so the extra work is proportional to the number of tests that did not pass.
With retries.onDiff on, a test whose difference is real costs one extra capture per run until its baseline is updated, because the second capture reproduces the first. A capture that varies between attempts costs up to retries.default extra captures. It is reported as passed when one attempt matches the baseline, and as a difference that carries attemptsDiffer: true when every attempt differs. With retries.onDiffLimit set, the limit bounds this cost: a run takes at most that many items again (see Retake verdict).
A retry repeats the shots of its own capture, so a suite with retries.onDiff pays the cost of stable capture (stability.stableCapture) per retry. Stable capture runs inside one attempt, before any comparison, and does not look at the baseline.
Retake verdict
With retries.onDiff on, an item whose comparison completed and differs, and that the runner takes again, ends with a verdict in the field attemptsDiffer. The verdict reads the fingerprints of the attempts, which the loop computes anyway. It never compares two images again.
attemptsDiffer | Meaning |
|---|---|
true | Two attempts captured different bytes. The capture is not reproducible, so the item is flaky. |
false | The attempts that ran captured the same bytes. It says nothing about determinism beyond those attempts. |
| absent | The runner did not take the item again, or it ended with no difference to judge. |
Read the field with === true. An absent field is not false. false proves nothing about stability: a capture that varies can still produce the same bytes in the attempts of one run. A dimension mismatch carries no verdict, because it takes no slot (see Limit). The field is absent for these items:
- an item whose first attempt passed;
- an item that passed on a retry, because its
retryCountalready marks it as flaky; - an item that ends as a capture failure or an HTTP error;
- an item that the limit left as it was;
- every item of a run with
retries.onDiffoff.
Only the items in the failed bucket carry the field. It is in manifest.json and in RUN.json, and it is not in reg.json. The run adds no verdict string and changes no exit code: a flaky difference still counts as a difference. design-tests review draft reads attemptsDiffer: true and proposes leave with the rule retake-flaky.
The console marks such an item in the list after the summary:
🔄 Changed:
[SITE] Pages/Home "Interactive Home" (Desktop) [2.34% diff] [attempts differ] - https://example.dev/iframe.html?id=...
Limit
retries.onDiffLimit is the number of items per run that retries.onDiff takes again. It has no default in 1.x, so a run without it has no cap, as in 1.0.0; the default becomes 100 in 2.0. One count covers every project, and the sequential and the parallel runner share it. An item uses one place of the limit when its first completed pixel comparison that differs is found and a retake follows. A dimension mismatch uses no place and is not counted: the loop captures it again whatever retries.onDiff says. An item that finds no place left behaves as with retries.onDiff off: its pixel difference is final at once, and the item carries no attemptsDiffer and no kept attempt. retries.onDiffLimit: 0 therefore takes no pixel difference again. The limit counts items, not captures.
The console and manifest.json state what the limit did. The console prints one line after the summary:
⚠️ retries.onDiff took 100 items again and left 37 that differ as they were: the limit is 100 items per run (retries.onDiffLimit)
🔁 retries.onDiff took 12 items again (limit 100)
🔁 retries.onDiff took 12 items again
manifest.json carries the same numbers in the block retakes: { limit, taken, skipped }. The block exists only when retries.onDiff is on, and limit is absent when retries.onDiffLimit is not set. The third console line shows a run without a limit.
Kept attempt
Every attempt writes the same actual path, so the next attempt overwrites the image of the one before. When an item takes a retake slot, the runner copies the image of its first attempt that differs before the next attempt starts. It keeps the copy next to the report, outside the directories that reg-cli compares:
<reportDir>/attempt-images/<path of the item>.attempt-1.png
The number in the file name is the number of the kept attempt, from 1. The runner keeps the copy only when a later attempt captured different bytes, and the kept image is never the final capture in actualDir, so whenever attemptsDiffer is true the two form a differing pair. The runner keeps the first attempt that differs, unless the final attempt equals it; then it keeps the first later attempt that differs from the final one. Attempts A, B keep A; A, B, B keep A; A, B, C keep A; A, A, B keep A; A, B, A keep B; A, B, A, B keep A. With retries.default: 1 the pair is A and B. When every attempt captured the same bytes, or the item ends as a pass, a capture failure or an HTTP error, no copy remains.
attemptPath on the item names the copy relative to the directory of manifest.json. The copy is not in actualDir, so reg-cli lists no item for it and Promotion cannot copy it into a baseline. RUN.json leaves out attemptPath, because the file lives in the report and not in the baseline repository. The runner removes <reportDir>/attempt-images at the start of a run. When the copy fails, for example on a full disk, the runner logs one warning, keeps no attempt and the run goes on as without it.
Output
One line per retry names the attempt and the outcome that caused it. The result line shows the retries the result used:
📸 🔄 [W04/32] [#125/1368] Retry 1/2 Desktop Pages/Home "Interactive Home"
↳ Diff: 147 pixels (0.49%)
📸 ✅ OK [W08/32] [#125/1368] Desktop Pages/Home "Interactive Home" (7321ms, 1 retry)
A test that passed after at least one retry is flaky. Its baseline is confirmed; its capture is not reproducible on the first attempt, so it is a candidate for a stabilisation fix. The summary line adds N flaky when N is above 0, and the URL list after the summary lists every flaky test with its public URL under Flaky (passed after retry).
manifest.json carries retryCount on every captured item and summary.flaky. Flaky items stay in passed. A failed item that was taken again also carries attemptsDiffer and, when a third attempt followed, attemptPath. With retries.onDiff on, the manifest carries the block retakes. Schema version 1.4.0 added these fields; a manifest written without retries.onDiff is the same as one of version 1.3.0 apart from the version string. A run with retries.onDiff on takes the same retakes as in 1.1.0 and adds these outputs: the block retakes: { taken, skipped } (with limit when set), the console line "took N items again", attemptsDiffer and attemptPath on items, and the files below <reportDir>/attempt-images.
Exit codes
A flaky test is a passed test. A difference with attemptsDiffer: true is still a difference, and the verdict changes no exit code. With --fail-on-changes, a difference that remains after the last attempt exits 1 and a capture failure that remains exits 2. Without the flag the run exits 0 once the report is written.
Error screenshots
The parallel runner writes an error screenshot after the last attempt of a capture that never produced a screenshot, not after every attempt. The screenshot carries no timestamp, so the same error produces the same PNG (src/error-handling/error-screenshot.ts).
Implementation
src/cli/retry.ts—runWithRetries,isFinal,resolveRetryPolicy,fingerprintActual,RetakeBudget,startRetakeSessionsrc/cli/executor.ts— both execution paths callrunWithRetrieswith an attempt that opens a fresh page and share one retake session per runsrc/config/schema.ts—retrieswithonDiffLimit, the rejectedplaywright.retries,pages[].retriessrc/core/test-matrix.ts— copiesparameters.designTests.retriesintospec.maxRetriessrc/report/manifest.ts—retryCount,summary.flaky,attemptsDiffer,attemptPath,retakessrc/cli/run-record.ts— copies the failed items intoRUN.jsonwithoutattemptPathsrc/report/console-logger.ts— the[attempts differ]tag