@percy/config 1.30.9-beta.2 → 1.30.9-beta.3
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/validate.js +48 -5
- package/package.json +3 -3
package/dist/validate.js
CHANGED
|
@@ -184,8 +184,8 @@ function shouldHideError(key, path, error) {
|
|
|
184
184
|
|
|
185
185
|
// Validates data according to the associated schema and returns a list of errors, if any.
|
|
186
186
|
export function validate(data, key = '/config') {
|
|
187
|
+
let errors = new Map();
|
|
187
188
|
if (!ajv.validate(key, data)) {
|
|
188
|
-
let errors = new Map();
|
|
189
189
|
for (let error of ajv.errors) {
|
|
190
190
|
var _parentSchema$errors2;
|
|
191
191
|
let {
|
|
@@ -242,12 +242,55 @@ export function validate(data, key = '/config') {
|
|
|
242
242
|
message
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
|
-
|
|
246
245
|
// filter empty values as a result of scrubbing
|
|
247
246
|
filterEmpty(data);
|
|
248
|
-
|
|
249
|
-
// return an array of errors
|
|
250
|
-
return Array.from(errors.values());
|
|
251
247
|
}
|
|
248
|
+
if (data.regions && Array.isArray(data.regions)) {
|
|
249
|
+
data.regions.forEach((region, index) => {
|
|
250
|
+
/* istanbul ignore next */
|
|
251
|
+
if (region.elementSelector) {
|
|
252
|
+
const selectorKeys = ['elementCSS', 'elementXpath', 'boundingBox'];
|
|
253
|
+
const providedKeys = selectorKeys.filter(key => region.elementSelector[key] !== undefined);
|
|
254
|
+
if (providedKeys.length !== 1) {
|
|
255
|
+
const pathStr = `regions[${index}].elementSelector`;
|
|
256
|
+
errors.set(pathStr, {
|
|
257
|
+
path: pathStr,
|
|
258
|
+
message: "Exactly one of 'elementCSS', 'elementXpath', or 'boundingBox' must be provided."
|
|
259
|
+
});
|
|
260
|
+
delete data.regions[index];
|
|
261
|
+
}
|
|
262
|
+
} else {
|
|
263
|
+
if (region.algorithm === 'ignore') {
|
|
264
|
+
const pathStr = `regions[${index}].elementSelector`;
|
|
265
|
+
errors.set(pathStr, {
|
|
266
|
+
path: pathStr,
|
|
267
|
+
message: "'elementSelector' is required when algorithm is 'ignore'."
|
|
268
|
+
});
|
|
269
|
+
delete data.regions[index];
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const algorithmType = region.algorithm;
|
|
273
|
+
const hasConfiguration = region.configuration !== undefined;
|
|
274
|
+
if (algorithmType === 'layout' || algorithmType === 'ignore') {
|
|
275
|
+
if (hasConfiguration) {
|
|
276
|
+
const pathStr = `regions[${index}].configuration`;
|
|
277
|
+
errors.set(pathStr, {
|
|
278
|
+
path: pathStr,
|
|
279
|
+
message: `Configuration is not applicable for '${algorithmType}' algorithm`
|
|
280
|
+
});
|
|
281
|
+
delete data.regions[index];
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if ((algorithmType === 'standard' || algorithmType === 'intelliignore') && !hasConfiguration) {
|
|
285
|
+
const pathStr = `regions[${index}]`;
|
|
286
|
+
errors.set(pathStr, {
|
|
287
|
+
path: pathStr,
|
|
288
|
+
message: `Configuration is recommended for '${algorithmType}' algorithm`
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
const errorArray = Array.from(errors.values());
|
|
294
|
+
return errorArray.length > 0 ? errorArray : undefined;
|
|
252
295
|
}
|
|
253
296
|
export default validate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/config",
|
|
3
|
-
"version": "1.30.9-beta.
|
|
3
|
+
"version": "1.30.9-beta.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"test:types": "tsd"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@percy/logger": "1.30.9-beta.
|
|
41
|
+
"@percy/logger": "1.30.9-beta.3",
|
|
42
42
|
"ajv": "^8.6.2",
|
|
43
43
|
"cosmiconfig": "^8.0.0",
|
|
44
44
|
"yaml": "^2.0.0"
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"json-schema-typed": "^7.0.3"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "06ceb56e04806677d41a22eb1ccbee81a8d32c15"
|
|
50
50
|
}
|