-
-
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
base: main
Are you sure you want to change the base?
Changes from all commits
76f2332
b7a7204
aab3b26
ea74a0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // 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 | ||
|
Member
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. Could we use a smaller viewport here, closer to the screenshot that we have in the README today? With 1280x900 there is a lot of empty space on the sides and at the bottom. A smaller viewport would keep the screenshot more focused on the PDF and the elements. |
||
|
|
||
| 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) { | ||
|
Member
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. Could we also save the generated screenshot when the image dimensions are different? Right now this throws before |
||
| throw new Error( | ||
| `Screenshot size changed: committed ${committed.width}x${committed.height}, ` + | ||
| `generated ${current.width}x${current.height}. ` + | ||
| '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 | ||
| }) | ||
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.
Could you regenerate this screenshot after #107 is merged?
The current image still has the invisible action icon above the signature. Since this image will be shown in the README, I think we should avoid committing that visual issue in the final screenshot.