@percy/core 1.7.2 → 1.9.0
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 +80 -29
- package/package.json +6 -6
- package/types/index.d.ts +2 -0
package/dist/api.js
CHANGED
|
@@ -12,6 +12,18 @@ export function createPercyServer(percy, port) {
|
|
|
12
12
|
port
|
|
13
13
|
}) // facilitate logger websocket connections
|
|
14
14
|
.websocket('/(logger)?', ws => {
|
|
15
|
+
var _percy$testing, _percy$testing2;
|
|
16
|
+
|
|
17
|
+
// support sabotaging remote logging connections in testing mode
|
|
18
|
+
if (((_percy$testing = percy.testing) === null || _percy$testing === void 0 ? void 0 : _percy$testing.remoteLogging) === false) return ws.terminate(); // track all remote logging connections in testing mode
|
|
19
|
+
|
|
20
|
+
if (percy.testing) ((_percy$testing2 = percy.testing).remoteLoggers || (_percy$testing2.remoteLoggers = new Set())).add(ws);
|
|
21
|
+
ws.addEventListener('close', () => {
|
|
22
|
+
var _percy$testing3, _percy$testing3$remot;
|
|
23
|
+
|
|
24
|
+
return (_percy$testing3 = percy.testing) === null || _percy$testing3 === void 0 ? void 0 : (_percy$testing3$remot = _percy$testing3.remoteLoggers) === null || _percy$testing3$remot === void 0 ? void 0 : _percy$testing3$remot.delete(ws);
|
|
25
|
+
}); // listen for messages with specific logging payloads
|
|
26
|
+
|
|
15
27
|
ws.addEventListener('message', ({
|
|
16
28
|
data
|
|
17
29
|
}) => {
|
|
@@ -23,13 +35,14 @@ export function createPercyServer(percy, port) {
|
|
|
23
35
|
for (let m of messages) logger.instance.messages.add(m);
|
|
24
36
|
|
|
25
37
|
if (log) logger.instance.log(...log);
|
|
26
|
-
});
|
|
38
|
+
}); // respond with the current loglevel
|
|
39
|
+
|
|
27
40
|
ws.send(JSON.stringify({
|
|
28
41
|
loglevel: logger.loglevel()
|
|
29
42
|
}));
|
|
30
43
|
}) // general middleware
|
|
31
44
|
.route((req, res, next) => {
|
|
32
|
-
var _percy$
|
|
45
|
+
var _percy$testing4, _percy$testing7, _percy$testing7$api, _percy$testing8, _percy$testing8$api;
|
|
33
46
|
|
|
34
47
|
// treat all request bodies as json
|
|
35
48
|
if (req.body) try {
|
|
@@ -38,35 +51,55 @@ export function createPercyServer(percy, port) {
|
|
|
38
51
|
|
|
39
52
|
res.setHeader('Access-Control-Expose-Headers', '*, X-Percy-Core-Version'); // skip or change api version header in testing mode
|
|
40
53
|
|
|
41
|
-
if (((_percy$
|
|
42
|
-
var _percy$
|
|
54
|
+
if (((_percy$testing4 = percy.testing) === null || _percy$testing4 === void 0 ? void 0 : _percy$testing4.version) !== false) {
|
|
55
|
+
var _percy$testing5;
|
|
43
56
|
|
|
44
|
-
res.setHeader('X-Percy-Core-Version', ((_percy$
|
|
45
|
-
} //
|
|
57
|
+
res.setHeader('X-Percy-Core-Version', ((_percy$testing5 = percy.testing) === null || _percy$testing5 === void 0 ? void 0 : _percy$testing5.version) ?? pkg.version);
|
|
58
|
+
} // track all api reqeusts in testing mode
|
|
46
59
|
|
|
47
60
|
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
61
|
+
if (percy.testing && !req.url.pathname.startsWith('/test/')) {
|
|
62
|
+
var _percy$testing6;
|
|
63
|
+
|
|
64
|
+
((_percy$testing6 = percy.testing).requests || (_percy$testing6.requests = [])).push({
|
|
65
|
+
url: `${req.url.pathname}${req.url.search}`,
|
|
66
|
+
method: req.method,
|
|
67
|
+
body: req.body
|
|
52
68
|
});
|
|
53
|
-
}
|
|
54
|
-
|
|
69
|
+
} // support sabotaging requests in testing mode
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if (((_percy$testing7 = percy.testing) === null || _percy$testing7 === void 0 ? void 0 : (_percy$testing7$api = _percy$testing7.api) === null || _percy$testing7$api === void 0 ? void 0 : _percy$testing7$api[req.url.pathname]) === 'error') {
|
|
73
|
+
next = () => {
|
|
74
|
+
var _percy$testing$build;
|
|
75
|
+
|
|
76
|
+
return Promise.reject(new Error(((_percy$testing$build = percy.testing.build) === null || _percy$testing$build === void 0 ? void 0 : _percy$testing$build.error) || 'testing'));
|
|
77
|
+
};
|
|
78
|
+
} else if (((_percy$testing8 = percy.testing) === null || _percy$testing8 === void 0 ? void 0 : (_percy$testing8$api = _percy$testing8.api) === null || _percy$testing8$api === void 0 ? void 0 : _percy$testing8$api[req.url.pathname]) === 'disconnect') {
|
|
79
|
+
next = () => req.connection.destroy();
|
|
55
80
|
} // return json errors
|
|
56
81
|
|
|
57
82
|
|
|
58
|
-
return next().catch(e =>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
83
|
+
return next().catch(e => {
|
|
84
|
+
var _percy$testing9;
|
|
85
|
+
|
|
86
|
+
return res.json(e.status ?? 500, {
|
|
87
|
+
build: ((_percy$testing9 = percy.testing) === null || _percy$testing9 === void 0 ? void 0 : _percy$testing9.build) || percy.build,
|
|
88
|
+
error: e.message,
|
|
89
|
+
success: false
|
|
90
|
+
});
|
|
91
|
+
});
|
|
63
92
|
}) // healthcheck returns basic information
|
|
64
|
-
.route('get', '/percy/healthcheck', (req, res) =>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
93
|
+
.route('get', '/percy/healthcheck', (req, res) => {
|
|
94
|
+
var _percy$testing10;
|
|
95
|
+
|
|
96
|
+
return res.json(200, {
|
|
97
|
+
build: ((_percy$testing10 = percy.testing) === null || _percy$testing10 === void 0 ? void 0 : _percy$testing10.build) ?? percy.build,
|
|
98
|
+
loglevel: percy.loglevel(),
|
|
99
|
+
config: percy.config,
|
|
100
|
+
success: true
|
|
101
|
+
});
|
|
102
|
+
}) // get or set config options
|
|
70
103
|
.route(['get', 'post'], '/percy/config', async (req, res) => res.json(200, {
|
|
71
104
|
config: req.body ? await percy.setConfig(req.body) : percy.config,
|
|
72
105
|
success: true
|
|
@@ -107,26 +140,44 @@ export function createPercyServer(percy, port) {
|
|
|
107
140
|
body = Buffer.isBuffer(body) ? body.toString() : body;
|
|
108
141
|
|
|
109
142
|
if (cmd === 'reset') {
|
|
110
|
-
|
|
111
|
-
|
|
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());
|
|
112
147
|
logger.instance.messages.clear();
|
|
148
|
+
percy.testing = {};
|
|
113
149
|
} else if (cmd === 'version') {
|
|
114
150
|
// the version command will update the api version header for testing
|
|
115
151
|
percy.testing.version = body;
|
|
116
152
|
} else if (cmd === 'error' || cmd === 'disconnect') {
|
|
153
|
+
var _percy$testing11;
|
|
154
|
+
|
|
117
155
|
// the error or disconnect commands will cause specific endpoints to fail
|
|
118
|
-
percy.testing.api = {
|
|
119
|
-
|
|
156
|
+
((_percy$testing11 = percy.testing).api || (_percy$testing11.api = {}))[body] = cmd;
|
|
157
|
+
} else if (cmd === 'build-failure') {
|
|
158
|
+
// the build-failure command will cause api errors to include a failed build
|
|
159
|
+
percy.testing.build = {
|
|
160
|
+
failed: true,
|
|
161
|
+
error: 'Build failed'
|
|
120
162
|
};
|
|
163
|
+
} else if (cmd === 'remote-logging') {
|
|
164
|
+
var _percy$testing$remote2;
|
|
165
|
+
|
|
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());
|
|
168
|
+
percy.testing.remoteLogging = body;
|
|
121
169
|
} else {
|
|
122
170
|
// 404 for unknown commands
|
|
123
171
|
return res.send(404);
|
|
124
172
|
}
|
|
125
173
|
|
|
126
174
|
return res.json(200, {
|
|
127
|
-
|
|
175
|
+
success: true
|
|
128
176
|
});
|
|
129
|
-
}) // returns an array of raw
|
|
177
|
+
}) // returns an array of raw requests made to the api
|
|
178
|
+
.route('get', '/test/requests', (req, res) => res.json(200, {
|
|
179
|
+
requests: percy.testing.requests
|
|
180
|
+
})) // returns an array of raw logs from the logger
|
|
130
181
|
.route('get', '/test/logs', (req, res) => res.json(200, {
|
|
131
182
|
logs: Array.from(logger.instance.messages)
|
|
132
183
|
})) // serves a very basic html page for testing snapshots
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
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.
|
|
43
|
-
"@percy/config": "1.
|
|
44
|
-
"@percy/dom": "1.
|
|
45
|
-
"@percy/logger": "1.
|
|
42
|
+
"@percy/client": "1.9.0",
|
|
43
|
+
"@percy/config": "1.9.0",
|
|
44
|
+
"@percy/dom": "1.9.0",
|
|
45
|
+
"@percy/logger": "1.9.0",
|
|
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": "
|
|
56
|
+
"gitHead": "3332a2a63802c58848d0a5fbdd3c7aadc076212b"
|
|
57
57
|
}
|
package/types/index.d.ts
CHANGED