flexysnap 0.4.4 → 0.5.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/testUtils.js +32 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flexysnap",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "description": "Flexible visual snapshot testing for Playwright, built for e-commerce.",
5
5
  "keywords": [
6
6
  "playwright",
package/src/testUtils.js CHANGED
@@ -6,15 +6,29 @@ async function callClosePopups(page) {
6
6
  await closePopups(page);
7
7
  }
8
8
 
9
+ function logIfErrorResponse(response, url) {
10
+ if (response && response.status() >= 400) {
11
+ logTimestamp(`HTTP error ${response.status()} ${response.statusText()} while loading ${url}`);
12
+ }
13
+ }
14
+
9
15
  async function gotoWithRetry(page, url) {
16
+ let response;
10
17
  try {
11
18
  logTimestamp('Loading ' + url);
12
- await page.goto(url, { timeout: 30_000, waitUntil: "commit" });
19
+ response = await page.goto(url, { timeout: 5000, waitUntil: "commit" });
13
20
  } catch (firstError) {
21
+ logTimestamp(firstError);
14
22
  logTimestamp('Retry loading ' + url);
15
- await page.goto(url, { timeout: 30_000, waitUntil: "commit" });
23
+ response = await page.goto(url, { timeout: 5000, waitUntil: "commit" });
16
24
  }
17
- await waitForCompleteLoad(page)
25
+ logIfErrorResponse(response, url);
26
+ try {
27
+ await waitForCompleteLoad(page);
28
+ } catch(e) {
29
+ logTimestamp(await page.pageErrors());
30
+ throw e;
31
+ }
18
32
  }
19
33
 
20
34
 
@@ -34,7 +48,7 @@ test.beforeEach(async ({ context }) => {
34
48
  const req = route.request();
35
49
  const url = new URL(req.url());
36
50
  const path = url.pathname.toLowerCase();
37
- if (req.method() !== 'GET' || path.includes('/wp-content/') || !path.includes(baseUrl)) {
51
+ if (req.method() !== 'GET' || path.includes('/wp-content/') || !url.href.includes(baseUrl)) {
38
52
  return route.continue();
39
53
  }
40
54
  url.searchParams.set('_cb', Date.now().toString());
@@ -69,9 +83,20 @@ function logTimestamp(eventName) {
69
83
  }
70
84
 
71
85
  async function waitForCompleteLoad(page) {
72
- await page.waitForLoadState('domcontentloaded');
73
- await page.waitForLoadState('load');
74
- await page.waitForTimeout(500);
86
+ try {
87
+ await page.waitForLoadState('domcontentloaded', { timeout: 5000 });
88
+ } catch (e) {
89
+ logTimestamp(e);
90
+ logTimestamp('Retry waiting for DOMContentLoaded event after 5 seconds');
91
+ await page.waitForLoadState('domcontentloaded', { timeout: 5000 });
92
+ }
93
+ try {
94
+ await page.waitForLoadState('load', { timeout: 5000 });
95
+ } catch (e) {
96
+ logTimestamp(e);
97
+ logTimestamp('Retry waiting for load event after 5 seconds');
98
+ await page.waitForLoadState('load', { timeout: 5000 });
99
+ }
75
100
  }
76
101
 
77
102