@percy/core 1.28.1-alpha.2 → 1.28.1-alpha.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/config.js CHANGED
@@ -71,6 +71,9 @@ export const configSchema = {
71
71
  sync: {
72
72
  type: 'boolean'
73
73
  },
74
+ testCase: {
75
+ type: 'string'
76
+ },
74
77
  fullPage: {
75
78
  type: 'boolean',
76
79
  onlyAutomate: true
@@ -249,10 +252,6 @@ export const configSchema = {
249
252
  type: 'integer',
250
253
  minimum: 1
251
254
  },
252
- retry: {
253
- type: 'boolean',
254
- default: false
255
- },
256
255
  launchOptions: {
257
256
  type: 'object',
258
257
  additionalProperties: false,
@@ -316,6 +315,9 @@ export const snapshotSchema = {
316
315
  sync: {
317
316
  $ref: '/config/snapshot#/properties/sync'
318
317
  },
318
+ testCase: {
319
+ $ref: '/config/snapshot#/properties/testCase'
320
+ },
319
321
  reshuffleInvalidTags: {
320
322
  $ref: '/config/snapshot#/properties/reshuffleInvalidTags'
321
323
  },
package/dist/discovery.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import logger from '@percy/logger';
2
2
  import Queue from './queue.js';
3
- import { normalizeURL, hostnameMatches, createResource, createRootResource, createPercyCSSResource, createLogResource, yieldAll, withRetries } from './utils.js';
3
+ import { normalizeURL, hostnameMatches, createResource, createRootResource, createPercyCSSResource, createLogResource, yieldAll, snapshotLogName } from './utils.js';
4
4
 
5
5
  // Logs verbose debug logs detailing various snapshot options.
6
6
  function debugSnapshotOptions(snapshot) {
@@ -139,8 +139,8 @@ function processSnapshotResources({
139
139
 
140
140
  // include associated snapshot logs matched by meta information
141
141
  resources.push(createLogResource(logger.query(log => {
142
- var _log$meta$snapshot;
143
- return ((_log$meta$snapshot = log.meta.snapshot) === null || _log$meta$snapshot === void 0 ? void 0 : _log$meta$snapshot.name) === snapshot.meta.snapshot.name;
142
+ var _log$meta$snapshot, _log$meta$snapshot2;
143
+ return ((_log$meta$snapshot = log.meta.snapshot) === null || _log$meta$snapshot === void 0 ? void 0 : _log$meta$snapshot.testCase) === snapshot.meta.snapshot.testCase && ((_log$meta$snapshot2 = log.meta.snapshot) === null || _log$meta$snapshot2 === void 0 ? void 0 : _log$meta$snapshot2.name) === snapshot.meta.snapshot.name;
144
144
  })));
145
145
  return {
146
146
  ...snapshot,
@@ -279,8 +279,7 @@ export const RESOURCE_CACHE_KEY = Symbol('resource-cache');
279
279
  // snapshot which is used to intercept and capture snapshot resource requests.
280
280
  export function createDiscoveryQueue(percy) {
281
281
  let {
282
- concurrency,
283
- retry
282
+ concurrency
284
283
  } = percy.config.discovery;
285
284
  let queue = new Queue('discovery');
286
285
  let cache;
@@ -297,11 +296,12 @@ export function createDiscoveryQueue(percy) {
297
296
  .handle('end', async () => {
298
297
  await percy.browser.close();
299
298
  })
300
- // snapshots are unique by name; when deferred also by widths
299
+ // snapshots are unique by name and testCase; when deferred also by widths
301
300
  .handle('find', ({
302
301
  name,
302
+ testCase,
303
303
  widths
304
- }, snapshot) => snapshot.name === name && (!percy.deferUploads || !widths || widths.join() === snapshot.widths.join()))
304
+ }, snapshot) => snapshot.testCase === testCase && snapshot.name === name && (!percy.deferUploads || !widths || widths.join() === snapshot.widths.join()))
305
305
  // initialize the resources for DOM snapshots
306
306
  .handle('push', snapshot => {
307
307
  let resources = parseDomResources(snapshot);
@@ -318,53 +318,46 @@ export function createDiscoveryQueue(percy) {
318
318
  /* istanbul ignore next: tested, but coverage is stripped */
319
319
  let assetDiscoveryPageEnableJS = snapshot.cliEnableJavaScript && !snapshot.domSnapshot || (snapshot.enableJavaScript ?? !snapshot.domSnapshot);
320
320
  percy.log.debug(`Asset discovery Browser Page enable JS: ${assetDiscoveryPageEnableJS}`);
321
- await withRetries(async function* () {
322
- // create a new browser page
323
- let page = yield percy.browser.page({
324
- enableJavaScript: assetDiscoveryPageEnableJS,
325
- networkIdleTimeout: snapshot.discovery.networkIdleTimeout,
326
- requestHeaders: snapshot.discovery.requestHeaders,
327
- authorization: snapshot.discovery.authorization,
328
- userAgent: snapshot.discovery.userAgent,
329
- captureMockedServiceWorker: snapshot.discovery.captureMockedServiceWorker,
330
- meta: snapshot.meta,
331
- // enable network inteception
332
- intercept: {
333
- enableJavaScript: snapshot.enableJavaScript,
334
- disableCache: snapshot.discovery.disableCache,
335
- allowedHostnames: snapshot.discovery.allowedHostnames,
336
- disallowedHostnames: snapshot.discovery.disallowedHostnames,
337
- getResource: u => snapshot.resources.get(u) || cache.get(u),
338
- saveResource: r => {
339
- snapshot.resources.set(r.url, r);
340
- if (!r.root) {
341
- cache.set(r.url, r);
342
- }
321
+ // create a new browser page
322
+ let page = yield percy.browser.page({
323
+ enableJavaScript: assetDiscoveryPageEnableJS,
324
+ networkIdleTimeout: snapshot.discovery.networkIdleTimeout,
325
+ requestHeaders: snapshot.discovery.requestHeaders,
326
+ authorization: snapshot.discovery.authorization,
327
+ userAgent: snapshot.discovery.userAgent,
328
+ captureMockedServiceWorker: snapshot.discovery.captureMockedServiceWorker,
329
+ meta: snapshot.meta,
330
+ // enable network inteception
331
+ intercept: {
332
+ enableJavaScript: snapshot.enableJavaScript,
333
+ disableCache: snapshot.discovery.disableCache,
334
+ allowedHostnames: snapshot.discovery.allowedHostnames,
335
+ disallowedHostnames: snapshot.discovery.disallowedHostnames,
336
+ getResource: u => snapshot.resources.get(u) || cache.get(u),
337
+ saveResource: r => {
338
+ snapshot.resources.set(r.url, r);
339
+ if (!r.root) {
340
+ cache.set(r.url, r);
343
341
  }
344
342
  }
345
- });
346
- try {
347
- yield* captureSnapshotResources(page, snapshot, {
348
- captureWidths: !snapshot.domSnapshot && percy.deferUploads,
349
- capture: callback
350
- });
351
- } finally {
352
- // always close the page when done
353
- await page.close();
354
- }
355
- }, {
356
- count: retry ? 3 : 1,
357
- onRetry: () => {
358
- percy.log.debug(`Retrying snapshot: ${snapshot.name}`, snapshot.meta);
359
343
  }
360
344
  });
345
+ try {
346
+ yield* captureSnapshotResources(page, snapshot, {
347
+ captureWidths: !snapshot.domSnapshot && percy.deferUploads,
348
+ capture: callback
349
+ });
350
+ } finally {
351
+ // always close the page when done
352
+ await page.close();
353
+ }
361
354
  }).handle('error', ({
362
355
  name,
363
356
  meta
364
357
  }, error) => {
365
358
  if (error.name === 'AbortError' && queue.readyState < 3) {
366
359
  // only error about aborted snapshots when not closed
367
- percy.log.error('Received a duplicate snapshot, ' + `the previous snapshot was aborted: ${name}`, meta);
360
+ percy.log.error('Received a duplicate snapshot, ' + `the previous snapshot was aborted: ${snapshotLogName(name, meta)}`, meta);
368
361
  } else {
369
362
  // log all other encountered errors
370
363
  percy.log.error(`Encountered an error taking snapshot: ${name}`, meta);
package/dist/network.js CHANGED
@@ -28,7 +28,6 @@ export class Network {
28
28
  #requests = new Map();
29
29
  #authentications = new Set();
30
30
  #aborted = new Set();
31
- #finishedUrls = new Set();
32
31
  constructor(page, options) {
33
32
  this.page = page;
34
33
  this.timeout = options.networkIdleTimeout ?? 100;
@@ -79,12 +78,6 @@ export class Network {
79
78
  throw new Error(`Network error: ${this.page.session.closedReason}`);
80
79
  }
81
80
  requests = Array.from(this.#requests.values()).filter(filter);
82
- // remove requests which are finished at least once
83
- // this happens when same request is made multiple times by browser in parallel and one of
84
- // them gets stuck in pending state in browser [ need to debug why ]. So we dont receive
85
- // loadingFinished event, causing it to show up in Active requests, but we can only store one
86
- // response per url so as long as we have captured one, we dont care about other such requests
87
- requests = requests.filter(req => !this.#finishedUrls.has(req.url));
88
81
  return requests.length === 0;
89
82
  }, {
90
83
  timeout: Network.TIMEOUT,
@@ -127,12 +120,10 @@ export class Network {
127
120
  // Called when a request should be removed from various trackers
128
121
  _forgetRequest({
129
122
  requestId,
130
- interceptId,
131
- url
123
+ interceptId
132
124
  }, keepPending) {
133
125
  this.#requests.delete(requestId);
134
126
  this.#authentications.delete(interceptId);
135
- this.#finishedUrls.add(url);
136
127
  if (!keepPending) {
137
128
  this.#pending.delete(requestId);
138
129
  }
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 } from './utils.js';
6
+ import { request, hostnameMatches, yieldTo, snapshotLogName } 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
@@ -113,7 +113,8 @@ function getSnapshotOptions(options, {
113
113
  meta: {
114
114
  ...meta,
115
115
  snapshot: {
116
- name: options.name
116
+ name: options.name,
117
+ testCase: options.testCase
117
118
  }
118
119
  }
119
120
  }, config.snapshot, {
@@ -391,10 +392,11 @@ export function createSnapshotsQueue(percy) {
391
392
  });
392
393
  }
393
394
  })
394
- // snapshots are unique by name alone
395
+ // snapshots are unique by name and testCase both
395
396
  .handle('find', ({
396
- name
397
- }, snapshot) => snapshot.name === name)
397
+ name,
398
+ testCase
399
+ }, snapshot) => snapshot.testCase === testCase && snapshot.name === name)
398
400
  // when pushed, maybe flush old snapshots or possibly merge with existing snapshots
399
401
  .handle('push', (snapshot, existing) => {
400
402
  let {
@@ -403,8 +405,8 @@ export function createSnapshotsQueue(percy) {
403
405
  } = snapshot;
404
406
 
405
407
  // log immediately when not deferred or dry-running
406
- if (!percy.deferUploads) percy.log.info(`Snapshot taken: ${name}`, meta);
407
- if (percy.dryRun) percy.log.info(`Snapshot found: ${name}`, meta);
408
+ if (!percy.deferUploads) percy.log.info(`Snapshot taken: ${snapshotLogName(name, meta)}`, meta);
409
+ if (percy.dryRun) percy.log.info(`Snapshot found: ${snapshotLogName(name, meta)}`, meta);
408
410
 
409
411
  // immediately flush when uploads are delayed but not skipped
410
412
  if (percy.delayUploads && !percy.deferUploads) queue.flush();
package/dist/utils.js CHANGED
@@ -328,24 +328,12 @@ export function serializeFunction(fn) {
328
328
  }
329
329
  return fnbody;
330
330
  }
331
- export async function withRetries(fn, {
332
- count,
333
- onRetry
334
- }) {
335
- count || (count = 1); // default a single try
336
- let run = 0;
337
- while (true) {
338
- run += 1;
339
- try {
340
- return await generatePromise(fn);
341
- } catch (e) {
342
- if (run < count) {
343
- await (onRetry === null || onRetry === void 0 ? void 0 : onRetry());
344
- continue;
345
- }
346
- throw e;
347
- }
331
+ export function snapshotLogName(name, meta) {
332
+ var _meta$snapshot;
333
+ if (meta !== null && meta !== void 0 && (_meta$snapshot = meta.snapshot) !== null && _meta$snapshot !== void 0 && _meta$snapshot.testCase) {
334
+ return `testCase: ${meta.snapshot.testCase}, ${name}`;
348
335
  }
336
+ return name;
349
337
  }
350
338
 
351
339
  // DefaultMap, which returns a default value for an uninitialized key
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/core",
3
- "version": "1.28.1-alpha.2",
3
+ "version": "1.28.1-alpha.4",
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": "alpha"
12
+ "tag": "beta"
13
13
  },
14
14
  "engines": {
15
15
  "node": ">=14"
@@ -43,11 +43,11 @@
43
43
  "test:types": "tsd"
44
44
  },
45
45
  "dependencies": {
46
- "@percy/client": "1.28.1-alpha.2",
47
- "@percy/config": "1.28.1-alpha.2",
48
- "@percy/dom": "1.28.1-alpha.2",
49
- "@percy/logger": "1.28.1-alpha.2",
50
- "@percy/webdriver-utils": "1.28.1-alpha.2",
46
+ "@percy/client": "1.28.1-alpha.4",
47
+ "@percy/config": "1.28.1-alpha.4",
48
+ "@percy/dom": "1.28.1-alpha.4",
49
+ "@percy/logger": "1.28.1-alpha.4",
50
+ "@percy/webdriver-utils": "1.28.1-alpha.4",
51
51
  "content-disposition": "^0.5.4",
52
52
  "cross-spawn": "^7.0.3",
53
53
  "extract-zip": "^2.0.1",
@@ -58,5 +58,5 @@
58
58
  "rimraf": "^3.0.2",
59
59
  "ws": "^8.0.0"
60
60
  },
61
- "gitHead": "a3f2e709d0a6445e15a1128686578b1659243a95"
61
+ "gitHead": "90d1c1135441a631d5fdbbce0a7e2efbe8ab4e21"
62
62
  }