@percy/core 1.28.1-alpha.1 → 1.28.1-alpha.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/dist/config.js +4 -0
- package/dist/discovery.js +39 -31
- package/dist/utils.js +19 -0
- package/package.json +7 -7
package/dist/config.js
CHANGED
package/dist/discovery.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import logger from '@percy/logger';
|
|
2
2
|
import Queue from './queue.js';
|
|
3
|
-
import { normalizeURL, hostnameMatches, createResource, createRootResource, createPercyCSSResource, createLogResource, yieldAll } from './utils.js';
|
|
3
|
+
import { normalizeURL, hostnameMatches, createResource, createRootResource, createPercyCSSResource, createLogResource, yieldAll, withRetries } from './utils.js';
|
|
4
4
|
|
|
5
5
|
// Logs verbose debug logs detailing various snapshot options.
|
|
6
6
|
function debugSnapshotOptions(snapshot) {
|
|
@@ -279,7 +279,8 @@ export const RESOURCE_CACHE_KEY = Symbol('resource-cache');
|
|
|
279
279
|
// snapshot which is used to intercept and capture snapshot resource requests.
|
|
280
280
|
export function createDiscoveryQueue(percy) {
|
|
281
281
|
let {
|
|
282
|
-
concurrency
|
|
282
|
+
concurrency,
|
|
283
|
+
retry
|
|
283
284
|
} = percy.config.discovery;
|
|
284
285
|
let queue = new Queue('discovery');
|
|
285
286
|
let cache;
|
|
@@ -317,39 +318,46 @@ export function createDiscoveryQueue(percy) {
|
|
|
317
318
|
/* istanbul ignore next: tested, but coverage is stripped */
|
|
318
319
|
let assetDiscoveryPageEnableJS = snapshot.cliEnableJavaScript && !snapshot.domSnapshot || (snapshot.enableJavaScript ?? !snapshot.domSnapshot);
|
|
319
320
|
percy.log.debug(`Asset discovery Browser Page enable JS: ${assetDiscoveryPageEnableJS}`);
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
321
|
+
await withRetries(async function* () {
|
|
322
|
+
// create a new browser page
|
|
323
|
+
let page = yield percy.browser.page({
|
|
324
|
+
enableJavaScript: assetDiscoveryPageEnableJS,
|
|
325
|
+
networkIdleTimeout: snapshot.discovery.networkIdleTimeout,
|
|
326
|
+
requestHeaders: snapshot.discovery.requestHeaders,
|
|
327
|
+
authorization: snapshot.discovery.authorization,
|
|
328
|
+
userAgent: snapshot.discovery.userAgent,
|
|
329
|
+
captureMockedServiceWorker: snapshot.discovery.captureMockedServiceWorker,
|
|
330
|
+
meta: snapshot.meta,
|
|
331
|
+
// enable network inteception
|
|
332
|
+
intercept: {
|
|
333
|
+
enableJavaScript: snapshot.enableJavaScript,
|
|
334
|
+
disableCache: snapshot.discovery.disableCache,
|
|
335
|
+
allowedHostnames: snapshot.discovery.allowedHostnames,
|
|
336
|
+
disallowedHostnames: snapshot.discovery.disallowedHostnames,
|
|
337
|
+
getResource: u => snapshot.resources.get(u) || cache.get(u),
|
|
338
|
+
saveResource: r => {
|
|
339
|
+
snapshot.resources.set(r.url, r);
|
|
340
|
+
if (!r.root) {
|
|
341
|
+
cache.set(r.url, r);
|
|
342
|
+
}
|
|
340
343
|
}
|
|
341
344
|
}
|
|
345
|
+
});
|
|
346
|
+
try {
|
|
347
|
+
yield* captureSnapshotResources(page, snapshot, {
|
|
348
|
+
captureWidths: !snapshot.domSnapshot && percy.deferUploads,
|
|
349
|
+
capture: callback
|
|
350
|
+
});
|
|
351
|
+
} finally {
|
|
352
|
+
// always close the page when done
|
|
353
|
+
await page.close();
|
|
354
|
+
}
|
|
355
|
+
}, {
|
|
356
|
+
count: retry ? 3 : 1,
|
|
357
|
+
onRetry: () => {
|
|
358
|
+
percy.log.debug(`Retrying snapshot: ${snapshot.name}`, snapshot.meta);
|
|
342
359
|
}
|
|
343
360
|
});
|
|
344
|
-
try {
|
|
345
|
-
yield* captureSnapshotResources(page, snapshot, {
|
|
346
|
-
captureWidths: !snapshot.domSnapshot && percy.deferUploads,
|
|
347
|
-
capture: callback
|
|
348
|
-
});
|
|
349
|
-
} finally {
|
|
350
|
-
// always close the page when done
|
|
351
|
-
await page.close();
|
|
352
|
-
}
|
|
353
361
|
}).handle('error', ({
|
|
354
362
|
name,
|
|
355
363
|
meta
|
package/dist/utils.js
CHANGED
|
@@ -328,6 +328,25 @@ export function serializeFunction(fn) {
|
|
|
328
328
|
}
|
|
329
329
|
return fnbody;
|
|
330
330
|
}
|
|
331
|
+
export async function withRetries(fn, {
|
|
332
|
+
count,
|
|
333
|
+
onRetry
|
|
334
|
+
}) {
|
|
335
|
+
count || (count = 1); // default a single try
|
|
336
|
+
let run = 0;
|
|
337
|
+
while (true) {
|
|
338
|
+
run += 1;
|
|
339
|
+
try {
|
|
340
|
+
return await generatePromise(fn);
|
|
341
|
+
} catch (e) {
|
|
342
|
+
if (run < count) {
|
|
343
|
+
await (onRetry === null || onRetry === void 0 ? void 0 : onRetry());
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
throw e;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
331
350
|
|
|
332
351
|
// DefaultMap, which returns a default value for an uninitialized key
|
|
333
352
|
// Similar to defaultDict in python
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/core",
|
|
3
|
-
"version": "1.28.1-alpha.
|
|
3
|
+
"version": "1.28.1-alpha.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"test:types": "tsd"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@percy/client": "1.28.1-alpha.
|
|
47
|
-
"@percy/config": "1.28.1-alpha.
|
|
48
|
-
"@percy/dom": "1.28.1-alpha.
|
|
49
|
-
"@percy/logger": "1.28.1-alpha.
|
|
50
|
-
"@percy/webdriver-utils": "1.28.1-alpha.
|
|
46
|
+
"@percy/client": "1.28.1-alpha.2",
|
|
47
|
+
"@percy/config": "1.28.1-alpha.2",
|
|
48
|
+
"@percy/dom": "1.28.1-alpha.2",
|
|
49
|
+
"@percy/logger": "1.28.1-alpha.2",
|
|
50
|
+
"@percy/webdriver-utils": "1.28.1-alpha.2",
|
|
51
51
|
"content-disposition": "^0.5.4",
|
|
52
52
|
"cross-spawn": "^7.0.3",
|
|
53
53
|
"extract-zip": "^2.0.1",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"rimraf": "^3.0.2",
|
|
59
59
|
"ws": "^8.0.0"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "a3f2e709d0a6445e15a1128686578b1659243a95"
|
|
62
62
|
}
|