Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@percy/core

Package Overview
Dependencies
Maintainers
6
Versions
240
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@percy/core - npm Package Compare versions

Comparing version 1.0.0-beta.3 to 1.0.0-beta.4

20

dist/discoverer.js

@@ -169,11 +169,15 @@ "use strict";

meta
})); // navigate to the root URL and wait for the network to idle
}));
await page.goto(rootUrl);
await (0, _idle.default)(() => processing, this.networkIdleTimeout); // cleanup
page.removeAllListeners('request');
page.removeAllListeners('requestfailed');
page.removeAllListeners('requestfinished');
await page.close();
try {
// navigate to the root URL and wait for the network to idle
await page.goto(rootUrl);
await (0, _idle.default)(() => processing, this.networkIdleTimeout);
} finally {
// cleanup
page.removeAllListeners('request');
page.removeAllListeners('requestfailed');
page.removeAllListeners('requestfinished');
await page.close();
}
});

@@ -180,0 +184,0 @@ } // Creates a request handler for the specific root URL and DOM. The handler

136

dist/percy.js

@@ -192,19 +192,14 @@ "use strict";

_logger.default.info('Stopping percy...', meta); // clear queued page captures and wait for any pending
_logger.default.info('Stopping percy...', meta); // log about queued captures or uploads
if (_classPrivateFieldGet(this, _captures).clear()) {
_logger.default.info(`Waiting for ${_classPrivateFieldGet(this, _captures).length} page(s) to complete`, meta);
if (_classPrivateFieldGet(this, _captures).length) {
_logger.default.info(`Waiting for ${_classPrivateFieldGet(this, _captures).length} page(s) to finish snapshotting`, meta);
} else if (_classPrivateFieldGet(this, _snapshots).length) {
_logger.default.info(`Waiting for ${_classPrivateFieldGet(this, _snapshots).length} snapshot(s) to finish uploading`, meta);
} // wait for any queued captures or snapshots
await _classPrivateFieldGet(this, _captures).idle();
} // clear queued snapshots and wait for any pending
await this.idle(); // close the server and browser
if (_classPrivateFieldGet(this, _snapshots).clear()) {
_logger.default.info(`Waiting for ${_classPrivateFieldGet(this, _snapshots).length} snapshot(s) to complete`, meta);
await _classPrivateFieldGet(this, _snapshots).idle();
} // close the server and browser
(_this$server2 = this.server) === null || _this$server2 === void 0 ? void 0 : _this$server2.close();

@@ -228,4 +223,5 @@ await this.discoverer.close();

} // Handles asset discovery for the URL and DOM snapshot at each requested
// width with the provided options. Resolves when the snapshot is complete,
// although shouldn't be awaited on as snapshots are handled concurrently.
// width with the provided options. Resolves when the snapshot has been taken
// and asset discovery is finished, but does not gaurantee that the snapshot
// will be succesfully uploaded.

@@ -267,74 +263,77 @@

enableJavaScript = (_ref = (_enableJavaScript = enableJavaScript) !== null && _enableJavaScript !== void 0 ? _enableJavaScript : this.config.snapshot.enableJavaScript) !== null && _ref !== void 0 ? _ref : false; // add this snapshot task to the snapshot queue
enableJavaScript = (_ref = (_enableJavaScript = enableJavaScript) !== null && _enableJavaScript !== void 0 ? _enableJavaScript : this.config.snapshot.enableJavaScript) !== null && _ref !== void 0 ? _ref : false; // useful meta info for the logfile
return _classPrivateFieldGet(this, _snapshots).push(async () => {
let meta = {
snapshot: {
name
},
build: {
id: this.client.build.id
}
};
let meta = {
snapshot: {
name
},
build: {
id: this.client.build.id
}
};
_logger.default.debug('---------');
_logger.default.debug('---------');
_logger.default.debug('Handling snapshot:', meta);
_logger.default.debug('Handling snapshot:', meta);
_logger.default.debug(`-> name: ${name}`, meta);
_logger.default.debug(`-> name: ${name}`, meta);
_logger.default.debug(`-> url: ${url}`, meta);
_logger.default.debug(`-> url: ${url}`, meta);
_logger.default.debug(`-> widths: ${widths.join('px, ')}px`, meta);
_logger.default.debug(`-> widths: ${widths.join('px, ')}px`, meta);
_logger.default.debug(`-> clientInfo: ${clientInfo}`, meta);
_logger.default.debug(`-> clientInfo: ${clientInfo}`, meta);
_logger.default.debug(`-> environmentInfo: ${environmentInfo}`, meta);
_logger.default.debug(`-> environmentInfo: ${environmentInfo}`, meta);
_logger.default.debug(`-> requestHeaders: ${JSON.stringify(requestHeaders)}`, meta);
_logger.default.debug(`-> requestHeaders: ${JSON.stringify(requestHeaders)}`, meta);
_logger.default.debug(`-> domSnapshot:\n${domSnapshot.length <= 1024 ? domSnapshot : domSnapshot.substr(0, 1024) + '... [truncated]'}`, meta);
_logger.default.debug(`-> domSnapshot:\n${domSnapshot.length <= 1024 ? domSnapshot : domSnapshot.substr(0, 1024) + '... [truncated]'}`, meta); // use a promise as a try-catch so we can do the remaining work
// asynchronously, but perform the above synchronously
try {
// inject Percy CSS
let [percyDOM, percyCSSResource] = (0, _percyCss.default)(url, domSnapshot, percyCSS, meta); // use a map so resources remain unique by url
let resources = new Map([[url, (0, _resources.createRootResource)(url, percyDOM)]]); // gather resources at each width concurrently
return Promise.resolve().then(async () => {
// inject Percy CSS
let [percyDOM, percyCSSResource] = (0, _percyCss.default)(url, domSnapshot, percyCSS, meta); // use a map so resources remain unique by url
await Promise.all(widths.map(width => this.discoverer.gatherResources(resources, {
rootUrl: url,
rootDom: domSnapshot,
enableJavaScript,
requestHeaders,
width,
meta
}))); // convert resource map to array
let resources = new Map([[url, (0, _resources.createRootResource)(url, percyDOM)]]); // include the Percy CSS resource if there was one
resources = Array.from(resources.values()); // include the Percy CSS resource if there was one
if (percyCSSResource) resources.set('percy-css', percyCSSResource); // gather resources at each width concurrently
if (percyCSSResource) resources.push(percyCSSResource); // include a log resource for debugging
await Promise.all(widths.map(width => this.discoverer.gatherResources(resources, {
rootUrl: url,
rootDom: domSnapshot,
enableJavaScript,
requestHeaders,
width,
meta
}))); // include a log resource for debugging
let logs = await _logger.default.query({
filter: ({
snapshot: s
}) => (s === null || s === void 0 ? void 0 : s.name) === name
});
resources.push((0, _resources.createLogResource)(logs)); // create, upload, and finalize the snapshot
let logs = await _logger.default.query({
filter: ({
snapshot: s
}) => (s === null || s === void 0 ? void 0 : s.name) === name
});
resources.set('percy-logs', (0, _resources.createLogResource)(logs)); // log that the snapshot has been taken before uploading it
await this.client.sendSnapshot({
name,
widths,
minimumHeight,
enableJavaScript,
clientInfo,
environmentInfo,
resources
});
_logger.default.info(`Snapshot taken: ${name}`, meta); // upload within the async snapshot queue
_logger.default.info(`Snapshot taken: ${name}`, meta);
} catch (error) {
_logger.default.error(`Encountered an error for snapshot: ${name}`, meta);
_classPrivateFieldGet(this, _snapshots).push(() => this.client.sendSnapshot({
name,
widths,
minimumHeight,
enableJavaScript,
clientInfo,
environmentInfo,
resources: Array.from(resources.values())
}).catch(error => {
_logger.default.error(`Encountered an error uploading snapshot: ${name}`, meta);
_logger.default.error(error);
}
}));
}).catch(error => {
_logger.default.error(`Encountered an error taking snapshot: ${name}`, meta);
_logger.default.error(error);
});

@@ -357,3 +356,4 @@ }

}].concat(snapshots) : snapshots;
(0, _assert.default)(snapshots.length && snapshots.every(s => s.name), `Missing name for ${url}`);
(0, _assert.default)(snapshots.length && snapshots.every(s => s.name), `Missing name for ${url}`); // the entire capture process happens within the async capture queue
return _classPrivateFieldGet(this, _captures).push(async () => {

@@ -412,3 +412,3 @@ let results = [];

// awaiting on resulting snapshots syncs this task with those snapshot tasks
// await on any resulting snapshots
await Promise.all(results);

@@ -415,0 +415,0 @@ await ((_page = page) === null || _page === void 0 ? void 0 : _page.close());

@@ -45,6 +45,5 @@ "use strict";

res.sendFile(require.resolve('@percy/dom'));
}) // snapshot requests are concurrent by default
}) // forward snapshot requests
.post('/percy/snapshot', asyncRoute(async (req, res) => {
let snapshot = percy.snapshot(req.body);
if (req.body.concurrent === false) await snapshot;
await percy.snapshot(req.body);
res.json({

@@ -51,0 +50,0 @@ success: true

{
"name": "@percy/core",
"version": "1.0.0-beta.3",
"version": "1.0.0-beta.4",
"license": "MIT",

@@ -27,5 +27,5 @@ "main": "dist/index.js",

"dependencies": {
"@percy/client": "^1.0.0-beta.3",
"@percy/dom": "^1.0.0-beta.3",
"@percy/logger": "^1.0.0-beta.3",
"@percy/client": "^1.0.0-beta.4",
"@percy/dom": "^1.0.0-beta.4",
"@percy/logger": "^1.0.0-beta.4",
"body-parser": "^1.19.0",

@@ -42,3 +42,3 @@ "cors": "^2.8.5",

},
"gitHead": "4f66b0b984ef715774002b19bd6e767a9e50d01a"
"gitHead": "3764125115d56bfa90fcbb9f44159d75f5c5ac44"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc