@percy/core 1.10.2 → 1.10.4
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/api.js +15 -54
- package/dist/config.js +14 -44
- package/dist/server.js +1 -46
- package/dist/snapshot.js +2 -2
- package/package.json +6 -6
package/dist/api.js
CHANGED
|
@@ -10,39 +10,9 @@ export function createPercyServer(percy, port) {
|
|
|
10
10
|
let pkg = getPackageJSON(import.meta.url);
|
|
11
11
|
let server = Server.createServer({
|
|
12
12
|
port
|
|
13
|
-
}) // facilitate logger websocket connections
|
|
14
|
-
.websocket('/(logger)?', ws => {
|
|
15
|
-
var _percy$testing, _percy$testing2;
|
|
16
|
-
|
|
17
|
-
// support sabotaging remote logging connections in testing mode
|
|
18
|
-
if (((_percy$testing = percy.testing) === null || _percy$testing === void 0 ? void 0 : _percy$testing.remoteLogging) === false) return ws.terminate(); // track all remote logging connections in testing mode
|
|
19
|
-
|
|
20
|
-
if (percy.testing) ((_percy$testing2 = percy.testing).remoteLoggers || (_percy$testing2.remoteLoggers = new Set())).add(ws);
|
|
21
|
-
ws.addEventListener('close', () => {
|
|
22
|
-
var _percy$testing3, _percy$testing3$remot;
|
|
23
|
-
|
|
24
|
-
return (_percy$testing3 = percy.testing) === null || _percy$testing3 === void 0 ? void 0 : (_percy$testing3$remot = _percy$testing3.remoteLoggers) === null || _percy$testing3$remot === void 0 ? void 0 : _percy$testing3$remot.delete(ws);
|
|
25
|
-
}); // listen for messages with specific logging payloads
|
|
26
|
-
|
|
27
|
-
ws.addEventListener('message', ({
|
|
28
|
-
data
|
|
29
|
-
}) => {
|
|
30
|
-
let {
|
|
31
|
-
log,
|
|
32
|
-
messages = []
|
|
33
|
-
} = JSON.parse(data);
|
|
34
|
-
|
|
35
|
-
for (let m of messages) logger.instance.messages.add(m);
|
|
36
|
-
|
|
37
|
-
if (log) logger.instance.log(...log);
|
|
38
|
-
}); // respond with the current loglevel
|
|
39
|
-
|
|
40
|
-
ws.send(JSON.stringify({
|
|
41
|
-
loglevel: logger.loglevel()
|
|
42
|
-
}));
|
|
43
13
|
}) // general middleware
|
|
44
14
|
.route((req, res, next) => {
|
|
45
|
-
var _percy$
|
|
15
|
+
var _percy$testing, _percy$testing4, _percy$testing4$api, _percy$testing5, _percy$testing5$api;
|
|
46
16
|
|
|
47
17
|
// treat all request bodies as json
|
|
48
18
|
if (req.body) try {
|
|
@@ -51,17 +21,17 @@ export function createPercyServer(percy, port) {
|
|
|
51
21
|
|
|
52
22
|
res.setHeader('Access-Control-Expose-Headers', '*, X-Percy-Core-Version'); // skip or change api version header in testing mode
|
|
53
23
|
|
|
54
|
-
if (((_percy$
|
|
55
|
-
var _percy$
|
|
24
|
+
if (((_percy$testing = percy.testing) === null || _percy$testing === void 0 ? void 0 : _percy$testing.version) !== false) {
|
|
25
|
+
var _percy$testing2;
|
|
56
26
|
|
|
57
|
-
res.setHeader('X-Percy-Core-Version', ((_percy$
|
|
27
|
+
res.setHeader('X-Percy-Core-Version', ((_percy$testing2 = percy.testing) === null || _percy$testing2 === void 0 ? void 0 : _percy$testing2.version) ?? pkg.version);
|
|
58
28
|
} // track all api reqeusts in testing mode
|
|
59
29
|
|
|
60
30
|
|
|
61
31
|
if (percy.testing && !req.url.pathname.startsWith('/test/')) {
|
|
62
|
-
var _percy$
|
|
32
|
+
var _percy$testing3;
|
|
63
33
|
|
|
64
|
-
((_percy$
|
|
34
|
+
((_percy$testing3 = percy.testing).requests || (_percy$testing3.requests = [])).push({
|
|
65
35
|
url: `${req.url.pathname}${req.url.search}`,
|
|
66
36
|
method: req.method,
|
|
67
37
|
body: req.body
|
|
@@ -69,32 +39,32 @@ export function createPercyServer(percy, port) {
|
|
|
69
39
|
} // support sabotaging requests in testing mode
|
|
70
40
|
|
|
71
41
|
|
|
72
|
-
if (((_percy$
|
|
42
|
+
if (((_percy$testing4 = percy.testing) === null || _percy$testing4 === void 0 ? void 0 : (_percy$testing4$api = _percy$testing4.api) === null || _percy$testing4$api === void 0 ? void 0 : _percy$testing4$api[req.url.pathname]) === 'error') {
|
|
73
43
|
next = () => {
|
|
74
44
|
var _percy$testing$build;
|
|
75
45
|
|
|
76
46
|
return Promise.reject(new Error(((_percy$testing$build = percy.testing.build) === null || _percy$testing$build === void 0 ? void 0 : _percy$testing$build.error) || 'testing'));
|
|
77
47
|
};
|
|
78
|
-
} else if (((_percy$
|
|
48
|
+
} else if (((_percy$testing5 = percy.testing) === null || _percy$testing5 === void 0 ? void 0 : (_percy$testing5$api = _percy$testing5.api) === null || _percy$testing5$api === void 0 ? void 0 : _percy$testing5$api[req.url.pathname]) === 'disconnect') {
|
|
79
49
|
next = () => req.connection.destroy();
|
|
80
50
|
} // return json errors
|
|
81
51
|
|
|
82
52
|
|
|
83
53
|
return next().catch(e => {
|
|
84
|
-
var _percy$
|
|
54
|
+
var _percy$testing6;
|
|
85
55
|
|
|
86
56
|
return res.json(e.status ?? 500, {
|
|
87
|
-
build: ((_percy$
|
|
57
|
+
build: ((_percy$testing6 = percy.testing) === null || _percy$testing6 === void 0 ? void 0 : _percy$testing6.build) || percy.build,
|
|
88
58
|
error: e.message,
|
|
89
59
|
success: false
|
|
90
60
|
});
|
|
91
61
|
});
|
|
92
62
|
}) // healthcheck returns basic information
|
|
93
63
|
.route('get', '/percy/healthcheck', (req, res) => {
|
|
94
|
-
var _percy$
|
|
64
|
+
var _percy$testing7;
|
|
95
65
|
|
|
96
66
|
return res.json(200, {
|
|
97
|
-
build: ((_percy$
|
|
67
|
+
build: ((_percy$testing7 = percy.testing) === null || _percy$testing7 === void 0 ? void 0 : _percy$testing7.build) ?? percy.build,
|
|
98
68
|
loglevel: percy.loglevel(),
|
|
99
69
|
config: percy.config,
|
|
100
70
|
success: true
|
|
@@ -138,34 +108,25 @@ export function createPercyServer(percy, port) {
|
|
|
138
108
|
}
|
|
139
109
|
}, res) => {
|
|
140
110
|
body = Buffer.isBuffer(body) ? body.toString() : body;
|
|
141
|
-
let {
|
|
142
|
-
remoteLoggers
|
|
143
|
-
} = percy.testing;
|
|
144
111
|
|
|
145
112
|
if (cmd === 'reset') {
|
|
146
113
|
// the reset command will reset testing mode and clear any logs
|
|
147
|
-
percy.testing =
|
|
148
|
-
remoteLoggers
|
|
149
|
-
} : {};
|
|
114
|
+
percy.testing = {};
|
|
150
115
|
logger.instance.messages.clear();
|
|
151
116
|
} else if (cmd === 'version') {
|
|
152
117
|
// the version command will update the api version header for testing
|
|
153
118
|
percy.testing.version = body;
|
|
154
119
|
} else if (cmd === 'error' || cmd === 'disconnect') {
|
|
155
|
-
var _percy$
|
|
120
|
+
var _percy$testing8;
|
|
156
121
|
|
|
157
122
|
// the error or disconnect commands will cause specific endpoints to fail
|
|
158
|
-
((_percy$
|
|
123
|
+
((_percy$testing8 = percy.testing).api || (_percy$testing8.api = {}))[body] = cmd;
|
|
159
124
|
} else if (cmd === 'build-failure') {
|
|
160
125
|
// the build-failure command will cause api errors to include a failed build
|
|
161
126
|
percy.testing.build = {
|
|
162
127
|
failed: true,
|
|
163
128
|
error: 'Build failed'
|
|
164
129
|
};
|
|
165
|
-
} else if (cmd === 'remote-logging') {
|
|
166
|
-
// the remote-logging command will toggle remote logging support
|
|
167
|
-
if (body === false) remoteLoggers === null || remoteLoggers === void 0 ? void 0 : remoteLoggers.forEach(ws => ws.terminate());
|
|
168
|
-
percy.testing.remoteLogging = body;
|
|
169
130
|
} else {
|
|
170
131
|
// 404 for unknown commands
|
|
171
132
|
return res.send(404);
|
package/dist/config.js
CHANGED
|
@@ -28,9 +28,6 @@ export const configSchema = {
|
|
|
28
28
|
},
|
|
29
29
|
scope: {
|
|
30
30
|
type: 'string'
|
|
31
|
-
},
|
|
32
|
-
devicePixelRatio: {
|
|
33
|
-
type: 'integer'
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
33
|
},
|
|
@@ -129,6 +126,9 @@ export const configSchema = {
|
|
|
129
126
|
userAgent: {
|
|
130
127
|
type: 'string'
|
|
131
128
|
},
|
|
129
|
+
devicePixelRatio: {
|
|
130
|
+
type: 'integer'
|
|
131
|
+
},
|
|
132
132
|
concurrency: {
|
|
133
133
|
type: 'integer',
|
|
134
134
|
minimum: 1
|
|
@@ -180,9 +180,6 @@ export const snapshotSchema = {
|
|
|
180
180
|
enableJavaScript: {
|
|
181
181
|
$ref: '/config/snapshot#/properties/enableJavaScript'
|
|
182
182
|
},
|
|
183
|
-
devicePixelRatio: {
|
|
184
|
-
$ref: '/config/snapshot#/properties/devicePixelRatio'
|
|
185
|
-
},
|
|
186
183
|
discovery: {
|
|
187
184
|
type: 'object',
|
|
188
185
|
additionalProperties: false,
|
|
@@ -204,6 +201,9 @@ export const snapshotSchema = {
|
|
|
204
201
|
},
|
|
205
202
|
userAgent: {
|
|
206
203
|
$ref: '/config/discovery#/properties/userAgent'
|
|
204
|
+
},
|
|
205
|
+
devicePixelRatio: {
|
|
206
|
+
$ref: '/config/discovery#/properties/devicePixelRatio'
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
}
|
|
@@ -485,41 +485,21 @@ export function configMigration(config, util) {
|
|
|
485
485
|
util.map('agent.assetDiscovery.pagePoolSizeMax', 'discovery.concurrency');
|
|
486
486
|
util.del('agent');
|
|
487
487
|
} else {
|
|
488
|
-
|
|
488
|
+
util.deprecate('snapshot.devicePixelRatio', {
|
|
489
|
+
map: 'discovery.devicePixelRatio',
|
|
489
490
|
type: 'config',
|
|
490
|
-
until: '
|
|
491
|
-
}; // snapshot discovery options have moved
|
|
492
|
-
|
|
493
|
-
util.deprecate('snapshot.authorization', {
|
|
494
|
-
map: 'discovery.authorization',
|
|
495
|
-
...notice
|
|
496
|
-
});
|
|
497
|
-
util.deprecate('snapshot.requestHeaders', {
|
|
498
|
-
map: 'discovery.requestHeaders',
|
|
499
|
-
...notice
|
|
491
|
+
until: '2.0.0'
|
|
500
492
|
});
|
|
501
493
|
}
|
|
502
494
|
} // Snapshot option migrate function
|
|
503
495
|
|
|
504
496
|
export function snapshotMigration(config, util, root = '') {
|
|
505
|
-
|
|
497
|
+
// discovery options have moved
|
|
498
|
+
util.deprecate(`${root}.devicePixelRatio`, {
|
|
499
|
+
map: `${root}.discovery.devicePixelRatio`,
|
|
506
500
|
type: 'snapshot',
|
|
507
|
-
until: '
|
|
501
|
+
until: '2.0.0',
|
|
508
502
|
warn: true
|
|
509
|
-
}; // discovery options have moved
|
|
510
|
-
|
|
511
|
-
util.deprecate(`${root}.authorization`, {
|
|
512
|
-
map: `${root}.discovery.authorization`,
|
|
513
|
-
...notice
|
|
514
|
-
});
|
|
515
|
-
util.deprecate(`${root}.requestHeaders`, {
|
|
516
|
-
map: `${root}.discovery.requestHeaders`,
|
|
517
|
-
...notice
|
|
518
|
-
}); // snapshots option was renamed
|
|
519
|
-
|
|
520
|
-
util.deprecate(`${root}.snapshots`, {
|
|
521
|
-
map: `${root}.additionalSnapshots`,
|
|
522
|
-
...notice
|
|
523
503
|
});
|
|
524
504
|
} // Snapshot list options migrate function
|
|
525
505
|
|
|
@@ -531,18 +511,8 @@ export function snapshotListMigration(config, util) {
|
|
|
531
511
|
snapshotMigration(config, util, `snapshots[${i}]`);
|
|
532
512
|
}
|
|
533
513
|
}
|
|
534
|
-
} //
|
|
535
|
-
|
|
514
|
+
} // migrate options
|
|
536
515
|
|
|
537
|
-
let notice = {
|
|
538
|
-
type: 'snapshot',
|
|
539
|
-
until: '1.0.0',
|
|
540
|
-
warn: true
|
|
541
|
-
};
|
|
542
|
-
util.deprecate('overrides', {
|
|
543
|
-
map: 'options',
|
|
544
|
-
...notice
|
|
545
|
-
}); // migrate options
|
|
546
516
|
|
|
547
517
|
if (Array.isArray(config.options)) {
|
|
548
518
|
for (let i in config.options) {
|
package/dist/server.js
CHANGED
|
@@ -19,7 +19,6 @@ function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.
|
|
|
19
19
|
import fs from 'fs';
|
|
20
20
|
import path from 'path';
|
|
21
21
|
import http from 'http';
|
|
22
|
-
import { WebSocketServer } from 'ws';
|
|
23
22
|
import mime from 'mime-types';
|
|
24
23
|
import disposition from 'content-disposition';
|
|
25
24
|
import { pathToRegexp, match as pathToMatch, compile as makeToPath } from 'path-to-regexp'; // custom incoming message adds a `url` and `body` properties containing the parsed URL and message
|
|
@@ -117,10 +116,6 @@ var _sockets = /*#__PURE__*/new WeakMap();
|
|
|
117
116
|
|
|
118
117
|
var _defaultPort = /*#__PURE__*/new WeakMap();
|
|
119
118
|
|
|
120
|
-
var _up = /*#__PURE__*/new WeakMap();
|
|
121
|
-
|
|
122
|
-
var _handleUpgrade = /*#__PURE__*/new WeakSet();
|
|
123
|
-
|
|
124
119
|
var _routes = /*#__PURE__*/new WeakMap();
|
|
125
120
|
|
|
126
121
|
var _route = /*#__PURE__*/new WeakSet();
|
|
@@ -140,8 +135,6 @@ export class Server extends http.Server {
|
|
|
140
135
|
|
|
141
136
|
_classPrivateMethodInitSpec(this, _route);
|
|
142
137
|
|
|
143
|
-
_classPrivateMethodInitSpec(this, _handleUpgrade);
|
|
144
|
-
|
|
145
138
|
_classPrivateFieldInitSpec(this, _sockets, {
|
|
146
139
|
writable: true,
|
|
147
140
|
value: new Set()
|
|
@@ -152,11 +145,6 @@ export class Server extends http.Server {
|
|
|
152
145
|
value: void 0
|
|
153
146
|
});
|
|
154
147
|
|
|
155
|
-
_classPrivateFieldInitSpec(this, _up, {
|
|
156
|
-
writable: true,
|
|
157
|
-
value: []
|
|
158
|
-
});
|
|
159
|
-
|
|
160
148
|
_classPrivateFieldInitSpec(this, _routes, {
|
|
161
149
|
writable: true,
|
|
162
150
|
value: [{
|
|
@@ -186,10 +174,6 @@ export class Server extends http.Server {
|
|
|
186
174
|
|
|
187
175
|
this.on('request', (req, res) => {
|
|
188
176
|
req.on('end', () => _classPrivateMethodGet(this, _handleRequest, _handleRequest2).call(this, req, res));
|
|
189
|
-
}); // handle websocket upgrades
|
|
190
|
-
|
|
191
|
-
this.on('upgrade', (req, sock, head) => {
|
|
192
|
-
_classPrivateMethodGet(this, _handleUpgrade, _handleUpgrade2).call(this, req, sock, head);
|
|
193
177
|
}); // track open connections to terminate when the server closes
|
|
194
178
|
|
|
195
179
|
this.on('connection', socket => {
|
|
@@ -231,29 +215,8 @@ export class Server extends http.Server {
|
|
|
231
215
|
|
|
232
216
|
super.close(resolve);
|
|
233
217
|
});
|
|
234
|
-
} //
|
|
235
|
-
|
|
218
|
+
} // initial routes include cors and 404 handling
|
|
236
219
|
|
|
237
|
-
websocket(pathname, handle) {
|
|
238
|
-
if (!handle) [pathname, handle] = [null, pathname];
|
|
239
|
-
|
|
240
|
-
_classPrivateFieldGet(this, _up).push({
|
|
241
|
-
match: pathname && pathToMatch(pathname),
|
|
242
|
-
handle: (req, sock, head) => new Promise(resolve => {
|
|
243
|
-
let wss = new WebSocketServer({
|
|
244
|
-
noServer: true,
|
|
245
|
-
clientTracking: false
|
|
246
|
-
});
|
|
247
|
-
wss.handleUpgrade(req, sock, head, resolve);
|
|
248
|
-
}).then(ws => handle(ws, req))
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
if (pathname) {
|
|
252
|
-
_classPrivateFieldGet(this, _up).sort((a, b) => (a.match ? -1 : 1) - (b.match ? -1 : 1));
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
return this;
|
|
256
|
-
}
|
|
257
220
|
|
|
258
221
|
// set request routing and handling for pathnames and methods
|
|
259
222
|
route(method, pathname, handle) {
|
|
@@ -312,14 +275,6 @@ export class Server extends http.Server {
|
|
|
312
275
|
|
|
313
276
|
} // create a url rewriter from provided rewrite rules
|
|
314
277
|
|
|
315
|
-
function _handleUpgrade2(req, sock, head) {
|
|
316
|
-
let up = _classPrivateFieldGet(this, _up).find(u => !u.match || u.match(req.url));
|
|
317
|
-
|
|
318
|
-
if (up) return up.handle(req, sock, head);
|
|
319
|
-
sock.write(`HTTP/1.1 400 ${http.STATUS_CODES[400]}\r\n` + 'Connection: close\r\n\r\n');
|
|
320
|
-
sock.destroy();
|
|
321
|
-
}
|
|
322
|
-
|
|
323
278
|
function _route2(route) {
|
|
324
279
|
let i = _classPrivateFieldGet(this, _routes).findIndex(r => r.priority >= route.priority);
|
|
325
280
|
|
package/dist/snapshot.js
CHANGED
|
@@ -404,11 +404,11 @@ export async function* discoverSnapshotResources(percy, snapshot, callback) {
|
|
|
404
404
|
try {
|
|
405
405
|
yield* triggerResourceRequests(page, snapshot); // trigger resource requests for any alternate device pixel ratio
|
|
406
406
|
|
|
407
|
-
if (snapshot.devicePixelRatio) {
|
|
407
|
+
if (snapshot.discovery.devicePixelRatio) {
|
|
408
408
|
// wait for any existing pending resource requests first
|
|
409
409
|
yield waitForDiscoveryNetworkIdle(page, snapshot.discovery);
|
|
410
410
|
yield* triggerResourceRequests(page, snapshot, {
|
|
411
|
-
deviceScaleFactor: snapshot.devicePixelRatio,
|
|
411
|
+
deviceScaleFactor: snapshot.discovery.devicePixelRatio,
|
|
412
412
|
mobile: true
|
|
413
413
|
});
|
|
414
414
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/core",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"test:types": "tsd"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@percy/client": "1.10.
|
|
43
|
-
"@percy/config": "1.10.
|
|
44
|
-
"@percy/dom": "1.10.
|
|
45
|
-
"@percy/logger": "1.10.
|
|
42
|
+
"@percy/client": "1.10.4",
|
|
43
|
+
"@percy/config": "1.10.4",
|
|
44
|
+
"@percy/dom": "1.10.4",
|
|
45
|
+
"@percy/logger": "1.10.4",
|
|
46
46
|
"content-disposition": "^0.5.4",
|
|
47
47
|
"cross-spawn": "^7.0.3",
|
|
48
48
|
"extract-zip": "^2.0.1",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"rimraf": "^3.0.2",
|
|
54
54
|
"ws": "^8.0.0"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "16a9a410bfcb8eab51b86a08cff12d8d35e4747e"
|
|
57
57
|
}
|