flexysnap 0.5.0 → 0.5.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 +1 -1
- package/src/index.js +2 -1
- package/src/testUtils.js +52 -36
package/package.json
CHANGED
package/src/index.js
CHANGED
package/src/testUtils.js
CHANGED
|
@@ -6,29 +6,44 @@ 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
10
|
async function gotoWithRetry(page, url) {
|
|
16
|
-
let
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
11
|
+
let error = null;
|
|
12
|
+
for (let i = 1; i <= 3; ++i) {
|
|
13
|
+
error = null;
|
|
14
|
+
let timeout = i * 5000;
|
|
15
|
+
logTimestamp('Loading ' + url);
|
|
16
|
+
let response = null;
|
|
17
|
+
try {
|
|
18
|
+
response = await page.goto(url, {timeout: timeout, waitUntil: "commit"});
|
|
19
|
+
} catch (e) {
|
|
20
|
+
logTimestamp('Error navigating to page');
|
|
21
|
+
error = e
|
|
22
|
+
continue
|
|
23
|
+
}
|
|
24
|
+
if (response && response.status() >= 400) {
|
|
25
|
+
logTimestamp(`HTTP error ${response.status()} ${response.statusText()} while loading ${url}`);
|
|
26
|
+
error = new Error('Could not load page.')
|
|
27
|
+
continue
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
await page.waitForLoadState('domcontentloaded', {timeout: timeout});
|
|
31
|
+
} catch (e) {
|
|
32
|
+
logTimestamp('Error while waiting for DOMContentLoaded event');
|
|
33
|
+
error = e
|
|
34
|
+
continue
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
await page.waitForLoadState('load', {timeout: timeout});
|
|
38
|
+
} catch (e) {
|
|
39
|
+
logTimestamp('Error while waiting for load event');
|
|
40
|
+
error = e
|
|
41
|
+
continue
|
|
42
|
+
}
|
|
43
|
+
break
|
|
31
44
|
}
|
|
45
|
+
if (error)
|
|
46
|
+
throw error
|
|
32
47
|
}
|
|
33
48
|
|
|
34
49
|
|
|
@@ -41,6 +56,12 @@ function setBaseUrl(url) {
|
|
|
41
56
|
baseUrl = url;
|
|
42
57
|
}
|
|
43
58
|
|
|
59
|
+
let cacheableUrlPatterns = ['/wp-content/', '/wp-includes/']
|
|
60
|
+
|
|
61
|
+
function setCacheableUrlPattern(pattern) {
|
|
62
|
+
cacheableUrlPatterns.push(pattern)
|
|
63
|
+
}
|
|
64
|
+
|
|
44
65
|
test.beforeEach(async ({ context }) => {
|
|
45
66
|
startTimer();
|
|
46
67
|
logTimestamp('Test execution started');
|
|
@@ -48,6 +69,12 @@ test.beforeEach(async ({ context }) => {
|
|
|
48
69
|
const req = route.request();
|
|
49
70
|
const url = new URL(req.url());
|
|
50
71
|
const path = url.pathname.toLowerCase();
|
|
72
|
+
|
|
73
|
+
for (let pattern of cacheableUrlPatterns) {
|
|
74
|
+
if (path.includes(pattern))
|
|
75
|
+
return route.continue();
|
|
76
|
+
}
|
|
77
|
+
|
|
51
78
|
if (req.method() !== 'GET' || path.includes('/wp-content/') || !url.href.includes(baseUrl)) {
|
|
52
79
|
return route.continue();
|
|
53
80
|
}
|
|
@@ -82,21 +109,9 @@ function logTimestamp(eventName) {
|
|
|
82
109
|
return { currentTime, elapsedMs, elapsedSec };
|
|
83
110
|
}
|
|
84
111
|
|
|
85
|
-
async function waitForCompleteLoad(page) {
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
}
|
|
112
|
+
async function waitForCompleteLoad(page, timeout = 5000) {
|
|
113
|
+
await page.waitForLoadState('domcontentloaded', { timeout: timeout });
|
|
114
|
+
await page.waitForLoadState('load', { timeout: timeout });
|
|
100
115
|
}
|
|
101
116
|
|
|
102
117
|
|
|
@@ -240,5 +255,6 @@ export {
|
|
|
240
255
|
setClosePopups,
|
|
241
256
|
callClosePopups,
|
|
242
257
|
logTimestamp,
|
|
243
|
-
setBaseUrl
|
|
258
|
+
setBaseUrl,
|
|
259
|
+
setCacheableUrlPattern
|
|
244
260
|
};
|