@percy/core 1.28.1 → 1.28.2-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/config.js CHANGED
@@ -199,6 +199,9 @@ export const configSchema = {
199
199
  type: 'boolean',
200
200
  default: false
201
201
  },
202
+ captureSrcset: {
203
+ type: 'boolean'
204
+ },
202
205
  requestHeaders: {
203
206
  type: 'object',
204
207
  normalize: false,
@@ -346,6 +349,9 @@ export const snapshotSchema = {
346
349
  captureMockedServiceWorker: {
347
350
  $ref: '/config/discovery#/properties/captureMockedServiceWorker'
348
351
  },
352
+ captureSrcset: {
353
+ $ref: '/config/discovery#/properties/captureSrcset'
354
+ },
349
355
  userAgent: {
350
356
  $ref: '/config/discovery#/properties/userAgent'
351
357
  },
package/dist/discovery.js CHANGED
@@ -44,6 +44,7 @@ function debugSnapshotOptions(snapshot) {
44
44
  debugProp(snapshot, 'discovery.authorization', JSON.stringify);
45
45
  debugProp(snapshot, 'discovery.disableCache');
46
46
  debugProp(snapshot, 'discovery.captureMockedServiceWorker');
47
+ debugProp(snapshot, 'discovery.captureSrcset');
47
48
  debugProp(snapshot, 'discovery.userAgent');
48
49
  debugProp(snapshot, 'clientInfo');
49
50
  debugProp(snapshot, 'environmentInfo');
@@ -151,6 +152,7 @@ function processSnapshotResources({
151
152
  // Triggers the capture of resource requests for a page by iterating over snapshot widths to resize
152
153
  // the page and calling any provided execute options.
153
154
  async function* captureSnapshotResources(page, snapshot, options) {
155
+ const log = logger('core:discovery');
154
156
  let {
155
157
  discovery,
156
158
  additionalSnapshots = [],
@@ -160,7 +162,8 @@ async function* captureSnapshotResources(page, snapshot, options) {
160
162
  capture,
161
163
  captureWidths,
162
164
  deviceScaleFactor,
163
- mobile
165
+ mobile,
166
+ captureForDevices
164
167
  } = options;
165
168
 
166
169
  // used to take snapshots and remove any discovered root resource
@@ -193,6 +196,14 @@ async function* captureSnapshotResources(page, snapshot, options) {
193
196
  yield page.evaluate(snapshot.execute.afterNavigation);
194
197
  }
195
198
 
199
+ // Running before page idle since this will trigger many network calls
200
+ // so need to run as early as possible. plus it is just reading urls from dom srcset
201
+ // which will be already loaded after navigation complete
202
+ if (discovery.captureSrcset) {
203
+ await page.insertPercyDom();
204
+ yield page.eval('window.PercyDOM.loadAllSrcsetLinks()');
205
+ }
206
+
196
207
  // iterate over additional snapshots for proper DOM capturing
197
208
  for (let additionalSnapshot of [baseSnapshot, ...additionalSnapshots]) {
198
209
  let isBaseSnapshot = additionalSnapshot === baseSnapshot;
@@ -206,6 +217,21 @@ async function* captureSnapshotResources(page, snapshot, options) {
206
217
  } = snap;
207
218
  let [width] = widths;
208
219
 
220
+ // iterate over device to trigger reqeusts and capture other dpr width
221
+ if (captureForDevices) {
222
+ for (const device of captureForDevices) {
223
+ yield waitForDiscoveryNetworkIdle(page, discovery);
224
+ // We are not adding these widths and pixels ratios in loop below because we want to explicitly reload the page after resize which we dont do below
225
+ yield* captureSnapshotResources(page, {
226
+ ...snapshot,
227
+ widths: [device.width]
228
+ }, {
229
+ deviceScaleFactor: device.deviceScaleFactor,
230
+ mobile: true
231
+ });
232
+ }
233
+ }
234
+
209
235
  // iterate over widths to trigger reqeusts and capture other widths
210
236
  if (isBaseSnapshot || captureWidths) {
211
237
  for (let i = 0; i < widths.length - 1; i++) {
@@ -230,12 +256,8 @@ async function* captureSnapshotResources(page, snapshot, options) {
230
256
  }
231
257
 
232
258
  // recursively trigger resource requests for any alternate device pixel ratio
233
- if (deviceScaleFactor !== discovery.devicePixelRatio) {
234
- yield waitForDiscoveryNetworkIdle(page, discovery);
235
- yield* captureSnapshotResources(page, snapshot, {
236
- deviceScaleFactor: discovery.devicePixelRatio,
237
- mobile: true
238
- });
259
+ if (discovery.devicePixelRatio) {
260
+ log.deprecated('discovery.devicePixelRatio is deprecated percy will now auto capture resource in all devicePixelRatio, Ignoring configuration');
239
261
  }
240
262
 
241
263
  // wait for final network idle when not capturing DOM
@@ -345,7 +367,8 @@ export function createDiscoveryQueue(percy) {
345
367
  try {
346
368
  yield* captureSnapshotResources(page, snapshot, {
347
369
  captureWidths: !snapshot.domSnapshot && percy.deferUploads,
348
- capture: callback
370
+ capture: callback,
371
+ captureForDevices: percy.deviceDetails || []
349
372
  });
350
373
  } finally {
351
374
  // always close the page when done
package/dist/page.js CHANGED
@@ -131,6 +131,16 @@ export class Page {
131
131
  });
132
132
  for (let script of scripts) await this.eval(script);
133
133
  }
134
+ async insertPercyDom() {
135
+ // inject @percy/dom for serialization by evaluating the file contents which adds a global
136
+ // PercyDOM object that we can later check against
137
+ /* istanbul ignore next: no instrumenting injected code */
138
+ if (await this.eval(() => !window.PercyDOM)) {
139
+ this.log.debug('Inject @percy/dom', this.meta);
140
+ let script = await fs.promises.readFile(PERCY_DOM, 'utf-8');
141
+ await this.eval(new Function(script)); /* eslint-disable-line no-new-func */
142
+ }
143
+ }
134
144
 
135
145
  // Takes a snapshot after waiting for any timeout, waiting for any selector, executing any
136
146
  // scripts, and waiting for the network idle. Returns all other provided snapshot options along
@@ -171,15 +181,7 @@ export class Page {
171
181
 
172
182
  // wait for any final network activity before capturing the dom snapshot
173
183
  await this.network.idle();
174
-
175
- // inject @percy/dom for serialization by evaluating the file contents which adds a global
176
- // PercyDOM object that we can later check against
177
- /* istanbul ignore next: no instrumenting injected code */
178
- if (await this.eval(() => !window.PercyDOM)) {
179
- this.log.debug('Inject @percy/dom', this.meta);
180
- let script = await fs.promises.readFile(PERCY_DOM, 'utf-8');
181
- await this.eval(new Function(script)); /* eslint-disable-line no-new-func */
182
- }
184
+ await this.insertPercyDom();
183
185
 
184
186
  // serialize and capture a DOM snapshot
185
187
  this.log.debug('Serialize DOM', this.meta);
package/dist/percy.js CHANGED
@@ -145,12 +145,14 @@ export class Percy {
145
145
  if (this.readyState != null) return;
146
146
  this.readyState = 0;
147
147
  try {
148
+ var _this$build;
148
149
  // start the snapshots queue immediately when not delayed or deferred
149
150
  if (!this.delayUploads && !this.deferUploads) yield this.#snapshots.start();
150
151
  // do not start the discovery queue when not needed
151
152
  if (!this.skipDiscovery) yield this.#discovery.start();
152
153
  // start a local API server for SDK communication
153
154
  if (this.server) yield this.server.listen();
155
+ if (this.projectType === 'web') this.deviceDetails = yield this.client.getDeviceDetails((_this$build = this.build) === null || _this$build === void 0 ? void 0 : _this$build.id);
154
156
  const snapshotType = this.projectType === 'web' ? 'snapshot' : 'comparison';
155
157
  this.syncQueue = new WaitForJob(snapshotType, this);
156
158
  // log and mark this instance as started
@@ -258,10 +260,10 @@ export class Percy {
258
260
  // snapshots. Once asset discovery has completed for the provided snapshots, the queued task will
259
261
  // resolve and an upload task will be queued separately.
260
262
  snapshot(options, snapshotPromise = {}) {
261
- var _this$build;
263
+ var _this$build2;
262
264
  if (this.readyState !== 1) {
263
265
  throw new Error('Not running');
264
- } else if ((_this$build = this.build) !== null && _this$build !== void 0 && _this$build.error) {
266
+ } else if ((_this$build2 = this.build) !== null && _this$build2 !== void 0 && _this$build2.error) {
265
267
  throw new Error(this.build.error);
266
268
  } else if (Array.isArray(options)) {
267
269
  return yieldAll(options.map(o => this.yield.snapshot(o, snapshotPromise)));
package/dist/snapshot.js CHANGED
@@ -128,6 +128,7 @@ function getSnapshotOptions(options, {
128
128
  authorization: config.discovery.authorization,
129
129
  disableCache: config.discovery.disableCache,
130
130
  captureMockedServiceWorker: config.discovery.captureMockedServiceWorker,
131
+ captureSrcset: config.discovery.captureSrcset,
131
132
  userAgent: config.discovery.userAgent
132
133
  }
133
134
  }, options], (path, prev, next) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/core",
3
- "version": "1.28.1",
3
+ "version": "1.28.2-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"
@@ -43,11 +43,11 @@
43
43
  "test:types": "tsd"
44
44
  },
45
45
  "dependencies": {
46
- "@percy/client": "1.28.1",
47
- "@percy/config": "1.28.1",
48
- "@percy/dom": "1.28.1",
49
- "@percy/logger": "1.28.1",
50
- "@percy/webdriver-utils": "1.28.1",
46
+ "@percy/client": "1.28.2-beta.1",
47
+ "@percy/config": "1.28.2-beta.1",
48
+ "@percy/dom": "1.28.2-beta.1",
49
+ "@percy/logger": "1.28.2-beta.1",
50
+ "@percy/webdriver-utils": "1.28.2-beta.1",
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": "f3b0fad3c511fe9eea44eef939195a9d0310216b"
61
+ "gitHead": "c4d0637366dbc28eeda234f93d44424d9c565f49"
62
62
  }
package/types/index.d.ts CHANGED
@@ -19,6 +19,7 @@ interface DiscoveryOptions {
19
19
  allowedHostnames?: string[];
20
20
  disableCache?: boolean;
21
21
  captureMockedServiceWorker?: boolean;
22
+ captureSrcset?: boolean;
22
23
  }
23
24
 
24
25
  interface ScopeOptions {