@percy/sdk-utils 1.11.0 → 1.13.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/bundle.js +23 -37
- package/dist/flush-snapshots.js +0 -5
- package/dist/index.js +0 -14
- package/dist/logger.js +6 -5
- package/dist/percy-dom.js +0 -6
- package/dist/percy-enabled.js +0 -9
- package/dist/percy-idle.js +0 -5
- package/dist/percy-info.js +4 -14
- package/dist/post-comparison.js +0 -6
- package/dist/post-snapshot.js +0 -6
- package/dist/request.js +7 -16
- package/package.json +2 -2
- package/test/client.js +0 -8
package/dist/bundle.js
CHANGED
|
@@ -12,15 +12,15 @@
|
|
|
12
12
|
info: 1,
|
|
13
13
|
warn: 2,
|
|
14
14
|
error: 3
|
|
15
|
-
};
|
|
15
|
+
};
|
|
16
16
|
|
|
17
|
+
// Create a small logger util using the specified namespace
|
|
17
18
|
function logger(namespace) {
|
|
18
19
|
return Object.keys(LOG_LEVELS).reduce((ns, lvl) => Object.assign(ns, {
|
|
19
20
|
[lvl]: function () {
|
|
20
21
|
for (var _len = arguments.length, a = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
21
22
|
a[_key] = arguments[_key];
|
|
22
23
|
}
|
|
23
|
-
|
|
24
24
|
return logger.log(namespace, lvl, ...a);
|
|
25
25
|
}
|
|
26
26
|
}), {});
|
|
@@ -33,15 +33,16 @@
|
|
|
33
33
|
},
|
|
34
34
|
// Track and send/write logs for the specified namespace and log level
|
|
35
35
|
log: (ns, lvl, msg, meta) => {
|
|
36
|
-
let err = typeof msg !== 'string' && (lvl === 'error' || lvl === 'debug');
|
|
36
|
+
let err = typeof msg !== 'string' && (lvl === 'error' || lvl === 'debug');
|
|
37
37
|
|
|
38
|
+
// check if the specific level is within the local loglevel range
|
|
38
39
|
if (LOG_LEVELS[lvl] != null && LOG_LEVELS[lvl] >= LOG_LEVELS[logger.loglevel()]) {
|
|
39
40
|
let debug = logger.loglevel() === 'debug';
|
|
40
|
-
let label = debug ? `percy:${ns}` : 'percy';
|
|
41
|
+
let label = debug ? `percy:${ns}` : 'percy';
|
|
41
42
|
|
|
43
|
+
// colorize the label when possible for consistency with the CLI logger
|
|
42
44
|
if (!process.env.__PERCY_BROWSERIFIED__) label = `\u001b[95m${label}\u001b[39m`;
|
|
43
45
|
msg = `[${label}] ${err && debug && msg.stack || msg}`;
|
|
44
|
-
|
|
45
46
|
if (process.env.__PERCY_BROWSERIFIED__) {
|
|
46
47
|
// use console[warn|error|log] in browsers
|
|
47
48
|
console[['warn', 'error'].includes(lvl) ? lvl : 'log'](msg);
|
|
@@ -64,89 +65,78 @@
|
|
|
64
65
|
get major() {
|
|
65
66
|
return this[0] || 0;
|
|
66
67
|
},
|
|
67
|
-
|
|
68
68
|
get minor() {
|
|
69
69
|
return this[1] || 0;
|
|
70
70
|
},
|
|
71
|
-
|
|
72
71
|
get patch() {
|
|
73
72
|
return this[2] || 0;
|
|
74
73
|
},
|
|
75
|
-
|
|
76
74
|
get prerelease() {
|
|
77
75
|
return this[3];
|
|
78
76
|
},
|
|
79
|
-
|
|
80
77
|
get build() {
|
|
81
78
|
return this[4];
|
|
82
79
|
},
|
|
83
|
-
|
|
84
80
|
toString() {
|
|
85
81
|
return str;
|
|
86
82
|
}
|
|
87
|
-
|
|
88
83
|
});
|
|
89
|
-
}
|
|
90
|
-
|
|
84
|
+
}
|
|
91
85
|
|
|
92
|
-
|
|
86
|
+
// private version cache
|
|
87
|
+
let version = toVersion();
|
|
93
88
|
|
|
89
|
+
// contains local percy info
|
|
94
90
|
const info = {
|
|
95
91
|
// get or set the CLI API address via the environment
|
|
96
92
|
get address() {
|
|
97
93
|
return process.env.PERCY_SERVER_ADDRESS || 'http://localhost:5338';
|
|
98
94
|
},
|
|
99
|
-
|
|
100
95
|
set address(addr) {
|
|
101
96
|
return process.env.PERCY_SERVER_ADDRESS = addr;
|
|
102
97
|
},
|
|
103
|
-
|
|
104
98
|
// version information
|
|
105
99
|
get version() {
|
|
106
100
|
return version;
|
|
107
101
|
},
|
|
108
|
-
|
|
109
102
|
set version(v) {
|
|
110
103
|
return version = toVersion(v);
|
|
111
104
|
}
|
|
112
|
-
|
|
113
105
|
};
|
|
114
106
|
|
|
107
|
+
// Helper to send a request to the local CLI API
|
|
115
108
|
async function request(path) {
|
|
116
109
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
117
|
-
let response = await request.fetch(`${info.address}${path}`, options);
|
|
110
|
+
let response = await request.fetch(`${info.address}${path}`, options);
|
|
118
111
|
|
|
112
|
+
// maybe parse response body as json
|
|
119
113
|
if (typeof response.body === 'string' && response.headers['content-type'] === 'application/json') {
|
|
120
114
|
try {
|
|
121
115
|
response.body = JSON.parse(response.body);
|
|
122
116
|
} catch (e) {}
|
|
123
|
-
}
|
|
124
|
-
|
|
117
|
+
}
|
|
125
118
|
|
|
119
|
+
// throw an error if status is not ok
|
|
126
120
|
if (!(response.status >= 200 && response.status < 300)) {
|
|
127
121
|
throw Object.assign(new Error(), {
|
|
128
|
-
message: response.body.error ||
|
|
129
|
-
/* istanbul ignore next: in tests, there's always an error message */
|
|
122
|
+
message: response.body.error || /* istanbul ignore next: in tests, there's always an error message */
|
|
130
123
|
`${response.status} ${response.statusText}`,
|
|
131
124
|
response
|
|
132
125
|
});
|
|
133
126
|
}
|
|
134
|
-
|
|
135
127
|
return response;
|
|
136
128
|
}
|
|
137
|
-
|
|
138
129
|
request.post = function post(url, json) {
|
|
139
130
|
return request(url, {
|
|
140
131
|
method: 'POST',
|
|
141
132
|
body: JSON.stringify(json)
|
|
142
133
|
});
|
|
143
|
-
};
|
|
144
|
-
|
|
134
|
+
};
|
|
145
135
|
|
|
136
|
+
// environment specific implementation
|
|
146
137
|
if (process.env.__PERCY_BROWSERIFIED__) {
|
|
147
138
|
// use window.fetch in browsers
|
|
148
139
|
const winFetch = window.fetch;
|
|
149
|
-
|
|
150
140
|
request.fetch = async function fetch(url, options) {
|
|
151
141
|
let response = await winFetch(url, options);
|
|
152
142
|
return {
|
|
@@ -177,11 +167,11 @@
|
|
|
177
167
|
};
|
|
178
168
|
}
|
|
179
169
|
|
|
170
|
+
// Check if Percy is enabled using the healthcheck endpoint
|
|
180
171
|
async function isPercyEnabled() {
|
|
181
172
|
if (info.enabled == null) {
|
|
182
173
|
let log = logger('utils');
|
|
183
174
|
let error;
|
|
184
|
-
|
|
185
175
|
try {
|
|
186
176
|
let response = await request('/percy/healthcheck');
|
|
187
177
|
info.version = response.headers['x-percy-core-version'];
|
|
@@ -191,7 +181,6 @@
|
|
|
191
181
|
info.enabled = false;
|
|
192
182
|
error = e;
|
|
193
183
|
}
|
|
194
|
-
|
|
195
184
|
if (info.enabled && info.version.major !== 1) {
|
|
196
185
|
log.info('Unsupported Percy CLI version, disabling snapshots');
|
|
197
186
|
log.debug(`Found version: ${info.version}`);
|
|
@@ -201,7 +190,6 @@
|
|
|
201
190
|
log.debug(error);
|
|
202
191
|
}
|
|
203
192
|
}
|
|
204
|
-
|
|
205
193
|
return info.enabled;
|
|
206
194
|
}
|
|
207
195
|
|
|
@@ -214,22 +202,21 @@
|
|
|
214
202
|
}
|
|
215
203
|
}
|
|
216
204
|
|
|
205
|
+
// Fetch and cache the @percy/dom script
|
|
217
206
|
async function fetchPercyDOM() {
|
|
218
207
|
if (info.domScript == null) {
|
|
219
208
|
let response = await request('/percy/dom.js');
|
|
220
209
|
info.domScript = response.body;
|
|
221
210
|
}
|
|
222
|
-
|
|
223
211
|
return info.domScript;
|
|
224
212
|
}
|
|
225
213
|
|
|
214
|
+
// Post snapshot data to the CLI snapshot endpoint. If the endpoint responds with a build error,
|
|
226
215
|
// indicate that Percy has been disabled.
|
|
227
|
-
|
|
228
216
|
async function postSnapshot(options, params) {
|
|
229
217
|
let query = params ? `?${new URLSearchParams(params)}` : '';
|
|
230
218
|
await request.post(`/percy/snapshot${query}`, options).catch(err => {
|
|
231
219
|
var _err$response, _err$response$body, _err$response$body$bu;
|
|
232
|
-
|
|
233
220
|
if ((_err$response = err.response) !== null && _err$response !== void 0 && (_err$response$body = _err$response.body) !== null && _err$response$body !== void 0 && (_err$response$body$bu = _err$response$body.build) !== null && _err$response$body$bu !== void 0 && _err$response$body$bu.error) {
|
|
234
221
|
info.enabled = false;
|
|
235
222
|
} else {
|
|
@@ -238,13 +225,12 @@
|
|
|
238
225
|
});
|
|
239
226
|
}
|
|
240
227
|
|
|
228
|
+
// Post snapshot data to the CLI snapshot endpoint. If the endpoint responds with a build error,
|
|
241
229
|
// indicate that Percy has been disabled.
|
|
242
|
-
|
|
243
230
|
async function postComparison(options, params) {
|
|
244
231
|
let query = params ? `?${new URLSearchParams(params)}` : '';
|
|
245
232
|
await request.post(`/percy/comparison${query}`, options).catch(err => {
|
|
246
233
|
var _err$response, _err$response$body, _err$response$body$bu;
|
|
247
|
-
|
|
248
234
|
if ((_err$response = err.response) !== null && _err$response !== void 0 && (_err$response$body = _err$response.body) !== null && _err$response$body !== void 0 && (_err$response$body$bu = _err$response$body.build) !== null && _err$response$body$bu !== void 0 && _err$response$body$bu.error) {
|
|
249
235
|
info.enabled = false;
|
|
250
236
|
} else {
|
|
@@ -253,8 +239,8 @@
|
|
|
253
239
|
});
|
|
254
240
|
}
|
|
255
241
|
|
|
242
|
+
// Posts to the local Percy server one or more snapshots to flush. Given no arguments, all snapshots
|
|
256
243
|
// will be flushed. Does nothing when Percy is not enabled.
|
|
257
|
-
|
|
258
244
|
async function flushSnapshots(options) {
|
|
259
245
|
if (info.enabled) {
|
|
260
246
|
// accept one or more snapshot names
|
package/dist/flush-snapshots.js
CHANGED
|
@@ -5,13 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.flushSnapshots = flushSnapshots;
|
|
8
|
-
|
|
9
8
|
var _percyInfo = _interopRequireDefault(require("./percy-info.js"));
|
|
10
|
-
|
|
11
9
|
var _request = _interopRequireDefault(require("./request.js"));
|
|
12
|
-
|
|
13
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
11
|
// Posts to the local Percy server one or more snapshots to flush. Given no arguments, all snapshots
|
|
16
12
|
// will be flushed. Does nothing when Percy is not enabled.
|
|
17
13
|
async function flushSnapshots(options) {
|
|
@@ -23,6 +19,5 @@ async function flushSnapshots(options) {
|
|
|
23
19
|
await _request.default.post('/percy/flush', options);
|
|
24
20
|
}
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
var _default = flushSnapshots;
|
|
28
23
|
exports.default = _default;
|
package/dist/index.js
CHANGED
|
@@ -58,31 +58,17 @@ Object.defineProperty(exports, "waitForPercyIdle", {
|
|
|
58
58
|
return _percyIdle.default;
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
|
-
|
|
62
61
|
var _logger = _interopRequireDefault(require("./logger.js"));
|
|
63
|
-
|
|
64
62
|
var _percyInfo = _interopRequireDefault(require("./percy-info.js"));
|
|
65
|
-
|
|
66
63
|
var _request = _interopRequireDefault(require("./request.js"));
|
|
67
|
-
|
|
68
64
|
var _percyEnabled = _interopRequireDefault(require("./percy-enabled.js"));
|
|
69
|
-
|
|
70
65
|
var _percyIdle = _interopRequireDefault(require("./percy-idle.js"));
|
|
71
|
-
|
|
72
66
|
var _percyDom = _interopRequireDefault(require("./percy-dom.js"));
|
|
73
|
-
|
|
74
67
|
var _postSnapshot = _interopRequireDefault(require("./post-snapshot.js"));
|
|
75
|
-
|
|
76
68
|
var _postComparison = _interopRequireDefault(require("./post-comparison.js"));
|
|
77
|
-
|
|
78
69
|
var _flushSnapshots = _interopRequireDefault(require("./flush-snapshots.js"));
|
|
79
|
-
|
|
80
70
|
var _default = _interopRequireWildcard(require("./index.js"));
|
|
81
|
-
|
|
82
71
|
exports.default = _default;
|
|
83
|
-
|
|
84
72
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
85
|
-
|
|
86
73
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
87
|
-
|
|
88
74
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/dist/logger.js
CHANGED
|
@@ -11,14 +11,14 @@ const LOG_LEVELS = {
|
|
|
11
11
|
info: 1,
|
|
12
12
|
warn: 2,
|
|
13
13
|
error: 3
|
|
14
|
-
};
|
|
14
|
+
};
|
|
15
15
|
|
|
16
|
+
// Create a small logger util using the specified namespace
|
|
16
17
|
function logger(namespace) {
|
|
17
18
|
return Object.keys(LOG_LEVELS).reduce((ns, lvl) => Object.assign(ns, {
|
|
18
19
|
[lvl]: (...a) => logger.log(namespace, lvl, ...a)
|
|
19
20
|
}), {});
|
|
20
21
|
}
|
|
21
|
-
|
|
22
22
|
Object.assign(logger, {
|
|
23
23
|
// Set and/or return the local loglevel
|
|
24
24
|
loglevel: (lvl = logger.loglevel.lvl) => {
|
|
@@ -26,15 +26,16 @@ Object.assign(logger, {
|
|
|
26
26
|
},
|
|
27
27
|
// Track and send/write logs for the specified namespace and log level
|
|
28
28
|
log: (ns, lvl, msg, meta) => {
|
|
29
|
-
let err = typeof msg !== 'string' && (lvl === 'error' || lvl === 'debug');
|
|
29
|
+
let err = typeof msg !== 'string' && (lvl === 'error' || lvl === 'debug');
|
|
30
30
|
|
|
31
|
+
// check if the specific level is within the local loglevel range
|
|
31
32
|
if (LOG_LEVELS[lvl] != null && LOG_LEVELS[lvl] >= LOG_LEVELS[logger.loglevel()]) {
|
|
32
33
|
let debug = logger.loglevel() === 'debug';
|
|
33
|
-
let label = debug ? `percy:${ns}` : 'percy';
|
|
34
|
+
let label = debug ? `percy:${ns}` : 'percy';
|
|
34
35
|
|
|
36
|
+
// colorize the label when possible for consistency with the CLI logger
|
|
35
37
|
if (!process.env.__PERCY_BROWSERIFIED__) label = `\u001b[95m${label}\u001b[39m`;
|
|
36
38
|
msg = `[${label}] ${err && debug && msg.stack || msg}`;
|
|
37
|
-
|
|
38
39
|
if (process.env.__PERCY_BROWSERIFIED__) {
|
|
39
40
|
// use console[warn|error|log] in browsers
|
|
40
41
|
console[['warn', 'error'].includes(lvl) ? lvl : 'log'](msg);
|
package/dist/percy-dom.js
CHANGED
|
@@ -5,22 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.fetchPercyDOM = fetchPercyDOM;
|
|
8
|
-
|
|
9
8
|
var _percyInfo = _interopRequireDefault(require("./percy-info.js"));
|
|
10
|
-
|
|
11
9
|
var _request = _interopRequireDefault(require("./request.js"));
|
|
12
|
-
|
|
13
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
11
|
// Fetch and cache the @percy/dom script
|
|
16
12
|
async function fetchPercyDOM() {
|
|
17
13
|
if (_percyInfo.default.domScript == null) {
|
|
18
14
|
let response = await (0, _request.default)('/percy/dom.js');
|
|
19
15
|
_percyInfo.default.domScript = response.body;
|
|
20
16
|
}
|
|
21
|
-
|
|
22
17
|
return _percyInfo.default.domScript;
|
|
23
18
|
}
|
|
24
|
-
|
|
25
19
|
var _default = fetchPercyDOM;
|
|
26
20
|
exports.default = _default;
|
package/dist/percy-enabled.js
CHANGED
|
@@ -5,21 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.isPercyEnabled = isPercyEnabled;
|
|
8
|
-
|
|
9
8
|
var _percyInfo = _interopRequireDefault(require("./percy-info.js"));
|
|
10
|
-
|
|
11
9
|
var _request = _interopRequireDefault(require("./request.js"));
|
|
12
|
-
|
|
13
10
|
var _logger = _interopRequireDefault(require("./logger.js"));
|
|
14
|
-
|
|
15
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
12
|
// Check if Percy is enabled using the healthcheck endpoint
|
|
18
13
|
async function isPercyEnabled() {
|
|
19
14
|
if (_percyInfo.default.enabled == null) {
|
|
20
15
|
let log = (0, _logger.default)('utils');
|
|
21
16
|
let error;
|
|
22
|
-
|
|
23
17
|
try {
|
|
24
18
|
let response = await (0, _request.default)('/percy/healthcheck');
|
|
25
19
|
_percyInfo.default.version = response.headers['x-percy-core-version'];
|
|
@@ -29,7 +23,6 @@ async function isPercyEnabled() {
|
|
|
29
23
|
_percyInfo.default.enabled = false;
|
|
30
24
|
error = e;
|
|
31
25
|
}
|
|
32
|
-
|
|
33
26
|
if (_percyInfo.default.enabled && _percyInfo.default.version.major !== 1) {
|
|
34
27
|
log.info('Unsupported Percy CLI version, disabling snapshots');
|
|
35
28
|
log.debug(`Found version: ${_percyInfo.default.version}`);
|
|
@@ -39,9 +32,7 @@ async function isPercyEnabled() {
|
|
|
39
32
|
log.debug(error);
|
|
40
33
|
}
|
|
41
34
|
}
|
|
42
|
-
|
|
43
35
|
return _percyInfo.default.enabled;
|
|
44
36
|
}
|
|
45
|
-
|
|
46
37
|
var _default = isPercyEnabled;
|
|
47
38
|
exports.default = _default;
|
package/dist/percy-idle.js
CHANGED
|
@@ -5,13 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.waitForPercyIdle = waitForPercyIdle;
|
|
8
|
-
|
|
9
8
|
var _request = _interopRequireDefault(require("./request.js"));
|
|
10
|
-
|
|
11
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
|
|
13
10
|
const RETRY_ERROR_CODES = ['ECONNRESET', 'ETIMEDOUT'];
|
|
14
|
-
|
|
15
11
|
async function waitForPercyIdle() {
|
|
16
12
|
try {
|
|
17
13
|
return !!(await (0, _request.default)('/percy/idle'));
|
|
@@ -19,6 +15,5 @@ async function waitForPercyIdle() {
|
|
|
19
15
|
return RETRY_ERROR_CODES.includes(e.code) && waitForPercyIdle();
|
|
20
16
|
}
|
|
21
17
|
}
|
|
22
|
-
|
|
23
18
|
var _default = waitForPercyIdle;
|
|
24
19
|
exports.default = _default;
|
package/dist/percy-info.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
// helper to create a version object from a string
|
|
9
8
|
function toVersion(str) {
|
|
10
9
|
str || (str = '0.0.0');
|
|
@@ -16,52 +15,43 @@ function toVersion(str) {
|
|
|
16
15
|
get major() {
|
|
17
16
|
return this[0] || 0;
|
|
18
17
|
},
|
|
19
|
-
|
|
20
18
|
get minor() {
|
|
21
19
|
return this[1] || 0;
|
|
22
20
|
},
|
|
23
|
-
|
|
24
21
|
get patch() {
|
|
25
22
|
return this[2] || 0;
|
|
26
23
|
},
|
|
27
|
-
|
|
28
24
|
get prerelease() {
|
|
29
25
|
return this[3];
|
|
30
26
|
},
|
|
31
|
-
|
|
32
27
|
get build() {
|
|
33
28
|
return this[4];
|
|
34
29
|
},
|
|
35
|
-
|
|
36
30
|
toString() {
|
|
37
31
|
return str;
|
|
38
32
|
}
|
|
39
|
-
|
|
40
33
|
});
|
|
41
|
-
}
|
|
42
|
-
|
|
34
|
+
}
|
|
43
35
|
|
|
44
|
-
|
|
36
|
+
// private version cache
|
|
37
|
+
let version = toVersion();
|
|
45
38
|
|
|
39
|
+
// contains local percy info
|
|
46
40
|
const info = {
|
|
47
41
|
// get or set the CLI API address via the environment
|
|
48
42
|
get address() {
|
|
49
43
|
return process.env.PERCY_SERVER_ADDRESS || 'http://localhost:5338';
|
|
50
44
|
},
|
|
51
|
-
|
|
52
45
|
set address(addr) {
|
|
53
46
|
return process.env.PERCY_SERVER_ADDRESS = addr;
|
|
54
47
|
},
|
|
55
|
-
|
|
56
48
|
// version information
|
|
57
49
|
get version() {
|
|
58
50
|
return version;
|
|
59
51
|
},
|
|
60
|
-
|
|
61
52
|
set version(v) {
|
|
62
53
|
return version = toVersion(v);
|
|
63
54
|
}
|
|
64
|
-
|
|
65
55
|
};
|
|
66
56
|
var _default = info;
|
|
67
57
|
exports.default = _default;
|
package/dist/post-comparison.js
CHANGED
|
@@ -5,20 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.postComparison = postComparison;
|
|
8
|
-
|
|
9
8
|
var _percyInfo = _interopRequireDefault(require("./percy-info.js"));
|
|
10
|
-
|
|
11
9
|
var _request = _interopRequireDefault(require("./request.js"));
|
|
12
|
-
|
|
13
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
11
|
// Post snapshot data to the CLI snapshot endpoint. If the endpoint responds with a build error,
|
|
16
12
|
// indicate that Percy has been disabled.
|
|
17
13
|
async function postComparison(options, params) {
|
|
18
14
|
let query = params ? `?${new URLSearchParams(params)}` : '';
|
|
19
15
|
await _request.default.post(`/percy/comparison${query}`, options).catch(err => {
|
|
20
16
|
var _err$response, _err$response$body, _err$response$body$bu;
|
|
21
|
-
|
|
22
17
|
if ((_err$response = err.response) !== null && _err$response !== void 0 && (_err$response$body = _err$response.body) !== null && _err$response$body !== void 0 && (_err$response$body$bu = _err$response$body.build) !== null && _err$response$body$bu !== void 0 && _err$response$body$bu.error) {
|
|
23
18
|
_percyInfo.default.enabled = false;
|
|
24
19
|
} else {
|
|
@@ -26,6 +21,5 @@ async function postComparison(options, params) {
|
|
|
26
21
|
}
|
|
27
22
|
});
|
|
28
23
|
}
|
|
29
|
-
|
|
30
24
|
var _default = postComparison;
|
|
31
25
|
exports.default = _default;
|
package/dist/post-snapshot.js
CHANGED
|
@@ -5,20 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.postSnapshot = postSnapshot;
|
|
8
|
-
|
|
9
8
|
var _percyInfo = _interopRequireDefault(require("./percy-info.js"));
|
|
10
|
-
|
|
11
9
|
var _request = _interopRequireDefault(require("./request.js"));
|
|
12
|
-
|
|
13
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
11
|
// Post snapshot data to the CLI snapshot endpoint. If the endpoint responds with a build error,
|
|
16
12
|
// indicate that Percy has been disabled.
|
|
17
13
|
async function postSnapshot(options, params) {
|
|
18
14
|
let query = params ? `?${new URLSearchParams(params)}` : '';
|
|
19
15
|
await _request.default.post(`/percy/snapshot${query}`, options).catch(err => {
|
|
20
16
|
var _err$response, _err$response$body, _err$response$body$bu;
|
|
21
|
-
|
|
22
17
|
if ((_err$response = err.response) !== null && _err$response !== void 0 && (_err$response$body = _err$response.body) !== null && _err$response$body !== void 0 && (_err$response$body$bu = _err$response$body.build) !== null && _err$response$body$bu !== void 0 && _err$response$body$bu.error) {
|
|
23
18
|
_percyInfo.default.enabled = false;
|
|
24
19
|
} else {
|
|
@@ -26,6 +21,5 @@ async function postSnapshot(options, params) {
|
|
|
26
21
|
}
|
|
27
22
|
});
|
|
28
23
|
}
|
|
29
|
-
|
|
30
24
|
var _default = postSnapshot;
|
|
31
25
|
exports.default = _default;
|
package/dist/request.js
CHANGED
|
@@ -5,50 +5,42 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.request = request;
|
|
8
|
-
|
|
9
8
|
var _percyInfo = _interopRequireDefault(require("./percy-info.js"));
|
|
10
|
-
|
|
11
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
|
|
13
10
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
14
|
-
|
|
15
11
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
16
|
-
|
|
17
12
|
// Helper to send a request to the local CLI API
|
|
18
13
|
async function request(path, options = {}) {
|
|
19
|
-
let response = await request.fetch(`${_percyInfo.default.address}${path}`, options);
|
|
14
|
+
let response = await request.fetch(`${_percyInfo.default.address}${path}`, options);
|
|
20
15
|
|
|
16
|
+
// maybe parse response body as json
|
|
21
17
|
if (typeof response.body === 'string' && response.headers['content-type'] === 'application/json') {
|
|
22
18
|
try {
|
|
23
19
|
response.body = JSON.parse(response.body);
|
|
24
20
|
} catch (e) {}
|
|
25
|
-
}
|
|
26
|
-
|
|
21
|
+
}
|
|
27
22
|
|
|
23
|
+
// throw an error if status is not ok
|
|
28
24
|
if (!(response.status >= 200 && response.status < 300)) {
|
|
29
25
|
throw Object.assign(new Error(), {
|
|
30
|
-
message: response.body.error ||
|
|
31
|
-
/* istanbul ignore next: in tests, there's always an error message */
|
|
26
|
+
message: response.body.error || /* istanbul ignore next: in tests, there's always an error message */
|
|
32
27
|
`${response.status} ${response.statusText}`,
|
|
33
28
|
response
|
|
34
29
|
});
|
|
35
30
|
}
|
|
36
|
-
|
|
37
31
|
return response;
|
|
38
32
|
}
|
|
39
|
-
|
|
40
33
|
request.post = function post(url, json) {
|
|
41
34
|
return request(url, {
|
|
42
35
|
method: 'POST',
|
|
43
36
|
body: JSON.stringify(json)
|
|
44
37
|
});
|
|
45
|
-
};
|
|
46
|
-
|
|
38
|
+
};
|
|
47
39
|
|
|
40
|
+
// environment specific implementation
|
|
48
41
|
if (process.env.__PERCY_BROWSERIFIED__) {
|
|
49
42
|
// use window.fetch in browsers
|
|
50
43
|
const winFetch = window.fetch;
|
|
51
|
-
|
|
52
44
|
request.fetch = async function fetch(url, options) {
|
|
53
45
|
let response = await winFetch(url, options);
|
|
54
46
|
return {
|
|
@@ -78,6 +70,5 @@ if (process.env.__PERCY_BROWSERIFIED__) {
|
|
|
78
70
|
});
|
|
79
71
|
};
|
|
80
72
|
}
|
|
81
|
-
|
|
82
73
|
var _default = request;
|
|
83
74
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/sdk-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
]
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "d2e812d14aa446fa580ffa75144a6280627b5a27"
|
|
54
54
|
}
|
package/test/client.js
CHANGED
|
@@ -31,31 +31,25 @@
|
|
|
31
31
|
if (logger) helpers.logger.mock();
|
|
32
32
|
await helpers.test('reset');
|
|
33
33
|
},
|
|
34
|
-
|
|
35
34
|
async test(cmd, arg) {
|
|
36
35
|
let res = await utils.request.post(`/test/api/${cmd}`, arg);
|
|
37
36
|
return res.body;
|
|
38
37
|
},
|
|
39
|
-
|
|
40
38
|
async get(what, map) {
|
|
41
39
|
let res = await utils.request(`/test/${what}`);
|
|
42
40
|
if (!map) map = what === 'logs' ? l => l.message : i => i;
|
|
43
41
|
return Array.isArray(res.body[what]) ? res.body[what].map(map) : map(res.body);
|
|
44
42
|
},
|
|
45
|
-
|
|
46
43
|
get testSnapshotURL() {
|
|
47
44
|
return `${utils.percy.address}/test/snapshot`;
|
|
48
45
|
},
|
|
49
|
-
|
|
50
46
|
logger: {
|
|
51
47
|
__log__: utils.logger.log,
|
|
52
48
|
loglevel: utils.logger.loglevel,
|
|
53
49
|
stdout: [],
|
|
54
50
|
stderr: [],
|
|
55
|
-
|
|
56
51
|
mock() {
|
|
57
52
|
helpers.logger.reset();
|
|
58
|
-
|
|
59
53
|
utils.logger.log = (ns, lvl, msg) => {
|
|
60
54
|
if (lvl === 'debug' && helpers.logger.loglevel.lvl !== 'debug') return;
|
|
61
55
|
msg = `[percy${lvl === 'debug' ? `:${ns}` : ''}] ${msg}`;
|
|
@@ -63,13 +57,11 @@
|
|
|
63
57
|
helpers.logger[io].push(msg);
|
|
64
58
|
};
|
|
65
59
|
},
|
|
66
|
-
|
|
67
60
|
reset() {
|
|
68
61
|
helpers.logger.stdout = [];
|
|
69
62
|
helpers.logger.stderr = [];
|
|
70
63
|
helpers.logger.loglevel('info');
|
|
71
64
|
}
|
|
72
|
-
|
|
73
65
|
}
|
|
74
66
|
};
|
|
75
67
|
var helpers_1 = helpers;
|