Repository navigation
ci: the PR report shows before/after/diff thumbnails for visual changes, from frames a frames-only job publishes #9201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3f60781
947e1ed
4c9cfea
207c6fa
d285fd0
104373c
b1dc73e
1b07327
a4d7aac
918fa69
197273f
2b2736f
6c19dca
219ccc5
a9980aa
7271897
4557523
077507f
b7c3bb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -283,14 +283,22 @@ function buildComponentTable({analysis, origin, a11yReport, visualVerdict}) { | |
| } | ||
|
|
||
| /** | ||
| * The changed shots, largest change first: up to VISUAL_FRAME_LIMIT rows | ||
| * naming each shot and its change, inside one disclosure whose summary | ||
| * carries the counts. The run's visual report holds the frames. | ||
| * The changed shots, largest change first: up to VISUAL_FRAME_LIMIT rows, | ||
| * inside one disclosure whose summary carries the counts. With `frames` | ||
| * (publish-frames.mjs's `imageBase` and the `<kind>/<key>.png` it published), | ||
| * each row shows its before/after/diff thumbnails, and only published frames; | ||
| * without it, each row names its change. | ||
| */ | ||
| function buildVisualDeltas({verdict}) { | ||
| /** | ||
| * The changed shots in report order: changed by pixels changed, largest first, | ||
| * then added, then removed. The report lists the first VISUAL_FRAME_LIMIT, | ||
| * and publish-frames.mjs publishes frames for the same ones, so thumbnails | ||
| * and rows cannot drift apart. | ||
| */ | ||
| function visualShots(verdict) { | ||
| if (!verdict || verdict.status === 'skipped' || verdict.status === 'failed') | ||
| return ''; | ||
| const all = [ | ||
| return []; | ||
| return [ | ||
| ...[...(verdict.changes || [])] | ||
| .sort((a, b) => Number(b.diffPixels ?? 0) - Number(a.diffPixels ?? 0)) | ||
| .map(change => ({...change, kinds: ['before', 'after', 'diff']})), | ||
|
|
@@ -301,6 +309,10 @@ function buildVisualDeltas({verdict}) { | |
| kinds: ['before'], | ||
| })), | ||
| ]; | ||
| } | ||
|
|
||
| function buildVisualDeltas({verdict, frames = null}) { | ||
| const all = visualShots(verdict); | ||
| if (all.length === 0) return ''; | ||
| const rows = all.slice(0, VISUAL_FRAME_LIMIT); | ||
| const unshown = all.length - rows.length; | ||
|
|
@@ -321,8 +333,24 @@ function buildVisualDeltas({verdict}) { | |
| .join(', '); | ||
| return variant ? `${story} (${variant})` : story; | ||
| }; | ||
| const header = '| Component · story | Change |\n|---|---|\n'; | ||
| const line = row => `| ${label(row)} | ${changeText(row)} |`; | ||
| const published = new Set(frames?.published || []); | ||
| const base = | ||
| frames?.imageBase && published.size > 0 | ||
| ? `${String(frames.imageBase).replace(/\/+$/, '')}/` | ||
| : null; | ||
| const frame = (row, kind) => { | ||
| if (!row.kinds.includes(kind)) return '—'; | ||
| const file = `${kind}/${row.key}.png`; | ||
| if (!published.has(file)) return 'not published'; | ||
| return `<img src="${base}${kind}/${encodeURIComponent(String(row.key))}.png" height="120" alt="${kind} frame">`; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a second Before / After / Diff renderer: |
||
| }; | ||
| const header = base | ||
| ? '| Component · story | Before | After | Diff |\n|---|---|---|---|\n' | ||
| : '| Component · story | Change |\n|---|---|\n'; | ||
| const line = row => | ||
| base | ||
| ? `| ${label(row)} | ${frame(row, 'before')} | ${frame(row, 'after')} | ${frame(row, 'diff')} |` | ||
| : `| ${label(row)} | ${changeText(row)} |`; | ||
| // A shot key is `<package>-<component>--<story>__<theme>-<mode>`. | ||
| const componentOf = row => | ||
| String( | ||
|
|
@@ -432,6 +460,7 @@ function buildCompactReport({ | |
| a11yReport = null, | ||
| visualVerdict = null, | ||
| packageSize = null, | ||
| visualFrames = null, | ||
| }) { | ||
| const origin = | ||
| preview?.state === 'ready' ? preview.url : preview?.aliasOrigin || ''; | ||
|
|
@@ -440,10 +469,11 @@ function buildCompactReport({ | |
| origin, | ||
| a11yReport, | ||
| visualVerdict, | ||
| })}${buildVisualDeltas({verdict: visualVerdict})}${packagesLine(packageSize)}${notRunLine({jobs, a11yReport, visualVerdict})}`; | ||
| })}${buildVisualDeltas({verdict: visualVerdict, frames: visualFrames})}${packagesLine(packageSize)}${notRunLine({jobs, a11yReport, visualVerdict})}`; | ||
| } | ||
|
|
||
| module.exports = { | ||
| visualShots, | ||
| SUITES, | ||
| VISUAL_FRAME_LIMIT, | ||
| baseJobName, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: the JSDoc just above (lines 285-291) describes
buildVisualDeltasbut now sits orphaned abovevisualShots's own, sobuildVisualDeltas(line 314) has none. Moving it down, and adding the published frames and thumbnails to the file header's@input/@output, keeps the docs accurate.