@percy/core 1.30.7 → 1.30.8-beta.2

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,
@@ -504,6 +505,14 @@ async function saveResponseResource(network, request, session) {
504
505
  url,
505
506
  responseStatus: response === null || response === void 0 ? void 0 : response.status
506
507
  };
508
+ // Checing for content length more than 100MB, to prevent websocket error which is governed by
509
+ // maxPayload option of websocket defaulted to 100MB.
510
+ // If content-length is more than our allowed 25MB, no need to process that resouce we can return log.
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);
513
+ if (contentLength > MAX_RESOURCE_SIZE) {
514
+ return log.debug('- Skipping resource larger than 25MB', meta);
515
+ }
507
516
  let resource = network.intercept.getResource(url);
508
517
  if (!resource || !resource.root && !resource.provided && disableCache) {
509
518
  try {
@@ -521,6 +530,7 @@ async function saveResponseResource(network, request, session) {
521
530
  } else if (!body.length) {
522
531
  return log.debug('- Skipping empty response', meta);
523
532
  } else if (body.length > MAX_RESOURCE_SIZE) {
533
+ log.debug('- Missing headers for the requested resource.', meta);
524
534
  return log.debug('- Skipping resource larger than 25MB', meta);
525
535
  } else if (!ALLOWED_STATUSES.includes(response.status)) {
526
536
  return log.debug(`- Skipping disallowed status [${response.status}]`, meta);
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.7",
3
+ "version": "1.30.8-beta.2",
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.7",
47
- "@percy/config": "1.30.7",
48
- "@percy/dom": "1.30.7",
49
- "@percy/logger": "1.30.7",
50
- "@percy/monitoring": "1.30.7",
51
- "@percy/webdriver-utils": "1.30.7",
46
+ "@percy/client": "1.30.8-beta.2",
47
+ "@percy/config": "1.30.8-beta.2",
48
+ "@percy/dom": "1.30.8-beta.2",
49
+ "@percy/logger": "1.30.8-beta.2",
50
+ "@percy/monitoring": "1.30.8-beta.2",
51
+ "@percy/webdriver-utils": "1.30.8-beta.2",
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": "a76ee38901384e71ef6d1be0e7aadd55f23ff003"
64
+ "gitHead": "d51b58a8cfbd2938379a23b96fcb4f38340c3634"
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