@decocms/parity 0.33.37 → 0.33.39
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/dist/cli.js +111 -88
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -39037,6 +39037,49 @@ function parseIntOrNull(v) {
|
|
|
39037
39037
|
return Number.isFinite(n) ? n : null;
|
|
39038
39038
|
}
|
|
39039
39039
|
var SKELETON_SELECTOR = "[aria-busy='true'],[data-skeleton],[data-loading='true'],.skeleton,[class*='skeleton' i],[class*='Skeleton'],[class*='shimmer' i],.animate-pulse,.placeholder-shimmer,.react-loading-skeleton";
|
|
39040
|
+
async function settlePage(page, opts = {}) {
|
|
39041
|
+
const {
|
|
39042
|
+
waitMs = 0,
|
|
39043
|
+
fonts = true,
|
|
39044
|
+
layoutStable = true,
|
|
39045
|
+
stabilize = true,
|
|
39046
|
+
scroll = true,
|
|
39047
|
+
scrollBudgetMs = 30000,
|
|
39048
|
+
skeletons = scroll
|
|
39049
|
+
} = opts;
|
|
39050
|
+
const out = {};
|
|
39051
|
+
if (waitMs > 0)
|
|
39052
|
+
await page.waitForTimeout(waitMs);
|
|
39053
|
+
if (fonts)
|
|
39054
|
+
await reloadIfOptionalFonts(page, waitMs);
|
|
39055
|
+
if (layoutStable)
|
|
39056
|
+
out.settle = await waitForLayoutStable(page);
|
|
39057
|
+
if (stabilize) {
|
|
39058
|
+
await Promise.race([
|
|
39059
|
+
stabilizeCarousels(page).catch(() => {
|
|
39060
|
+
return;
|
|
39061
|
+
}),
|
|
39062
|
+
new Promise((r) => setTimeout(r, 3000))
|
|
39063
|
+
]);
|
|
39064
|
+
}
|
|
39065
|
+
if (scroll) {
|
|
39066
|
+
await Promise.race([
|
|
39067
|
+
scrollFullPage(page, scrollBudgetMs).catch(() => {
|
|
39068
|
+
return;
|
|
39069
|
+
}),
|
|
39070
|
+
new Promise((r) => setTimeout(r, scrollBudgetMs + 2000))
|
|
39071
|
+
]);
|
|
39072
|
+
}
|
|
39073
|
+
if (skeletons) {
|
|
39074
|
+
await Promise.race([
|
|
39075
|
+
waitForSkeletonsToResolve(page, 5000).catch(() => {
|
|
39076
|
+
return;
|
|
39077
|
+
}),
|
|
39078
|
+
new Promise((r) => setTimeout(r, 5000))
|
|
39079
|
+
]);
|
|
39080
|
+
}
|
|
39081
|
+
return out;
|
|
39082
|
+
}
|
|
39040
39083
|
async function waitForSkeletonsToResolve(page, maxMs = 1e4) {
|
|
39041
39084
|
const start = Date.now();
|
|
39042
39085
|
while (Date.now() - start < maxMs) {
|
|
@@ -64969,31 +65012,11 @@ async function gatherSide(browser, opts) {
|
|
|
64969
65012
|
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
64970
65013
|
return;
|
|
64971
65014
|
});
|
|
64972
|
-
|
|
64973
|
-
|
|
64974
|
-
|
|
64975
|
-
|
|
64976
|
-
|
|
64977
|
-
stabilizeCarousels(page).catch(() => {
|
|
64978
|
-
return;
|
|
64979
|
-
}),
|
|
64980
|
-
new Promise((resolve) => setTimeout(resolve, 3000))
|
|
64981
|
-
]);
|
|
64982
|
-
if (opts.wantScreenshot) {
|
|
64983
|
-
const scrollBudget = 30000;
|
|
64984
|
-
await Promise.race([
|
|
64985
|
-
scrollFullPage(page, scrollBudget).catch(() => {
|
|
64986
|
-
return;
|
|
64987
|
-
}),
|
|
64988
|
-
new Promise((resolve) => setTimeout(resolve, scrollBudget + 2000))
|
|
64989
|
-
]);
|
|
64990
|
-
await Promise.race([
|
|
64991
|
-
waitForSkeletonsToResolve(page, 5000).catch(() => {
|
|
64992
|
-
return;
|
|
64993
|
-
}),
|
|
64994
|
-
new Promise((resolve) => setTimeout(resolve, 5000))
|
|
64995
|
-
]);
|
|
64996
|
-
}
|
|
65015
|
+
const settled = await settlePage(page, {
|
|
65016
|
+
waitMs: opts.waitMs,
|
|
65017
|
+
scroll: opts.wantScreenshot
|
|
65018
|
+
});
|
|
65019
|
+
result.settle = settled.settle;
|
|
64997
65020
|
const artifacts = await captureSectionArtifacts(page, {
|
|
64998
65021
|
selector: opts.selector,
|
|
64999
65022
|
wantHtml: opts.wantHtml,
|
|
@@ -68436,18 +68459,7 @@ async function migrateCommand(opts) {
|
|
|
68436
68459
|
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
68437
68460
|
return;
|
|
68438
68461
|
});
|
|
68439
|
-
await
|
|
68440
|
-
return;
|
|
68441
|
-
}), sleep3(3000)]);
|
|
68442
|
-
await Promise.race([scrollFullPage(page, 30000).catch(() => {
|
|
68443
|
-
return;
|
|
68444
|
-
}), sleep3(32000)]);
|
|
68445
|
-
await Promise.race([
|
|
68446
|
-
waitForSkeletonsToResolve(page, 5000).catch(() => {
|
|
68447
|
-
return;
|
|
68448
|
-
}),
|
|
68449
|
-
sleep3(5000)
|
|
68450
|
-
]);
|
|
68462
|
+
await settlePage(page, { fonts: false, layoutStable: false });
|
|
68451
68463
|
samples.push(await scrapeThemeSamples(page));
|
|
68452
68464
|
const shot = resolve6(runDir, "screenshots", `${vp}.png`);
|
|
68453
68465
|
await page.screenshot({ path: shot, fullPage: true, animations: "disabled", timeout: 15000 }).then(() => screenshots.push({ viewport: vp, path: `screenshots/${vp}.png` })).catch(() => {
|
|
@@ -68669,18 +68681,7 @@ async function capturePages(browser, viewport, resolvedPages, theme, cfg) {
|
|
|
68669
68681
|
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
68670
68682
|
return;
|
|
68671
68683
|
});
|
|
68672
|
-
await
|
|
68673
|
-
return;
|
|
68674
|
-
}), sleep3(3000)]);
|
|
68675
|
-
await Promise.race([scrollFullPage(page, 30000).catch(() => {
|
|
68676
|
-
return;
|
|
68677
|
-
}), sleep3(32000)]);
|
|
68678
|
-
await Promise.race([
|
|
68679
|
-
waitForSkeletonsToResolve(page, 5000).catch(() => {
|
|
68680
|
-
return;
|
|
68681
|
-
}),
|
|
68682
|
-
sleep3(5000)
|
|
68683
|
-
]);
|
|
68684
|
+
await settlePage(page, { fonts: false, layoutStable: false });
|
|
68684
68685
|
let detected = await detectComponents(page, { llm: cfg.llm });
|
|
68685
68686
|
if (cfg.allowlist)
|
|
68686
68687
|
detected = detected.filter((c) => matchesAllowlist2(c.role, cfg.allowlist));
|
|
@@ -68931,9 +68932,6 @@ function isValidUrl4(s) {
|
|
|
68931
68932
|
return false;
|
|
68932
68933
|
}
|
|
68933
68934
|
}
|
|
68934
|
-
function sleep3(ms) {
|
|
68935
|
-
return new Promise((resolveTimeout) => setTimeout(resolveTimeout, ms));
|
|
68936
|
-
}
|
|
68937
68935
|
|
|
68938
68936
|
// src/commands/plan.ts
|
|
68939
68937
|
import { readFileSync as readFileSync27 } from "node:fs";
|
|
@@ -74433,6 +74431,16 @@ function applyMask(pngPath, mask, outPath) {
|
|
|
74433
74431
|
}
|
|
74434
74432
|
writeFileSync31(outPath, PNG5.sync.write(png));
|
|
74435
74433
|
}
|
|
74434
|
+
function readPngSize(pngPath) {
|
|
74435
|
+
try {
|
|
74436
|
+
const head = readFileSync36(pngPath).subarray(0, 24);
|
|
74437
|
+
if (head.length < 24)
|
|
74438
|
+
return null;
|
|
74439
|
+
return { width: head.readUInt32BE(16), height: head.readUInt32BE(20) };
|
|
74440
|
+
} catch {
|
|
74441
|
+
return null;
|
|
74442
|
+
}
|
|
74443
|
+
}
|
|
74436
74444
|
|
|
74437
74445
|
// src/report/qa-comment.ts
|
|
74438
74446
|
import { execFile } from "node:child_process";
|
|
@@ -74609,10 +74617,11 @@ function hostsOnlyOnOneSide(v) {
|
|
|
74609
74617
|
}
|
|
74610
74618
|
|
|
74611
74619
|
// src/commands/heatmap.ts
|
|
74612
|
-
var
|
|
74620
|
+
var ALL_VIEWPORTS = "mobile,tablet,1024x768,desktop,1920x1080,2560x1440";
|
|
74621
|
+
var DEFAULT_VIEWPORTS = "mobile,desktop";
|
|
74613
74622
|
var MOBILE_UA_MAX_WIDTH = 767;
|
|
74614
74623
|
function parseViewports2(raw) {
|
|
74615
|
-
const entries = raw.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
74624
|
+
const entries = (raw.trim() === "all" ? ALL_VIEWPORTS : raw).split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
74616
74625
|
if (entries.length === 0)
|
|
74617
74626
|
return "--viewports is empty";
|
|
74618
74627
|
const specs = [];
|
|
@@ -74860,6 +74869,30 @@ function judgePair(args) {
|
|
|
74860
74869
|
reason: `prod could not reproduce ${(mask.coverage * 100).toFixed(1)}% of the frame across two captures (${mask.masked} px) — too much of the page is in motion to hold the candidate to anything (noise heatmap: ${paths.noise})`
|
|
74861
74870
|
};
|
|
74862
74871
|
}
|
|
74872
|
+
const candSize = readPngSize(cand.screenshot);
|
|
74873
|
+
if (!candSize) {
|
|
74874
|
+
return {
|
|
74875
|
+
...base,
|
|
74876
|
+
noiseFloorPixels,
|
|
74877
|
+
maskedCoverage,
|
|
74878
|
+
verdict: "inconclusive",
|
|
74879
|
+
reason: "the candidate screenshot could not be read"
|
|
74880
|
+
};
|
|
74881
|
+
}
|
|
74882
|
+
if (candSize.width !== mask.width || candSize.height !== mask.height) {
|
|
74883
|
+
return {
|
|
74884
|
+
...base,
|
|
74885
|
+
size: {
|
|
74886
|
+
prod: [mask.width, mask.height],
|
|
74887
|
+
cand: [candSize.width, candSize.height],
|
|
74888
|
+
matched: false
|
|
74889
|
+
},
|
|
74890
|
+
noiseFloorPixels,
|
|
74891
|
+
maskedCoverage,
|
|
74892
|
+
verdict: "inconclusive",
|
|
74893
|
+
reason: `different dimensions (prod ${mask.width}×${mask.height}, cand ${candSize.width}×${candSize.height}) — the comparison would only look at the intersection`
|
|
74894
|
+
};
|
|
74895
|
+
}
|
|
74863
74896
|
if (mask.masked > 0) {
|
|
74864
74897
|
applyMask(prod.screenshot, mask, paths.prodMasked);
|
|
74865
74898
|
applyMask(cand.screenshot, mask, paths.candMasked);
|
|
@@ -74981,29 +75014,10 @@ async function captureSide(browser, args) {
|
|
|
74981
75014
|
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
74982
75015
|
return;
|
|
74983
75016
|
});
|
|
74984
|
-
|
|
74985
|
-
|
|
74986
|
-
|
|
74987
|
-
|
|
74988
|
-
await Promise.race([
|
|
74989
|
-
stabilizeCarousels(page).catch(() => {
|
|
74990
|
-
return;
|
|
74991
|
-
}),
|
|
74992
|
-
new Promise((r) => setTimeout(r, 3000))
|
|
74993
|
-
]);
|
|
74994
|
-
const scrollBudget = 30000;
|
|
74995
|
-
await Promise.race([
|
|
74996
|
-
scrollFullPage(page, scrollBudget).catch(() => {
|
|
74997
|
-
return;
|
|
74998
|
-
}),
|
|
74999
|
-
new Promise((r) => setTimeout(r, scrollBudget + 2000))
|
|
75000
|
-
]);
|
|
75001
|
-
await Promise.race([
|
|
75002
|
-
waitForSkeletonsToResolve(page, 5000).catch(() => {
|
|
75003
|
-
return;
|
|
75004
|
-
}),
|
|
75005
|
-
new Promise((r) => setTimeout(r, 5000))
|
|
75006
|
-
]);
|
|
75017
|
+
await settlePage(page, {
|
|
75018
|
+
waitMs: args.waitMs,
|
|
75019
|
+
scroll: !await isAlreadyOnScreen(page, args.selector)
|
|
75020
|
+
});
|
|
75007
75021
|
side.devicePixelRatio = await page.evaluate(() => window.devicePixelRatio);
|
|
75008
75022
|
side.fontsStatus = await page.evaluate(() => document.fonts?.status ?? "unknown");
|
|
75009
75023
|
if (args.selector) {
|
|
@@ -75051,6 +75065,24 @@ async function captureSide(browser, args) {
|
|
|
75051
75065
|
}
|
|
75052
75066
|
return { side, repeatScreenshot, repeatError, boxTree };
|
|
75053
75067
|
}
|
|
75068
|
+
async function isAlreadyOnScreen(page, selector) {
|
|
75069
|
+
if (!selector)
|
|
75070
|
+
return false;
|
|
75071
|
+
try {
|
|
75072
|
+
const loc = page.locator(selector);
|
|
75073
|
+
if (await loc.count() !== 1)
|
|
75074
|
+
return false;
|
|
75075
|
+
const box = await loc.first().boundingBox({ timeout: 2000 });
|
|
75076
|
+
if (!box)
|
|
75077
|
+
return false;
|
|
75078
|
+
const viewport = page.viewportSize();
|
|
75079
|
+
if (!viewport)
|
|
75080
|
+
return false;
|
|
75081
|
+
return box.y >= 0 && box.y + box.height <= viewport.height;
|
|
75082
|
+
} catch {
|
|
75083
|
+
return false;
|
|
75084
|
+
}
|
|
75085
|
+
}
|
|
75054
75086
|
async function readImageHosts(page, selector) {
|
|
75055
75087
|
return page.evaluate((sel) => {
|
|
75056
75088
|
const root = sel ? document.querySelector(sel) : document.body;
|
|
@@ -75264,16 +75296,7 @@ async function gatherStates(browser, opts) {
|
|
|
75264
75296
|
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
75265
75297
|
return;
|
|
75266
75298
|
});
|
|
75267
|
-
|
|
75268
|
-
await page.waitForTimeout(opts.waitMs);
|
|
75269
|
-
await reloadIfOptionalFonts(page, opts.waitMs);
|
|
75270
|
-
out.settle = await waitForLayoutStable(page);
|
|
75271
|
-
await Promise.race([
|
|
75272
|
-
stabilizeCarousels(page).catch(() => {
|
|
75273
|
-
return;
|
|
75274
|
-
}),
|
|
75275
|
-
new Promise((r) => setTimeout(r, 3000))
|
|
75276
|
-
]);
|
|
75299
|
+
out.settle = (await settlePage(page, { waitMs: opts.waitMs, scroll: false })).settle;
|
|
75277
75300
|
out.motion = await readMotion(page, opts.selector);
|
|
75278
75301
|
const base = await readBoxTree(page, opts.selector);
|
|
75279
75302
|
if (!base.found) {
|
|
@@ -76461,7 +76484,7 @@ program.command("check").argument("<name>", "check name (kebab-case, e.g. consol
|
|
|
76461
76484
|
json: opts.json
|
|
76462
76485
|
}));
|
|
76463
76486
|
});
|
|
76464
|
-
program.command("heatmap").description("Is the candidate PIXEL-IDENTICAL to prod — yes, no, or 'nothing was compared'. Zero tolerance, no LLM, no flag to loosen it: one differing pixel fails. Sweeps mobile→2560px so a broken breakpoint cannot hide at the one size you checked, and captures prod twice first so a page that is not identical to itself reports its own noise floor instead of blaming the candidate. Use `parity section` to find out WHY something differs; use this to decide WHETHER it does.").requiredOption("--prod <url>", "Production URL (the reference)").requiredOption("--cand <url>", "Candidate URL").option("--selector <sel>", "Compare only this section instead of the whole page. Without it the comparison is full-page.").option("--cand-selector <sel>", "Selector on the CANDIDATE side, when the ported component no longer answers to --selector. Defaults to --selector.").option("--viewports <list>", "Comma-separated
|
|
76487
|
+
program.command("heatmap").description("Is the candidate PIXEL-IDENTICAL to prod — yes, no, or 'nothing was compared'. Zero tolerance, no LLM, no flag to loosen it: one differing pixel fails. Sweeps mobile→2560px so a broken breakpoint cannot hide at the one size you checked, and captures prod twice first so a page that is not identical to itself reports its own noise floor instead of blaming the candidate. Use `parity section` to find out WHY something differs; use this to decide WHETHER it does.").requiredOption("--prod <url>", "Production URL (the reference)").requiredOption("--cand <url>", "Candidate URL").option("--selector <sel>", "Compare only this section instead of the whole page. Without it the comparison is full-page.").option("--cand-selector <sel>", "Selector on the CANDIDATE side, when the ported component no longer answers to --selector. Defaults to --selector.").option("--viewports <list>", "Comma-separated; each entry is a preset (mobile|tablet|desktop) or a literal <width>x<height>, and every entry must be clean for the run to pass. `all` expands to the full sweep (mobile→2560px) — worth it to close a page, too slow to put in a per-component loop, which is why it is not the default.", DEFAULT_VIEWPORTS).option("--wait <ms>", "Extra ms after networkidle so hydration settles", "2000").option("--pr <number>", "Publish the verdict as a PR comment, with the diff images inline. Reporting only — a failure to publish never changes the verdict or the exit code.").option("--repo <owner/name>", "Repo for --pr. Defaults to whatever `gh` infers from the cwd.").option("--out-dir <dir>", "Where to write the screenshots and heatmaps", "./parity-output/heatmap").option("--json", "Emit one-line JSON instead of pretty text", false).action(async (opts) => {
|
|
76465
76488
|
process.exit(await heatmapCommand({
|
|
76466
76489
|
prod: opts.prod,
|
|
76467
76490
|
cand: opts.cand,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/parity",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.39",
|
|
4
4
|
"description": "E2E parity validator for site migrations. Compares prod vs cand and reports UI, functional, SEO, visual, and Web Vitals deltas with an LLM-ranked HTML report.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|