flexysnap 0.4.4 → 0.5.1
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 +1 -1
- package/src/index.js +2 -1
- package/src/testUtils.js +46 -8
package/package.json
CHANGED
package/src/index.js
CHANGED
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:
|
|
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:
|
|
23
|
+
response = await page.goto(url, { timeout: 5000, waitUntil: "commit" });
|
|
16
24
|
}
|
|
17
|
-
|
|
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
|
|
|
@@ -27,6 +41,12 @@ function setBaseUrl(url) {
|
|
|
27
41
|
baseUrl = url;
|
|
28
42
|
}
|
|
29
43
|
|
|
44
|
+
let cacheableUrlPatterns = ['/wp-content/', '/wp-includes/']
|
|
45
|
+
|
|
46
|
+
function setCacheableUrlPattern(pattern) {
|
|
47
|
+
cacheableUrlPatterns.push(pattern)
|
|
48
|
+
}
|
|
49
|
+
|
|
30
50
|
test.beforeEach(async ({ context }) => {
|
|
31
51
|
startTimer();
|
|
32
52
|
logTimestamp('Test execution started');
|
|
@@ -34,7 +54,13 @@ test.beforeEach(async ({ context }) => {
|
|
|
34
54
|
const req = route.request();
|
|
35
55
|
const url = new URL(req.url());
|
|
36
56
|
const path = url.pathname.toLowerCase();
|
|
37
|
-
|
|
57
|
+
|
|
58
|
+
for (let pattern of cacheableUrlPatterns) {
|
|
59
|
+
if (path.includes(pattern))
|
|
60
|
+
return route.continue();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (req.method() !== 'GET' || path.includes('/wp-content/') || !url.href.includes(baseUrl)) {
|
|
38
64
|
return route.continue();
|
|
39
65
|
}
|
|
40
66
|
url.searchParams.set('_cb', Date.now().toString());
|
|
@@ -69,9 +95,20 @@ function logTimestamp(eventName) {
|
|
|
69
95
|
}
|
|
70
96
|
|
|
71
97
|
async function waitForCompleteLoad(page) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
98
|
+
try {
|
|
99
|
+
await page.waitForLoadState('domcontentloaded', { timeout: 5000 });
|
|
100
|
+
} catch (e) {
|
|
101
|
+
logTimestamp(e);
|
|
102
|
+
logTimestamp('Retry waiting for DOMContentLoaded event after 5 seconds');
|
|
103
|
+
await page.waitForLoadState('domcontentloaded', { timeout: 5000 });
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
await page.waitForLoadState('load', { timeout: 5000 });
|
|
107
|
+
} catch (e) {
|
|
108
|
+
logTimestamp(e);
|
|
109
|
+
logTimestamp('Retry waiting for load event after 5 seconds');
|
|
110
|
+
await page.waitForLoadState('load', { timeout: 5000 });
|
|
111
|
+
}
|
|
75
112
|
}
|
|
76
113
|
|
|
77
114
|
|
|
@@ -215,5 +252,6 @@ export {
|
|
|
215
252
|
setClosePopups,
|
|
216
253
|
callClosePopups,
|
|
217
254
|
logTimestamp,
|
|
218
|
-
setBaseUrl
|
|
255
|
+
setBaseUrl,
|
|
256
|
+
setCacheableUrlPattern
|
|
219
257
|
};
|