@percy/core 1.30.1 → 1.30.2-alpha.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/dist/discovery.js +3 -2
- package/dist/findRevision.sh +37 -0
- package/dist/network.js +24 -7
- package/dist/timing.js +21 -0
- package/package.json +8 -8
- package/test/helpers/server.js +1 -1
package/dist/discovery.js
CHANGED
|
@@ -75,7 +75,8 @@ function parseCookies(cookies) {
|
|
|
75
75
|
return cookies.map(c => ({
|
|
76
76
|
name: c.name,
|
|
77
77
|
value: c.value,
|
|
78
|
-
secure: c.secure
|
|
78
|
+
secure: c.secure,
|
|
79
|
+
domain: c.domain
|
|
79
80
|
}));
|
|
80
81
|
}
|
|
81
82
|
if (!(typeof cookies === 'string' && cookies !== '')) return null;
|
|
@@ -243,7 +244,7 @@ async function* captureSnapshotResources(page, snapshot, options) {
|
|
|
243
244
|
mobile,
|
|
244
245
|
captureForDevices
|
|
245
246
|
} = options;
|
|
246
|
-
let cookies = (
|
|
247
|
+
let cookies = ((_snapshot$domSnapshot = snapshot.domSnapshot) === null || _snapshot$domSnapshot === void 0 ? void 0 : _snapshot$domSnapshot.cookies) || ((_snapshot$domSnapshot2 = snapshot.domSnapshot) === null || _snapshot$domSnapshot2 === void 0 || (_snapshot$domSnapshot2 = _snapshot$domSnapshot2[0]) === null || _snapshot$domSnapshot2 === void 0 ? void 0 : _snapshot$domSnapshot2.cookies);
|
|
247
248
|
cookies = parseCookies(cookies);
|
|
248
249
|
|
|
249
250
|
// iterate over device to trigger reqeusts and capture other dpr width
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
function download_url {
|
|
4
|
+
if [[ "$OS" == "Linux" ]]; then
|
|
5
|
+
echo "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F${1}%2Fchrome-linux.zip?alt=media"
|
|
6
|
+
elif [[ "$OS" == "Mac" ]] || [[ "$OS" == "Mac_Arm" ]]; then
|
|
7
|
+
echo "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/$OS%2F${1}%2Fchrome-mac.zip?alt=media"
|
|
8
|
+
elif [[ "$OS" == "Win" ]] || [[ "$OS" == "Win_x64" ]]; then
|
|
9
|
+
echo "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/$OS%2F${1}%2Fchrome-win.zip?alt=media"
|
|
10
|
+
fi
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function get_closest_rev {
|
|
14
|
+
while true; do
|
|
15
|
+
curl -I 2>/dev/null `download_url $REVISION` | head -1 | grep 404 >/dev/null
|
|
16
|
+
if (($? == 1)); then
|
|
17
|
+
break
|
|
18
|
+
fi
|
|
19
|
+
REVISION=$(($REVISION-1))
|
|
20
|
+
done
|
|
21
|
+
echo $REVISION
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
if (($# < 1)); then
|
|
26
|
+
printf "usage: \n"
|
|
27
|
+
printf " ./get_chromuim [-r] rev - will get chromium by revision\n"
|
|
28
|
+
exit 1
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
export REVISION=$1
|
|
32
|
+
|
|
33
|
+
for os in "Linux" "Mac" "Mac_Arm" "Win" "Win_x64";
|
|
34
|
+
do
|
|
35
|
+
export OS=$os
|
|
36
|
+
echo "$OS" `get_closest_rev`
|
|
37
|
+
done
|
package/dist/network.js
CHANGED
|
@@ -46,7 +46,7 @@ export class Network {
|
|
|
46
46
|
session.on('Network.requestWillBeSent', this._handleRequestWillBeSent);
|
|
47
47
|
session.on('Network.responseReceived', this._handleResponseReceived.bind(this, session));
|
|
48
48
|
session.on('Network.eventSourceMessageReceived', this._handleEventSourceMessageReceived);
|
|
49
|
-
session.on('Network.loadingFinished', this._handleLoadingFinished);
|
|
49
|
+
session.on('Network.loadingFinished', this._handleLoadingFinished.bind(this, session));
|
|
50
50
|
session.on('Network.loadingFailed', this._handleLoadingFailed);
|
|
51
51
|
let commands = [session.send('Network.enable'), session.send('Network.setBypassServiceWorker', {
|
|
52
52
|
bypass: !this.captureMockedServiceWorker
|
|
@@ -309,7 +309,7 @@ export class Network {
|
|
|
309
309
|
|
|
310
310
|
// Called when a request has finished loading which triggers the this.onrequestfinished
|
|
311
311
|
// callback. The request should have an associated response and be finished with any redirects.
|
|
312
|
-
_handleLoadingFinished = async event => {
|
|
312
|
+
_handleLoadingFinished = async (session, event) => {
|
|
313
313
|
let {
|
|
314
314
|
requestId
|
|
315
315
|
} = event;
|
|
@@ -318,7 +318,7 @@ export class Network {
|
|
|
318
318
|
let request = this.#requests.get(requestId);
|
|
319
319
|
/* istanbul ignore if: race condition paranioa */
|
|
320
320
|
if (!request) return;
|
|
321
|
-
await saveResponseResource(this, request);
|
|
321
|
+
await saveResponseResource(this, request, session);
|
|
322
322
|
this._forgetRequest(request);
|
|
323
323
|
};
|
|
324
324
|
|
|
@@ -441,10 +441,27 @@ async function sendResponseResource(network, request, session) {
|
|
|
441
441
|
}
|
|
442
442
|
|
|
443
443
|
// Make a new request with Node based on a network request
|
|
444
|
-
function makeDirectRequest(network, request) {
|
|
444
|
+
async function makeDirectRequest(network, request, session) {
|
|
445
445
|
var _network$authorizatio;
|
|
446
|
+
const {
|
|
447
|
+
cookies
|
|
448
|
+
} = await session.send('Network.getCookies', {
|
|
449
|
+
urls: [request.url]
|
|
450
|
+
});
|
|
446
451
|
let headers = {
|
|
447
|
-
|
|
452
|
+
// add default browser
|
|
453
|
+
accept: '*/*',
|
|
454
|
+
'sec-fetch-site': 'same-origin',
|
|
455
|
+
'sec-fetch-mode': 'cors',
|
|
456
|
+
'sec-fetch-dest': 'font',
|
|
457
|
+
'sec-ch-ua': '"Chromium";v="123", "Google Chrome";v="123", "Not?A_Brand";v="99"',
|
|
458
|
+
'sec-ch-ua-mobile': '?0',
|
|
459
|
+
'sec-ch-ua-platform': '"macOS"',
|
|
460
|
+
'sec-fetch-user': '?1',
|
|
461
|
+
// add request fetched headers
|
|
462
|
+
...request.headers,
|
|
463
|
+
// add applicable cookies
|
|
464
|
+
cookie: cookies.map(cookie => `${cookie.name}=${cookie.value}`).join('; ')
|
|
448
465
|
};
|
|
449
466
|
if ((_network$authorizatio = network.authorization) !== null && _network$authorizatio !== void 0 && _network$authorizatio.username) {
|
|
450
467
|
// include basic authorization username and password
|
|
@@ -462,7 +479,7 @@ function makeDirectRequest(network, request) {
|
|
|
462
479
|
}
|
|
463
480
|
|
|
464
481
|
// Save a resource from a request, skipping it if specific paramters are not met
|
|
465
|
-
async function saveResponseResource(network, request) {
|
|
482
|
+
async function saveResponseResource(network, request, session) {
|
|
466
483
|
let {
|
|
467
484
|
disableCache,
|
|
468
485
|
allowedHostnames,
|
|
@@ -514,7 +531,7 @@ async function saveResponseResource(network, request) {
|
|
|
514
531
|
// so request them directly.
|
|
515
532
|
if (mimeType !== null && mimeType !== void 0 && mimeType.includes('font') || detectedMime && detectedMime.includes('font')) {
|
|
516
533
|
log.debug('- Requesting asset directly', meta);
|
|
517
|
-
body = await makeDirectRequest(network, request);
|
|
534
|
+
body = await makeDirectRequest(network, request, session);
|
|
518
535
|
log.debug('- Got direct response', meta);
|
|
519
536
|
}
|
|
520
537
|
resource = createResource(url, body, mimeType, {
|
package/dist/timing.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import logger from '@percy/logger';
|
|
2
|
+
export default class TimeIt {
|
|
3
|
+
log = logger('timer');
|
|
4
|
+
// returns a singleton instance
|
|
5
|
+
constructor() {
|
|
6
|
+
let {
|
|
7
|
+
instance = this
|
|
8
|
+
} = this.constructor;
|
|
9
|
+
this.constructor.instance = instance;
|
|
10
|
+
return instance;
|
|
11
|
+
}
|
|
12
|
+
async measure(name, identifier, callback) {
|
|
13
|
+
const startTime = Date.now();
|
|
14
|
+
try {
|
|
15
|
+
return await callback();
|
|
16
|
+
} finally {
|
|
17
|
+
const duration = Date.now() - startTime;
|
|
18
|
+
this.log.debug(`${name} - ${identifier} - ${duration / 1000}s`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/core",
|
|
3
|
-
"version": "1.30.1",
|
|
3
|
+
"version": "1.30.2-alpha.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public",
|
|
12
|
-
"tag": "
|
|
12
|
+
"tag": "alpha"
|
|
13
13
|
},
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": ">=14"
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"test:types": "tsd"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@percy/client": "1.30.1",
|
|
47
|
-
"@percy/config": "1.30.1",
|
|
48
|
-
"@percy/dom": "1.30.1",
|
|
49
|
-
"@percy/logger": "1.30.1",
|
|
50
|
-
"@percy/webdriver-utils": "1.30.1",
|
|
46
|
+
"@percy/client": "1.30.2-alpha.1",
|
|
47
|
+
"@percy/config": "1.30.2-alpha.1",
|
|
48
|
+
"@percy/dom": "1.30.2-alpha.1",
|
|
49
|
+
"@percy/logger": "1.30.2-alpha.1",
|
|
50
|
+
"@percy/webdriver-utils": "1.30.2-alpha.1",
|
|
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": "49e55e3851ae4b0fd489327cd980e352a440aa19"
|
|
64
64
|
}
|
package/test/helpers/server.js
CHANGED
|
@@ -21,7 +21,7 @@ export function createTestServer({ default: defaultReply, ...replies }, port = 8
|
|
|
21
21
|
server.route(async (req, res, next) => {
|
|
22
22
|
let pathname = req.url.pathname;
|
|
23
23
|
if (req.url.search) pathname += req.url.search;
|
|
24
|
-
server.requests.push(req.body ? [pathname, req.body] : [pathname]);
|
|
24
|
+
server.requests.push(req.body ? [pathname, req.body, req.headers] : [pathname, req.headers]);
|
|
25
25
|
let reply = replies[pathname] || defaultReply;
|
|
26
26
|
return reply ? await reply(req, res) : next();
|
|
27
27
|
});
|