@percy/core 1.9.0 → 1.10.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
@@ -138,14 +138,16 @@ export function createPercyServer(percy, port) {
138
138
  }
139
139
  }, res) => {
140
140
  body = Buffer.isBuffer(body) ? body.toString() : body;
141
+ let {
142
+ remoteLoggers
143
+ } = percy.testing;
141
144
 
142
145
  if (cmd === 'reset') {
143
- var _percy$testing$remote;
144
-
145
- // the reset command will terminate connections, clear logs, and reset testing mode
146
- (_percy$testing$remote = percy.testing.remoteLoggers) === null || _percy$testing$remote === void 0 ? void 0 : _percy$testing$remote.forEach(ws => ws.terminate());
146
+ // the reset command will reset testing mode and clear any logs
147
+ percy.testing = remoteLoggers ? {
148
+ remoteLoggers
149
+ } : {};
147
150
  logger.instance.messages.clear();
148
- percy.testing = {};
149
151
  } else if (cmd === 'version') {
150
152
  // the version command will update the api version header for testing
151
153
  percy.testing.version = body;
@@ -161,10 +163,8 @@ export function createPercyServer(percy, port) {
161
163
  error: 'Build failed'
162
164
  };
163
165
  } else if (cmd === 'remote-logging') {
164
- var _percy$testing$remote2;
165
-
166
166
  // the remote-logging command will toggle remote logging support
167
- if (body === false) (_percy$testing$remote2 = percy.testing.remoteLoggers) === null || _percy$testing$remote2 === void 0 ? void 0 : _percy$testing$remote2.forEach(ws => ws.terminate());
167
+ if (body === false) remoteLoggers === null || remoteLoggers === void 0 ? void 0 : remoteLoggers.forEach(ws => ws.terminate());
168
168
  percy.testing.remoteLogging = body;
169
169
  } else {
170
170
  // 404 for unknown commands
@@ -189,15 +189,17 @@ export function createPercyServer(percy, port) {
189
189
  export function createStaticServer(options) {
190
190
  let {
191
191
  serve: dir,
192
- baseUrl = '/'
192
+ baseUrl = ''
193
193
  } = options;
194
- let server = Server.createServer(options); // used when generating an automatic sitemap
194
+ let server = Server.createServer(options); // remove trailing slashes so the base snapshot name matches other snapshots
195
+
196
+ baseUrl = baseUrl.replace(/\/$/, ''); // used when generating an automatic sitemap
195
197
 
196
198
  let toURL = Server.createRewriter( // reverse rewrites' src, dest, & order
197
- Object.entries((options === null || options === void 0 ? void 0 : options.rewrites) ?? {}).reduce((acc, rw) => [rw.reverse(), ...acc], []), (filename, rewrite) => new URL(path.posix.join(baseUrl, // cleanUrls will trim trailing .html/index.html from paths
199
+ Object.entries((options === null || options === void 0 ? void 0 : options.rewrites) ?? {}).reduce((acc, rw) => [rw.reverse(), ...acc], []), (filename, rewrite) => new URL(path.posix.join('/', baseUrl, // cleanUrls will trim trailing .html/index.html from paths
198
200
  !options.cleanUrls ? rewrite(filename) : rewrite(filename).replace(/(\/index)?\.html$/, '')), server.address())); // include automatic sitemap route
199
201
 
200
- server.route('get', '/sitemap.xml', async (req, res) => {
202
+ server.route('get', `${baseUrl}/sitemap.xml`, async (req, res) => {
201
203
  let {
202
204
  default: glob
203
205
  } = await import('fast-glob');
package/dist/percy.js CHANGED
@@ -31,7 +31,9 @@ export class Percy {
31
31
  deferUploads,
32
32
  // run without uploading anything
33
33
  skipUploads,
34
- // implies `skipUploads` and also skips asset discovery
34
+ // run without asset discovery
35
+ skipDiscovery,
36
+ // implies `skipUploads` and `skipDiscovery`
35
37
  dryRun,
36
38
  // implies `dryRun`, silent logs, and adds extra api endpoints
37
39
  testing,
@@ -53,6 +55,7 @@ export class Percy {
53
55
  this.testing = testing ? {} : null;
54
56
  this.dryRun = !!testing || !!dryRun;
55
57
  this.skipUploads = this.dryRun || !!skipUploads;
58
+ this.skipDiscovery = this.dryRun || !!skipDiscovery;
56
59
  this.delayUploads = this.skipUploads || !!delayUploads;
57
60
  this.deferUploads = this.delayUploads || !!deferUploads;
58
61
  if (this.deferUploads) this.#uploads.stop();
@@ -150,7 +153,7 @@ export class Percy {
150
153
  // at a later time when uploads are deferred, or run immediately when not deferred.
151
154
 
152
155
 
153
- async *start(options) {
156
+ async *start() {
154
157
  // already starting or started
155
158
  if (this.readyState != null) return;
156
159
  this.readyState = 0; // create a percy build as the first immediately queued task
@@ -193,10 +196,7 @@ export class Percy {
193
196
  // when not deferred, wait until the build is created first
194
197
  if (!this.deferUploads) await buildTask; // maybe launch the discovery browser
195
198
 
196
- if (!this.dryRun && (options === null || options === void 0 ? void 0 : options.browser) !== false) {
197
- yield this.browser.launch();
198
- } // start the server after everything else is ready
199
-
199
+ if (!this.skipDiscovery) yield this.browser.launch(); // start the server after everything else is ready
200
200
 
201
201
  yield (_this$server2 = this.server) === null || _this$server2 === void 0 ? void 0 : _this$server2.listen(); // mark instance as started
202
202
 
@@ -234,8 +234,8 @@ export class Percy {
234
234
  if (this.#snapshots.size) {
235
235
  if (close) this.#snapshots.close();
236
236
  yield* this.#snapshots.flush(s => {
237
- // do not log a count when not closing or while dry-running
238
- if (!close || this.dryRun) return;
237
+ // do not log a count when not closing or if asset discovery is disabled
238
+ if (!close || this.skipDiscovery) return;
239
239
  this.log.progress(`Processing ${s} snapshot${s !== 1 ? 's' : ''}...`, !!s);
240
240
  });
241
241
  } // run, close, and wait for the upload queue to empty
package/dist/snapshot.js CHANGED
@@ -117,6 +117,8 @@ export async function* gatherSnapshots(percy, options) {
117
117
  // other invalid options which are also scrubbed from the returned migrated options.
118
118
 
119
119
  export function validateSnapshotOptions(options) {
120
+ var _migrated$baseUrl;
121
+
120
122
  // decide which schema to validate against
121
123
  let schema = ['domSnapshot', 'dom-snapshot', 'dom_snapshot'].some(k => k in options) && '/snapshot/dom' || 'url' in options && '/snapshot' || 'sitemap' in options && '/snapshot/sitemap' || 'serve' in options && '/snapshot/server' || 'snapshots' in options && '/snapshot/list' || '/snapshot';
122
124
  let {
@@ -125,10 +127,12 @@ export function validateSnapshotOptions(options) {
125
127
  environmentInfo,
126
128
  snapshots,
127
129
  ...migrated
128
- } = PercyConfig.migrate(options, schema); // gather info for validating individual snapshot URLs
130
+ } = PercyConfig.migrate(options, schema); // maintain a trailing slash for base URLs to normalize them
131
+
132
+ if (((_migrated$baseUrl = migrated.baseUrl) === null || _migrated$baseUrl === void 0 ? void 0 : _migrated$baseUrl.endsWith('/')) === false) migrated.baseUrl += '/';
133
+ let baseUrl = schema === '/snapshot/server' ? 'http://localhost/' : migrated.baseUrl; // gather info for validating individual snapshot URLs
129
134
 
130
135
  let isSnapshot = schema === '/snapshot/dom' || schema === '/snapshot';
131
- let baseUrl = schema === '/snapshot/server' ? 'http://localhost' : options.baseUrl;
132
136
  let snaps = isSnapshot ? [migrated] : Array.isArray(snapshots) ? snapshots : [];
133
137
 
134
138
  for (let snap of snaps) validURL(typeof snap === 'string' ? snap : snap.url, baseUrl); // add back snapshots before validating and scrubbing; function snapshots are validated later
@@ -370,7 +374,14 @@ export async function* discoverSnapshotResources(percy, snapshot, callback) {
370
374
 
371
375
  let cache = percy[RESOURCE_CACHE_KEY] || (percy[RESOURCE_CACHE_KEY] = new Map()); // preload the root resource for existing dom snapshots
372
376
 
373
- let resources = new Map(snapshot.domSnapshot && [createRootResource(snapshot.url, snapshot.domSnapshot)].map(resource => [resource.url, resource])); // open a new browser page
377
+ let resources = new Map(snapshot.domSnapshot && [createRootResource(snapshot.url, snapshot.domSnapshot)].map(resource => [resource.url, resource])); // when no discovery browser is available, do not attempt to discover other resources
378
+
379
+ if (percy.skipDiscovery && !snapshot.domSnapshot) {
380
+ throw new Error('Cannot capture DOM snapshot when asset discovery is disabled');
381
+ } else if (percy.skipDiscovery) {
382
+ return handleSnapshotResources(snapshot, resources, callback);
383
+ } // open a new browser page
384
+
374
385
 
375
386
  let page = yield percy.browser.page({
376
387
  enableJavaScript: snapshot.enableJavaScript ?? !snapshot.domSnapshot,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/core",
3
- "version": "1.9.0",
3
+ "version": "1.10.1",
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.9.0",
43
- "@percy/config": "1.9.0",
44
- "@percy/dom": "1.9.0",
45
- "@percy/logger": "1.9.0",
42
+ "@percy/client": "1.10.1",
43
+ "@percy/config": "1.10.1",
44
+ "@percy/dom": "1.10.1",
45
+ "@percy/logger": "1.10.1",
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": "3332a2a63802c58848d0a5fbdd3c7aadc076212b"
56
+ "gitHead": "3e16144300e8b49aab638ceb699630f4be71bb9f"
57
57
  }