@percy/core 1.6.1 → 1.6.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/percy.js CHANGED
@@ -25,7 +25,9 @@ export class Percy {
25
25
  constructor({
26
26
  // initial log level
27
27
  loglevel,
28
- // do not eagerly upload snapshots
28
+ // process uploads before the next snapshot
29
+ delayUploads,
30
+ // process uploads after all snapshots
29
31
  deferUploads,
30
32
  // run without uploading anything
31
33
  skipUploads,
@@ -51,7 +53,8 @@ export class Percy {
51
53
  this.testing = testing ? {} : null;
52
54
  this.dryRun = !!testing || !!dryRun;
53
55
  this.skipUploads = this.dryRun || !!skipUploads;
54
- this.deferUploads = this.skipUploads || !!deferUploads;
56
+ this.delayUploads = this.skipUploads || !!delayUploads;
57
+ this.deferUploads = this.delayUploads || !!deferUploads;
55
58
  if (this.deferUploads) this.#uploads.stop();
56
59
  this.config = PercyConfig.load({
57
60
  overrides: options,
@@ -66,6 +69,10 @@ export class Percy {
66
69
  this.#snapshots.concurrency = concurrency;
67
70
  }
68
71
 
72
+ if (this.delayUploads) {
73
+ this.#uploads.concurrency = 1;
74
+ }
75
+
69
76
  this.client = new PercyClient({
70
77
  token,
71
78
  clientInfo,
@@ -166,7 +173,7 @@ export class Percy {
166
173
  };
167
174
  this.build.number = attributes['build-number'];
168
175
  this.build.url = attributes['web-url'];
169
- this.#uploads.run();
176
+ if (!this.delayUploads) this.#uploads.run();
170
177
  });
171
178
  }, 0); // handle deferred build errors
172
179
 
@@ -449,11 +456,13 @@ export class Percy {
449
456
  _scheduleUpload(name, options) {
450
457
  var _this$build4;
451
458
 
452
- if ((_this$build4 = this.build) !== null && _this$build4 !== void 0 && _this$build4.error) {
453
- throw new Error(this.build.error);
454
- }
459
+ if ((_this$build4 = this.build) !== null && _this$build4 !== void 0 && _this$build4.error) throw new Error(this.build.error); // maybe process any existing delayed uploads
455
460
 
461
+ if (!this.skipUploads && this.delayUploads) this.#uploads.run();
456
462
  return this.#uploads.push(`upload/${name}`, async () => {
463
+ // when delayed, stop the queue before other uploads are processed
464
+ if (this.delayUploads) this.#uploads.stop();
465
+
457
466
  try {
458
467
  /* istanbul ignore if: useful for other internal packages */
459
468
  if (typeof options === 'function') options = await options();
package/dist/utils.js CHANGED
@@ -182,11 +182,14 @@ async function scrollToBottom(options, onScroll) {
182
182
  });
183
183
  await ((_onScroll = onScroll) === null || _onScroll === void 0 ? void 0 : _onScroll(i, s));
184
184
  }
185
- } // Serializes the provided function with percy helpers for use in evaluating browser scripts
185
+ } // Used to test if a string looks like a function
186
186
 
187
187
 
188
+ const FUNC_REG = /^(async\s+)?(function\s*)?(\w+\s*)?\(.*?\)\s*(\{|=>)/is; // Serializes the provided function with percy helpers for use in evaluating browser scripts
189
+
188
190
  export function serializeFunction(fn) {
189
- let fnbody = typeof fn === 'string' ? `async eval() {\n${fn}\n}` : fn.toString(); // we might have a function shorthand if this fails
191
+ // stringify or convert a function body into a complete function
192
+ let fnbody = typeof fn === 'string' && !FUNC_REG.test(fn) ? `async function eval() {\n${fn}\n}` : fn.toString(); // we might have a function shorthand if this fails
190
193
 
191
194
  /* eslint-disable-next-line no-new, no-new-func */
192
195
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/core",
3
- "version": "1.6.1",
3
+ "version": "1.6.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.6.1",
43
- "@percy/config": "1.6.1",
44
- "@percy/dom": "1.6.1",
45
- "@percy/logger": "1.6.1",
42
+ "@percy/client": "1.6.4",
43
+ "@percy/config": "1.6.4",
44
+ "@percy/dom": "1.6.4",
45
+ "@percy/logger": "1.6.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": "87e8afc35605110fa7c7bde2100be18e6e74826b"
56
+ "gitHead": "651c0fad62f128053723f9b8d565c69496dc51e4"
57
57
  }