-
-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/readme screenshot #114
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3b4f58b
feat(docs): generate the README screenshot with Playwright
nva138 8c86aa7
feat(docs): verify the README screenshot against the committed image
nva138 c8994e3
ci: check the README screenshot in pull requests
nva138 8e0aabf
ci: upload the generated screenshot alongside the diff
nva138 b5b3b05
ci: temporarily measure the screenshot check inside the Playwright co…
nva138 a24bb24
docs: tighten the screenshot viewport and regenerate after the icon fix
nva138 939b6a3
ci: keep the generated screenshot when the size check fails
nva138 7955caa
docs: generate the README screenshot in the pinned Playwright container
nva138 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // SPDX-FileCopyrightText: 2026 LibreCode coop and contributors | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
|
||
| import { mkdir, readFile, writeFile } from 'node:fs/promises' | ||
| import path from 'node:path' | ||
| import process from 'node:process' | ||
| import pixelmatch from 'pixelmatch' | ||
| import { PNG } from 'pngjs' | ||
| import { generateScreenshot, packageRoot, screenshotPath } from './generate-screenshots.mjs' | ||
|
|
||
|
|
||
| const maxDiffRatio = 0.001 | ||
|
vitormattos marked this conversation as resolved.
|
||
|
|
||
| const diffPath = path.join(packageRoot, 'test-results', 'demo-screenshot-diff.png') | ||
| const currentPath = path.join(packageRoot, 'test-results', 'demo-screenshot-current.png') | ||
|
|
||
| async function main() { | ||
| const committed = PNG.sync.read(await readFile(screenshotPath)) | ||
| const currentImage = await generateScreenshot() | ||
| const current = PNG.sync.read(currentImage) | ||
|
|
||
| if (committed.width !== current.width || committed.height !== current.height) { | ||
|
vitormattos marked this conversation as resolved.
|
||
| await mkdir(path.dirname(currentPath), { recursive: true }) | ||
| await writeFile(currentPath, currentImage) | ||
|
|
||
| throw new Error( | ||
| `Screenshot size changed: committed ${committed.width}x${committed.height}, ` + | ||
| `generated ${current.width}x${current.height}.\n` + | ||
| `Generated screenshot written to ${path.relative(packageRoot, currentPath)}.\n` + | ||
| 'Run "npm run screenshots:update" and commit the result.' | ||
| ) | ||
| } | ||
|
|
||
| const {width, height} = committed | ||
| const diff = new PNG({width, height}) | ||
| const changedPixels = pixelmatch(committed.data, current.data, diff.data, width, height, { | ||
| threshold: 0.1, | ||
| }) | ||
|
|
||
| const totalPixels = width * height | ||
| const ratio = changedPixels / totalPixels | ||
| const report = `${changedPixels} of ${totalPixels} pixels differ (${(ratio * 100).toFixed(4)}%)` | ||
|
|
||
| if (ratio <= maxDiffRatio) { | ||
| globalThis.console.log(`Screenshot is up to date: ${report}.`) | ||
| return | ||
| } | ||
|
|
||
| await mkdir(path.dirname(diffPath), {recursive: true}) | ||
| await writeFile(currentPath, currentImage) | ||
| await writeFile(diffPath, PNG.sync.write(diff)) | ||
|
vitormattos marked this conversation as resolved.
|
||
|
|
||
| throw new Error( | ||
| `${report}, above the allowed ${(maxDiffRatio * 100).toFixed(4)}%.\n` + | ||
| `Generated screenshot written to ${path.relative(packageRoot, currentPath)}.\n` + | ||
| `Visual diff written to ${path.relative(packageRoot, diffPath)}.\n` + | ||
| 'If the change is expected, run "npm run screenshots:update" and commit the result.' | ||
| ) | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| globalThis.console.error(error instanceof Error ? error.message : error) | ||
| process.exitCode = 1 | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.