@percy/core 1.27.5-alpha.0 → 1.27.6-alpha.0
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 +10 -1
- package/dist/config.js +18 -0
- package/dist/discovery.js +10 -1
- package/dist/page.js +4 -2
- package/dist/queue.js +13 -3
- package/dist/snapshot.js +1 -1
- package/dist/utils.js +34 -0
- package/package.json +7 -7
- package/types/index.d.ts +3 -0
package/dist/api.js
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import { createRequire } from 'module';
|
|
4
4
|
import logger from '@percy/logger';
|
|
5
5
|
import { normalize } from '@percy/config/utils';
|
|
6
|
-
import { getPackageJSON, Server, percyAutomateRequestHandler } from './utils.js';
|
|
6
|
+
import { getPackageJSON, Server, percyAutomateRequestHandler, percyBuildEventHandler } from './utils.js';
|
|
7
7
|
import WebdriverUtils from '@percy/webdriver-utils';
|
|
8
8
|
// need require.resolve until import.meta.resolve can be transpiled
|
|
9
9
|
export const PERCY_DOM = createRequire(import.meta.url).resolve('@percy/dom');
|
|
@@ -144,6 +144,15 @@ export function createPercyServer(percy, port) {
|
|
|
144
144
|
success: true
|
|
145
145
|
});
|
|
146
146
|
})
|
|
147
|
+
// Recieves events from sdk's.
|
|
148
|
+
.route('post', '/percy/events', async (req, res) => {
|
|
149
|
+
var _percy$build2;
|
|
150
|
+
const body = percyBuildEventHandler(req, pkg.version);
|
|
151
|
+
await percy.client.sendBuildEvents((_percy$build2 = percy.build) === null || _percy$build2 === void 0 ? void 0 : _percy$build2.id, body);
|
|
152
|
+
res.json(200, {
|
|
153
|
+
success: true
|
|
154
|
+
});
|
|
155
|
+
})
|
|
147
156
|
// stops percy at the end of the current event loop
|
|
148
157
|
.route('/percy/stop', (req, res) => {
|
|
149
158
|
setImmediate(() => percy.stop());
|
package/dist/config.js
CHANGED
|
@@ -47,9 +47,15 @@ export const configSchema = {
|
|
|
47
47
|
type: 'boolean',
|
|
48
48
|
default: false
|
|
49
49
|
},
|
|
50
|
+
enableLayout: {
|
|
51
|
+
type: 'boolean'
|
|
52
|
+
},
|
|
50
53
|
domTransformation: {
|
|
51
54
|
type: 'string'
|
|
52
55
|
},
|
|
56
|
+
reshuffleInvalidTags: {
|
|
57
|
+
type: 'boolean'
|
|
58
|
+
},
|
|
53
59
|
scope: {
|
|
54
60
|
type: 'string'
|
|
55
61
|
},
|
|
@@ -280,6 +286,12 @@ export const snapshotSchema = {
|
|
|
280
286
|
domTransformation: {
|
|
281
287
|
$ref: '/config/snapshot#/properties/domTransformation'
|
|
282
288
|
},
|
|
289
|
+
enableLayout: {
|
|
290
|
+
$ref: '/config/snapshot#/properties/enableLayout'
|
|
291
|
+
},
|
|
292
|
+
reshuffleInvalidTags: {
|
|
293
|
+
$ref: '/config/snapshot#/properties/reshuffleInvalidTags'
|
|
294
|
+
},
|
|
283
295
|
discovery: {
|
|
284
296
|
type: 'object',
|
|
285
297
|
additionalProperties: false,
|
|
@@ -524,6 +536,12 @@ export const snapshotSchema = {
|
|
|
524
536
|
}
|
|
525
537
|
}
|
|
526
538
|
}
|
|
539
|
+
},
|
|
540
|
+
hints: {
|
|
541
|
+
type: 'array',
|
|
542
|
+
items: {
|
|
543
|
+
type: 'string'
|
|
544
|
+
}
|
|
527
545
|
}
|
|
528
546
|
}
|
|
529
547
|
}]
|
package/dist/discovery.js
CHANGED
|
@@ -26,6 +26,9 @@ function debugSnapshotOptions(snapshot) {
|
|
|
26
26
|
debugProp(snapshot, 'enableJavaScript');
|
|
27
27
|
debugProp(snapshot, 'cliEnableJavaScript');
|
|
28
28
|
debugProp(snapshot, 'disableShadowDOM');
|
|
29
|
+
debugProp(snapshot, 'enableLayout');
|
|
30
|
+
debugProp(snapshot, 'domTransformation');
|
|
31
|
+
debugProp(snapshot, 'reshuffleInvalidTags');
|
|
29
32
|
debugProp(snapshot, 'deviceScaleFactor');
|
|
30
33
|
debugProp(snapshot, 'waitForTimeout');
|
|
31
34
|
debugProp(snapshot, 'waitForSelector');
|
|
@@ -101,6 +104,7 @@ function processSnapshotResources({
|
|
|
101
104
|
...snapshot
|
|
102
105
|
}) {
|
|
103
106
|
var _resources;
|
|
107
|
+
let log = logger('core:snapshot');
|
|
104
108
|
resources = [...(((_resources = resources) === null || _resources === void 0 ? void 0 : _resources.values()) ?? [])];
|
|
105
109
|
|
|
106
110
|
// find any root resource matching the provided dom snapshot
|
|
@@ -119,6 +123,11 @@ function processSnapshotResources({
|
|
|
119
123
|
|
|
120
124
|
// inject Percy CSS
|
|
121
125
|
if (snapshot.percyCSS) {
|
|
126
|
+
// check @percy/dom/serialize-dom.js
|
|
127
|
+
let domSnapshotHints = (domSnapshot === null || domSnapshot === void 0 ? void 0 : domSnapshot.hints) ?? [];
|
|
128
|
+
if (domSnapshotHints.includes('DOM elements found outside </body>')) {
|
|
129
|
+
log.warn('DOM elements found outside </body>, percyCSS might not work');
|
|
130
|
+
}
|
|
122
131
|
let css = createPercyCSSResource(root.url, snapshot.percyCSS);
|
|
123
132
|
resources.push(css);
|
|
124
133
|
|
|
@@ -270,7 +279,7 @@ export function createDiscoveryQueue(percy) {
|
|
|
270
279
|
let {
|
|
271
280
|
concurrency
|
|
272
281
|
} = percy.config.discovery;
|
|
273
|
-
let queue = new Queue();
|
|
282
|
+
let queue = new Queue('discovery');
|
|
274
283
|
let cache;
|
|
275
284
|
return queue.set({
|
|
276
285
|
concurrency
|
package/dist/page.js
CHANGED
|
@@ -146,7 +146,8 @@ export class Page {
|
|
|
146
146
|
width,
|
|
147
147
|
enableJavaScript,
|
|
148
148
|
disableShadowDOM,
|
|
149
|
-
domTransformation
|
|
149
|
+
domTransformation,
|
|
150
|
+
reshuffleInvalidTags
|
|
150
151
|
} = snapshot;
|
|
151
152
|
this.log.debug(`Taking snapshot: ${name}${width ? ` @${width}px` : ''}`, this.meta);
|
|
152
153
|
|
|
@@ -191,7 +192,8 @@ export class Page {
|
|
|
191
192
|
}), {
|
|
192
193
|
enableJavaScript,
|
|
193
194
|
disableShadowDOM,
|
|
194
|
-
domTransformation
|
|
195
|
+
domTransformation,
|
|
196
|
+
reshuffleInvalidTags
|
|
195
197
|
});
|
|
196
198
|
return {
|
|
197
199
|
...snapshot,
|
package/dist/queue.js
CHANGED
|
@@ -9,6 +9,7 @@ function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classEx
|
|
|
9
9
|
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
10
10
|
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
11
11
|
import { yieldFor, generatePromise, AbortController } from './utils.js';
|
|
12
|
+
import logger from '@percy/logger';
|
|
12
13
|
|
|
13
14
|
// Assigns a deffered promise and resolve & reject functions to an object
|
|
14
15
|
function deferred(obj) {
|
|
@@ -46,12 +47,15 @@ var _end = /*#__PURE__*/new WeakMap();
|
|
|
46
47
|
var _process = /*#__PURE__*/new WeakSet();
|
|
47
48
|
var _until = /*#__PURE__*/new WeakSet();
|
|
48
49
|
export class Queue {
|
|
49
|
-
|
|
50
|
+
// item concurrency
|
|
51
|
+
|
|
52
|
+
constructor(name) {
|
|
50
53
|
_classPrivateMethodInitSpec(this, _until);
|
|
51
54
|
_classPrivateMethodInitSpec(this, _process);
|
|
52
55
|
_classPrivateMethodInitSpec(this, _find);
|
|
53
56
|
_classPrivateMethodInitSpec(this, _dequeue);
|
|
54
57
|
_defineProperty(this, "concurrency", 10);
|
|
58
|
+
_defineProperty(this, "log", logger('core:queue'));
|
|
55
59
|
_classPrivateFieldInitSpec(this, _handlers, {
|
|
56
60
|
writable: true,
|
|
57
61
|
value: {}
|
|
@@ -73,7 +77,9 @@ export class Queue {
|
|
|
73
77
|
value: null
|
|
74
78
|
});
|
|
75
79
|
_defineProperty(this, "readyState", 0);
|
|
80
|
+
this.name = name;
|
|
76
81
|
}
|
|
82
|
+
|
|
77
83
|
// Configure queue properties
|
|
78
84
|
set({
|
|
79
85
|
concurrency
|
|
@@ -201,6 +207,7 @@ export class Queue {
|
|
|
201
207
|
// clear and abort any queued tasks
|
|
202
208
|
clear() {
|
|
203
209
|
let tasks = [..._classPrivateFieldGet(this, _queued)];
|
|
210
|
+
this.log.debug(`Clearing ${this.name} queue, queued state: ${_classPrivateFieldGet(this, _queued).size}, pending state: ${_classPrivateFieldGet(this, _pending).size}`);
|
|
204
211
|
_classPrivateFieldGet(this, _queued).clear();
|
|
205
212
|
for (let task of tasks) {
|
|
206
213
|
task.ctrl.abort();
|
|
@@ -235,6 +242,7 @@ export class Queue {
|
|
|
235
242
|
// process items up to the latest queued item, starting the queue if necessary;
|
|
236
243
|
// returns a generator that yields until the flushed item has finished processing
|
|
237
244
|
flush(callback) {
|
|
245
|
+
this.log.debug(`Flushing ${this.name} queue, queued state: ${_classPrivateFieldGet(this, _queued).size}, pending state: ${_classPrivateFieldGet(this, _pending).size}`);
|
|
238
246
|
let interrupt =
|
|
239
247
|
// check for existing interrupts
|
|
240
248
|
[..._classPrivateFieldGet(this, _pending)].find(t => t.stop) ?? [..._classPrivateFieldGet(this, _queued)].find(t => t.stop);
|
|
@@ -317,9 +325,11 @@ async function* _until2(task, callback) {
|
|
|
317
325
|
// calculate the position within queued when not pending
|
|
318
326
|
if (task && task.pending == null) queued = positionOf(_classPrivateFieldGet(this, _queued), task);
|
|
319
327
|
// calculate the position within pending when not stopping
|
|
320
|
-
|
|
328
|
+
// Commenting below line reason being currently if the task passed is found we will stop flushing
|
|
329
|
+
// rest of the tasks but ideally it should wait for flushing of all the tasks till the last dequeued task.
|
|
330
|
+
// if (!task?.stop && task?.pending != null) pending = positionOf(this.#pending, task);
|
|
321
331
|
// call the callback and return true when not queued or pending
|
|
322
|
-
let position = (queued ?? 0) +
|
|
332
|
+
let position = (queued ?? 0) + pending;
|
|
323
333
|
callback === null || callback === void 0 ? void 0 : callback(position);
|
|
324
334
|
return !position;
|
|
325
335
|
}, {
|
package/dist/snapshot.js
CHANGED
package/dist/utils.js
CHANGED
|
@@ -55,6 +55,40 @@ export function percyAutomateRequestHandler(req, percy) {
|
|
|
55
55
|
req.body.buildInfo = percy.build;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
// Returns the body for sendEvent structure
|
|
59
|
+
export function percyBuildEventHandler(req, cliVersion) {
|
|
60
|
+
if (Array.isArray(req.body)) {
|
|
61
|
+
return req.body.map(item => processSendEventData(item, cliVersion));
|
|
62
|
+
} else {
|
|
63
|
+
// Treat the input as an object and perform instructions
|
|
64
|
+
return processSendEventData(req.body, cliVersion);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Process sendEvent object
|
|
69
|
+
function processSendEventData(input, cliVersion) {
|
|
70
|
+
// Add Properties here to send to eventData
|
|
71
|
+
const allowedEventProperties = ['message', 'cliVersion', 'clientInfo', 'errorKind', 'extra'];
|
|
72
|
+
const extractedData = {};
|
|
73
|
+
for (const property of allowedEventProperties) {
|
|
74
|
+
if (Object.prototype.hasOwnProperty.call(input, property)) {
|
|
75
|
+
extractedData[property] = input[property];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (extractedData.clientInfo) {
|
|
79
|
+
const [client, clientVersion] = extractedData.clientInfo.split('/');
|
|
80
|
+
|
|
81
|
+
// Add the client and clientVersion fields to the object
|
|
82
|
+
extractedData.client = client;
|
|
83
|
+
extractedData.clientVersion = clientVersion;
|
|
84
|
+
delete extractedData.clientInfo;
|
|
85
|
+
}
|
|
86
|
+
if (!input.cliVersion) {
|
|
87
|
+
extractedData.cliVersion = cliVersion;
|
|
88
|
+
}
|
|
89
|
+
return extractedData;
|
|
90
|
+
}
|
|
91
|
+
|
|
58
92
|
// Creates a local resource object containing the resource URL, mimetype, content, sha, and any
|
|
59
93
|
// other additional resources attributes.
|
|
60
94
|
export function createResource(url, content, mimetype, attrs) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/core",
|
|
3
|
-
"version": "1.27.
|
|
3
|
+
"version": "1.27.6-alpha.0",
|
|
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.27.
|
|
47
|
-
"@percy/config": "1.27.
|
|
48
|
-
"@percy/dom": "1.27.
|
|
49
|
-
"@percy/logger": "1.27.
|
|
50
|
-
"@percy/webdriver-utils": "1.27.
|
|
46
|
+
"@percy/client": "1.27.6-alpha.0",
|
|
47
|
+
"@percy/config": "1.27.6-alpha.0",
|
|
48
|
+
"@percy/dom": "1.27.6-alpha.0",
|
|
49
|
+
"@percy/logger": "1.27.6-alpha.0",
|
|
50
|
+
"@percy/webdriver-utils": "1.27.6-alpha.0",
|
|
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": "415a083dc13e9453990b042a41d6676f6618df0c"
|
|
62
62
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -39,6 +39,9 @@ interface CommonSnapshotOptions {
|
|
|
39
39
|
percyCSS?: string;
|
|
40
40
|
enableJavaScript?: boolean;
|
|
41
41
|
disableShadowDOM?: boolean;
|
|
42
|
+
enableLayout?: boolean;
|
|
43
|
+
domTransformation?: string;
|
|
44
|
+
reshuffleInvalidTags?: boolean;
|
|
42
45
|
devicePixelRatio?: number;
|
|
43
46
|
scope?: string;
|
|
44
47
|
}
|