tuffgal 0.1.0-alpha.8 → 0.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +140 -1
- package/README.md +82 -4
- package/dist/cli.d.ts +50 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +204 -18
- package/dist/cli.js.map +1 -1
- package/dist/commands/init.d.ts +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +19 -2
- package/dist/commands/init.js.map +1 -1
- package/dist/config.d.ts +121 -10
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +114 -9
- package/dist/config.js.map +1 -1
- package/dist/coverage/screens.d.ts +11 -6
- package/dist/coverage/screens.d.ts.map +1 -1
- package/dist/coverage/screens.js +12 -7
- package/dist/coverage/screens.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/reporter/assets/report.css +330 -50
- package/dist/reporter/assets/report.js +361 -55
- package/dist/reporter/template.d.ts +8 -1
- package/dist/reporter/template.d.ts.map +1 -1
- package/dist/reporter/template.js +447 -78
- package/dist/reporter/template.js.map +1 -1
- package/dist/reporter/writeReport.d.ts +2 -2
- package/dist/reporter/writeReport.d.ts.map +1 -1
- package/dist/reporter/writeReport.js +3 -3
- package/dist/reporter/writeReport.js.map +1 -1
- package/dist/runner/approve.d.ts +34 -9
- package/dist/runner/approve.d.ts.map +1 -1
- package/dist/runner/approve.js +54 -10
- package/dist/runner/approve.js.map +1 -1
- package/dist/runner/approveFrom.d.ts +58 -0
- package/dist/runner/approveFrom.d.ts.map +1 -0
- package/dist/runner/approveFrom.js +384 -0
- package/dist/runner/approveFrom.js.map +1 -0
- package/dist/runner/breakpointPasses.d.ts +39 -0
- package/dist/runner/breakpointPasses.d.ts.map +1 -0
- package/dist/runner/breakpointPasses.js +107 -0
- package/dist/runner/breakpointPasses.js.map +1 -0
- package/dist/runner/bridges/database.d.ts +4 -3
- package/dist/runner/bridges/database.d.ts.map +1 -1
- package/dist/runner/bridges/database.js +4 -3
- package/dist/runner/bridges/database.js.map +1 -1
- package/dist/runner/exitCode.d.ts +34 -0
- package/dist/runner/exitCode.d.ts.map +1 -0
- package/dist/runner/exitCode.js +41 -0
- package/dist/runner/exitCode.js.map +1 -0
- package/dist/runner/manifest.d.ts +149 -0
- package/dist/runner/manifest.d.ts.map +1 -0
- package/dist/runner/manifest.js +229 -0
- package/dist/runner/manifest.js.map +1 -0
- package/dist/runner/mode.d.ts +41 -0
- package/dist/runner/mode.d.ts.map +1 -0
- package/dist/runner/mode.js +43 -0
- package/dist/runner/mode.js.map +1 -0
- package/dist/runner/orphanScan.d.ts +68 -0
- package/dist/runner/orphanScan.d.ts.map +1 -0
- package/dist/runner/orphanScan.js +150 -0
- package/dist/runner/orphanScan.js.map +1 -0
- package/dist/runner/run.d.ts +85 -1
- package/dist/runner/run.d.ts.map +1 -1
- package/dist/runner/run.js +267 -41
- package/dist/runner/run.js.map +1 -1
- package/dist/runner/runAction.d.ts +22 -0
- package/dist/runner/runAction.d.ts.map +1 -1
- package/dist/runner/runAction.js +146 -24
- package/dist/runner/runAction.js.map +1 -1
- package/dist/runner/runStory.d.ts +40 -2
- package/dist/runner/runStory.d.ts.map +1 -1
- package/dist/runner/runStory.js +195 -62
- package/dist/runner/runStory.js.map +1 -1
- package/dist/runner/storyFilter.d.ts +8 -0
- package/dist/runner/storyFilter.d.ts.map +1 -1
- package/dist/runner/storyFilter.js +11 -0
- package/dist/runner/storyFilter.js.map +1 -1
- package/dist/schema/action.d.ts +11 -11
- package/dist/schema/result.d.ts +124 -6
- package/dist/schema/result.d.ts.map +1 -1
- package/dist/schema/result.js.map +1 -1
- package/dist/schema/story.d.ts +15 -4
- package/dist/schema/story.d.ts.map +1 -1
- package/dist/schema/story.js +35 -11
- package/dist/schema/story.js.map +1 -1
- package/dist/screenshots/baselineStore.d.ts +111 -5
- package/dist/screenshots/baselineStore.d.ts.map +1 -1
- package/dist/screenshots/baselineStore.js +132 -20
- package/dist/screenshots/baselineStore.js.map +1 -1
- package/dist/screenshots/capture.d.ts +10 -5
- package/dist/screenshots/capture.d.ts.map +1 -1
- package/dist/screenshots/capture.js +31 -18
- package/dist/screenshots/capture.js.map +1 -1
- package/package.json +1 -1
|
@@ -17,8 +17,15 @@ const STATUS_MARKERS = {
|
|
|
17
17
|
* Static HTML report. Rocks a terminal, dev-tool aesthetic. Dark mode by
|
|
18
18
|
* default, monospace font for data, sharp borders, and minimal but
|
|
19
19
|
* evocative icons + neon colors to indicate statuses.
|
|
20
|
+
*
|
|
21
|
+
* `<main>` reading order: an optional environment-mismatch banner (first, only
|
|
22
|
+
* when `environment.mismatch`), then the summary, the stories, and an optional
|
|
23
|
+
* deleted (orphaned-baseline) section last. The banner and deleted section are
|
|
24
|
+
* peer `<h2>` landmarks; the two supplementary per-action notes (candidate /
|
|
25
|
+
* a11y-drift) contribute no heading levels, so the outline stays
|
|
26
|
+
* H1 → summary → stories → deleted.
|
|
20
27
|
*/
|
|
21
|
-
export function renderReport(result, reportDir) {
|
|
28
|
+
export function renderReport(result, reportDir, interactiveMode = false) {
|
|
22
29
|
const dateLabel = formatDate(result.finishedAt);
|
|
23
30
|
return `
|
|
24
31
|
<!doctype html>
|
|
@@ -40,101 +47,158 @@ export function renderReport(result, reportDir) {
|
|
|
40
47
|
</p>
|
|
41
48
|
</header>
|
|
42
49
|
<main id="main" tabindex="-1">
|
|
50
|
+
${renderEnvMismatch(result)}
|
|
43
51
|
${renderSummary(result)}
|
|
44
|
-
${renderStories(result, reportDir)}
|
|
52
|
+
${renderStories(result, reportDir, interactiveMode)}
|
|
53
|
+
${renderDeleted(result)}
|
|
45
54
|
</main>
|
|
46
55
|
<script src="assets/report.js"></script>
|
|
47
56
|
</body>
|
|
48
57
|
</html>
|
|
49
58
|
`;
|
|
50
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* The status totals double as the report's filter controls: each is a native
|
|
62
|
+
* `<button aria-pressed>` single-select filter, with the "stories" total acting
|
|
63
|
+
* as the "show all / clear" control (pressed by default). The expand-all /
|
|
64
|
+
* collapse-all pair sits at the right end of the same row — the slot the old
|
|
65
|
+
* coverage stats used to occupy. The `<ul>` stays a plain list (no composite
|
|
66
|
+
* role): a non-filter total and the bulk-toggle group share it, so a
|
|
67
|
+
* radiogroup/fieldset could not cleanly scope just the filters.
|
|
68
|
+
*/
|
|
51
69
|
function renderSummary(result) {
|
|
52
|
-
const screens = result.customCoverage.screens;
|
|
53
|
-
const flows = result.customCoverage.flows;
|
|
54
70
|
return `
|
|
55
71
|
<section class="summary" aria-labelledby="summary-heading">
|
|
56
72
|
<h2 id="summary-heading">summary</h2>
|
|
57
73
|
<ul class="summary-list" aria-label="Run totals">
|
|
58
|
-
${
|
|
59
|
-
${
|
|
60
|
-
${
|
|
61
|
-
${
|
|
62
|
-
${
|
|
63
|
-
|
|
74
|
+
${summaryFilter('stories', result.totals.stories, 'all', true, ' — show all stories')}
|
|
75
|
+
${summaryFilter('passed', result.totals.passed, 'pass', false, ', show only passed stories')}
|
|
76
|
+
${summaryFilter('new', result.totals.new, 'new', false, ', show only new stories')}
|
|
77
|
+
${summaryFilter('changed', result.totals.changed, 'changed', false, ', show only changed stories')}
|
|
78
|
+
${summaryFilter('failed', result.totals.failed, 'failed', false, ', show only failed stories')}
|
|
79
|
+
<li class="story-bulk-toggle">
|
|
80
|
+
<button type="button" class="story-bulk-toggle-button" data-bulk-toggle="expand"><span class="bulk-verb">Expand</span><span class="bulk-scope-sr sr-only"> all screenshots</span></button>
|
|
81
|
+
<span class="bulk-sep" aria-hidden="true">/</span>
|
|
82
|
+
<button type="button" class="story-bulk-toggle-button" data-bulk-toggle="collapse"><span class="bulk-verb">Collapse</span><span class="bulk-scope-sr sr-only"> all screenshots</span></button>
|
|
83
|
+
<span class="bulk-scope" aria-hidden="true">screenshots</span>
|
|
84
|
+
</li>
|
|
64
85
|
</ul>
|
|
65
86
|
</section>
|
|
66
87
|
`;
|
|
67
88
|
}
|
|
68
|
-
|
|
69
|
-
|
|
89
|
+
/**
|
|
90
|
+
* One status total rendered as a single-select filter button. The visible count
|
|
91
|
+
* sits OUTSIDE the button as a sibling span and is wired to it via
|
|
92
|
+
* aria-describedby, so only the word ("passed") is the underlined link while the
|
|
93
|
+
* count still reads as the button's description. The accessible name is the
|
|
94
|
+
* visible label plus a visually-hidden action suffix (e.g. ", show only passed
|
|
95
|
+
* stories"), composed from contents so the visible text is never dropped (WCAG
|
|
96
|
+
* 2.5.3 — never an aria-label). The `data-filter` token ("pass") is kept
|
|
97
|
+
* distinct from the visible label ("passed") so report.js matches
|
|
98
|
+
* `story[data-status="pass"]`.
|
|
99
|
+
*/
|
|
100
|
+
function summaryFilter(label, value, filter, pressed, actionSuffix) {
|
|
70
101
|
return `
|
|
71
|
-
<li class="summary-item
|
|
72
|
-
<span class="count">${
|
|
73
|
-
<span class="
|
|
74
|
-
<span class="coverage-detail" aria-hidden="true">· ${metric.covered}/${metric.total}</span>
|
|
75
|
-
<span class="sr-only">${metric.covered} of ${metric.total} ${label} covered</span>
|
|
102
|
+
<li class="summary-item" data-status="${filter}">
|
|
103
|
+
<span class="count" id="summary-count-${filter}">${value}</span><button type="button" class="summary-filter" data-filter="${filter}" aria-pressed="${pressed}" aria-controls="stories-list" aria-describedby="summary-count-${filter}"><span class="indicator label">${label}</span><span class="sr-only">${actionSuffix}</span></button>
|
|
104
|
+
<span class="bulk-sep" aria-hidden="true">·</span>
|
|
76
105
|
</li>
|
|
77
106
|
`;
|
|
78
107
|
}
|
|
79
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Environment-mismatch banner, rendered first inside `<main>` (above the
|
|
110
|
+
* summary) ONLY when `environment.mismatch === true` — i.e. a CI run whose
|
|
111
|
+
* committed baselines were captured under a different, pixel-affecting
|
|
112
|
+
* environment, or whose committed manifest could not be read at all.
|
|
113
|
+
*
|
|
114
|
+
* `role="alert"` is an explicit acceptance criterion. It does NOT auto-announce
|
|
115
|
+
* on content present at load, so the real discoverability comes from the banner
|
|
116
|
+
* being first in reading order behind a `<h2>` landmark. Kept because it is
|
|
117
|
+
* harmless and specified.
|
|
118
|
+
*
|
|
119
|
+
* The "warning" meaning is carried by the TEXT (the heading word and body copy),
|
|
120
|
+
* never by color alone (WCAG 1.4.1): body text stays `--text` / amber
|
|
121
|
+
* `--changed`, and the red accent lives only on the section's left border (a
|
|
122
|
+
* non-text ≥3:1 cue, mirroring `.action-error`).
|
|
123
|
+
*
|
|
124
|
+
* Two copy branches: the `['manifest']` sentinel (committed manifest unreadable,
|
|
125
|
+
* so the diverging keys can't be enumerated) drops the key list for a plain
|
|
126
|
+
* "can't be verified" message; any other mismatch lists the diverging keys.
|
|
127
|
+
*/
|
|
128
|
+
function renderEnvMismatch(result) {
|
|
129
|
+
const environment = result.environment;
|
|
130
|
+
if (environment?.mismatch !== true) {
|
|
131
|
+
return '';
|
|
132
|
+
}
|
|
133
|
+
const isManifestSentinel = environment.mismatchKeys.length === 1 &&
|
|
134
|
+
environment.mismatchKeys[0] === 'manifest';
|
|
135
|
+
const body = isManifestSentinel
|
|
136
|
+
? `<p>The committed baseline manifest could not be read, so the capture environment can't be verified. Expect a full re-approve.</p>`
|
|
137
|
+
: `<p>Expect a full re-approve — baselines were captured under a different environment.</p>
|
|
138
|
+
<ul aria-label="Changed environment keys">
|
|
139
|
+
${environment.mismatchKeys
|
|
140
|
+
.map((key) => `<li><code>${escapeHtml(key)}</code></li>`)
|
|
141
|
+
.join('\n ')}
|
|
142
|
+
</ul>`;
|
|
80
143
|
return `
|
|
81
|
-
<
|
|
82
|
-
<
|
|
83
|
-
|
|
84
|
-
</
|
|
144
|
+
<section class="env-mismatch" role="alert" aria-labelledby="env-mismatch-heading">
|
|
145
|
+
<h2 id="env-mismatch-heading">capture environment changed</h2>
|
|
146
|
+
${body}
|
|
147
|
+
</section>
|
|
85
148
|
`;
|
|
86
149
|
}
|
|
87
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Deleted (orphaned committed baselines) section — a peer landmark rendered
|
|
152
|
+
* AFTER the stories section, inside `<main>`, ONLY when `deleted` is non-empty.
|
|
153
|
+
* Lists each orphaned baseline (action + breakpoint) that `approve --prune`
|
|
154
|
+
* would remove. A `'legacy'` breakpoint (the pre-breakpoint `<action>/0.png`
|
|
155
|
+
* layout) reads cryptically on its own, so it carries an sr-only clarifier.
|
|
156
|
+
*/
|
|
157
|
+
function renderDeleted(result) {
|
|
158
|
+
if (result.deleted.length === 0) {
|
|
159
|
+
return '';
|
|
160
|
+
}
|
|
161
|
+
const items = result.deleted
|
|
162
|
+
.map((entry) => renderDeletedEntry(entry))
|
|
163
|
+
.join('\n ');
|
|
164
|
+
return `
|
|
165
|
+
<section class="deleted" aria-labelledby="deleted-heading">
|
|
166
|
+
<h2 id="deleted-heading">deleted</h2>
|
|
167
|
+
<p>These committed baselines have no matching story this run. <code>tuffgal approve --prune</code> removes them.</p>
|
|
168
|
+
<ul aria-label="Orphaned baselines to be pruned on approve">
|
|
169
|
+
${items}
|
|
170
|
+
</ul>
|
|
171
|
+
</section>
|
|
172
|
+
`;
|
|
173
|
+
}
|
|
174
|
+
function renderDeletedEntry(entry) {
|
|
175
|
+
const breakpoint = entry.breakpoint === 'legacy'
|
|
176
|
+
? 'legacy<span class="sr-only"> (pre-breakpoint layout)</span>'
|
|
177
|
+
: escapeHtml(entry.breakpoint);
|
|
178
|
+
return `<li><code>${escapeHtml(entry.action)}</code> ${breakpoint}</li>`;
|
|
179
|
+
}
|
|
180
|
+
function renderStories(result, reportDir, interactiveMode) {
|
|
88
181
|
const items = result.stories
|
|
89
|
-
.map((story, index) => renderStory(story, index, reportDir))
|
|
182
|
+
.map((story, index) => renderStory(story, index, reportDir, interactiveMode))
|
|
90
183
|
.join('\n');
|
|
91
184
|
const total = result.stories.length;
|
|
185
|
+
// The interactive controls now live in the summary row; this section keeps
|
|
186
|
+
// only the two live regions (both server-rendered between the heading and the
|
|
187
|
+
// list so a screen reader announces filter/bulk changes reliably) and the
|
|
188
|
+
// list itself, whose id the summary filter buttons target via aria-controls.
|
|
92
189
|
return `
|
|
93
190
|
<section aria-labelledby="stories-heading">
|
|
94
191
|
<h2 id="stories-heading">stories</h2>
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
${storyFilterRadio('all', true)}
|
|
99
|
-
${storyFilterRadio('passed', false)}
|
|
100
|
-
${storyFilterRadio('changed', false)}
|
|
101
|
-
${storyFilterRadio('failed', false)}
|
|
102
|
-
</fieldset>
|
|
103
|
-
<p class="story-filter-status" role="status" aria-live="polite">Showing all ${total} stories</p>
|
|
104
|
-
<div class="story-bulk-toggle">
|
|
105
|
-
<button type="button" class="chip story-bulk-toggle-button" data-bulk-toggle="expand">Expand all</button>
|
|
106
|
-
<button type="button" class="chip story-bulk-toggle-button" data-bulk-toggle="collapse">Collapse all</button>
|
|
107
|
-
</div>
|
|
108
|
-
<p class="bulk-toggle-status sr-only" role="status" aria-live="polite"></p>
|
|
109
|
-
</div>
|
|
110
|
-
<ol class="stories" aria-label="Stories executed in dependency order">
|
|
192
|
+
<p class="story-filter-status" role="status" aria-live="polite" aria-atomic="true">Showing all ${total} stories</p>
|
|
193
|
+
<p class="bulk-toggle-status sr-only" role="status" aria-live="polite" aria-atomic="true"></p>
|
|
194
|
+
<ol class="stories" id="stories-list" aria-label="Stories executed in dependency order">
|
|
111
195
|
${items}
|
|
112
196
|
</ol>
|
|
113
197
|
<p class="stories-empty" hidden>No matching stories</p>
|
|
114
198
|
</section>
|
|
115
199
|
`;
|
|
116
200
|
}
|
|
117
|
-
function
|
|
118
|
-
const inputId = `story-filter-${status}`;
|
|
119
|
-
const value = status === 'passed' ? 'pass' : status;
|
|
120
|
-
return `
|
|
121
|
-
<label for="${inputId}" class="chip chip--toggle story-filter-label">
|
|
122
|
-
<input
|
|
123
|
-
type="radio"
|
|
124
|
-
name="story-filter"
|
|
125
|
-
id="${inputId}"
|
|
126
|
-
value="${value}"
|
|
127
|
-
data-filter-name="${status}"
|
|
128
|
-
${checked ? 'checked' : ''}
|
|
129
|
-
/>
|
|
130
|
-
${status}
|
|
131
|
-
</label>
|
|
132
|
-
`;
|
|
133
|
-
}
|
|
134
|
-
function renderStory(story, storyIndex, reportDir) {
|
|
135
|
-
const actions = story.actions
|
|
136
|
-
.map((action, actionIndex) => renderAction(action, `s${storyIndex}-a${actionIndex}`, reportDir))
|
|
137
|
-
.join('\n');
|
|
201
|
+
function renderStory(story, storyIndex, reportDir, interactiveMode) {
|
|
138
202
|
return `
|
|
139
203
|
<li class="story" data-status="${story.status}">
|
|
140
204
|
<div class="story-row">
|
|
@@ -145,14 +209,105 @@ function renderStory(story, storyIndex, reportDir) {
|
|
|
145
209
|
</div>
|
|
146
210
|
<p class="story-prose">${escapeHtml(story.story)}</p>
|
|
147
211
|
<br/>
|
|
148
|
-
|
|
212
|
+
${renderStoryActions(story, storyIndex, reportDir, interactiveMode)}
|
|
213
|
+
</li>
|
|
214
|
+
`;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Renders a story's action results as one labelled group per breakpoint, in
|
|
218
|
+
* first-seen order (which the runner emits in run-set order). Two shapes:
|
|
219
|
+
*
|
|
220
|
+
* - Single mode: when the story ran at exactly one breakpoint (the common
|
|
221
|
+
* default `desktop` project), we render the historical flat
|
|
222
|
+
* `<ol class="actions">` with no per-mode caption — no breakpoint chrome
|
|
223
|
+
* when there is only one mode to show.
|
|
224
|
+
* - Multi mode: when the story ran at two or more breakpoints, we render one
|
|
225
|
+
* labelled group per mode so a reader sees results per mode instead of a
|
|
226
|
+
* flat interleaved list. An action with `screenshot:false` still appears
|
|
227
|
+
* once per breakpoint — it simply renders as a shot-less row in its mode's
|
|
228
|
+
* group, no special-casing needed.
|
|
229
|
+
*
|
|
230
|
+
* `actionId` is keyed by the action's index in the original flat array
|
|
231
|
+
* (`s<story>-a<flatIndex>`), NOT a per-group counter, so radio `name`s and
|
|
232
|
+
* shot-panel `id`s stay globally unique across groups and report.js's
|
|
233
|
+
* `name="<actionId>-shot"` radio grouping never collides between modes.
|
|
234
|
+
*/
|
|
235
|
+
function renderStoryActions(story, storyIndex, reportDir, interactiveMode) {
|
|
236
|
+
// Bucket actions by breakpoint, preserving first-seen order.
|
|
237
|
+
const order = [];
|
|
238
|
+
const buckets = new Map();
|
|
239
|
+
story.actions.forEach((action, actionIndex) => {
|
|
240
|
+
const key = action.breakpoint ?? '';
|
|
241
|
+
if (!buckets.has(key)) {
|
|
242
|
+
buckets.set(key, []);
|
|
243
|
+
order.push(key);
|
|
244
|
+
}
|
|
245
|
+
buckets.get(key).push({ action, id: `s${storyIndex}-a${actionIndex}` });
|
|
246
|
+
});
|
|
247
|
+
// One mode (or untagged) → flat list, no caption. Captions only earn their
|
|
248
|
+
// chrome when there is more than one mode to tell apart.
|
|
249
|
+
if (order.length <= 1) {
|
|
250
|
+
const actions = story.actions
|
|
251
|
+
.map((action, actionIndex) => renderAction(action, `s${storyIndex}-a${actionIndex}`, reportDir, interactiveMode))
|
|
252
|
+
.join('\n');
|
|
253
|
+
return `<ol class="actions" aria-label="Actions">
|
|
254
|
+
${actions}
|
|
255
|
+
</ol>`;
|
|
256
|
+
}
|
|
257
|
+
return order
|
|
258
|
+
.map((key, groupIndex) => renderBreakpointGroup(key, buckets.get(key), `s${storyIndex}-bp${groupIndex}`, reportDir, interactiveMode))
|
|
259
|
+
.join('\n');
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* One labelled per-breakpoint subsection. The mode label carries the breakpoint
|
|
263
|
+
* NAME and its DIMENSIONS — the real capture size recorded on the result, so
|
|
264
|
+
* per-config and per-story overrides show their actual size. The label is a
|
|
265
|
+
* non-heading caption: stories live inside an `<ol>` list, not a heading
|
|
266
|
+
* outline, so injecting an `<h3>` here would orphan it under the story's
|
|
267
|
+
* list-item subtree. Instead the action list is a labelled region — its
|
|
268
|
+
* `<ol aria-labelledby>` points at the visible caption, so assistive tech
|
|
269
|
+
* announces e.g. "mobile 375 by 667 pixels actions" without minting a heading
|
|
270
|
+
* level. The trailing "actions" is an sr-only token inside the caption —
|
|
271
|
+
* "actions" never appears in the visible label, only in the computed accessible
|
|
272
|
+
* name, so the region reads as a list of actions rather than a bare dimension
|
|
273
|
+
* string.
|
|
274
|
+
*
|
|
275
|
+
* Dimensions render in their own `aria-hidden` span (decorative "375×667")
|
|
276
|
+
* with an sr-only longhand ("375 by 667 pixels") so screen readers don't read
|
|
277
|
+
* the `×` glyph as "x" mid-stream.
|
|
278
|
+
*/
|
|
279
|
+
function renderBreakpointGroup(key, entries, groupId, reportDir, interactiveMode) {
|
|
280
|
+
const labelId = `${groupId}-label`;
|
|
281
|
+
const name = key;
|
|
282
|
+
// The capture dimensions recorded on the result reflect per-config and
|
|
283
|
+
// per-story overrides. A result always carries them post-migration; the guard
|
|
284
|
+
// only keeps a malformed entry from emitting a half-empty dimension span.
|
|
285
|
+
const recorded = entries[0]?.action;
|
|
286
|
+
const dimensions = recorded?.breakpointWidth !== undefined &&
|
|
287
|
+
recorded.breakpointHeight !== undefined
|
|
288
|
+
? { width: recorded.breakpointWidth, height: recorded.breakpointHeight }
|
|
289
|
+
: undefined;
|
|
290
|
+
const dimensionMarkup = dimensions
|
|
291
|
+
? `<span class="breakpoint-dimensions" aria-hidden="true">${dimensions.width}×${dimensions.height}</span><span class="sr-only">${dimensions.width} by ${dimensions.height} pixels</span>`
|
|
292
|
+
: '';
|
|
293
|
+
const actions = entries
|
|
294
|
+
.map(({ action, id }) => renderAction(action, id, reportDir, interactiveMode))
|
|
295
|
+
.join('\n');
|
|
296
|
+
return `
|
|
297
|
+
<div class="breakpoint-group">
|
|
298
|
+
<p class="breakpoint-label" id="${labelId}">
|
|
299
|
+
<span class="breakpoint-name">${escapeHtml(name)}</span>
|
|
300
|
+
${dimensionMarkup}
|
|
301
|
+
<span class="sr-only"> actions</span>
|
|
302
|
+
</p>
|
|
303
|
+
<ol class="actions" aria-labelledby="${labelId}">
|
|
149
304
|
${actions}
|
|
150
305
|
</ol>
|
|
151
|
-
</
|
|
306
|
+
</div>
|
|
152
307
|
`;
|
|
153
308
|
}
|
|
154
|
-
function renderAction(action, actionId, reportDir) {
|
|
155
|
-
const screenshots = renderScreenshots(action, actionId, reportDir);
|
|
309
|
+
function renderAction(action, actionId, reportDir, interactiveMode) {
|
|
310
|
+
const screenshots = renderScreenshots(action, actionId, reportDir, interactiveMode);
|
|
156
311
|
const errorBlock = action.status === 'failed'
|
|
157
312
|
? `<pre class="action-error">${escapeHtml(action.failureMessage ?? 'unknown error')}</pre>`
|
|
158
313
|
: '';
|
|
@@ -176,14 +331,53 @@ ${statusBadge(action.status)}
|
|
|
176
331
|
${rowInner}
|
|
177
332
|
</div>
|
|
178
333
|
`;
|
|
334
|
+
const notes = renderActionNotes(action, reportDir);
|
|
179
335
|
return `
|
|
180
336
|
<li class="action" data-status="${action.status}">
|
|
181
337
|
${row}
|
|
182
338
|
${parameters}
|
|
183
339
|
${errorBlock}
|
|
340
|
+
${notes}
|
|
184
341
|
</li>
|
|
185
342
|
`;
|
|
186
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Supplementary per-action prose, rendered inside `li.action` after the
|
|
346
|
+
* row/screenshots/error block. Both are plain `<p role="note">` — NOT headings:
|
|
347
|
+
* they live in the story `<ol>` subtree, so a heading would orphan under a
|
|
348
|
+
* list-item (same rationale as {@link renderBreakpointGroup}'s caption). Neither
|
|
349
|
+
* is a live region (present at load), so an a11y-only `changed` row can carry
|
|
350
|
+
* BOTH with no double-announce.
|
|
351
|
+
*
|
|
352
|
+
* - candidate note: on `changed`/`new` rows only — supplementary prose flagging
|
|
353
|
+
* "this render is the proposed new baseline". No aria wiring; it does not
|
|
354
|
+
* duplicate the status badge's sr-only label.
|
|
355
|
+
* - a11y-drift note: gated STRICTLY on `a11yChanged === true`, NEVER inferred
|
|
356
|
+
* from a missing `diffPath` (a size-mismatch `changed` row also lacks a
|
|
357
|
+
* diffPath yet deliberately omits `a11yChanged`; keying on `!diffPath` would
|
|
358
|
+
* misfire on it — the load-bearing discriminator, per the ActionResult
|
|
359
|
+
* contract). Renders the recorded `a11yBaselinePath` as plain escaped
|
|
360
|
+
* `<code>` TEXT, not a link (the report is portable / opened over file://),
|
|
361
|
+
* relativized like the other paths when absolute.
|
|
362
|
+
*
|
|
363
|
+
* Order: candidate note first, then a11y-drift note, so an a11y-only changed row
|
|
364
|
+
* reads "proposed new baseline" before the a11y specifics.
|
|
365
|
+
*/
|
|
366
|
+
function renderActionNotes(action, reportDir) {
|
|
367
|
+
const notes = [];
|
|
368
|
+
if (action.status === 'changed' || action.status === 'new') {
|
|
369
|
+
notes.push(`<p class="candidate-note" role="note">This render is the proposed new baseline.</p>`);
|
|
370
|
+
}
|
|
371
|
+
if (action.a11yChanged === true) {
|
|
372
|
+
const path = action.a11yBaselinePath;
|
|
373
|
+
const displayPath = path !== undefined ? toReportRelative(reportDir, path) : undefined;
|
|
374
|
+
const pathMarkup = displayPath !== undefined
|
|
375
|
+
? ` Proposed a11y baseline written to <code>${escapeHtml(displayPath)}</code>.`
|
|
376
|
+
: '';
|
|
377
|
+
notes.push(`<p class="a11y-drift-note" role="note">Accessibility snapshot changed.${pathMarkup}</p>`);
|
|
378
|
+
}
|
|
379
|
+
return notes.join('\n ');
|
|
380
|
+
}
|
|
187
381
|
function renderParameters(parameters) {
|
|
188
382
|
if (!parameters || Object.keys(parameters).length === 0) {
|
|
189
383
|
return '';
|
|
@@ -193,11 +387,42 @@ function renderParameters(parameters) {
|
|
|
193
387
|
.join('');
|
|
194
388
|
return `<dl class="action-parameters">${entries}</dl>`;
|
|
195
389
|
}
|
|
196
|
-
|
|
390
|
+
/**
|
|
391
|
+
* A "changed" row whose diff could not be computed: baseline and actual differ
|
|
392
|
+
* in dimensions, so pixelmatch throws before producing a diffRatio or diff
|
|
393
|
+
* image, leaving only the recorded failureMessage. Centralizes the predicate
|
|
394
|
+
* shared by the radio fallback, the diff radio's describedby wiring, and
|
|
395
|
+
* renderDiffStats' unavailable note.
|
|
396
|
+
*/
|
|
397
|
+
function isDiffUnavailable(action) {
|
|
398
|
+
return (action.diffRatio === undefined &&
|
|
399
|
+
action.status === 'changed' &&
|
|
400
|
+
!!action.failureMessage);
|
|
401
|
+
}
|
|
402
|
+
function renderScreenshots(action, actionId, reportDir, interactiveMode) {
|
|
197
403
|
if (!action.actualPath && !action.baselinePath) {
|
|
198
404
|
return '';
|
|
199
405
|
}
|
|
200
|
-
|
|
406
|
+
// interactiveMode swaps the radio-tab output for the single-image hover/press
|
|
407
|
+
// viewer. When it is false the function falls through to the radio-tab output
|
|
408
|
+
// below, byte-identical with the pre-interactiveMode render.
|
|
409
|
+
//
|
|
410
|
+
// When the baseline and actual differ in dimensions the diff is uncomputable
|
|
411
|
+
// (renderDiffStats' unavailable branch — both paths present, `changed` status,
|
|
412
|
+
// a recorded failureMessage, no diffRatio). The hover/press gesture has no diff
|
|
413
|
+
// image to reveal, so fall back to the radio-tab render: visible chips,
|
|
414
|
+
// baseline + actual, and the disabled diff option carrying the mismatch reason.
|
|
415
|
+
const diffUncomputable = action.baselinePath !== undefined &&
|
|
416
|
+
action.actualPath !== undefined &&
|
|
417
|
+
isDiffUnavailable(action);
|
|
418
|
+
if (interactiveMode && !diffUncomputable) {
|
|
419
|
+
return renderInteractiveScreenshots(action, actionId, reportDir);
|
|
420
|
+
}
|
|
421
|
+
// A `new` baseline writes its baseline straight from this run's actual, so the
|
|
422
|
+
// two paths point at byte-identical PNGs. There is no prior state to compare
|
|
423
|
+
// against, so suppress the baseline variant for display — like the diff, it is
|
|
424
|
+
// not a real artifact here. The path stays in the data model for `approve`.
|
|
425
|
+
const baseline = action.baselinePath && action.status !== 'new'
|
|
201
426
|
? toReportRelative(reportDir, action.baselinePath)
|
|
202
427
|
: undefined;
|
|
203
428
|
const actual = action.actualPath
|
|
@@ -206,30 +431,174 @@ function renderScreenshots(action, actionId, reportDir) {
|
|
|
206
431
|
const diff = action.diffPath
|
|
207
432
|
? toReportRelative(reportDir, action.diffPath)
|
|
208
433
|
: undefined;
|
|
209
|
-
const defaultTab =
|
|
434
|
+
const defaultTab = 'actual';
|
|
210
435
|
const available = { baseline, actual, diff };
|
|
211
436
|
const initialTab = available[defaultTab] !== undefined
|
|
212
437
|
? defaultTab
|
|
213
438
|
: ['baseline', 'actual', 'diff'].find((name) => available[name] !== undefined);
|
|
214
439
|
const diffStatsId = `${actionId}-diff-stats`;
|
|
215
|
-
const diffStats = action
|
|
216
|
-
|
|
217
|
-
|
|
440
|
+
const diffStats = renderDiffStats(action, diffStatsId);
|
|
441
|
+
// renderDiffStats emits the `diff-stats--unavailable` note (with this id) when
|
|
442
|
+
// the diff is uncomputable. The diff radio is disabled in that case, so wire
|
|
443
|
+
// its aria-describedby to the note — a keyboard/AT user reaching the disabled
|
|
444
|
+
// diff option then hears why no diff exists. (The diff PANEL only takes the
|
|
445
|
+
// association when a real diff image renders, below.)
|
|
446
|
+
const diffNoteUnavailable = isDiffUnavailable(action);
|
|
447
|
+
// When only one variant is real (the common case for a `new` baseline, whose
|
|
448
|
+
// baseline is suppressed and has no diff), a radio group offering a single
|
|
449
|
+
// choice is noise to AT. Drop the controls and show the image alone; the row's
|
|
450
|
+
// status badge already announces "new baseline". Zero variants — a `new` row
|
|
451
|
+
// whose actual capture is somehow missing — collapses to nothing.
|
|
452
|
+
const soleVariant = ['baseline', 'actual', 'diff'].filter((name) => available[name] !== undefined);
|
|
453
|
+
if (soleVariant.length <= 1) {
|
|
454
|
+
const only = soleVariant[0];
|
|
455
|
+
if (only === undefined) {
|
|
456
|
+
return '';
|
|
457
|
+
}
|
|
458
|
+
const lone = shotPanel(actionId, only, available[only], SHOT_ALT[only](action), true);
|
|
459
|
+
return `${diffStats}${lone}`;
|
|
460
|
+
}
|
|
218
461
|
return `
|
|
219
462
|
<fieldset class="shot-radio" data-default-tab="${defaultTab}">
|
|
220
463
|
<legend class="sr-only">Screenshot to display</legend>
|
|
221
464
|
${shotRadio(actionId, 'baseline', baseline === undefined, initialTab === 'baseline')}
|
|
222
465
|
${shotRadio(actionId, 'actual', actual === undefined, initialTab === 'actual')}
|
|
223
|
-
${shotRadio(actionId, 'diff', diff === undefined, initialTab === 'diff')}
|
|
466
|
+
${shotRadio(actionId, 'diff', diff === undefined, initialTab === 'diff', diffNoteUnavailable ? { describedById: diffStatsId } : undefined)}
|
|
224
467
|
${diffStats}
|
|
225
468
|
</fieldset>
|
|
226
|
-
${shotPanel(actionId, 'baseline', baseline,
|
|
227
|
-
${shotPanel(actionId, 'actual', actual,
|
|
228
|
-
${shotPanel(actionId, 'diff', diff,
|
|
469
|
+
${shotPanel(actionId, 'baseline', baseline, SHOT_ALT.baseline(action), initialTab === 'baseline')}
|
|
470
|
+
${shotPanel(actionId, 'actual', actual, SHOT_ALT.actual(action), initialTab === 'actual')}
|
|
471
|
+
${shotPanel(actionId, 'diff', diff, SHOT_ALT.diff(action), initialTab === 'diff', action.diffRatio !== undefined ? diffStatsId : undefined)}
|
|
229
472
|
`;
|
|
230
473
|
}
|
|
231
|
-
|
|
474
|
+
/** Alt text per screenshot variant, shared by the radio-tab and collapsed render. */
|
|
475
|
+
const SHOT_ALT = {
|
|
476
|
+
baseline: (action) => `${action.action} baseline screenshot`,
|
|
477
|
+
actual: (action) => `${action.action} actual screenshot from this run`,
|
|
478
|
+
diff: (action) => `Pixel diff overlay for ${action.action}; changed regions are highlighted`,
|
|
479
|
+
};
|
|
480
|
+
/**
|
|
481
|
+
* The pixel-diff overlay only exists when baseline and actual share dimensions.
|
|
482
|
+
* A mismatch (e.g. a fullPage capture whose document grew taller) throws before
|
|
483
|
+
* a diff is computed, so `diffRatio` is absent and there is no diff image to
|
|
484
|
+
* show — surface the recorded reason here, in the slot the "% differs" stat
|
|
485
|
+
* would normally occupy, so a "changed" row never reads as an unexplained no-op.
|
|
486
|
+
*/
|
|
487
|
+
function renderDiffStats(action, diffStatsId) {
|
|
488
|
+
return action.diffRatio !== undefined
|
|
489
|
+
? `<p class="diff-stats" id="${diffStatsId}"><span class="count">${parseFloat((action.diffRatio * 100).toFixed(2))}%</span> <span class="label">differs</span> <span class="coverage-detail">· ${(action.diffPixels ?? 0).toLocaleString('en-US')} pixels</span></p>`
|
|
490
|
+
: action.status === 'changed' && action.failureMessage
|
|
491
|
+
? `<p class="diff-stats diff-stats--unavailable" id="${diffStatsId}"><span class="label">No pixel diff. ${escapeHtml(action.failureMessage)}</span></p>`
|
|
492
|
+
: '';
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Interactive screenshot viewer (interactiveMode). One native radio group per
|
|
496
|
+
* action is the committed-state source of truth — keyboard, touch, and AT all
|
|
497
|
+
* operate the radios (reusing `name="${actionId}-shot"`). report.js layers a
|
|
498
|
+
* VISUAL-ONLY mouse preview (hover→baseline, press→diff, release→committed) on
|
|
499
|
+
* a SINGLE shared `<img>`; that gesture never mutates radio state, the img alt,
|
|
500
|
+
* or any ARIA. The controls + caption live OUTSIDE the clipped `.shot-stage` so
|
|
501
|
+
* the focus ring is never clipped or painted over screenshot pixels. The diff
|
|
502
|
+
* variant — and its radio — is omitted entirely (not disabled) when this action
|
|
503
|
+
* produced no diff image; the existing diff-stats association then rides on the
|
|
504
|
+
* diff radio control rather than the image, leaving no dangling describedby.
|
|
505
|
+
* (Distinct from the dimension-mismatch case, where the diff is uncomputable:
|
|
506
|
+
* renderScreenshots never reaches this viewer and instead falls back to the
|
|
507
|
+
* radio-tab render with a disabled — not omitted — diff radio.)
|
|
508
|
+
*/
|
|
509
|
+
function renderInteractiveScreenshots(action, actionId, reportDir) {
|
|
510
|
+
// A `new` baseline writes its baseline straight from this run's actual, so the
|
|
511
|
+
// two paths point at byte-identical PNGs. There is no prior state to compare
|
|
512
|
+
// against, so suppress the baseline variant for display — like the diff, it is
|
|
513
|
+
// omitted (no radio, no image). The path stays in the data model for `approve`.
|
|
514
|
+
const baseline = action.baselinePath && action.status !== 'new'
|
|
515
|
+
? toReportRelative(reportDir, action.baselinePath)
|
|
516
|
+
: undefined;
|
|
517
|
+
const actual = action.actualPath
|
|
518
|
+
? toReportRelative(reportDir, action.actualPath)
|
|
519
|
+
: undefined;
|
|
520
|
+
const diff = action.diffPath
|
|
521
|
+
? toReportRelative(reportDir, action.diffPath)
|
|
522
|
+
: undefined;
|
|
523
|
+
// Default committed variant is `actual`; only a baseline-only row (no actual
|
|
524
|
+
// capture this run) commits to baseline instead. renderScreenshots' guard
|
|
525
|
+
// guarantees at least one of the two exists, so `committedSrc` is never empty
|
|
526
|
+
// at runtime — the `?? ''` only satisfies the optional types.
|
|
527
|
+
const committed = actual !== undefined ? 'actual' : 'baseline';
|
|
528
|
+
const committedSrc = (committed === 'actual' ? actual : baseline) ?? '';
|
|
529
|
+
// When only one variant is real (the common case for a `new` baseline, whose
|
|
530
|
+
// baseline is suppressed and has no diff), the hover/press switcher has nothing
|
|
531
|
+
// to toggle to — a lone radio in a group is noise to AT. Render the image alone;
|
|
532
|
+
// the row's status badge already announces "new baseline". Zero variants — a
|
|
533
|
+
// `new` row whose actual capture is missing — collapses to nothing.
|
|
534
|
+
const variantCount = [baseline, actual, diff].filter((v) => v !== undefined).length;
|
|
535
|
+
if (variantCount === 0) {
|
|
536
|
+
return '';
|
|
537
|
+
}
|
|
538
|
+
if (variantCount === 1) {
|
|
539
|
+
return `
|
|
540
|
+
<div class="shot-stage">
|
|
541
|
+
<img
|
|
542
|
+
class="shot-image"
|
|
543
|
+
src="${escapeHtml(committedSrc)}"
|
|
544
|
+
alt="${escapeHtml(`Screenshot of ${action.action}`)}"
|
|
545
|
+
loading="lazy"
|
|
546
|
+
/>
|
|
547
|
+
</div>
|
|
548
|
+
`;
|
|
549
|
+
}
|
|
550
|
+
const diffStatsId = `${actionId}-diff-stats`;
|
|
551
|
+
const diffStats = renderDiffStats(action, diffStatsId);
|
|
552
|
+
const radios = [
|
|
553
|
+
baseline !== undefined
|
|
554
|
+
? shotRadio(actionId, 'baseline', false, committed === 'baseline', {
|
|
555
|
+
label: 'Baseline',
|
|
556
|
+
})
|
|
557
|
+
: '',
|
|
558
|
+
actual !== undefined
|
|
559
|
+
? shotRadio(actionId, 'actual', false, committed === 'actual', {
|
|
560
|
+
label: 'Actual',
|
|
561
|
+
})
|
|
562
|
+
: '',
|
|
563
|
+
diff !== undefined
|
|
564
|
+
? shotRadio(actionId, 'diff', false, false, {
|
|
565
|
+
label: 'Diff',
|
|
566
|
+
describedById: diffStats !== '' ? diffStatsId : undefined,
|
|
567
|
+
})
|
|
568
|
+
: '',
|
|
569
|
+
].join('');
|
|
570
|
+
const captionLabel = committed === 'actual' ? 'Actual' : 'Baseline';
|
|
571
|
+
const dataSrc = [
|
|
572
|
+
baseline !== undefined
|
|
573
|
+
? ` data-src-baseline="${escapeHtml(baseline)}"`
|
|
574
|
+
: '',
|
|
575
|
+
actual !== undefined ? ` data-src-actual="${escapeHtml(actual)}"` : '',
|
|
576
|
+
diff !== undefined ? ` data-src-diff="${escapeHtml(diff)}"` : '',
|
|
577
|
+
].join('');
|
|
578
|
+
return `
|
|
579
|
+
<fieldset class="shot-interactive">
|
|
580
|
+
<legend class="sr-only">${escapeHtml(action.action)} screenshot</legend>
|
|
581
|
+
${radios}
|
|
582
|
+
<p class="shot-caption" aria-hidden="true">Showing: <span class="shot-caption-variant">${captionLabel}</span></p>
|
|
583
|
+
${diffStats}
|
|
584
|
+
</fieldset>
|
|
585
|
+
<div class="shot-stage">
|
|
586
|
+
<img
|
|
587
|
+
class="shot-image"
|
|
588
|
+
src="${escapeHtml(committedSrc)}"
|
|
589
|
+
alt="${escapeHtml(`Screenshot of ${action.action}`)}"
|
|
590
|
+
loading="lazy"
|
|
591
|
+
${dataSrc}
|
|
592
|
+
/>
|
|
593
|
+
</div>
|
|
594
|
+
`;
|
|
595
|
+
}
|
|
596
|
+
function shotRadio(actionId, name, disabled, checked, opts) {
|
|
232
597
|
const inputId = `${actionId}-radio-${name}`;
|
|
598
|
+
const label = opts?.label ?? name;
|
|
599
|
+
const describedBy = opts?.describedById
|
|
600
|
+
? ` aria-describedby="${opts.describedById}"`
|
|
601
|
+
: '';
|
|
233
602
|
return `
|
|
234
603
|
<label for="${inputId}" class="chip chip--toggle shot-radio-label">
|
|
235
604
|
<input
|
|
@@ -237,11 +606,11 @@ function shotRadio(actionId, name, disabled, checked) {
|
|
|
237
606
|
name="${actionId}-shot"
|
|
238
607
|
id="${inputId}"
|
|
239
608
|
value="${name}"
|
|
240
|
-
data-tab="${name}"
|
|
609
|
+
data-tab="${name}"${describedBy}
|
|
241
610
|
${disabled ? 'disabled' : ''}
|
|
242
611
|
${checked ? 'checked' : ''}
|
|
243
612
|
/>
|
|
244
|
-
${
|
|
613
|
+
${label}
|
|
245
614
|
</label>
|
|
246
615
|
`;
|
|
247
616
|
}
|