@percy/core 1.29.4-beta.1 → 1.29.4-beta.3
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 +14 -0
- package/dist/discovery.js +29 -15
- package/dist/network.js +2 -2
- package/dist/snapshot.js +2 -0
- package/dist/utils.js +9 -0
- package/package.json +7 -7
package/dist/config.js
CHANGED
|
@@ -205,6 +205,14 @@ export const configSchema = {
|
|
|
205
205
|
maximum: 750,
|
|
206
206
|
minimum: 1
|
|
207
207
|
},
|
|
208
|
+
waitForSelector: {
|
|
209
|
+
type: 'string'
|
|
210
|
+
},
|
|
211
|
+
waitForTimeout: {
|
|
212
|
+
type: 'integer',
|
|
213
|
+
minimum: 1,
|
|
214
|
+
maximum: 30000
|
|
215
|
+
},
|
|
208
216
|
disableCache: {
|
|
209
217
|
type: 'boolean'
|
|
210
218
|
},
|
|
@@ -363,6 +371,12 @@ export const snapshotSchema = {
|
|
|
363
371
|
requestHeaders: {
|
|
364
372
|
$ref: '/config/discovery#/properties/requestHeaders'
|
|
365
373
|
},
|
|
374
|
+
waitForSelector: {
|
|
375
|
+
$ref: '/config/discovery#/properties/waitForSelector'
|
|
376
|
+
},
|
|
377
|
+
waitForTimeout: {
|
|
378
|
+
$ref: '/config/discovery#/properties/waitForTimeout'
|
|
379
|
+
},
|
|
366
380
|
authorization: {
|
|
367
381
|
$ref: '/config/discovery#/properties/authorization'
|
|
368
382
|
},
|
package/dist/discovery.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import logger from '@percy/logger';
|
|
2
2
|
import Queue from './queue.js';
|
|
3
|
-
import
|
|
3
|
+
import Page from './page.js';
|
|
4
|
+
import { normalizeURL, hostnameMatches, createResource, createRootResource, createPercyCSSResource, createLogResource, yieldAll, snapshotLogName, waitForTimeout, withRetries, waitForSelectorInsideBrowser } from './utils.js';
|
|
4
5
|
import { sha256hash } from '@percy/client/utils';
|
|
5
6
|
import Pako from 'pako';
|
|
6
7
|
import TimeIt from './timing.js';
|
|
@@ -60,6 +61,19 @@ function debugSnapshotOptions(snapshot) {
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
// parse browser cookies in correct format if flag is enabled
|
|
65
|
+
// it assumes that cookiesStr is string returned by document.cookie
|
|
66
|
+
function parseCookies(cookiesStr) {
|
|
67
|
+
if (process.env.PERCY_DO_NOT_USE_CAPTURED_COOKIES === 'true' || !(typeof cookiesStr === 'string' && cookiesStr !== '')) return null;
|
|
68
|
+
return cookiesStr.split('; ').map(c => {
|
|
69
|
+
const eqIdx = c.indexOf('=');
|
|
70
|
+
return {
|
|
71
|
+
name: c.substring(0, eqIdx),
|
|
72
|
+
value: c.substring(eqIdx + 1)
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
63
77
|
// Wait for a page's asset discovery network to idle
|
|
64
78
|
function waitForDiscoveryNetworkIdle(page, options) {
|
|
65
79
|
let {
|
|
@@ -162,6 +176,7 @@ function processSnapshotResources({
|
|
|
162
176
|
// Triggers the capture of resource requests for a page by iterating over snapshot widths to resize
|
|
163
177
|
// the page and calling any provided execute options.
|
|
164
178
|
async function* captureSnapshotResources(page, snapshot, options) {
|
|
179
|
+
var _snapshot$domSnapshot;
|
|
165
180
|
const log = logger('core:discovery');
|
|
166
181
|
let {
|
|
167
182
|
discovery,
|
|
@@ -175,20 +190,7 @@ async function* captureSnapshotResources(page, snapshot, options) {
|
|
|
175
190
|
mobile,
|
|
176
191
|
captureForDevices
|
|
177
192
|
} = options;
|
|
178
|
-
let cookies;
|
|
179
|
-
if (process.env.PERCY_DO_NOT_USE_CAPTURED_COOKIES !== 'true') {
|
|
180
|
-
var _snapshot$domSnapshot;
|
|
181
|
-
cookies = snapshot === null || snapshot === void 0 ? void 0 : (_snapshot$domSnapshot = snapshot.domSnapshot) === null || _snapshot$domSnapshot === void 0 ? void 0 : _snapshot$domSnapshot.cookies;
|
|
182
|
-
}
|
|
183
|
-
if (typeof cookies === 'string' && cookies !== '') {
|
|
184
|
-
cookies = cookies.split('; ').map(c => c.split('='));
|
|
185
|
-
cookies = cookies.map(([key, value]) => {
|
|
186
|
-
return {
|
|
187
|
-
name: key,
|
|
188
|
-
value: value
|
|
189
|
-
};
|
|
190
|
-
});
|
|
191
|
-
}
|
|
193
|
+
let cookies = parseCookies(snapshot === null || snapshot === void 0 ? void 0 : (_snapshot$domSnapshot = snapshot.domSnapshot) === null || _snapshot$domSnapshot === void 0 ? void 0 : _snapshot$domSnapshot.cookies);
|
|
192
194
|
|
|
193
195
|
// iterate over device to trigger reqeusts and capture other dpr width
|
|
194
196
|
async function* captureResponsiveAssets() {
|
|
@@ -238,6 +240,18 @@ async function* captureSnapshotResources(page, snapshot, options) {
|
|
|
238
240
|
yield page.goto(snapshot.url, {
|
|
239
241
|
cookies
|
|
240
242
|
});
|
|
243
|
+
|
|
244
|
+
// wait for any specified timeout
|
|
245
|
+
if (snapshot.discovery.waitForTimeout && page.enableJavaScript) {
|
|
246
|
+
log.debug(`Wait for ${snapshot.discovery.waitForTimeout}ms timeout`);
|
|
247
|
+
await waitForTimeout(snapshot.discovery.waitForTimeout);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// wait for any specified selector
|
|
251
|
+
if (snapshot.discovery.waitForSelector && page.enableJavaScript) {
|
|
252
|
+
log.debug(`Wait for selector: ${snapshot.discovery.waitForSelector}`);
|
|
253
|
+
await waitForSelectorInsideBrowser(page, snapshot.discovery.waitForSelector, Page.TIMEOUT);
|
|
254
|
+
}
|
|
241
255
|
if (snapshot.execute) {
|
|
242
256
|
// when any execute options are provided, inject snapshot options
|
|
243
257
|
/* istanbul ignore next: cannot detect coverage of injected code */
|
package/dist/network.js
CHANGED
|
@@ -510,7 +510,7 @@ async function saveResponseResource(network, request) {
|
|
|
510
510
|
// font anyway as font responses from the browser may not be properly encoded,
|
|
511
511
|
// so request them directly.
|
|
512
512
|
if (mimeType !== null && mimeType !== void 0 && mimeType.includes('font') || detectedMime && detectedMime.includes('font')) {
|
|
513
|
-
log.debug('- Requesting asset directly');
|
|
513
|
+
log.debug('- Requesting asset directly', meta);
|
|
514
514
|
body = await makeDirectRequest(network, request);
|
|
515
515
|
}
|
|
516
516
|
resource = createResource(url, body, mimeType, {
|
|
@@ -525,7 +525,7 @@ async function saveResponseResource(network, request) {
|
|
|
525
525
|
log.debug(`- mimetype: ${resource.mimetype}`, meta);
|
|
526
526
|
} catch (error) {
|
|
527
527
|
log.debug(`Encountered an error processing resource: ${url}`, meta);
|
|
528
|
-
log.debug(error);
|
|
528
|
+
log.debug(error, meta);
|
|
529
529
|
}
|
|
530
530
|
}
|
|
531
531
|
if (resource) {
|
package/dist/snapshot.js
CHANGED
|
@@ -142,6 +142,8 @@ function getSnapshotOptions(options, {
|
|
|
142
142
|
allowedHostnames: config.discovery.allowedHostnames,
|
|
143
143
|
disallowedHostnames: config.discovery.disallowedHostnames,
|
|
144
144
|
networkIdleTimeout: config.discovery.networkIdleTimeout,
|
|
145
|
+
waitForTimeout: config.discovery.waitForTimeout,
|
|
146
|
+
waitForSelector: config.discovery.waitForSelector,
|
|
145
147
|
devicePixelRatio: config.discovery.devicePixelRatio,
|
|
146
148
|
requestHeaders: config.discovery.requestHeaders,
|
|
147
149
|
authorization: config.discovery.authorization,
|
package/dist/utils.js
CHANGED
|
@@ -274,6 +274,15 @@ async function waitForSelector(selector, timeout) {
|
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
+
// wait for a query selector to exist within an optional timeout inside browser
|
|
278
|
+
export async function waitForSelectorInsideBrowser(page, selector, timeout) {
|
|
279
|
+
try {
|
|
280
|
+
return page.eval(`await waitForSelector(${JSON.stringify(selector)}, ${timeout})`);
|
|
281
|
+
} catch {
|
|
282
|
+
throw new Error(`Unable to find: ${selector}`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
277
286
|
// Browser-specific util to wait for an xpath selector to exist within an optional timeout.
|
|
278
287
|
/* istanbul ignore next: tested, but coverage is stripped */
|
|
279
288
|
async function waitForXPath(selector, timeout) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/core",
|
|
3
|
-
"version": "1.29.4-beta.
|
|
3
|
+
"version": "1.29.4-beta.3",
|
|
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.29.4-beta.
|
|
47
|
-
"@percy/config": "1.29.4-beta.
|
|
48
|
-
"@percy/dom": "1.29.4-beta.
|
|
49
|
-
"@percy/logger": "1.29.4-beta.
|
|
50
|
-
"@percy/webdriver-utils": "1.29.4-beta.
|
|
46
|
+
"@percy/client": "1.29.4-beta.3",
|
|
47
|
+
"@percy/config": "1.29.4-beta.3",
|
|
48
|
+
"@percy/dom": "1.29.4-beta.3",
|
|
49
|
+
"@percy/logger": "1.29.4-beta.3",
|
|
50
|
+
"@percy/webdriver-utils": "1.29.4-beta.3",
|
|
51
51
|
"content-disposition": "^0.5.4",
|
|
52
52
|
"cross-spawn": "^7.0.3",
|
|
53
53
|
"extract-zip": "^2.0.1",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"ws": "^8.17.1",
|
|
61
61
|
"yaml": "^2.4.1"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "8c61c0ad7a8a1b61f199a2a011ac296764cdc2eb"
|
|
64
64
|
}
|