@percy/core 1.32.12 → 1.32.13-beta.1

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 CHANGED
@@ -237,9 +237,20 @@ export function createPercyServer(percy, port) {
237
237
  .route('post', '/percy/snapshot', async (req, res) => {
238
238
  let data;
239
239
  const snapshotPromise = {};
240
+ const isAsync = req.url.searchParams.has('async');
240
241
  const snapshot = percy.snapshot(req.body, snapshotPromise);
241
- if (!req.url.searchParams.has('async')) await snapshot;
242
- if (percy.syncMode(req.body)) data = await handleSyncJob(snapshotPromise[req.body.name], percy, 'snapshot');
242
+ if (!isAsync) await snapshot;
243
+ if (percy.syncMode(req.body)) {
244
+ if (isAsync) {
245
+ // the sync job is only registered once the snapshot has been processed
246
+ logger('core:server').warn('Sync mode results are not available for async snapshot requests');
247
+ data = {
248
+ error: 'Sync mode is not supported with the async parameter'
249
+ };
250
+ } else {
251
+ data = await handleSyncJob(snapshotPromise[req.body.name], percy, 'snapshot');
252
+ }
253
+ }
243
254
  return res.json(200, {
244
255
  success: true,
245
256
  data: data
package/dist/percy.js CHANGED
@@ -701,6 +701,9 @@ export class Percy {
701
701
  reject
702
702
  });
703
703
  });
704
+ // only the requested snapshot's promise is awaited, so a rejected extra
705
+ // (additional snapshots, array bodies) must not surface as unhandled
706
+ snapshotPromise[snapshot.name].catch(() => {});
704
707
  }
705
708
  // push each finished snapshot to the snapshots queue
706
709
  _classPrivateFieldGet(_snapshots, this).push(snapshot);
@@ -715,11 +718,14 @@ export class Percy {
715
718
 
716
719
  // Uploads one or more snapshots directly to the current Percy build
717
720
  upload(options, callback = null, screenshotFlow = null) {
718
- var _options$tag2;
721
+ var _this$build6, _options$tag2;
719
722
  if (this.readyState !== 1) {
720
723
  throw new Error('Not running');
721
724
  } else if (Array.isArray(options)) {
722
725
  return yieldAll(options.map(o => this.yield.upload(o)));
726
+ } else if ((_this$build6 = this.build) !== null && _this$build6 !== void 0 && _this$build6.error && callback && this.syncMode(options)) {
727
+ // a sync caller waits on the result, so fail it now instead of queueing it
728
+ throw new Error(this.build.error);
723
729
  }
724
730
  // validate comparison uploads and warn about any errors
725
731
 
@@ -786,10 +792,10 @@ export class Percy {
786
792
  // Pushes a pre-built snapshot directly to the upload queue without discovery.
787
793
  // Used by the replay command to upload previously archived snapshots.
788
794
  *replaySnapshot(snapshot) {
789
- var _this$build6;
795
+ var _this$build7;
790
796
  if (this.readyState !== 1) {
791
797
  throw new Error('Not running');
792
- } else if ((_this$build6 = this.build) !== null && _this$build6 !== void 0 && _this$build6.error) {
798
+ } else if ((_this$build7 = this.build) !== null && _this$build7 !== void 0 && _this$build7.error) {
793
799
  throw new Error(this.build.error);
794
800
  }
795
801
  snapshot.meta = {
@@ -881,7 +887,7 @@ export class Percy {
881
887
  async sendBuildLogs() {
882
888
  if (!process.env.PERCY_TOKEN) return;
883
889
  try {
884
- var _this$build7, _this$build8, _this$build9, _this$build10;
890
+ var _this$build8, _this$build9, _this$build10, _this$build11;
885
891
  const logsObject = {
886
892
  // Redact secrets from CLI logs before egress to the Percy API — these
887
893
  // can contain tokens or URLs with embedded credentials (CWE-532). The
@@ -896,10 +902,10 @@ export class Percy {
896
902
  logsObject.cilogs = redactedContent;
897
903
  }
898
904
  const content = base64encode(Pako.gzip(JSON.stringify(logsObject)));
899
- const referenceId = (_this$build7 = this.build) !== null && _this$build7 !== void 0 && _this$build7.id ? `build_${(_this$build8 = this.build) === null || _this$build8 === void 0 ? void 0 : _this$build8.id}` : (_this$build9 = this.build) === null || _this$build9 === void 0 ? void 0 : _this$build9.id;
905
+ const referenceId = (_this$build8 = this.build) !== null && _this$build8 !== void 0 && _this$build8.id ? `build_${(_this$build9 = this.build) === null || _this$build9 === void 0 ? void 0 : _this$build9.id}` : (_this$build10 = this.build) === null || _this$build10 === void 0 ? void 0 : _this$build10.id;
900
906
  const eventObject = {
901
907
  content: content,
902
- build_id: (_this$build10 = this.build) === null || _this$build10 === void 0 ? void 0 : _this$build10.id,
908
+ build_id: (_this$build11 = this.build) === null || _this$build11 === void 0 ? void 0 : _this$build11.id,
903
909
  reference_id: referenceId,
904
910
  service_name: 'cli',
905
911
  base64encoded: true
@@ -972,9 +978,9 @@ export class Percy {
972
978
  const newAllowedDomains = Array.from(processedHosts).filter(domain => !autoConfiguredHosts.has(domain));
973
979
  const hasNewDomains = newAllowedDomains.length > 0 || newErrorHosts.size > 0;
974
980
  try {
975
- var _this$build11;
981
+ var _this$build12;
976
982
  await this.client.updateProjectDomainConfig({
977
- buildId: (_this$build11 = this.build) === null || _this$build11 === void 0 ? void 0 : _this$build11.id,
983
+ buildId: (_this$build12 = this.build) === null || _this$build12 === void 0 ? void 0 : _this$build12.id,
978
984
  allowedDomains: Array.from(processedHosts),
979
985
  errorDomains: Array.from(newErrorHosts)
980
986
  });
package/dist/snapshot.js CHANGED
@@ -452,6 +452,9 @@ export async function uploadSnapshotLog(percy, buildId, snapshotId, meta = {}) {
452
452
  }
453
453
  }
454
454
 
455
+ // What a sync caller is told when its upload never ran and the build has not failed
456
+ const SYNC_CANCELLED = 'Snapshot upload was cancelled before it finished, because Percy stopped or a newer snapshot with the same name replaced it';
457
+
455
458
  // Creates a snapshots queue that manages a Percy build and uploads snapshots.
456
459
  export function createSnapshotsQueue(percy) {
457
460
  let {
@@ -604,7 +607,8 @@ export function createSnapshotsQueue(percy) {
604
607
 
605
608
  // Pushing to syncQueue, that will check for
606
609
  // snapshot processing status, and will resolve once done
607
- if (snapshot.sync) {
610
+ // (only when someone waits on it: a job without callbacks would throw in the poller)
611
+ if (snapshot.sync && snapshot.resolve) {
608
612
  percy.log.info(`Waiting for snapshot '${name}' to be completed`, meta);
609
613
  const data = new JobData(response.data.id, null, snapshot.resolve, snapshot.reject);
610
614
  percy.syncQueue.push(data);
@@ -616,7 +620,7 @@ export function createSnapshotsQueue(percy) {
616
620
  })
617
621
  // handle possible build errors returned by the API
618
622
  .handle('error', async (snapshot, error) => {
619
- var _error$response, _error$response2;
623
+ var _error$response, _error$response2, _snapshot$reject3;
620
624
  let result = {
621
625
  ...snapshot,
622
626
  error
@@ -625,8 +629,14 @@ export function createSnapshotsQueue(percy) {
625
629
  name,
626
630
  meta
627
631
  } = snapshot;
628
- if (error.name === 'QueueClosedError') return result;
629
- if (error.name === 'AbortError') return result;
632
+
633
+ // a closed or aborted queue never runs the task, so settle any sync caller
634
+ // here or the SDK request waiting on it hangs until its own timeout
635
+ if (error.name === 'QueueClosedError' || error.name === 'AbortError') {
636
+ var _snapshot$reject, _build3;
637
+ if (snapshot.sync) (_snapshot$reject = snapshot.reject) === null || _snapshot$reject === void 0 || _snapshot$reject.call(snapshot, new Error(((_build3 = build) === null || _build3 === void 0 ? void 0 : _build3.error) || SYNC_CANCELLED));
638
+ return result;
639
+ }
630
640
  let failed = ((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.statusCode) === 422 && error.response.body.errors.find(e => {
631
641
  var _e$source;
632
642
  return ((_e$source = e.source) === null || _e$source === void 0 ? void 0 : _e$source.pointer) === '/data/attributes/build';
@@ -639,8 +649,11 @@ export function createSnapshotsQueue(percy) {
639
649
  let errors = (_error$response2 = error.response) === null || _error$response2 === void 0 || (_error$response2 = _error$response2.body) === null || _error$response2 === void 0 ? void 0 : _error$response2.errors;
640
650
  let duplicate = (errors === null || errors === void 0 ? void 0 : errors.length) > 1 && errors[1].detail.includes('must be unique');
641
651
  if (duplicate) {
652
+ var _snapshot$reject2;
653
+ let errMsg = `Ignored duplicate snapshot. ${errors[1].detail}`;
654
+ // no comparison was created, so a sync caller has nothing to wait for
655
+ if (snapshot.sync) (_snapshot$reject2 = snapshot.reject) === null || _snapshot$reject2 === void 0 || _snapshot$reject2.call(snapshot, new Error(errMsg));
642
656
  if (process.env.PERCY_IGNORE_DUPLICATES !== 'true') {
643
- let errMsg = `Ignored duplicate snapshot. ${errors[1].detail}`;
644
657
  percy.log.warn(errMsg, meta);
645
658
  await percy.suggestionsForFix(errMsg, {
646
659
  snapshotLevel: true,
@@ -663,7 +676,7 @@ export function createSnapshotsQueue(percy) {
663
676
  snapshotLevel: true,
664
677
  snapshotName: name
665
678
  });
666
- if (snapshot.sync) snapshot.reject(error);
679
+ if (snapshot.sync) (_snapshot$reject3 = snapshot.reject) === null || _snapshot$reject3 === void 0 || _snapshot$reject3.call(snapshot, error);
667
680
  return result;
668
681
  });
669
682
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/core",
3
- "version": "1.32.12",
3
+ "version": "1.32.13-beta.1",
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"
@@ -46,12 +46,12 @@
46
46
  "dependencies": {
47
47
  "@grpc/grpc-js": "^1.14.3",
48
48
  "@grpc/proto-loader": "^0.8.0",
49
- "@percy/client": "1.32.12",
50
- "@percy/config": "1.32.12",
51
- "@percy/dom": "1.32.12",
52
- "@percy/logger": "1.32.12",
53
- "@percy/monitoring": "1.32.12",
54
- "@percy/webdriver-utils": "1.32.12",
49
+ "@percy/client": "1.32.13-beta.1",
50
+ "@percy/config": "1.32.13-beta.1",
51
+ "@percy/dom": "1.32.13-beta.1",
52
+ "@percy/logger": "1.32.13-beta.1",
53
+ "@percy/monitoring": "1.32.13-beta.1",
54
+ "@percy/webdriver-utils": "1.32.13-beta.1",
55
55
  "adm-zip": "^0.6.0",
56
56
  "busboy": "^1.6.0",
57
57
  "content-disposition": "^0.5.4",
@@ -67,8 +67,8 @@
67
67
  "yaml": "^2.4.1"
68
68
  },
69
69
  "optionalDependencies": {
70
- "@percy/cli-doctor": "1.32.12",
71
- "@percy/cli-pdf": "1.32.12"
70
+ "@percy/cli-doctor": "1.32.13-beta.1",
71
+ "@percy/cli-pdf": "1.32.13-beta.1"
72
72
  },
73
- "gitHead": "376d037c415012691acf5770c6216959fd2aef58"
73
+ "gitHead": "ce1817a2a31d00c29821e26af150e985d5ba8bf6"
74
74
  }