@percy/core 1.30.8 → 1.30.9-beta.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/network.js CHANGED
@@ -491,6 +491,7 @@ async function makeDirectRequest(network, request, session) {
491
491
 
492
492
  // Save a resource from a request, skipping it if specific paramters are not met
493
493
  async function saveResponseResource(network, request, session) {
494
+ var _response$headers;
494
495
  let {
495
496
  disableCache,
496
497
  allowedHostnames,
@@ -507,7 +508,8 @@ async function saveResponseResource(network, request, session) {
507
508
  // Checing for content length more than 100MB, to prevent websocket error which is governed by
508
509
  // maxPayload option of websocket defaulted to 100MB.
509
510
  // If content-length is more than our allowed 25MB, no need to process that resouce we can return log.
510
- let contentLength = parseInt(response.headers['Content-Length']);
511
+ let contentLength = (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers[Object.keys(response.headers).find(key => key.toLowerCase() === 'content-length')];
512
+ contentLength = parseInt(contentLength);
511
513
  if (contentLength > MAX_RESOURCE_SIZE) {
512
514
  return log.debug('- Skipping resource larger than 25MB', meta);
513
515
  }
@@ -527,6 +529,9 @@ async function saveResponseResource(network, request, session) {
527
529
  return log.debug('- Skipping remote resource', meta);
528
530
  } else if (!body.length) {
529
531
  return log.debug('- Skipping empty response', meta);
532
+ } else if (body.length > MAX_RESOURCE_SIZE) {
533
+ log.debug('- Missing headers for the requested resource.', meta);
534
+ return log.debug('- Skipping resource larger than 25MB', meta);
530
535
  } else if (!ALLOWED_STATUSES.includes(response.status)) {
531
536
  return log.debug(`- Skipping disallowed status [${response.status}]`, meta);
532
537
  } else if (!enableJavaScript && !ALLOWED_RESOURCES.includes(request.type)) {
package/dist/queue.js CHANGED
@@ -115,6 +115,13 @@ export class Queue {
115
115
  // return the deferred task promise
116
116
  return task.deferred;
117
117
  }
118
+ logQueueSize() {
119
+ this.log.debug(`${this.name} queueInfo: ${JSON.stringify({
120
+ queued: _classPrivateFieldGet(_queued, this).size,
121
+ pending: _classPrivateFieldGet(_pending, this).size,
122
+ total: _classPrivateFieldGet(_pending, this).size + _classPrivateFieldGet(_queued, this).size
123
+ })}`);
124
+ }
118
125
  // Cancels and aborts a specific item task.
119
126
  cancel(item) {
120
127
  let task = _assertClassBrand(_Queue_brand, this, _find).call(this, item);
@@ -243,6 +250,7 @@ export class Queue {
243
250
  // Repeatedly yields, calling the callback with the position of the task within the queue
244
251
  }
245
252
  function _dequeue() {
253
+ this.logQueueSize();
246
254
  if (!_classPrivateFieldGet(_queued, this).size || this.readyState < 2) return;
247
255
  if (_classPrivateFieldGet(_pending, this).size >= this.concurrency) return;
248
256
  let [task] = _classPrivateFieldGet(_queued, this);
package/dist/snapshot.js CHANGED
@@ -3,7 +3,7 @@ import PercyConfig from '@percy/config';
3
3
  import micromatch from 'micromatch';
4
4
  import { configSchema } from './config.js';
5
5
  import Queue from './queue.js';
6
- import { request, hostnameMatches, yieldTo, snapshotLogName, decodeAndEncodeURLWithLogging, compareObjectTypes } from './utils.js';
6
+ import { request, hostnameMatches, yieldTo, snapshotLogName, decodeAndEncodeURLWithLogging, compareObjectTypes, normalizeOptions } from './utils.js';
7
7
  import { JobData } from './wait-for-job.js';
8
8
 
9
9
  // Throw a better error message for missing or invalid urls
@@ -192,9 +192,9 @@ function getSnapshotOptions(options, {
192
192
  export function validateSnapshotOptions(options) {
193
193
  var _migrated$baseUrl, _migrated$domSnapshot;
194
194
  let log = logger('core:snapshot');
195
-
196
195
  // decide which schema to validate against
197
196
  let schema = ['domSnapshot', 'dom-snapshot', 'dom_snapshot'].some(k => k in options) && '/snapshot/dom' || 'url' in options && '/snapshot' || 'sitemap' in options && '/snapshot/sitemap' || 'serve' in options && '/snapshot/server' || 'snapshots' in options && '/snapshot/list' || '/snapshot';
197
+ options = normalizeOptions(options);
198
198
  let {
199
199
  // normalize, migrate, and remove certain properties from validating
200
200
  clientInfo,
@@ -226,7 +226,6 @@ export function validateSnapshotOptions(options) {
226
226
  log.warn('Encountered snapshot serialization warnings:');
227
227
  for (let w of domWarnings) log.warn(`- ${w}`);
228
228
  }
229
-
230
229
  // warn on validation errors
231
230
  let errors = PercyConfig.validate(migrated, schema);
232
231
  if ((errors === null || errors === void 0 ? void 0 : errors.length) > 0) {
package/dist/utils.js CHANGED
@@ -540,4 +540,31 @@ export function compareObjectTypes(obj1, obj2) {
540
540
  if (!keys2.includes(key) || !compareObjectTypes(obj1[key], obj2[key])) return false;
541
541
  }
542
542
  return true;
543
+ }
544
+ const OPTION_MAPPINGS = {
545
+ name: 'name',
546
+ widths: 'widths',
547
+ scope: 'scope',
548
+ scopeoptions: 'scopeOptions',
549
+ minheight: 'minHeight',
550
+ enablejavascript: 'enableJavaScript',
551
+ enablelayout: 'enableLayout',
552
+ clientinfo: 'clientInfo',
553
+ environmentinfo: 'environmentInfo',
554
+ sync: 'sync',
555
+ testcase: 'testCase',
556
+ labels: 'labels',
557
+ thtestcaseexecutionid: 'thTestCaseExecutionId',
558
+ resources: 'resources',
559
+ meta: 'meta',
560
+ snapshot: 'snapshot'
561
+ };
562
+ export function normalizeOptions(options) {
563
+ const normalizedOptions = {};
564
+ for (const key in options) {
565
+ const lowerCaseKey = key.toLowerCase().replace(/[-_]/g, '');
566
+ const normalizedKey = OPTION_MAPPINGS[lowerCaseKey] ? OPTION_MAPPINGS[lowerCaseKey] : key;
567
+ normalizedOptions[normalizedKey] = options[key];
568
+ }
569
+ return normalizedOptions;
543
570
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/core",
3
- "version": "1.30.8",
3
+ "version": "1.30.9-beta.0",
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": "latest"
12
+ "tag": "beta"
13
13
  },
14
14
  "engines": {
15
15
  "node": ">=14"
@@ -43,12 +43,12 @@
43
43
  "test:types": "tsd"
44
44
  },
45
45
  "dependencies": {
46
- "@percy/client": "1.30.8",
47
- "@percy/config": "1.30.8",
48
- "@percy/dom": "1.30.8",
49
- "@percy/logger": "1.30.8",
50
- "@percy/monitoring": "1.30.8",
51
- "@percy/webdriver-utils": "1.30.8",
46
+ "@percy/client": "1.30.9-beta.0",
47
+ "@percy/config": "1.30.9-beta.0",
48
+ "@percy/dom": "1.30.9-beta.0",
49
+ "@percy/logger": "1.30.9-beta.0",
50
+ "@percy/monitoring": "1.30.9-beta.0",
51
+ "@percy/webdriver-utils": "1.30.9-beta.0",
52
52
  "content-disposition": "^0.5.4",
53
53
  "cross-spawn": "^7.0.3",
54
54
  "extract-zip": "^2.0.1",
@@ -61,5 +61,5 @@
61
61
  "ws": "^8.17.1",
62
62
  "yaml": "^2.4.1"
63
63
  },
64
- "gitHead": "daa3c96d70488a49671e48427c9b363c68876935"
64
+ "gitHead": "5068eefe44f4ea22427d80e538b76603fc2f5f6b"
65
65
  }
@@ -1,18 +1,25 @@
1
1
  // aliased to src during tests
2
2
  import Server from '../../dist/server.js';
3
3
 
4
- export function createTestServer({ default: defaultReply, ...replies }, port = 8000) {
4
+ export function createTestServer({ default: defaultReply, ...replies }, port = 8000, options = {}) {
5
5
  let server = new Server();
6
6
 
7
7
  // alternate route handling
8
- let handleReply = reply => async (req, res) => {
8
+ let handleReply = (reply, options = {}) => async (req, res) => {
9
9
  let [status, headers, body] = typeof reply === 'function' ? await reply(req) : reply;
10
10
  if (!Buffer.isBuffer(body) && typeof body !== 'string') body = JSON.stringify(body);
11
+
12
+ if (options.noHeaders) {
13
+ return res.writeHead(status).end(body);
14
+ }
15
+ if (options.headersOverride) {
16
+ headers = { ...headers, ...options.headersOverride };
17
+ }
11
18
  return res.send(status, headers, body);
12
19
  };
13
20
 
14
21
  // map replies to alternate route handlers
15
- server.reply = (p, reply) => (replies[p] = handleReply(reply), null);
22
+ server.reply = (p, reply, options = {}) => (replies[p] = handleReply(reply, options), null);
16
23
  for (let [p, reply] of Object.entries(replies)) server.reply(p, reply);
17
24
  if (defaultReply) defaultReply = handleReply(defaultReply);
18
25