@percy/core
Advanced tools
Comparing version 1.5.1 to 1.6.0
@@ -11,3 +11,3 @@ import fs from 'fs'; | ||
let pkg = getPackageJSON(import.meta.url); | ||
return Server.createServer({ | ||
let server = Server.createServer({ | ||
port | ||
@@ -33,2 +33,4 @@ }) // facilitate logger websocket connections | ||
.route((req, res, next) => { | ||
var _percy$testing, _percy$testing3, _percy$testing3$api, _percy$testing4, _percy$testing4$api; | ||
// treat all request bodies as json | ||
@@ -39,5 +41,21 @@ if (req.body) try { | ||
res.setHeader('Access-Control-Expose-Headers', '*, X-Percy-Core-Version'); | ||
res.setHeader('X-Percy-Core-Version', pkg.version); // return json errors | ||
res.setHeader('Access-Control-Expose-Headers', '*, X-Percy-Core-Version'); // skip or change api version header in testing mode | ||
if (((_percy$testing = percy.testing) === null || _percy$testing === void 0 ? void 0 : _percy$testing.version) !== false) { | ||
var _percy$testing2; | ||
res.setHeader('X-Percy-Core-Version', ((_percy$testing2 = percy.testing) === null || _percy$testing2 === void 0 ? void 0 : _percy$testing2.version) ?? pkg.version); | ||
} // support sabotaging requests in testing mode | ||
if (((_percy$testing3 = percy.testing) === null || _percy$testing3 === void 0 ? void 0 : (_percy$testing3$api = _percy$testing3.api) === null || _percy$testing3$api === void 0 ? void 0 : _percy$testing3$api[req.url.pathname]) === 'error') { | ||
return res.json(500, { | ||
success: false, | ||
error: 'Error: testing' | ||
}); | ||
} else if (((_percy$testing4 = percy.testing) === null || _percy$testing4 === void 0 ? void 0 : (_percy$testing4$api = _percy$testing4.api) === null || _percy$testing4$api === void 0 ? void 0 : _percy$testing4$api[req.url.pathname]) === 'disconnect') { | ||
return req.connection.destroy(); | ||
} // return json errors | ||
return next().catch(e => res.json(e.status ?? 500, { | ||
@@ -83,2 +101,38 @@ build: percy.build, | ||
}); | ||
}); // add test endpoints only in testing mode | ||
return !percy.testing ? server : server // manipulates testing mode configuration to trigger specific scenarios | ||
.route('/test/api/:cmd', ({ | ||
body, | ||
params: { | ||
cmd | ||
} | ||
}, res) => { | ||
body = Buffer.isBuffer(body) ? body.toString() : body; | ||
if (cmd === 'reset') { | ||
// the reset command will reset testing mode to its default options | ||
percy.testing = {}; | ||
} else if (cmd === 'version') { | ||
// the version command will update the api version header for testing | ||
percy.testing.version = body; | ||
} else if (cmd === 'error' || cmd === 'disconnect') { | ||
// the error or disconnect commands will cause specific endpoints to fail | ||
percy.testing.api = { ...percy.testing.api, | ||
[body]: cmd | ||
}; | ||
} else { | ||
// 404 for unknown commands | ||
return res.send(404); | ||
} | ||
return res.json(200, { | ||
testing: percy.testing | ||
}); | ||
}) // returns an array of raw logs from the logger | ||
.route('get', '/test/logs', (req, res) => res.json(200, { | ||
logs: Array.from(logger.instance.messages) | ||
})) // serves a very basic html page for testing snapshots | ||
.route('get', '/test/snapshot', (req, res) => { | ||
return res.send(200, 'text/html', '<p>Snapshot Me!</p>'); | ||
}); | ||
@@ -85,0 +139,0 @@ } // Create a static server instance with an automatic sitemap |
@@ -34,2 +34,4 @@ import PercyClient from '@percy/client'; | ||
dryRun, | ||
// implies `dryRun`, silent logs, and adds extra api endpoints | ||
testing, | ||
// configuration filepath | ||
@@ -48,4 +50,6 @@ config, | ||
} = {}) { | ||
if (testing) loglevel = 'silent'; | ||
if (loglevel) this.loglevel(loglevel); | ||
this.dryRun = !!dryRun; | ||
this.testing = testing ? {} : null; | ||
this.dryRun = !!testing || !!dryRun; | ||
this.skipUploads = this.dryRun || !!skipUploads; | ||
@@ -52,0 +56,0 @@ this.deferUploads = this.skipUploads || !!deferUploads; |
{ | ||
"name": "@percy/core", | ||
"version": "1.5.1", | ||
"version": "1.6.0", | ||
"license": "MIT", | ||
@@ -42,6 +42,6 @@ "repository": { | ||
"dependencies": { | ||
"@percy/client": "1.5.1", | ||
"@percy/config": "1.5.1", | ||
"@percy/dom": "1.5.1", | ||
"@percy/logger": "1.5.1", | ||
"@percy/client": "1.6.0", | ||
"@percy/config": "1.6.0", | ||
"@percy/dom": "1.6.0", | ||
"@percy/logger": "1.6.0", | ||
"content-disposition": "^0.5.4", | ||
@@ -57,3 +57,3 @@ "cross-spawn": "^7.0.3", | ||
}, | ||
"gitHead": "c67c0d482d3da18e529f7bc2e1c219c04e59bbea" | ||
"gitHead": "dd03aec4a68a26425cda3afd10fa142011198b5f" | ||
} |
@@ -10,3 +10,3 @@ export async function request(url, method = 'GET', handle) { | ||
} catch (error) { | ||
if (typeof handle !== 'boolean') throw error; | ||
if (!error.response || typeof handle !== 'boolean') throw error; | ||
return handle ? [error.response.body, error.response] : error.response; | ||
@@ -13,0 +13,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
147121
3286
+ Added@percy/client@1.6.0(transitive)
+ Added@percy/config@1.6.0(transitive)
+ Added@percy/dom@1.6.0(transitive)
+ Added@percy/env@1.6.0(transitive)
+ Added@percy/logger@1.6.0(transitive)
- Removed@percy/client@1.5.1(transitive)
- Removed@percy/config@1.5.1(transitive)
- Removed@percy/dom@1.5.1(transitive)
- Removed@percy/env@1.5.1(transitive)
- Removed@percy/logger@1.5.1(transitive)
Updated@percy/client@1.6.0
Updated@percy/config@1.6.0
Updated@percy/dom@1.6.0
Updated@percy/logger@1.6.0