@testivai/witness-playwright 1.1.5 → 1.2.0

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/snapshot.js CHANGED
@@ -94,6 +94,32 @@ async function snapshot(page, testInfo, name, config) {
94
94
  const baseFilename = `${timestamp}_${safeName}`;
95
95
  // 1. Capture full-page screenshot
96
96
  const screenshotPath = path.join(outputDir, `${baseFilename}.png`);
97
+ // In local mode: hide elements matching ignoreSelectors before the screenshot
98
+ // so dynamic content (version badges, timestamps, ads) doesn't cause false diffs.
99
+ // Sources (merged, deduped):
100
+ // 1. .testivai/config.json → ignoreSelectors (global, OSS config)
101
+ // 2. testivai.config.ts → ignoreSelectors (global, power users)
102
+ // 3. testivai.witness(...) → { ignoreSelectors } (per-snapshot override)
103
+ let ignoreStyleEl = null;
104
+ if (isLocalMode) {
105
+ // Read global ignores from .testivai/config.json
106
+ let witnessConfigIgnore = [];
107
+ try {
108
+ const witnessConfigPath = path.join(process.cwd(), '.testivai', 'config.json');
109
+ if (fs.existsSync(witnessConfigPath)) {
110
+ const raw = JSON.parse(fs.readFileSync(witnessConfigPath, 'utf-8'));
111
+ witnessConfigIgnore = raw.ignoreSelectors ?? [];
112
+ }
113
+ }
114
+ catch { /* ignore malformed config */ }
115
+ const playwrightConfigIgnore = projectConfig.ignoreSelectors ?? [];
116
+ const perSnapshotIgnore = effectiveConfig.ignoreSelectors ?? [];
117
+ const allSelectors = [...new Set([...witnessConfigIgnore, ...playwrightConfigIgnore, ...perSnapshotIgnore])];
118
+ if (allSelectors.length > 0) {
119
+ const css = allSelectors.map(s => `${s} { visibility: hidden !important; }`).join('\n');
120
+ ignoreStyleEl = await page.addStyleTag({ content: css });
121
+ }
122
+ }
97
123
  // Check if scroll-and-stitch is explicitly requested (backup method)
98
124
  if (effectiveConfig.useBrowserCapture === false) {
99
125
  // Use scroll-and-stitch approach (backup method)
@@ -310,6 +336,11 @@ async function snapshot(page, testInfo, name, config) {
310
336
  await page.screenshot({ path: screenshotPath, fullPage: true });
311
337
  }
312
338
  }
339
+ // Restore any elements hidden for ignoreSelectors
340
+ if (ignoreStyleEl) {
341
+ await ignoreStyleEl.evaluate((el) => el.remove()).catch(() => { });
342
+ ignoreStyleEl = null;
343
+ }
313
344
  // 1.5. Local mode: also place the screenshot in the layout expected by
314
345
  // @testivai/witness/report (subdirectory keyed by snapshot name).
315
346
  // This is what `BaselineStore.listTemp()` and `compareAll()` enumerate.
package/dist/types.d.ts CHANGED
@@ -216,6 +216,18 @@ export interface TestivAIConfig {
216
216
  selectors?: string[];
217
217
  /** Use browser capture for full-page screenshots (default: true, set to false for scroll-and-stitch) */
218
218
  useBrowserCapture?: boolean;
219
+ /**
220
+ * CSS selectors for elements to hide during screenshot capture (local mode).
221
+ * Elements are set to `visibility: hidden` before the screenshot is taken and
222
+ * restored immediately after — so dynamic content (version badges, timestamps,
223
+ * ads, live clocks) never contributes to the pixel diff.
224
+ *
225
+ * Can also be set globally in `.testivai/config.json` under `ignoreSelectors`.
226
+ * Per-snapshot values are merged with (not replaced by) the global list.
227
+ *
228
+ * Example: ["[data-testivai-ignore]", ".version-badge", "#live-chat-widget"]
229
+ */
230
+ ignoreSelectors?: string[];
219
231
  }
220
232
  /**
221
233
  * Layout/Bounding box data for an element
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testivai/witness-playwright",
3
- "version": "1.1.5",
3
+ "version": "1.2.0",
4
4
  "description": "Playwright sensor for Testivai Visual Regression Test system",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -52,7 +52,7 @@
52
52
  "sharp": "^0.34.5",
53
53
  "simple-git": "^3.21.0",
54
54
  "@testivai/common": "0.2.2",
55
- "@testivai/witness": "1.0.4"
55
+ "@testivai/witness": "1.1.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@playwright/test": "^1.60.0",