@percy/core
Advanced tools
Comparing version 1.28.1-alpha.1 to 1.28.1-alpha.2
@@ -252,2 +252,6 @@ // Common config options used in Percy commands | ||
}, | ||
retry: { | ||
type: 'boolean', | ||
default: false | ||
}, | ||
launchOptions: { | ||
@@ -254,0 +258,0 @@ type: 'object', |
import logger from '@percy/logger'; | ||
import Queue from './queue.js'; | ||
import { normalizeURL, hostnameMatches, createResource, createRootResource, createPercyCSSResource, createLogResource, yieldAll } from './utils.js'; | ||
import { normalizeURL, hostnameMatches, createResource, createRootResource, createPercyCSSResource, createLogResource, yieldAll, withRetries } from './utils.js'; | ||
@@ -282,3 +282,4 @@ // Logs verbose debug logs detailing various snapshot options. | ||
let { | ||
concurrency | ||
concurrency, | ||
retry | ||
} = percy.config.discovery; | ||
@@ -321,35 +322,42 @@ let queue = new Queue('discovery'); | ||
percy.log.debug(`Asset discovery Browser Page enable JS: ${assetDiscoveryPageEnableJS}`); | ||
// create a new browser page | ||
let page = yield percy.browser.page({ | ||
enableJavaScript: assetDiscoveryPageEnableJS, | ||
networkIdleTimeout: snapshot.discovery.networkIdleTimeout, | ||
requestHeaders: snapshot.discovery.requestHeaders, | ||
authorization: snapshot.discovery.authorization, | ||
userAgent: snapshot.discovery.userAgent, | ||
captureMockedServiceWorker: snapshot.discovery.captureMockedServiceWorker, | ||
meta: snapshot.meta, | ||
// enable network inteception | ||
intercept: { | ||
enableJavaScript: snapshot.enableJavaScript, | ||
disableCache: snapshot.discovery.disableCache, | ||
allowedHostnames: snapshot.discovery.allowedHostnames, | ||
disallowedHostnames: snapshot.discovery.disallowedHostnames, | ||
getResource: u => snapshot.resources.get(u) || cache.get(u), | ||
saveResource: r => { | ||
snapshot.resources.set(r.url, r); | ||
if (!r.root) { | ||
cache.set(r.url, r); | ||
await withRetries(async function* () { | ||
// create a new browser page | ||
let page = yield percy.browser.page({ | ||
enableJavaScript: assetDiscoveryPageEnableJS, | ||
networkIdleTimeout: snapshot.discovery.networkIdleTimeout, | ||
requestHeaders: snapshot.discovery.requestHeaders, | ||
authorization: snapshot.discovery.authorization, | ||
userAgent: snapshot.discovery.userAgent, | ||
captureMockedServiceWorker: snapshot.discovery.captureMockedServiceWorker, | ||
meta: snapshot.meta, | ||
// enable network inteception | ||
intercept: { | ||
enableJavaScript: snapshot.enableJavaScript, | ||
disableCache: snapshot.discovery.disableCache, | ||
allowedHostnames: snapshot.discovery.allowedHostnames, | ||
disallowedHostnames: snapshot.discovery.disallowedHostnames, | ||
getResource: u => snapshot.resources.get(u) || cache.get(u), | ||
saveResource: r => { | ||
snapshot.resources.set(r.url, r); | ||
if (!r.root) { | ||
cache.set(r.url, r); | ||
} | ||
} | ||
} | ||
}); | ||
try { | ||
yield* captureSnapshotResources(page, snapshot, { | ||
captureWidths: !snapshot.domSnapshot && percy.deferUploads, | ||
capture: callback | ||
}); | ||
} finally { | ||
// always close the page when done | ||
await page.close(); | ||
} | ||
}, { | ||
count: retry ? 3 : 1, | ||
onRetry: () => { | ||
percy.log.debug(`Retrying snapshot: ${snapshot.name}`, snapshot.meta); | ||
} | ||
}); | ||
try { | ||
yield* captureSnapshotResources(page, snapshot, { | ||
captureWidths: !snapshot.domSnapshot && percy.deferUploads, | ||
capture: callback | ||
}); | ||
} finally { | ||
// always close the page when done | ||
await page.close(); | ||
} | ||
}).handle('error', ({ | ||
@@ -356,0 +364,0 @@ name, |
@@ -331,2 +331,21 @@ import EventEmitter from 'events'; | ||
} | ||
export async function withRetries(fn, { | ||
count, | ||
onRetry | ||
}) { | ||
count || (count = 1); // default a single try | ||
let run = 0; | ||
while (true) { | ||
run += 1; | ||
try { | ||
return await generatePromise(fn); | ||
} catch (e) { | ||
if (run < count) { | ||
await (onRetry === null || onRetry === void 0 ? void 0 : onRetry()); | ||
continue; | ||
} | ||
throw e; | ||
} | ||
} | ||
} | ||
@@ -333,0 +352,0 @@ // DefaultMap, which returns a default value for an uninitialized key |
{ | ||
"name": "@percy/core", | ||
"version": "1.28.1-alpha.1", | ||
"version": "1.28.1-alpha.2", | ||
"license": "MIT", | ||
@@ -46,7 +46,7 @@ "repository": { | ||
"dependencies": { | ||
"@percy/client": "1.28.1-alpha.1", | ||
"@percy/config": "1.28.1-alpha.1", | ||
"@percy/dom": "1.28.1-alpha.1", | ||
"@percy/logger": "1.28.1-alpha.1", | ||
"@percy/webdriver-utils": "1.28.1-alpha.1", | ||
"@percy/client": "1.28.1-alpha.2", | ||
"@percy/config": "1.28.1-alpha.2", | ||
"@percy/dom": "1.28.1-alpha.2", | ||
"@percy/logger": "1.28.1-alpha.2", | ||
"@percy/webdriver-utils": "1.28.1-alpha.2", | ||
"content-disposition": "^0.5.4", | ||
@@ -62,3 +62,3 @@ "cross-spawn": "^7.0.3", | ||
}, | ||
"gitHead": "a8ac47269d65a7cf88658c8899c61bef1808c2d0" | ||
"gitHead": "a3f2e709d0a6445e15a1128686578b1659243a95" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
201013
4866
241
4
12
1
73
+ Added@percy/client@1.28.1-alpha.2(transitive)
+ Added@percy/config@1.28.1-alpha.2(transitive)
+ Added@percy/dom@1.28.1-alpha.2(transitive)
+ Added@percy/env@1.28.1-alpha.2(transitive)
+ Added@percy/logger@1.28.1-alpha.2(transitive)
+ Added@percy/sdk-utils@1.28.1-alpha.2(transitive)
+ Added@percy/webdriver-utils@1.28.1-alpha.2(transitive)
- Removed@percy/client@1.28.1-alpha.1(transitive)
- Removed@percy/config@1.28.1-alpha.1(transitive)
- Removed@percy/dom@1.28.1-alpha.1(transitive)
- Removed@percy/env@1.28.1-alpha.1(transitive)
- Removed@percy/logger@1.28.1-alpha.1(transitive)
- Removed@percy/sdk-utils@1.28.1-alpha.1(transitive)
- Removed@percy/webdriver-utils@1.28.1-alpha.1(transitive)
Updated@percy/client@1.28.1-alpha.2
Updated@percy/config@1.28.1-alpha.2
Updated@percy/dom@1.28.1-alpha.2
Updated@percy/logger@1.28.1-alpha.2