@decocms/parity 0.33.37 → 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.
Files changed (2) hide show
  1. package/dist/cli.js +71 -16
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -74433,6 +74433,16 @@ function applyMask(pngPath, mask, outPath) {
74433
74433
  }
74434
74434
  writeFileSync31(outPath, PNG5.sync.write(png));
74435
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
+ }
74436
74446
 
74437
74447
  // src/report/qa-comment.ts
74438
74448
  import { execFile } from "node:child_process";
@@ -74609,10 +74619,11 @@ function hostsOnlyOnOneSide(v) {
74609
74619
  }
74610
74620
 
74611
74621
  // src/commands/heatmap.ts
74612
- var DEFAULT_VIEWPORTS = "mobile,tablet,1024x768,desktop,1920x1080,2560x1440";
74622
+ var ALL_VIEWPORTS = "mobile,tablet,1024x768,desktop,1920x1080,2560x1440";
74623
+ var DEFAULT_VIEWPORTS = "mobile,desktop";
74613
74624
  var MOBILE_UA_MAX_WIDTH = 767;
74614
74625
  function parseViewports2(raw) {
74615
- 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);
74616
74627
  if (entries.length === 0)
74617
74628
  return "--viewports is empty";
74618
74629
  const specs = [];
@@ -74860,6 +74871,30 @@ function judgePair(args) {
74860
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})`
74861
74872
  };
74862
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
+ }
74863
74898
  if (mask.masked > 0) {
74864
74899
  applyMask(prod.screenshot, mask, paths.prodMasked);
74865
74900
  applyMask(cand.screenshot, mask, paths.candMasked);
@@ -74991,19 +75026,21 @@ async function captureSide(browser, args) {
74991
75026
  }),
74992
75027
  new Promise((r) => setTimeout(r, 3000))
74993
75028
  ]);
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
- ]);
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
+ }
75007
75044
  side.devicePixelRatio = await page.evaluate(() => window.devicePixelRatio);
75008
75045
  side.fontsStatus = await page.evaluate(() => document.fonts?.status ?? "unknown");
75009
75046
  if (args.selector) {
@@ -75051,6 +75088,24 @@ async function captureSide(browser, args) {
75051
75088
  }
75052
75089
  return { side, repeatScreenshot, repeatError, boxTree };
75053
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
+ }
75054
75109
  async function readImageHosts(page, selector) {
75055
75110
  return page.evaluate((sel) => {
75056
75111
  const root = sel ? document.querySelector(sel) : document.body;
@@ -76461,7 +76516,7 @@ program.command("check").argument("<name>", "check name (kebab-case, e.g. consol
76461
76516
  json: opts.json
76462
76517
  }));
76463
76518
  });
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. Each entry is a preset (mobile|tablet|desktop) or a literal <width>x<height>. Every entry must be clean for the run to pass.", 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) => {
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) => {
76465
76520
  process.exit(await heatmapCommand({
76466
76521
  prod: opts.prod,
76467
76522
  cand: opts.cand,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/parity",
3
- "version": "0.33.37",
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",