u
This commit is contained in:
@@ -23,6 +23,7 @@ import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { ROUTES, VIEWPORTS } from './routes.mjs';
|
||||
import { capturePage } from './cdp.mjs';
|
||||
import { compareBuffers } from './compare.mjs';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const FRONT_ROOT = path.resolve(__dirname, '..');
|
||||
@@ -233,20 +234,55 @@ async function main() {
|
||||
);
|
||||
await waitForPort(DEBUG_PORT);
|
||||
|
||||
const isReference = OUT_DIR.endsWith('reference') || Boolean(args['diff-only']);
|
||||
const force = Boolean(args.force);
|
||||
|
||||
let failed = 0;
|
||||
try {
|
||||
for (const viewport of VIEWPORTS) {
|
||||
for (const route of ACTIVE_ROUTES) {
|
||||
const file = path.join(OUT_DIR, `${route.name}.${viewport.name}.png`);
|
||||
try {
|
||||
await capturePage(DEBUG_PORT, `${BASE}${route.path}`, file, {
|
||||
const buf = await capturePage(DEBUG_PORT, `${BASE}${route.path}`, null, {
|
||||
width: viewport.width,
|
||||
height: viewport.height,
|
||||
settleMs: SETTLE_MS,
|
||||
dialog: route.dialog,
|
||||
});
|
||||
const kb = (fs.statSync(file).size / 1024).toFixed(0);
|
||||
console.log(`[capture] ${route.name} (${route.path}) @ ${viewport.name} → ${path.basename(file)} (${kb} KiB)`);
|
||||
const kb = (buf.length / 1024).toFixed(0);
|
||||
|
||||
if (fs.existsSync(file)) {
|
||||
if (isReference && !force) {
|
||||
const existingBuf = fs.readFileSync(file);
|
||||
let diff;
|
||||
try {
|
||||
diff = compareBuffers(existingBuf, buf);
|
||||
} catch (err) {
|
||||
diff = { ok: false, reason: err.message };
|
||||
}
|
||||
|
||||
if (diff.ok) {
|
||||
console.log(
|
||||
`[capture] ${route.name} (${route.path}) @ ${viewport.name} → unchanged (no visible difference)`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
const pct = diff.frac != null ? `${(diff.frac * 100).toFixed(2)}%` : diff.reason;
|
||||
console.log(
|
||||
`[capture] ${route.name} (${route.path}) @ ${viewport.name} → UPDATED reference (visible diff ${pct}, maxΔ=${diff.maxDelta})`,
|
||||
);
|
||||
} else {
|
||||
console.log(
|
||||
`[capture] ${route.name} (${route.path}) @ ${viewport.name} → ${path.basename(file)} (${kb} KiB)`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.log(
|
||||
`[capture] ${route.name} (${route.path}) @ ${viewport.name} → ${path.basename(file)} (${kb} KiB) [NEW]`,
|
||||
);
|
||||
}
|
||||
|
||||
fs.writeFileSync(file, buf);
|
||||
} catch (err) {
|
||||
console.error(`[capture] FAIL ${route.name} (${route.path}) @ ${viewport.name}: ${err.message}`);
|
||||
failed++;
|
||||
|
||||
Reference in New Issue
Block a user