flexysnap 0.4.0 → 0.4.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flexysnap",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Flexible visual snapshot testing for Playwright, built for e-commerce.",
5
5
  "keywords": [
6
6
  "playwright",
@@ -260,7 +260,7 @@ function compareTexts(baselineTexts, currentTexts, options) {
260
260
  }
261
261
  }
262
262
 
263
- const allowExtraText = options?.allowExtra === true;
263
+ const allowExtraText = options?.extraAllowed === true;
264
264
  for (const currentIndex of unmatchedCurrent) {
265
265
  const currentText = currentTexts[currentIndex];
266
266
  currentText.differences = [{
@@ -269,7 +269,7 @@ function compareTexts(baselineTexts, currentTexts, options) {
269
269
  }];
270
270
  }
271
271
 
272
- const allowMissingText = options?.allowMissing === true;
272
+ const allowMissingText = options?.missingAllowed === true;
273
273
  for (const baselineIndex of unmatchedBaseline) {
274
274
  const baselineText = baselineTexts[baselineIndex];
275
275
  currentTexts.push(baselineText);
@@ -335,7 +335,7 @@ function compareWireframes(baselineWireframe, currentWireframe) {
335
335
  }
336
336
  }
337
337
 
338
- const allowExtraElements = currentElementGroup.options?.allowExtra === true;
338
+ const allowExtraElements = currentElementGroup.options?.extraAllowed === true;
339
339
  for (const currentIndex of unmatchedCurrent) {
340
340
  const currentElement = currentElementGroup.elements[currentIndex];
341
341
  currentElement.differences = [{
@@ -344,7 +344,7 @@ function compareWireframes(baselineWireframe, currentWireframe) {
344
344
  }];
345
345
  }
346
346
 
347
- const allowMissingElements = currentElementGroup.options?.allowMissing === true;
347
+ const allowMissingElements = currentElementGroup.options?.missingAllowed === true;
348
348
  for (const baselineIndex of unmatchedBaseline) {
349
349
  const baselineElement = baselineElementGroup.elements[baselineIndex];
350
350
  currentElementGroup.elements.push(baselineElement);
@@ -109,8 +109,8 @@ function createEmptyElementGroupResult(elementGroup) {
109
109
  strictPosition: elementGroup.options?.strictPosition !== false,
110
110
  strictSize: elementGroup.options?.strictSize !== false,
111
111
  maskDigits: elementGroup.options?.maskDigits !== false,
112
- allowExtra: elementGroup.options?.allowExtra === true,
113
- allowMissing: elementGroup.options?.allowMissing === true
112
+ extraAllowed: elementGroup.options?.extraAllowed === true,
113
+ missingAllowed: elementGroup.options?.missingAllowed === true
114
114
  },
115
115
  elements: []
116
116
  };
@@ -145,6 +145,13 @@ async function extractElementGroupData(page, elementGroup, groupIndex, elementId
145
145
  };
146
146
  }
147
147
 
148
+ function isRectWithinViewport(rect) {
149
+ return rect.right >= 0 &&
150
+ rect.left < window.innerWidth &&
151
+ rect.bottom >= 0 &&
152
+ rect.top < window.innerHeight;
153
+ }
154
+
148
155
  function isElementVisible(element) {
149
156
  const style = window.getComputedStyle(element);
150
157
  if (style.display === 'none' ||
@@ -155,12 +162,9 @@ async function extractElementGroupData(page, elementGroup, groupIndex, elementId
155
162
  return false;
156
163
  }
157
164
 
158
- const rect = element.getBoundingClientRect()
165
+ const rect = element.getBoundingClientRect();
159
166
 
160
- return rect.right >= 0 &&
161
- rect.left < window.innerWidth &&
162
- rect.bottom >= 0 &&
163
- rect.top < window.innerHeight;
167
+ return isRectWithinViewport(rect);
164
168
  }
165
169
 
166
170
  function getElementsWithDirectText(root, textIgnoreClasses) {
@@ -205,8 +209,8 @@ async function extractElementGroupData(page, elementGroup, groupIndex, elementId
205
209
  elementGroup.options.strictPosition = elementGroup.options.strictPosition !== false;
206
210
  elementGroup.options.strictSize = elementGroup.options.strictSize !== false;
207
211
  elementGroup.options.maskDigits = elementGroup.options.maskDigits !== false;
208
- elementGroup.options.allowExtra = elementGroup.options.allowExtra === true;
209
- elementGroup.options.allowMissing = elementGroup.options.allowMissing === true;
212
+ elementGroup.options.extraAllowed = elementGroup.options.extraAllowed === true;
213
+ elementGroup.options.missingAllowed = elementGroup.options.missingAllowed === true;
210
214
  elementGroup.elements = [];
211
215
 
212
216
  let index = 0;
@@ -237,9 +241,14 @@ async function extractElementGroupData(page, elementGroup, groupIndex, elementId
237
241
  if (isNested)
238
242
  continue;
239
243
 
244
+ const boundingRect = getTextNodeBoundingBox(descendant);
245
+
246
+ if (!isRectWithinViewport(boundingRect))
247
+ continue;
248
+
240
249
  texts.push({
241
250
  text: text,
242
- boundingRect: getTextNodeBoundingBox(descendant)
251
+ boundingRect: boundingRect
243
252
  });
244
253
  }
245
254
  }