@decocms/parity 0.33.36 → 0.33.38
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 +99 -24
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -62955,23 +62955,43 @@ async function captureSectionScreenshot(page, selector, outPath, preCapturedFull
|
|
|
62955
62955
|
await loc.scrollIntoViewIfNeeded({ timeout: 3000 }).catch(() => {
|
|
62956
62956
|
return;
|
|
62957
62957
|
});
|
|
62958
|
-
const fullPng = preCapturedFullPng ?? await page.screenshot({
|
|
62959
|
-
fullPage: true,
|
|
62960
|
-
animations: "disabled",
|
|
62961
|
-
timeout: 15000
|
|
62962
|
-
});
|
|
62963
62958
|
const box = await loc.boundingBox({ timeout: 3000 });
|
|
62964
62959
|
if (!box || box.width <= 0 || box.height <= 0) {
|
|
62965
62960
|
return `seletor '${selector}' não tem boundingBox visível`;
|
|
62966
62961
|
}
|
|
62967
|
-
const
|
|
62968
|
-
|
|
62969
|
-
|
|
62962
|
+
const detached = await isDetachedFromScroll(loc);
|
|
62963
|
+
if (preCapturedFullPng && !detached) {
|
|
62964
|
+
const dpr = await page.evaluate(() => window.devicePixelRatio).catch(() => 1);
|
|
62965
|
+
await writeFile(outPath, cropPngBuffer(preCapturedFullPng, box, dpr));
|
|
62966
|
+
return null;
|
|
62967
|
+
}
|
|
62968
|
+
if (detached)
|
|
62969
|
+
await settleAtTop(page);
|
|
62970
|
+
await loc.screenshot({ path: outPath, animations: "disabled", timeout: 15000 });
|
|
62970
62971
|
return null;
|
|
62971
62972
|
} catch (err) {
|
|
62972
62973
|
return `falha no screenshot: ${err.message}`;
|
|
62973
62974
|
}
|
|
62974
62975
|
}
|
|
62976
|
+
async function settleAtTop(page, attempts = 4) {
|
|
62977
|
+
for (let i = 0;i < attempts; i++) {
|
|
62978
|
+
await page.evaluate(() => window.scrollTo(0, 0)).catch(() => {
|
|
62979
|
+
return;
|
|
62980
|
+
});
|
|
62981
|
+
await page.waitForTimeout(200);
|
|
62982
|
+
const y = await page.evaluate(() => window.scrollY).catch(() => 0);
|
|
62983
|
+
if (y === 0) {
|
|
62984
|
+
await page.waitForTimeout(250);
|
|
62985
|
+
return;
|
|
62986
|
+
}
|
|
62987
|
+
}
|
|
62988
|
+
}
|
|
62989
|
+
async function isDetachedFromScroll(loc) {
|
|
62990
|
+
return loc.evaluate((el) => {
|
|
62991
|
+
const p = getComputedStyle(el).position;
|
|
62992
|
+
return p === "fixed" || p === "sticky";
|
|
62993
|
+
}).catch(() => true);
|
|
62994
|
+
}
|
|
62975
62995
|
|
|
62976
62996
|
// src/extract/extract-component.ts
|
|
62977
62997
|
var LINK_CAP = 30;
|
|
@@ -74413,6 +74433,16 @@ function applyMask(pngPath, mask, outPath) {
|
|
|
74413
74433
|
}
|
|
74414
74434
|
writeFileSync31(outPath, PNG5.sync.write(png));
|
|
74415
74435
|
}
|
|
74436
|
+
function readPngSize(pngPath) {
|
|
74437
|
+
try {
|
|
74438
|
+
const head = readFileSync36(pngPath).subarray(0, 24);
|
|
74439
|
+
if (head.length < 24)
|
|
74440
|
+
return null;
|
|
74441
|
+
return { width: head.readUInt32BE(16), height: head.readUInt32BE(20) };
|
|
74442
|
+
} catch {
|
|
74443
|
+
return null;
|
|
74444
|
+
}
|
|
74445
|
+
}
|
|
74416
74446
|
|
|
74417
74447
|
// src/report/qa-comment.ts
|
|
74418
74448
|
import { execFile } from "node:child_process";
|
|
@@ -74589,10 +74619,11 @@ function hostsOnlyOnOneSide(v) {
|
|
|
74589
74619
|
}
|
|
74590
74620
|
|
|
74591
74621
|
// src/commands/heatmap.ts
|
|
74592
|
-
var
|
|
74622
|
+
var ALL_VIEWPORTS = "mobile,tablet,1024x768,desktop,1920x1080,2560x1440";
|
|
74623
|
+
var DEFAULT_VIEWPORTS = "mobile,desktop";
|
|
74593
74624
|
var MOBILE_UA_MAX_WIDTH = 767;
|
|
74594
74625
|
function parseViewports2(raw) {
|
|
74595
|
-
const entries = raw.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
74626
|
+
const entries = (raw.trim() === "all" ? ALL_VIEWPORTS : raw).split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
74596
74627
|
if (entries.length === 0)
|
|
74597
74628
|
return "--viewports is empty";
|
|
74598
74629
|
const specs = [];
|
|
@@ -74840,6 +74871,30 @@ function judgePair(args) {
|
|
|
74840
74871
|
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})`
|
|
74841
74872
|
};
|
|
74842
74873
|
}
|
|
74874
|
+
const candSize = readPngSize(cand.screenshot);
|
|
74875
|
+
if (!candSize) {
|
|
74876
|
+
return {
|
|
74877
|
+
...base,
|
|
74878
|
+
noiseFloorPixels,
|
|
74879
|
+
maskedCoverage,
|
|
74880
|
+
verdict: "inconclusive",
|
|
74881
|
+
reason: "the candidate screenshot could not be read"
|
|
74882
|
+
};
|
|
74883
|
+
}
|
|
74884
|
+
if (candSize.width !== mask.width || candSize.height !== mask.height) {
|
|
74885
|
+
return {
|
|
74886
|
+
...base,
|
|
74887
|
+
size: {
|
|
74888
|
+
prod: [mask.width, mask.height],
|
|
74889
|
+
cand: [candSize.width, candSize.height],
|
|
74890
|
+
matched: false
|
|
74891
|
+
},
|
|
74892
|
+
noiseFloorPixels,
|
|
74893
|
+
maskedCoverage,
|
|
74894
|
+
verdict: "inconclusive",
|
|
74895
|
+
reason: `different dimensions (prod ${mask.width}×${mask.height}, cand ${candSize.width}×${candSize.height}) — the comparison would only look at the intersection`
|
|
74896
|
+
};
|
|
74897
|
+
}
|
|
74843
74898
|
if (mask.masked > 0) {
|
|
74844
74899
|
applyMask(prod.screenshot, mask, paths.prodMasked);
|
|
74845
74900
|
applyMask(cand.screenshot, mask, paths.candMasked);
|
|
@@ -74971,19 +75026,21 @@ async function captureSide(browser, args) {
|
|
|
74971
75026
|
}),
|
|
74972
75027
|
new Promise((r) => setTimeout(r, 3000))
|
|
74973
75028
|
]);
|
|
74974
|
-
|
|
74975
|
-
|
|
74976
|
-
|
|
74977
|
-
|
|
74978
|
-
|
|
74979
|
-
|
|
74980
|
-
|
|
74981
|
-
|
|
74982
|
-
|
|
74983
|
-
|
|
74984
|
-
|
|
74985
|
-
|
|
74986
|
-
|
|
75029
|
+
if (!await isAlreadyOnScreen(page, args.selector)) {
|
|
75030
|
+
const scrollBudget = 30000;
|
|
75031
|
+
await Promise.race([
|
|
75032
|
+
scrollFullPage(page, scrollBudget).catch(() => {
|
|
75033
|
+
return;
|
|
75034
|
+
}),
|
|
75035
|
+
new Promise((r) => setTimeout(r, scrollBudget + 2000))
|
|
75036
|
+
]);
|
|
75037
|
+
await Promise.race([
|
|
75038
|
+
waitForSkeletonsToResolve(page, 5000).catch(() => {
|
|
75039
|
+
return;
|
|
75040
|
+
}),
|
|
75041
|
+
new Promise((r) => setTimeout(r, 5000))
|
|
75042
|
+
]);
|
|
75043
|
+
}
|
|
74987
75044
|
side.devicePixelRatio = await page.evaluate(() => window.devicePixelRatio);
|
|
74988
75045
|
side.fontsStatus = await page.evaluate(() => document.fonts?.status ?? "unknown");
|
|
74989
75046
|
if (args.selector) {
|
|
@@ -75031,6 +75088,24 @@ async function captureSide(browser, args) {
|
|
|
75031
75088
|
}
|
|
75032
75089
|
return { side, repeatScreenshot, repeatError, boxTree };
|
|
75033
75090
|
}
|
|
75091
|
+
async function isAlreadyOnScreen(page, selector) {
|
|
75092
|
+
if (!selector)
|
|
75093
|
+
return false;
|
|
75094
|
+
try {
|
|
75095
|
+
const loc = page.locator(selector);
|
|
75096
|
+
if (await loc.count() !== 1)
|
|
75097
|
+
return false;
|
|
75098
|
+
const box = await loc.first().boundingBox({ timeout: 2000 });
|
|
75099
|
+
if (!box)
|
|
75100
|
+
return false;
|
|
75101
|
+
const viewport = page.viewportSize();
|
|
75102
|
+
if (!viewport)
|
|
75103
|
+
return false;
|
|
75104
|
+
return box.y >= 0 && box.y + box.height <= viewport.height;
|
|
75105
|
+
} catch {
|
|
75106
|
+
return false;
|
|
75107
|
+
}
|
|
75108
|
+
}
|
|
75034
75109
|
async function readImageHosts(page, selector) {
|
|
75035
75110
|
return page.evaluate((sel) => {
|
|
75036
75111
|
const root = sel ? document.querySelector(sel) : document.body;
|
|
@@ -76441,7 +76516,7 @@ program.command("check").argument("<name>", "check name (kebab-case, e.g. consol
|
|
|
76441
76516
|
json: opts.json
|
|
76442
76517
|
}));
|
|
76443
76518
|
});
|
|
76444
|
-
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
|
|
76519
|
+
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) => {
|
|
76445
76520
|
process.exit(await heatmapCommand({
|
|
76446
76521
|
prod: opts.prod,
|
|
76447
76522
|
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.38",
|
|
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",
|