@percy/core 1.32.6 → 1.32.7-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/config.js CHANGED
@@ -717,6 +717,15 @@ export const snapshotSchema = {
717
717
  thTestCaseExecutionId: {
718
718
  $ref: '/config/snapshot#/properties/thTestCaseExecutionId'
719
719
  },
720
+ // IntelliStory: injected per-snapshot by @percy/storybook so the API can
721
+ // do affected-story selection server-side. `storybookPath` is the
722
+ // project-relative path of the story's source module.
723
+ intelliStory: {
724
+ type: 'boolean'
725
+ },
726
+ storybookPath: {
727
+ type: 'string'
728
+ },
720
729
  browsers: {
721
730
  $ref: '/config/snapshot#/properties/browsers'
722
731
  },
package/dist/discovery.js CHANGED
@@ -233,12 +233,18 @@ function processSnapshotResources({
233
233
  const kept = [];
234
234
  for (let index = 0; index < resources.length; index++) {
235
235
  const resource = resources[index];
236
+ // Never compress in place: these objects are shared with the resource
237
+ // cache, which must keep replaying the original bytes to the browser.
238
+ let uploaded = resource;
236
239
  try {
237
- const alreadyZipped = isGzipped(resource.content);
238
- /* istanbul ignore next: very hard to mock true */
239
- if (!alreadyZipped) {
240
- resource.content = Pako.gzip(resource.content);
241
- resource.sha = sha256hash(resource.content);
240
+ /* istanbul ignore else: an already-gzipped resource is very hard to mock */
241
+ if (!isGzipped(resource.content)) {
242
+ const content = Pako.gzip(resource.content);
243
+ uploaded = {
244
+ ...resource,
245
+ content,
246
+ sha: sha256hash(content)
247
+ };
242
248
  log.debug(`- Gzipped resource: ${resource.url}`);
243
249
  }
244
250
  } catch (error) {
@@ -253,9 +259,8 @@ function processSnapshotResources({
253
259
  continue;
254
260
  }
255
261
 
256
- // resource.content is guaranteed by the try block above (either just
257
- // assigned from Pako.gzip, or alreadyZipped was true).
258
- const size = resource.content.length;
262
+ // Either the gzipped copy or, when already gzipped, the resource itself.
263
+ const size = uploaded.content.length;
259
264
  // Root (DOM HTML) and log resources are required for a valid snapshot;
260
265
  // shipping an oversized one and letting the API surface a clear error
261
266
  // is better than silently dropping it here.
@@ -271,7 +276,7 @@ function processSnapshotResources({
271
276
  });
272
277
  continue;
273
278
  }
274
- kept.push(resource);
279
+ kept.push(uploaded);
275
280
  }
276
281
  resources = kept;
277
282
  }
package/dist/page.js CHANGED
@@ -20,22 +20,40 @@ export const DEFAULT_WAIT_FOR_CUSTOM_ELEMENTS_TIMEOUT = 500;
20
20
  // IMPORTANT: this body is intentionally ES5 — it is evaluated in the
21
21
  // page's realm and must work in any browser the page targets. Don't
22
22
  // "modernize" with arrow functions, let/const, or optional chaining.
23
+ //
24
+ // serializeFunction() injects the Percy helpers object as `arguments[0]`, so
25
+ // the caller's first argument is `arguments[1]`.
23
26
  export const WAIT_FOR_CUSTOM_ELEMENTS_BODY = `
24
- var deadline = Date.now() + (arguments[0] || 500);
27
+ var timeoutMs = typeof arguments[1] === 'number' && isFinite(arguments[1]) && arguments[1] > 0
28
+ ? arguments[1]
29
+ : 500;
30
+ var deadline = Date.now() + timeoutMs;
25
31
  return new Promise(function(resolve) {
32
+ var settled = false;
33
+ function finish() {
34
+ if (settled) return;
35
+ settled = true;
36
+ resolve();
37
+ }
38
+ setTimeout(finish, timeoutMs);
26
39
  function tick() {
40
+ if (settled) return;
27
41
  var undef = document.querySelectorAll(":not(:defined)");
28
- if (!undef.length) return resolve();
29
- if (Date.now() >= deadline) return resolve();
42
+ if (!undef.length) return finish();
43
+ if (Date.now() >= deadline) return finish();
30
44
  var names = {};
31
45
  for (var i = 0; i < undef.length; i++) names[undef[i].localName] = true;
32
46
  var promises = Object.keys(names).map(function(n) {
33
- return window.customElements.whenDefined(n).catch(function(){});
47
+ try {
48
+ return window.customElements.whenDefined(n).catch(function(){});
49
+ } catch (e) {
50
+ return Promise.resolve();
51
+ }
34
52
  });
35
53
  Promise.race([
36
54
  Promise.all(promises),
37
55
  new Promise(function(r) { setTimeout(r, 100); })
38
- ]).then(tick);
56
+ ]).then(tick, finish);
39
57
  }
40
58
  tick();
41
59
  });
package/dist/percy.js CHANGED
@@ -157,7 +157,7 @@ export class Percy {
157
157
  };
158
158
 
159
159
  // generator methods are wrapped to autorun and return promises
160
- for (let m of ['start', 'stop', 'flush', 'idle', 'snapshot', 'upload', 'replaySnapshot']) {
160
+ for (let m of ['start', 'stop', 'flush', 'idle', 'snapshot', 'upload', 'replaySnapshot', 'startBuild']) {
161
161
  // the original generator can be referenced with percy.yield.<method>
162
162
  let method = (this.yield || (this.yield = {}))[m] = this[m].bind(this);
163
163
  this[m] = (...args) => generatePromise(method(...args));
@@ -363,6 +363,20 @@ export class Percy {
363
363
  this._lockHandle = null;
364
364
  }
365
365
 
366
+ // Forces the snapshots queue to start, which creates the Percy build up
367
+ // front and populates `percy.build.id`. Normally, when uploads are delayed
368
+ // or deferred, the build is created lazily on the first flush. IntelliStory
369
+ // needs the real build id before any snapshots are taken so it can enqueue
370
+ // the affected-story graph against it. Safe to call more than once — the
371
+ // queue memoizes its start task, so the build is only created once.
372
+ async *startBuild() {
373
+ var _this$build2, _this$build3;
374
+ if (!this.readyState) return this.build;
375
+ if ((_this$build2 = this.build) !== null && _this$build2 !== void 0 && _this$build2.id || (_this$build3 = this.build) !== null && _this$build3 !== void 0 && _this$build3.error) return this.build;
376
+ yield _classPrivateFieldGet(_snapshots, this).start();
377
+ return this.build;
378
+ }
379
+
366
380
  // Resolves once snapshot and upload queues are idle
367
381
  async *idle() {
368
382
  yield* _classPrivateFieldGet(_discovery, this).idle();
@@ -490,8 +504,8 @@ export class Percy {
490
504
  // early if no build is associated, swallows pager rejections — telemetry
491
505
  // loss must never fail a build.
492
506
  async sendCacheTelemetry(message, extra) {
493
- var _this$build2;
494
- if (!((_this$build2 = this.build) !== null && _this$build2 !== void 0 && _this$build2.id)) return;
507
+ var _this$build4;
508
+ if (!((_this$build4 = this.build) !== null && _this$build4 !== void 0 && _this$build4.id)) return;
495
509
  try {
496
510
  await this.client.sendBuildEvents(this.build.id, {
497
511
  message,
@@ -596,10 +610,10 @@ export class Percy {
596
610
  // snapshots. Once asset discovery has completed for the provided snapshots, the queued task will
597
611
  // resolve and an upload task will be queued separately.
598
612
  snapshot(options, snapshotPromise = {}) {
599
- var _this$build3;
613
+ var _this$build5;
600
614
  if (this.readyState !== 1) {
601
615
  throw new Error('Not running');
602
- } else if ((_this$build3 = this.build) !== null && _this$build3 !== void 0 && _this$build3.error) {
616
+ } else if ((_this$build5 = this.build) !== null && _this$build5 !== void 0 && _this$build5.error) {
603
617
  throw new Error(this.build.error);
604
618
  } else if (Array.isArray(options)) {
605
619
  return yieldAll(options.map(o => this.yield.snapshot(o, snapshotPromise)));
@@ -632,10 +646,18 @@ export class Percy {
632
646
  return async function* () {
633
647
  let server;
634
648
  try {
635
- // Check SDK version
649
+ // Check SDK version. This generator runs inside the POST /percy/snapshot
650
+ // request handler (see api.js), so anything awaited here delays the HTTP
651
+ // response the SDK is blocked on. checkSDKVersion reaches out to
652
+ // api.github.com — an unrelated third party that a corporate proxy,
653
+ // egress firewall or GitHub throttling can leave hanging — so it must
654
+ // never gate a snapshot. Set the flag first so exactly one check is ever
655
+ // started (it used to be set after the await, which meant every snapshot
656
+ // posted during a slow check started its own), and run it detached:
657
+ // checkSDKVersion swallows its own errors and only logs.
636
658
  if (!this.sdkInfoDisplayed && options.clientInfo) {
637
- await checkSDKVersion(options.clientInfo);
638
659
  this.sdkInfoDisplayed = true;
660
+ checkSDKVersion(options.clientInfo);
639
661
  }
640
662
  if ('serve' in options) {
641
663
  // create and start a static server
@@ -764,10 +786,10 @@ export class Percy {
764
786
  // Pushes a pre-built snapshot directly to the upload queue without discovery.
765
787
  // Used by the replay command to upload previously archived snapshots.
766
788
  *replaySnapshot(snapshot) {
767
- var _this$build4;
789
+ var _this$build6;
768
790
  if (this.readyState !== 1) {
769
791
  throw new Error('Not running');
770
- } else if ((_this$build4 = this.build) !== null && _this$build4 !== void 0 && _this$build4.error) {
792
+ } else if ((_this$build6 = this.build) !== null && _this$build6 !== void 0 && _this$build6.error) {
771
793
  throw new Error(this.build.error);
772
794
  }
773
795
  snapshot.meta = {
@@ -859,7 +881,7 @@ export class Percy {
859
881
  async sendBuildLogs() {
860
882
  if (!process.env.PERCY_TOKEN) return;
861
883
  try {
862
- var _this$build5, _this$build6, _this$build7, _this$build8;
884
+ var _this$build7, _this$build8, _this$build9, _this$build10;
863
885
  const logsObject = {
864
886
  // Redact secrets from CLI logs before egress to the Percy API — these
865
887
  // can contain tokens or URLs with embedded credentials (CWE-532). The
@@ -874,10 +896,10 @@ export class Percy {
874
896
  logsObject.cilogs = redactedContent;
875
897
  }
876
898
  const content = base64encode(Pako.gzip(JSON.stringify(logsObject)));
877
- const referenceId = (_this$build5 = this.build) !== null && _this$build5 !== void 0 && _this$build5.id ? `build_${(_this$build6 = this.build) === null || _this$build6 === void 0 ? void 0 : _this$build6.id}` : (_this$build7 = this.build) === null || _this$build7 === void 0 ? void 0 : _this$build7.id;
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;
878
900
  const eventObject = {
879
901
  content: content,
880
- build_id: (_this$build8 = this.build) === null || _this$build8 === void 0 ? void 0 : _this$build8.id,
902
+ build_id: (_this$build10 = this.build) === null || _this$build10 === void 0 ? void 0 : _this$build10.id,
881
903
  reference_id: referenceId,
882
904
  service_name: 'cli',
883
905
  base64encoded: true
@@ -950,9 +972,9 @@ export class Percy {
950
972
  const newAllowedDomains = Array.from(processedHosts).filter(domain => !autoConfiguredHosts.has(domain));
951
973
  const hasNewDomains = newAllowedDomains.length > 0 || newErrorHosts.size > 0;
952
974
  try {
953
- var _this$build9;
975
+ var _this$build11;
954
976
  await this.client.updateProjectDomainConfig({
955
- buildId: (_this$build9 = this.build) === null || _this$build9 === void 0 ? void 0 : _this$build9.id,
977
+ buildId: (_this$build11 = this.build) === null || _this$build11 === void 0 ? void 0 : _this$build11.id,
956
978
  allowedDomains: Array.from(processedHosts),
957
979
  errorDomains: Array.from(newErrorHosts)
958
980
  });
package/dist/utils.js CHANGED
@@ -952,6 +952,12 @@ export async function* maybeScrollToBottom(page, discovery) {
952
952
  }
953
953
  }
954
954
 
955
+ // How long the (purely informational) SDK version check may spend talking to
956
+ // api.github.com before it gives up. Kept short deliberately: the check now runs
957
+ // detached, so its socket is a live handle that would otherwise hold the event
958
+ // loop open at shutdown for as long as the peer stays silent.
959
+ const SDK_VERSION_CHECK_TIMEOUT = 5000;
960
+
955
961
  // Package to GitHub repo mapping
956
962
  const PACKAGE_TO_REPO = {
957
963
  '@percy/selenium-webdriver': 'percy-selenium-js',
@@ -994,11 +1000,15 @@ export async function checkSDKVersion(clientInfo) {
994
1000
  return;
995
1001
  }
996
1002
 
997
- // Fetch latest version from GitHub releases
1003
+ // Fetch latest version from GitHub releases. api.github.com is a third
1004
+ // party we don't control and networks routinely black-hole it (proxies,
1005
+ // egress firewalls, rate limiting), so this is bounded — without a timeout
1006
+ // the socket stays open for the life of the CLI process.
998
1007
  const githubData = await request(`https://api.github.com/repos/percy/${repoName}/releases?page=1`, {
999
1008
  headers: {
1000
1009
  'User-Agent': '@percy/cli'
1001
1010
  },
1011
+ timeout: SDK_VERSION_CHECK_TIMEOUT,
1002
1012
  retries: 0
1003
1013
  });
1004
1014
  const latestRelease = githubData.find(r => !r.prerelease);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/core",
3
- "version": "1.32.6",
3
+ "version": "1.32.7-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"
@@ -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.6",
50
- "@percy/config": "1.32.6",
51
- "@percy/dom": "1.32.6",
52
- "@percy/logger": "1.32.6",
53
- "@percy/monitoring": "1.32.6",
54
- "@percy/webdriver-utils": "1.32.6",
49
+ "@percy/client": "1.32.7-beta.2",
50
+ "@percy/config": "1.32.7-beta.2",
51
+ "@percy/dom": "1.32.7-beta.2",
52
+ "@percy/logger": "1.32.7-beta.2",
53
+ "@percy/monitoring": "1.32.7-beta.2",
54
+ "@percy/webdriver-utils": "1.32.7-beta.2",
55
55
  "adm-zip": "^0.6.0",
56
56
  "busboy": "^1.6.0",
57
57
  "content-disposition": "^0.5.4",
@@ -67,7 +67,7 @@
67
67
  "yaml": "^2.4.1"
68
68
  },
69
69
  "optionalDependencies": {
70
- "@percy/cli-doctor": "1.32.6"
70
+ "@percy/cli-doctor": "1.32.7-beta.2"
71
71
  },
72
- "gitHead": "e7dd935acf71273fd045ccceda6d1a37db8e4600"
72
+ "gitHead": "be6a40b9d99ef190e4f6123491241c27c8308161"
73
73
  }