vest 4.4.3-dev-c786f7 → 4.6.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/cjs/classnames.development.js +13 -36
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/parser.development.js +13 -36
- package/dist/cjs/parser.production.js +1 -1
- package/dist/cjs/vest.development.js +232 -187
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +14 -37
- package/dist/es/classnames.production.js +1 -1
- package/dist/es/parser.development.js +14 -37
- package/dist/es/parser.production.js +1 -1
- package/dist/es/vest.development.js +233 -189
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +19 -96
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +9 -665
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +17 -667
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +12 -668
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/parser.development.js +18 -95
- package/dist/umd/parser.production.js +1 -1
- package/dist/umd/promisify.development.js +5 -31
- package/dist/umd/promisify.production.js +1 -1
- package/dist/umd/vest.development.js +336 -1067
- package/dist/umd/vest.production.js +1 -1
- package/package.json +4 -4
- package/types/enforce/compose.d.ts +2 -1
- package/types/enforce/compounds.d.ts +8 -9
- package/types/enforce/schema.d.ts +7 -5
- package/types/parser.d.ts +8 -7
- package/types/promisify.d.ts +20 -35
- package/types/vest.d.ts +79 -81
|
@@ -1,820 +1,12 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vest = {}));
|
|
5
|
-
}(this, (function (exports) { 'use strict';
|
|
6
|
-
|
|
7
|
-
function bindNot(fn) {
|
|
8
|
-
return function () {
|
|
9
|
-
var args = [];
|
|
10
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
11
|
-
args[_i] = arguments[_i];
|
|
12
|
-
}
|
|
13
|
-
return !fn.apply(void 0, args);
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function isNumeric(value) {
|
|
18
|
-
var str = String(value);
|
|
19
|
-
var num = Number(value);
|
|
20
|
-
var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
|
|
21
|
-
return Boolean(result);
|
|
22
|
-
}
|
|
23
|
-
var isNotNumeric = bindNot(isNumeric);
|
|
24
|
-
|
|
25
|
-
function numberEquals(value, eq) {
|
|
26
|
-
return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
|
|
27
|
-
}
|
|
28
|
-
var numberNotEquals = bindNot(numberEquals);
|
|
29
|
-
|
|
30
|
-
function lengthEquals(value, arg1) {
|
|
31
|
-
return numberEquals(value.length, arg1);
|
|
32
|
-
}
|
|
33
|
-
var lengthNotEquals = bindNot(lengthEquals);
|
|
34
|
-
|
|
35
|
-
function greaterThan(value, gt) {
|
|
36
|
-
return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function longerThan(value, arg1) {
|
|
40
|
-
return greaterThan(value.length, arg1);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Creates a cache function
|
|
45
|
-
*/
|
|
46
|
-
function createCache(maxSize) {
|
|
47
|
-
if (maxSize === void 0) { maxSize = 1; }
|
|
48
|
-
var cacheStorage = [];
|
|
49
|
-
var cache = function (deps, cacheAction) {
|
|
50
|
-
var cacheHit = cache.get(deps);
|
|
51
|
-
// cache hit is not null
|
|
52
|
-
if (cacheHit)
|
|
53
|
-
return cacheHit[1];
|
|
54
|
-
var result = cacheAction();
|
|
55
|
-
cacheStorage.unshift([deps.concat(), result]);
|
|
56
|
-
if (longerThan(cacheStorage, maxSize))
|
|
57
|
-
cacheStorage.length = maxSize;
|
|
58
|
-
return result;
|
|
59
|
-
};
|
|
60
|
-
// invalidate an item in the cache by its dependencies
|
|
61
|
-
cache.invalidate = function (deps) {
|
|
62
|
-
var index = findIndex(deps);
|
|
63
|
-
if (index > -1)
|
|
64
|
-
cacheStorage.splice(index, 1);
|
|
65
|
-
};
|
|
66
|
-
// Retrieves an item from the cache.
|
|
67
|
-
cache.get = function (deps) {
|
|
68
|
-
return cacheStorage[findIndex(deps)] || null;
|
|
69
|
-
};
|
|
70
|
-
return cache;
|
|
71
|
-
function findIndex(deps) {
|
|
72
|
-
return cacheStorage.findIndex(function (_a) {
|
|
73
|
-
var cachedDeps = _a[0];
|
|
74
|
-
return lengthEquals(deps, cachedDeps.length) &&
|
|
75
|
-
deps.every(function (dep, i) { return dep === cachedDeps[i]; });
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function isNull(value) {
|
|
81
|
-
return value === null;
|
|
82
|
-
}
|
|
83
|
-
var isNotNull = bindNot(isNull);
|
|
84
|
-
|
|
85
|
-
function isUndefined(value) {
|
|
86
|
-
return value === undefined;
|
|
87
|
-
}
|
|
88
|
-
var isNotUndefined = bindNot(isUndefined);
|
|
89
|
-
|
|
90
|
-
function isNullish(value) {
|
|
91
|
-
return isNull(value) || isUndefined(value);
|
|
92
|
-
}
|
|
93
|
-
var isNotNullish = bindNot(isNullish);
|
|
94
|
-
|
|
95
|
-
function asArray(possibleArg) {
|
|
96
|
-
return [].concat(possibleArg);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function isFunction(value) {
|
|
100
|
-
return typeof value === 'function';
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function optionalFunctionValue(value) {
|
|
104
|
-
var args = [];
|
|
105
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
106
|
-
args[_i - 1] = arguments[_i];
|
|
107
|
-
}
|
|
108
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function defaultTo(value, defaultValue) {
|
|
112
|
-
var _a;
|
|
113
|
-
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// The module is named "isArrayValue" since it
|
|
117
|
-
// is conflicting with a nested npm dependency.
|
|
118
|
-
// We may need to revisit this in the future.
|
|
119
|
-
function isArray(value) {
|
|
120
|
-
return Boolean(Array.isArray(value));
|
|
121
|
-
}
|
|
122
|
-
var isNotArray = bindNot(isArray);
|
|
123
|
-
|
|
124
|
-
function last(values) {
|
|
125
|
-
var valuesArray = asArray(values);
|
|
126
|
-
return valuesArray[valuesArray.length - 1];
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// This is kind of a map/filter in one function.
|
|
130
|
-
// Normally, behaves like a nested-array map,
|
|
131
|
-
// but returning `null` will drop the element from the array
|
|
132
|
-
function transform(array, cb) {
|
|
133
|
-
var res = [];
|
|
134
|
-
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
|
|
135
|
-
var v = array_1[_i];
|
|
136
|
-
if (isArray(v)) {
|
|
137
|
-
res.push(transform(v, cb));
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
var output = cb(v);
|
|
141
|
-
if (isNotNull(output)) {
|
|
142
|
-
res.push(output);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return res;
|
|
147
|
-
}
|
|
148
|
-
function valueAtPath(array, path) {
|
|
149
|
-
return getCurrent(array, path)[last(path)];
|
|
150
|
-
}
|
|
151
|
-
function setValueAtPath(array, path, value) {
|
|
152
|
-
var current = getCurrent(array, path);
|
|
153
|
-
current[last(path)] = value;
|
|
154
|
-
return array;
|
|
155
|
-
}
|
|
156
|
-
function flatten(values) {
|
|
157
|
-
return asArray(values).reduce(function (acc, value) {
|
|
158
|
-
if (isArray(value)) {
|
|
159
|
-
return acc.concat(flatten(value));
|
|
160
|
-
}
|
|
161
|
-
return asArray(acc).concat(value);
|
|
162
|
-
}, []);
|
|
163
|
-
}
|
|
164
|
-
function getCurrent(array, path) {
|
|
165
|
-
var current = array;
|
|
166
|
-
for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) {
|
|
167
|
-
var p = _a[_i];
|
|
168
|
-
current[p] = defaultTo(current[p], []);
|
|
169
|
-
current = current[p];
|
|
170
|
-
}
|
|
171
|
-
return current;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function callEach(arr) {
|
|
175
|
-
return arr.forEach(function (fn) { return fn(); });
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* A safe hasOwnProperty access
|
|
180
|
-
*/
|
|
181
|
-
function hasOwnProperty(obj, key) {
|
|
182
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function isPromise(value) {
|
|
186
|
-
return value && isFunction(value.then);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
var assign = Object.assign;
|
|
190
|
-
|
|
191
|
-
function invariant(condition,
|
|
192
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
193
|
-
message) {
|
|
194
|
-
if (condition) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
// If message is a string object (rather than string literal)
|
|
198
|
-
// Throw the value directly as a string
|
|
199
|
-
// Alternatively, throw an error with the message
|
|
200
|
-
throw message instanceof String
|
|
201
|
-
? message.valueOf()
|
|
202
|
-
: new Error(message ? optionalFunctionValue(message) : message);
|
|
203
|
-
}
|
|
204
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
205
|
-
function StringObject(value) {
|
|
206
|
-
return new String(optionalFunctionValue(value));
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function isStringValue(v) {
|
|
210
|
-
return String(v) === v;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function either(a, b) {
|
|
214
|
-
return !!a !== !!b;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function isBoolean(value) {
|
|
218
|
-
return !!value === value;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function deferThrow(message) {
|
|
222
|
-
setTimeout(function () {
|
|
223
|
-
throw new Error(message);
|
|
224
|
-
}, 0);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function createBus() {
|
|
228
|
-
var listeners = {};
|
|
229
|
-
return {
|
|
230
|
-
emit: function (event, data) {
|
|
231
|
-
listener(event).forEach(function (handler) {
|
|
232
|
-
handler(data);
|
|
233
|
-
});
|
|
234
|
-
},
|
|
235
|
-
on: function (event, handler) {
|
|
236
|
-
listeners[event] = listener(event).concat(handler);
|
|
237
|
-
return {
|
|
238
|
-
off: function () {
|
|
239
|
-
listeners[event] = listener(event).filter(function (h) { return h !== handler; });
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
function listener(event) {
|
|
245
|
-
return listeners[event] || [];
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* @returns a unique numeric id.
|
|
251
|
-
*/
|
|
252
|
-
var genId = (function (n) { return function () {
|
|
253
|
-
return "".concat(n++);
|
|
254
|
-
}; })(0);
|
|
255
|
-
|
|
256
|
-
function mapFirst(array, callback) {
|
|
257
|
-
var broke = false;
|
|
258
|
-
var breakoutValue = null;
|
|
259
|
-
for (var i = 0; i < array.length; i++) {
|
|
260
|
-
callback(array[i], breakout, i);
|
|
261
|
-
if (broke) {
|
|
262
|
-
return breakoutValue;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
function breakout(conditional, value) {
|
|
266
|
-
if (conditional) {
|
|
267
|
-
broke = true;
|
|
268
|
-
breakoutValue = value;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function isEmpty(value) {
|
|
274
|
-
if (!value) {
|
|
275
|
-
return true;
|
|
276
|
-
}
|
|
277
|
-
else if (hasOwnProperty(value, 'length')) {
|
|
278
|
-
return lengthEquals(value, 0);
|
|
279
|
-
}
|
|
280
|
-
else if (typeof value === 'object') {
|
|
281
|
-
return lengthEquals(Object.keys(value), 0);
|
|
282
|
-
}
|
|
283
|
-
return false;
|
|
284
|
-
}
|
|
285
|
-
var isNotEmpty = bindNot(isEmpty);
|
|
286
|
-
|
|
287
|
-
function isPositive(value) {
|
|
288
|
-
return greaterThan(value, 0);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function endsWith(value, arg1) {
|
|
292
|
-
return isStringValue(value) && isStringValue(arg1) && value.endsWith(arg1);
|
|
293
|
-
}
|
|
294
|
-
var doesNotEndWith = bindNot(endsWith);
|
|
295
|
-
|
|
296
|
-
function equals(value, arg1) {
|
|
297
|
-
return value === arg1;
|
|
298
|
-
}
|
|
299
|
-
var notEquals = bindNot(equals);
|
|
300
|
-
|
|
301
|
-
function greaterThanOrEquals(value, gte) {
|
|
302
|
-
return numberEquals(value, gte) || greaterThan(value, gte);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function inside(value, arg1) {
|
|
306
|
-
if (isArray(arg1)) {
|
|
307
|
-
return arg1.indexOf(value) !== -1;
|
|
308
|
-
}
|
|
309
|
-
// both value and arg1 are strings
|
|
310
|
-
if (isStringValue(arg1) && isStringValue(value)) {
|
|
311
|
-
return arg1.indexOf(value) !== -1;
|
|
312
|
-
}
|
|
313
|
-
return false;
|
|
314
|
-
}
|
|
315
|
-
var notInside = bindNot(inside);
|
|
316
|
-
|
|
317
|
-
function lessThan(value, lt) {
|
|
318
|
-
return isNumeric(value) && isNumeric(lt) && Number(value) < Number(lt);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function lessThanOrEquals(value, lte) {
|
|
322
|
-
return numberEquals(value, lte) || lessThan(value, lte);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
function isBetween(value, min, max) {
|
|
326
|
-
return greaterThanOrEquals(value, min) && lessThanOrEquals(value, max);
|
|
327
|
-
}
|
|
328
|
-
var isNotBetween = bindNot(isBetween);
|
|
329
|
-
|
|
330
|
-
function isBlank(value) {
|
|
331
|
-
return isNullish(value) || (isStringValue(value) && !value.trim());
|
|
332
|
-
}
|
|
333
|
-
var isNotBlank = bindNot(isBlank);
|
|
334
|
-
|
|
335
|
-
var isNotBoolean = bindNot(isBoolean);
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Validates that a given value is an even number
|
|
339
|
-
*/
|
|
340
|
-
var isEven = function (value) {
|
|
341
|
-
if (isNumeric(value)) {
|
|
342
|
-
return value % 2 === 0;
|
|
343
|
-
}
|
|
344
|
-
return false;
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
function isKeyOf(key, obj) {
|
|
348
|
-
return key in obj;
|
|
349
|
-
}
|
|
350
|
-
var isNotKeyOf = bindNot(isKeyOf);
|
|
351
|
-
|
|
352
|
-
function isNaN$1(value) {
|
|
353
|
-
return Number.isNaN(value);
|
|
354
|
-
}
|
|
355
|
-
var isNotNaN = bindNot(isNaN$1);
|
|
356
|
-
|
|
357
|
-
function isNegative(value) {
|
|
358
|
-
return lessThan(value, 0);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
function isNumber(value) {
|
|
362
|
-
return Boolean(typeof value === 'number');
|
|
363
|
-
}
|
|
364
|
-
var isNotNumber = bindNot(isNumber);
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Validates that a given value is an odd number
|
|
368
|
-
*/
|
|
369
|
-
var isOdd = function (value) {
|
|
370
|
-
if (isNumeric(value)) {
|
|
371
|
-
return value % 2 !== 0;
|
|
372
|
-
}
|
|
373
|
-
return false;
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
var isNotString = bindNot(isStringValue);
|
|
377
|
-
|
|
378
|
-
function isTruthy(value) {
|
|
379
|
-
return !!value;
|
|
380
|
-
}
|
|
381
|
-
var isFalsy = bindNot(isTruthy);
|
|
382
|
-
|
|
383
|
-
function isValueOf(value, objectToCheck) {
|
|
384
|
-
if (isNullish(objectToCheck)) {
|
|
385
|
-
return false;
|
|
386
|
-
}
|
|
387
|
-
for (var key in objectToCheck) {
|
|
388
|
-
if (objectToCheck[key] === value) {
|
|
389
|
-
return true;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
return false;
|
|
393
|
-
}
|
|
394
|
-
var isNotValueOf = bindNot(isValueOf);
|
|
395
|
-
|
|
396
|
-
function longerThanOrEquals(value, arg1) {
|
|
397
|
-
return greaterThanOrEquals(value.length, arg1);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
function matches(value, regex) {
|
|
401
|
-
if (regex instanceof RegExp) {
|
|
402
|
-
return regex.test(value);
|
|
403
|
-
}
|
|
404
|
-
else if (isStringValue(regex)) {
|
|
405
|
-
return new RegExp(regex).test(value);
|
|
406
|
-
}
|
|
407
|
-
else {
|
|
408
|
-
return false;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
var notMatches = bindNot(matches);
|
|
412
|
-
|
|
413
|
-
function condition(value, callback) {
|
|
414
|
-
try {
|
|
415
|
-
return callback(value);
|
|
416
|
-
}
|
|
417
|
-
catch (_a) {
|
|
418
|
-
return false;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
function shorterThan(value, arg1) {
|
|
423
|
-
return lessThan(value.length, arg1);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
function shorterThanOrEquals(value, arg1) {
|
|
427
|
-
return lessThanOrEquals(value.length, arg1);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
function startsWith(value, arg1) {
|
|
431
|
-
return isStringValue(value) && isStringValue(arg1) && value.startsWith(arg1);
|
|
432
|
-
}
|
|
433
|
-
var doesNotStartWith = bindNot(startsWith);
|
|
434
|
-
|
|
435
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, max-lines-per-function
|
|
436
|
-
function rules() {
|
|
437
|
-
return {
|
|
438
|
-
condition: condition,
|
|
439
|
-
doesNotEndWith: doesNotEndWith,
|
|
440
|
-
doesNotStartWith: doesNotStartWith,
|
|
441
|
-
endsWith: endsWith,
|
|
442
|
-
equals: equals,
|
|
443
|
-
greaterThan: greaterThan,
|
|
444
|
-
greaterThanOrEquals: greaterThanOrEquals,
|
|
445
|
-
gt: greaterThan,
|
|
446
|
-
gte: greaterThanOrEquals,
|
|
447
|
-
inside: inside,
|
|
448
|
-
isArray: isArray,
|
|
449
|
-
isBetween: isBetween,
|
|
450
|
-
isBlank: isBlank,
|
|
451
|
-
isBoolean: isBoolean,
|
|
452
|
-
isEmpty: isEmpty,
|
|
453
|
-
isEven: isEven,
|
|
454
|
-
isFalsy: isFalsy,
|
|
455
|
-
isKeyOf: isKeyOf,
|
|
456
|
-
isNaN: isNaN$1,
|
|
457
|
-
isNegative: isNegative,
|
|
458
|
-
isNotArray: isNotArray,
|
|
459
|
-
isNotBetween: isNotBetween,
|
|
460
|
-
isNotBlank: isNotBlank,
|
|
461
|
-
isNotBoolean: isNotBoolean,
|
|
462
|
-
isNotEmpty: isNotEmpty,
|
|
463
|
-
isNotKeyOf: isNotKeyOf,
|
|
464
|
-
isNotNaN: isNotNaN,
|
|
465
|
-
isNotNull: isNotNull,
|
|
466
|
-
isNotNullish: isNotNullish,
|
|
467
|
-
isNotNumber: isNotNumber,
|
|
468
|
-
isNotNumeric: isNotNumeric,
|
|
469
|
-
isNotString: isNotString,
|
|
470
|
-
isNotUndefined: isNotUndefined,
|
|
471
|
-
isNotValueOf: isNotValueOf,
|
|
472
|
-
isNull: isNull,
|
|
473
|
-
isNullish: isNullish,
|
|
474
|
-
isNumber: isNumber,
|
|
475
|
-
isNumeric: isNumeric,
|
|
476
|
-
isOdd: isOdd,
|
|
477
|
-
isPositive: isPositive,
|
|
478
|
-
isString: isStringValue,
|
|
479
|
-
isTruthy: isTruthy,
|
|
480
|
-
isUndefined: isUndefined,
|
|
481
|
-
isValueOf: isValueOf,
|
|
482
|
-
lengthEquals: lengthEquals,
|
|
483
|
-
lengthNotEquals: lengthNotEquals,
|
|
484
|
-
lessThan: lessThan,
|
|
485
|
-
lessThanOrEquals: lessThanOrEquals,
|
|
486
|
-
longerThan: longerThan,
|
|
487
|
-
longerThanOrEquals: longerThanOrEquals,
|
|
488
|
-
lt: lessThan,
|
|
489
|
-
lte: lessThanOrEquals,
|
|
490
|
-
matches: matches,
|
|
491
|
-
notEquals: notEquals,
|
|
492
|
-
notInside: notInside,
|
|
493
|
-
notMatches: notMatches,
|
|
494
|
-
numberEquals: numberEquals,
|
|
495
|
-
numberNotEquals: numberNotEquals,
|
|
496
|
-
shorterThan: shorterThan,
|
|
497
|
-
shorterThanOrEquals: shorterThanOrEquals,
|
|
498
|
-
startsWith: startsWith
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
var baseRules = rules();
|
|
503
|
-
function getRule(ruleName) {
|
|
504
|
-
return baseRules[ruleName];
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
function eachEnforceRule(action) {
|
|
508
|
-
for (var ruleName in baseRules) {
|
|
509
|
-
var ruleFn = getRule(ruleName);
|
|
510
|
-
if (isFunction(ruleFn)) {
|
|
511
|
-
action(ruleName, ruleFn);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
// eslint-disable-next-line max-lines-per-function
|
|
517
|
-
function createContext(init) {
|
|
518
|
-
var storage = { ancestry: [] };
|
|
519
|
-
return {
|
|
520
|
-
bind: bind,
|
|
521
|
-
run: run,
|
|
522
|
-
use: use,
|
|
523
|
-
useX: useX
|
|
524
|
-
};
|
|
525
|
-
function useX(errorMessage) {
|
|
526
|
-
var ctx = use();
|
|
527
|
-
invariant(ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
|
|
528
|
-
return ctx;
|
|
529
|
-
}
|
|
530
|
-
function run(ctxRef, fn) {
|
|
531
|
-
var _a;
|
|
532
|
-
var parentContext = use();
|
|
533
|
-
var out = assign({}, parentContext ? parentContext : {}, (_a = optionalFunctionValue(init, ctxRef, parentContext)) !== null && _a !== void 0 ? _a : ctxRef);
|
|
534
|
-
var ctx = set(Object.freeze(out));
|
|
535
|
-
storage.ancestry.unshift(ctx);
|
|
536
|
-
var res = fn(ctx);
|
|
537
|
-
clear();
|
|
538
|
-
return res;
|
|
539
|
-
}
|
|
540
|
-
function bind(ctxRef, fn) {
|
|
541
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
542
|
-
// @ts-ignore - this one's pretty hard to get right
|
|
543
|
-
var returnedFn = function () {
|
|
544
|
-
var runTimeArgs = [];
|
|
545
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
546
|
-
runTimeArgs[_i] = arguments[_i];
|
|
547
|
-
}
|
|
548
|
-
return run(ctxRef, function () {
|
|
549
|
-
return fn.apply(void 0, runTimeArgs);
|
|
550
|
-
});
|
|
551
|
-
};
|
|
552
|
-
return returnedFn;
|
|
553
|
-
}
|
|
554
|
-
function use() {
|
|
555
|
-
return storage.ctx;
|
|
556
|
-
}
|
|
557
|
-
function set(value) {
|
|
558
|
-
return (storage.ctx = value);
|
|
559
|
-
}
|
|
560
|
-
function clear() {
|
|
561
|
-
var _a;
|
|
562
|
-
storage.ancestry.shift();
|
|
563
|
-
set((_a = storage.ancestry[0]) !== null && _a !== void 0 ? _a : null);
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
var ctx = createContext(function (ctxRef, parentContext) {
|
|
568
|
-
var base = {
|
|
569
|
-
value: ctxRef.value,
|
|
570
|
-
meta: ctxRef.meta || {}
|
|
571
|
-
};
|
|
572
|
-
if (!parentContext) {
|
|
573
|
-
return assign(base, {
|
|
574
|
-
parent: emptyParent
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
else if (ctxRef.set) {
|
|
578
|
-
return assign(base, {
|
|
579
|
-
parent: function () { return stripContext(parentContext); }
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
return parentContext;
|
|
583
|
-
});
|
|
584
|
-
function stripContext(ctx) {
|
|
585
|
-
if (!ctx) {
|
|
586
|
-
return ctx;
|
|
587
|
-
}
|
|
588
|
-
return {
|
|
589
|
-
value: ctx.value,
|
|
590
|
-
meta: ctx.meta,
|
|
591
|
-
parent: ctx.parent
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
function emptyParent() {
|
|
595
|
-
return null;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
/******************************************************************************
|
|
599
|
-
Copyright (c) Microsoft Corporation.
|
|
600
|
-
|
|
601
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
602
|
-
purpose with or without fee is hereby granted.
|
|
603
|
-
|
|
604
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
605
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
606
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
607
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
608
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
609
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
610
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
611
|
-
***************************************************************************** */
|
|
612
|
-
|
|
613
|
-
function __spreadArray(to, from, pack) {
|
|
614
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
615
|
-
if (ar || !(i in from)) {
|
|
616
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
617
|
-
ar[i] = from[i];
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
function isProxySupported() {
|
|
624
|
-
try {
|
|
625
|
-
return isFunction(Proxy);
|
|
626
|
-
}
|
|
627
|
-
catch (_a) {
|
|
628
|
-
return false;
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
function ruleReturn(pass, message) {
|
|
633
|
-
var output = { pass: pass };
|
|
634
|
-
if (message) {
|
|
635
|
-
output.message = message;
|
|
636
|
-
}
|
|
637
|
-
return output;
|
|
638
|
-
}
|
|
639
|
-
function passing() {
|
|
640
|
-
return ruleReturn(true);
|
|
641
|
-
}
|
|
642
|
-
function defaultToPassing(callback) {
|
|
643
|
-
return defaultTo(callback, passing());
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
/**
|
|
647
|
-
* Transform the result of a rule into a standard format
|
|
648
|
-
*/
|
|
649
|
-
function transformResult(result, ruleName, value) {
|
|
650
|
-
var args = [];
|
|
651
|
-
for (var _i = 3; _i < arguments.length; _i++) {
|
|
652
|
-
args[_i - 3] = arguments[_i];
|
|
653
|
-
}
|
|
654
|
-
validateResult(result);
|
|
655
|
-
// if result is boolean
|
|
656
|
-
if (isBoolean(result)) {
|
|
657
|
-
return ruleReturn(result);
|
|
658
|
-
}
|
|
659
|
-
else {
|
|
660
|
-
return ruleReturn(result.pass, optionalFunctionValue.apply(void 0, __spreadArray([result.message, ruleName, value], args, false)));
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
function validateResult(result) {
|
|
664
|
-
// if result is boolean, or if result.pass is boolean
|
|
665
|
-
invariant(isBoolean(result) || (result && isBoolean(result.pass)), 'Incorrect return value for rule: ' + JSON.stringify(result));
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
function enforceEager(value) {
|
|
669
|
-
var target = {};
|
|
670
|
-
if (!isProxySupported()) {
|
|
671
|
-
eachEnforceRule(function (ruleName, ruleFn) {
|
|
672
|
-
target[ruleName] = genRuleCall(target, ruleFn, ruleName);
|
|
673
|
-
});
|
|
674
|
-
return target;
|
|
675
|
-
}
|
|
676
|
-
var proxy = new Proxy(target, {
|
|
677
|
-
get: function (_, ruleName) {
|
|
678
|
-
var rule = getRule(ruleName);
|
|
679
|
-
if (rule) {
|
|
680
|
-
return genRuleCall(proxy, rule, ruleName);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
});
|
|
684
|
-
return proxy;
|
|
685
|
-
function genRuleCall(target, rule, ruleName) {
|
|
686
|
-
return function ruleCall() {
|
|
687
|
-
var args = [];
|
|
688
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
689
|
-
args[_i] = arguments[_i];
|
|
690
|
-
}
|
|
691
|
-
var transformedResult = ctx.run({ value: value }, function () {
|
|
692
|
-
return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args, false)), ruleName, value], args, false));
|
|
693
|
-
});
|
|
694
|
-
invariant(transformedResult.pass, isNullish(transformedResult.message)
|
|
695
|
-
? "enforce/".concat(ruleName, " failed with ").concat(JSON.stringify(value))
|
|
696
|
-
: StringObject(transformedResult.message));
|
|
697
|
-
return target;
|
|
698
|
-
};
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
// eslint-disable-next-line max-lines-per-function
|
|
703
|
-
function genEnforceLazy(key) {
|
|
704
|
-
var registeredRules = [];
|
|
705
|
-
var lazyMessage;
|
|
706
|
-
return addLazyRule(key);
|
|
707
|
-
// eslint-disable-next-line max-lines-per-function
|
|
708
|
-
function addLazyRule(ruleName) {
|
|
709
|
-
// eslint-disable-next-line max-lines-per-function
|
|
710
|
-
return function () {
|
|
711
|
-
var args = [];
|
|
712
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
713
|
-
args[_i] = arguments[_i];
|
|
714
|
-
}
|
|
715
|
-
var rule = getRule(ruleName);
|
|
716
|
-
registeredRules.push(function (value) {
|
|
717
|
-
return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args, false)), ruleName, value], args, false));
|
|
718
|
-
});
|
|
719
|
-
var proxy = {
|
|
720
|
-
run: function (value) {
|
|
721
|
-
return defaultToPassing(mapFirst(registeredRules, function (rule, breakout) {
|
|
722
|
-
var _a;
|
|
723
|
-
var res = ctx.run({ value: value }, function () { return rule(value); });
|
|
724
|
-
breakout(!res.pass, ruleReturn(!!res.pass, (_a = optionalFunctionValue(lazyMessage, value, res.message)) !== null && _a !== void 0 ? _a : res.message));
|
|
725
|
-
}));
|
|
726
|
-
},
|
|
727
|
-
test: function (value) { return proxy.run(value).pass; },
|
|
728
|
-
message: function (message) {
|
|
729
|
-
if (message) {
|
|
730
|
-
lazyMessage = message;
|
|
731
|
-
}
|
|
732
|
-
return proxy;
|
|
733
|
-
}
|
|
734
|
-
};
|
|
735
|
-
if (!isProxySupported()) {
|
|
736
|
-
eachEnforceRule(function (ruleName) {
|
|
737
|
-
proxy[ruleName] = addLazyRule(ruleName);
|
|
738
|
-
});
|
|
739
|
-
return proxy;
|
|
740
|
-
}
|
|
741
|
-
// reassigning the proxy here is not pretty
|
|
742
|
-
// but it's a cleaner way of getting `run` and `test` for free
|
|
743
|
-
proxy = new Proxy(proxy, {
|
|
744
|
-
get: function (target, key) {
|
|
745
|
-
if (getRule(key)) {
|
|
746
|
-
return addLazyRule(key);
|
|
747
|
-
}
|
|
748
|
-
return target[key]; // already has `run` and `test` on it
|
|
749
|
-
}
|
|
750
|
-
});
|
|
751
|
-
return proxy;
|
|
752
|
-
};
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
/**
|
|
757
|
-
* Enforce is quite complicated, I want to explain it in detail.
|
|
758
|
-
* It is dynamic in nature, so a lot of proxy objects are involved.
|
|
759
|
-
*
|
|
760
|
-
* Enforce has two main interfaces
|
|
761
|
-
* 1. eager
|
|
762
|
-
* 2. lazy
|
|
763
|
-
*
|
|
764
|
-
* The eager interface is the most commonly used, and the easier to understand.
|
|
765
|
-
* It throws an error when a rule is not satisfied.
|
|
766
|
-
* The eager interface is declared in enforceEager.ts and it is quite simple to understand.
|
|
767
|
-
* enforce is called with a value, and the return value is a proxy object that points back to all the rules.
|
|
768
|
-
* When a rule is called, the value is mapped as its first argument, and if the rule passes, the same
|
|
769
|
-
* proxy object is returned. Otherwise, an error is thrown.
|
|
770
|
-
*
|
|
771
|
-
* The lazy interface works quite differently. It is declared in genEnforceLazy.ts.
|
|
772
|
-
* Rather than calling enforce directly, the lazy interface has all the rules as "methods" (only by proxy).
|
|
773
|
-
* Calling the first function in the chain will initialize an array of calls. It stores the different rule calls
|
|
774
|
-
* and the parameters passed to them. None of the rules are called yet.
|
|
775
|
-
* The rules are only invoked in sequence once either of these chained functions are called:
|
|
776
|
-
* 1. test(value)
|
|
777
|
-
* 2. run(value)
|
|
778
|
-
*
|
|
779
|
-
* Calling run or test will call all the rules in sequence, with the difference that test will only return a boolean value,
|
|
780
|
-
* while run will return an object with the validation result and an optional message created by the rule.
|
|
781
|
-
*/
|
|
782
|
-
function genEnforce() {
|
|
783
|
-
var target = {
|
|
784
|
-
context: function () { return ctx.useX(); },
|
|
785
|
-
extend: function (customRules) {
|
|
786
|
-
assign(baseRules, customRules);
|
|
787
|
-
handleNoProxy(); // TODO: REMOVE when we stop supporting ES5
|
|
788
|
-
}
|
|
789
|
-
};
|
|
790
|
-
handleNoProxy();
|
|
791
|
-
return new Proxy(assign(enforceEager, target), {
|
|
792
|
-
get: function (target, key) {
|
|
793
|
-
if (key in target) {
|
|
794
|
-
return target[key];
|
|
795
|
-
}
|
|
796
|
-
if (!getRule(key)) {
|
|
797
|
-
return;
|
|
798
|
-
}
|
|
799
|
-
// Only on the first rule access - start the chain of calls
|
|
800
|
-
return genEnforceLazy(key);
|
|
801
|
-
}
|
|
802
|
-
});
|
|
803
|
-
function handleNoProxy() {
|
|
804
|
-
if (!isProxySupported()) {
|
|
805
|
-
eachEnforceRule(function (ruleName) {
|
|
806
|
-
// Only on the first rule access - start the chain of calls
|
|
807
|
-
target[ruleName] = genEnforceLazy(ruleName);
|
|
808
|
-
});
|
|
809
|
-
return assign(enforceEager, target);
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
var enforce = genEnforce();
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('n4s'), require('vest-utils'), require('context')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'n4s', 'vest-utils', 'context'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vest = {}, global.n4s, global['vest-utils'], global.context));
|
|
5
|
+
}(this, (function (exports, n4s, vestUtils, context$1) { 'use strict';
|
|
814
6
|
|
|
815
7
|
function shouldUseErrorAsMessage(message, error) {
|
|
816
8
|
// kind of cheating with this safe guard, but it does the job
|
|
817
|
-
return isUndefined(message) && isStringValue(error);
|
|
9
|
+
return vestUtils.isUndefined(message) && vestUtils.isStringValue(error);
|
|
818
10
|
}
|
|
819
11
|
|
|
820
12
|
var IsolateTypes;
|
|
@@ -868,10 +60,10 @@
|
|
|
868
60
|
};
|
|
869
61
|
}
|
|
870
62
|
|
|
871
|
-
var context = createContext(function (ctxRef, parentContext) {
|
|
63
|
+
var context = context$1.createContext(function (ctxRef, parentContext) {
|
|
872
64
|
return parentContext
|
|
873
65
|
? null
|
|
874
|
-
: assign({
|
|
66
|
+
: vestUtils.assign({
|
|
875
67
|
exclusion: {
|
|
876
68
|
tests: {},
|
|
877
69
|
groups: {}
|
|
@@ -898,29 +90,22 @@
|
|
|
898
90
|
return useStateRef().testCallbacks();
|
|
899
91
|
}
|
|
900
92
|
// OPTIONAL FIELDS
|
|
901
|
-
function useOptionalField(fieldName) {
|
|
902
|
-
var optionalFields = useOptionalFields()[0];
|
|
903
|
-
return optionalFields[fieldName];
|
|
904
|
-
}
|
|
905
93
|
function useOptionalFields() {
|
|
906
94
|
return useStateRef().optionalFields();
|
|
907
95
|
}
|
|
908
96
|
function useSetOptionalField(fieldName, setter) {
|
|
909
97
|
var _a = useOptionalFields(), setOptionalFields = _a[1];
|
|
910
|
-
setOptionalFields(function (
|
|
98
|
+
setOptionalFields(function (prev) {
|
|
911
99
|
var _a;
|
|
912
|
-
return assign(
|
|
913
|
-
_a[fieldName] =
|
|
100
|
+
return vestUtils.assign(prev, (_a = {},
|
|
101
|
+
_a[fieldName] = vestUtils.assign({}, prev[fieldName], setter(prev[fieldName])),
|
|
914
102
|
_a));
|
|
915
103
|
});
|
|
916
104
|
}
|
|
917
|
-
function
|
|
918
|
-
var _a;
|
|
919
|
-
return (_a = useOptionalField(fieldName)) === null || _a === void 0 ? void 0 : _a[1];
|
|
920
|
-
}
|
|
921
|
-
function useOptionalFieldConfig(fieldName) {
|
|
105
|
+
function useOptionalField(fieldName) {
|
|
922
106
|
var _a;
|
|
923
|
-
|
|
107
|
+
var optionalFields = useOptionalFields()[0];
|
|
108
|
+
return (_a = optionalFields[fieldName]) !== null && _a !== void 0 ? _a : {};
|
|
924
109
|
}
|
|
925
110
|
function useTestObjects() {
|
|
926
111
|
return useStateRef().testObjects();
|
|
@@ -935,7 +120,7 @@
|
|
|
935
120
|
var current = _a.current, prev = _a.prev;
|
|
936
121
|
return ({
|
|
937
122
|
prev: prev,
|
|
938
|
-
current: asArray(handler(current))
|
|
123
|
+
current: vestUtils.asArray(handler(current))
|
|
939
124
|
});
|
|
940
125
|
});
|
|
941
126
|
}
|
|
@@ -943,10 +128,10 @@
|
|
|
943
128
|
function useAllIncomplete() {
|
|
944
129
|
return useTestsFlat().filter(function (test) { return test.isPending(); });
|
|
945
130
|
}
|
|
946
|
-
var flatCache =
|
|
131
|
+
var flatCache = vestUtils.cache();
|
|
947
132
|
function useTestsFlat() {
|
|
948
133
|
var current = useTestObjects()[0].current;
|
|
949
|
-
return flatCache([current], function () { return flatten(current); });
|
|
134
|
+
return flatCache([current], function () { return vestUtils.nestedArray.flatten(current); });
|
|
950
135
|
}
|
|
951
136
|
function useEachTestObject(handler) {
|
|
952
137
|
var testObjects = useTestsFlat();
|
|
@@ -962,7 +147,7 @@
|
|
|
962
147
|
function VestTest(fieldName, testFn, _a) {
|
|
963
148
|
var _b = _a === void 0 ? {} : _a, message = _b.message, groupName = _b.groupName, key = _b.key;
|
|
964
149
|
this.key = null;
|
|
965
|
-
this.id =
|
|
150
|
+
this.id = vestUtils.seq();
|
|
966
151
|
this.severity = TestSeverity.Error;
|
|
967
152
|
this.status = STATUS_UNTESTED;
|
|
968
153
|
this.fieldName = fieldName;
|
|
@@ -1050,18 +235,9 @@
|
|
|
1050
235
|
VestTest.prototype.valueOf = function () {
|
|
1051
236
|
return !this.isFailing();
|
|
1052
237
|
};
|
|
1053
|
-
VestTest.prototype.hasFailures = function () {
|
|
1054
|
-
return this.isFailing() || this.isWarning();
|
|
1055
|
-
};
|
|
1056
|
-
VestTest.prototype.isNonActionable = function () {
|
|
1057
|
-
return this.isSkipped() || this.isOmitted() || this.isCanceled();
|
|
1058
|
-
};
|
|
1059
238
|
VestTest.prototype.isPending = function () {
|
|
1060
239
|
return this.statusEquals(STATUS_PENDING);
|
|
1061
240
|
};
|
|
1062
|
-
VestTest.prototype.isTested = function () {
|
|
1063
|
-
return this.hasFailures() || this.isPassing();
|
|
1064
|
-
};
|
|
1065
241
|
VestTest.prototype.isOmitted = function () {
|
|
1066
242
|
return this.statusEquals(STATUS_OMITTED);
|
|
1067
243
|
};
|
|
@@ -1083,6 +259,20 @@
|
|
|
1083
259
|
VestTest.prototype.isWarning = function () {
|
|
1084
260
|
return this.statusEquals(STATUS_WARNING);
|
|
1085
261
|
};
|
|
262
|
+
VestTest.prototype.hasFailures = function () {
|
|
263
|
+
return this.isFailing() || this.isWarning();
|
|
264
|
+
};
|
|
265
|
+
VestTest.prototype.isNonActionable = function () {
|
|
266
|
+
return this.isSkipped() || this.isOmitted() || this.isCanceled();
|
|
267
|
+
};
|
|
268
|
+
VestTest.prototype.isTested = function () {
|
|
269
|
+
return this.hasFailures() || this.isPassing();
|
|
270
|
+
};
|
|
271
|
+
VestTest.prototype.awaitsResolution = function () {
|
|
272
|
+
// Is the test in a state where it can still be run, or complete running
|
|
273
|
+
// and its final status is indeterminate?
|
|
274
|
+
return this.isSkipped() || this.isUntested() || this.isPending();
|
|
275
|
+
};
|
|
1086
276
|
VestTest.prototype.statusEquals = function (status) {
|
|
1087
277
|
return this.status === status;
|
|
1088
278
|
};
|
|
@@ -1135,12 +325,12 @@
|
|
|
1135
325
|
}
|
|
1136
326
|
function initKey(key, initialState, prevState) {
|
|
1137
327
|
current().push();
|
|
1138
|
-
set(key, optionalFunctionValue(initialState, prevState));
|
|
328
|
+
set(key, vestUtils.optionalFunctionValue(initialState, prevState));
|
|
1139
329
|
return function useStateKey() {
|
|
1140
330
|
return [
|
|
1141
331
|
current()[key],
|
|
1142
332
|
function (nextState) {
|
|
1143
|
-
return set(key, optionalFunctionValue(nextState, current()[key]));
|
|
333
|
+
return set(key, vestUtils.optionalFunctionValue(nextState, current()[key]));
|
|
1144
334
|
},
|
|
1145
335
|
];
|
|
1146
336
|
};
|
|
@@ -1152,10 +342,10 @@
|
|
|
1152
342
|
var prevValue = state.references[index];
|
|
1153
343
|
state.references[index] = value;
|
|
1154
344
|
var _a = registrations[index], onUpdate = _a[1];
|
|
1155
|
-
if (isFunction(onUpdate)) {
|
|
345
|
+
if (vestUtils.isFunction(onUpdate)) {
|
|
1156
346
|
onUpdate(value, prevValue);
|
|
1157
347
|
}
|
|
1158
|
-
if (isFunction(onStateChange)) {
|
|
348
|
+
if (vestUtils.isFunction(onStateChange)) {
|
|
1159
349
|
onStateChange();
|
|
1160
350
|
}
|
|
1161
351
|
}
|
|
@@ -1202,11 +392,11 @@
|
|
|
1202
392
|
|
|
1203
393
|
function usePrevKeys() {
|
|
1204
394
|
var prev = useTestObjects()[0].prev;
|
|
1205
|
-
return asArray(getCurrent(prev, useCurrentPath())).reduce(function (prevKeys, testObject) {
|
|
395
|
+
return vestUtils.asArray(vestUtils.nestedArray.getCurrent(prev, useCurrentPath())).reduce(function (prevKeys, testObject) {
|
|
1206
396
|
if (!(testObject instanceof VestTest)) {
|
|
1207
397
|
return prevKeys;
|
|
1208
398
|
}
|
|
1209
|
-
if (isNullish(testObject.key)) {
|
|
399
|
+
if (vestUtils.isNullish(testObject.key)) {
|
|
1210
400
|
return prevKeys;
|
|
1211
401
|
}
|
|
1212
402
|
prevKeys[testObject.key] = testObject;
|
|
@@ -1219,22 +409,22 @@
|
|
|
1219
409
|
}
|
|
1220
410
|
function useRetainTestKey(key, testObject) {
|
|
1221
411
|
var current = useIsolate().keys.current;
|
|
1222
|
-
if (isNullish(current[key])) {
|
|
412
|
+
if (vestUtils.isNullish(current[key])) {
|
|
1223
413
|
current[key] = testObject;
|
|
1224
414
|
}
|
|
1225
415
|
else {
|
|
1226
|
-
deferThrow("Encountered the same test key \"".concat(key, "\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."));
|
|
416
|
+
vestUtils.deferThrow("Encountered the same test key \"".concat(key, "\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."));
|
|
1227
417
|
}
|
|
1228
418
|
}
|
|
1229
419
|
|
|
1230
420
|
function isolate(_a, callback) {
|
|
1231
421
|
var _b = _a.type, type = _b === void 0 ? IsolateTypes.DEFAULT : _b;
|
|
1232
|
-
invariant(isFunction(callback));
|
|
422
|
+
vestUtils.invariant(vestUtils.isFunction(callback));
|
|
1233
423
|
// Generate a new Isolate layer, with its own cursor
|
|
1234
424
|
var isolate = generateIsolate(type, useCurrentPath());
|
|
1235
425
|
var output = context.run({ isolate: isolate }, function () {
|
|
1236
426
|
isolate.keys.prev = usePrevKeys();
|
|
1237
|
-
useSetTests(function (tests) { return setValueAtPath(tests, isolate.path, []); });
|
|
427
|
+
useSetTests(function (tests) { return vestUtils.nestedArray.setValueAtPath(tests, isolate.path, []); });
|
|
1238
428
|
var res = callback();
|
|
1239
429
|
return res;
|
|
1240
430
|
});
|
|
@@ -1272,7 +462,7 @@
|
|
|
1272
462
|
return !!(fieldName && testObject.fieldName === fieldName);
|
|
1273
463
|
}
|
|
1274
464
|
|
|
1275
|
-
var nonMatchingGroupName = bindNot(matchingGroupName);
|
|
465
|
+
var nonMatchingGroupName = vestUtils.bindNot(matchingGroupName);
|
|
1276
466
|
function matchingGroupName(testObject, groupName) {
|
|
1277
467
|
return testObject.groupName === groupName;
|
|
1278
468
|
}
|
|
@@ -1281,7 +471,7 @@
|
|
|
1281
471
|
* Checks that a given test object matches the currently specified severity level
|
|
1282
472
|
*/
|
|
1283
473
|
function nonMatchingSeverityProfile(severity, testObject) {
|
|
1284
|
-
return either(severity === Severity.WARNINGS, testObject.warns());
|
|
474
|
+
return vestUtils.either(severity === Severity.WARNINGS, testObject.warns());
|
|
1285
475
|
}
|
|
1286
476
|
|
|
1287
477
|
/**
|
|
@@ -1322,26 +512,85 @@
|
|
|
1322
512
|
return true;
|
|
1323
513
|
}
|
|
1324
514
|
|
|
515
|
+
/**
|
|
516
|
+
* Marks a field as optional, either just by name, or by a given condition.
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
*
|
|
520
|
+
* optional('field_name');
|
|
521
|
+
*
|
|
522
|
+
* optional({
|
|
523
|
+
* username: () => allowUsernameEmpty,
|
|
524
|
+
* });
|
|
525
|
+
*/
|
|
526
|
+
function optional(optionals) {
|
|
527
|
+
// There are two types of optional field declarations:
|
|
528
|
+
// 1. Delayed: A string, which is the name of the field to be optional.
|
|
529
|
+
// We will only determine whether to omit the test after the suite is done running
|
|
530
|
+
//
|
|
531
|
+
// 2. Immediate: Either a boolean or a function, which is used to determine
|
|
532
|
+
// if the field should be optional.
|
|
533
|
+
// Delayed case (field name)
|
|
534
|
+
if (vestUtils.isArray(optionals) || vestUtils.isStringValue(optionals)) {
|
|
535
|
+
vestUtils.asArray(optionals).forEach(function (optionalField) {
|
|
536
|
+
useSetOptionalField(optionalField, function () { return ({
|
|
537
|
+
type: OptionalFieldTypes.Delayed,
|
|
538
|
+
applied: false,
|
|
539
|
+
rule: null
|
|
540
|
+
}); });
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
var _loop_1 = function (field) {
|
|
545
|
+
var value = optionals[field];
|
|
546
|
+
useSetOptionalField(field, function () { return ({
|
|
547
|
+
type: OptionalFieldTypes.Immediate,
|
|
548
|
+
rule: value,
|
|
549
|
+
applied: vestUtils.optionalFunctionValue(value)
|
|
550
|
+
}); });
|
|
551
|
+
};
|
|
552
|
+
// Immediately case (function or boolean)
|
|
553
|
+
for (var field in optionals) {
|
|
554
|
+
_loop_1(field);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
function optionalFiedIsApplied(fieldName) {
|
|
559
|
+
if (!fieldName) {
|
|
560
|
+
return false;
|
|
561
|
+
}
|
|
562
|
+
return useOptionalField(fieldName).applied;
|
|
563
|
+
}
|
|
564
|
+
var OptionalFieldTypes;
|
|
565
|
+
(function (OptionalFieldTypes) {
|
|
566
|
+
OptionalFieldTypes[OptionalFieldTypes["Immediate"] = 0] = "Immediate";
|
|
567
|
+
OptionalFieldTypes[OptionalFieldTypes["Delayed"] = 1] = "Delayed";
|
|
568
|
+
})(OptionalFieldTypes || (OptionalFieldTypes = {}));
|
|
569
|
+
|
|
1325
570
|
// eslint-disable-next-line max-statements, complexity
|
|
1326
571
|
function shouldAddValidProperty(fieldName) {
|
|
1327
|
-
|
|
572
|
+
// Is the field optional, and the optional condition is applied
|
|
573
|
+
if (optionalFiedIsApplied(fieldName)) {
|
|
1328
574
|
return true;
|
|
1329
575
|
}
|
|
1330
|
-
|
|
576
|
+
var testObjects = useTestsFlat();
|
|
577
|
+
// Are there no tests?
|
|
578
|
+
if (vestUtils.isEmpty(testObjects)) {
|
|
1331
579
|
return false;
|
|
1332
580
|
}
|
|
1333
|
-
|
|
1334
|
-
if (
|
|
581
|
+
// Does the field have any tests with errors?
|
|
582
|
+
if (hasErrorsByTestObjects(fieldName)) {
|
|
1335
583
|
return false;
|
|
1336
584
|
}
|
|
1337
585
|
// Does the given field have any pending tests that are not optional?
|
|
1338
586
|
if (hasNonOptionalIncomplete(fieldName)) {
|
|
1339
587
|
return false;
|
|
1340
588
|
}
|
|
589
|
+
// Does the field have no missing tests?
|
|
1341
590
|
return noMissingTests(fieldName);
|
|
1342
591
|
}
|
|
1343
592
|
function shouldAddValidPropertyInGroup(groupName, fieldName) {
|
|
1344
|
-
if (
|
|
593
|
+
if (optionalFiedIsApplied(fieldName)) {
|
|
1345
594
|
return true;
|
|
1346
595
|
}
|
|
1347
596
|
if (hasGroupFailuresByTestObjects(Severity.ERRORS, groupName, fieldName)) {
|
|
@@ -1353,71 +602,76 @@
|
|
|
1353
602
|
}
|
|
1354
603
|
return noMissingTestsByGroup(groupName, fieldName);
|
|
1355
604
|
}
|
|
1356
|
-
function fieldIsOmitted(fieldName) {
|
|
1357
|
-
if (!fieldName) {
|
|
1358
|
-
return false;
|
|
1359
|
-
}
|
|
1360
|
-
return useOptionalFieldApplied(fieldName) === true;
|
|
1361
|
-
}
|
|
1362
605
|
// Does the given field have any pending tests that are not optional?
|
|
1363
606
|
function hasNonOptionalIncomplete(fieldName) {
|
|
1364
|
-
return isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
1365
|
-
return
|
|
607
|
+
return vestUtils.isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
608
|
+
return isTestObjectOptional(testObject, fieldName);
|
|
1366
609
|
}));
|
|
1367
610
|
}
|
|
1368
611
|
// Do the given group/field have any pending tests that are not optional?
|
|
1369
612
|
function hasNonOptionalIncompleteByGroup(groupName, fieldName) {
|
|
1370
|
-
return isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
613
|
+
return vestUtils.isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
1371
614
|
if (nonMatchingGroupName(testObject, groupName)) {
|
|
1372
615
|
return false;
|
|
1373
616
|
}
|
|
1374
|
-
return
|
|
617
|
+
return isTestObjectOptional(testObject, fieldName);
|
|
1375
618
|
}));
|
|
1376
619
|
}
|
|
1377
|
-
function
|
|
620
|
+
function isTestObjectOptional(testObject, fieldName) {
|
|
1378
621
|
if (nonMatchingFieldName(testObject, fieldName)) {
|
|
1379
622
|
return false;
|
|
1380
623
|
}
|
|
1381
|
-
return
|
|
624
|
+
return optionalFiedIsApplied(fieldName);
|
|
1382
625
|
}
|
|
626
|
+
// Did all of the tests for the provided field run/omit?
|
|
627
|
+
// This makes sure that the fields are not skipped or pending.
|
|
1383
628
|
function noMissingTests(fieldName) {
|
|
1384
629
|
var testObjects = useTestsFlat();
|
|
1385
630
|
return testObjects.every(function (testObject) {
|
|
1386
|
-
|
|
1387
|
-
return true;
|
|
1388
|
-
}
|
|
1389
|
-
return missingTestsLogic(testObject, fieldName);
|
|
631
|
+
return noMissingTestsLogic(testObject, fieldName);
|
|
1390
632
|
});
|
|
1391
633
|
}
|
|
634
|
+
// Does the group have no missing tests?
|
|
1392
635
|
function noMissingTestsByGroup(groupName, fieldName) {
|
|
1393
636
|
var testObjects = useTestsFlat();
|
|
1394
637
|
return testObjects.every(function (testObject) {
|
|
1395
638
|
if (nonMatchingGroupName(testObject, groupName)) {
|
|
1396
639
|
return true;
|
|
1397
640
|
}
|
|
1398
|
-
return
|
|
641
|
+
return noMissingTestsLogic(testObject, fieldName);
|
|
1399
642
|
});
|
|
1400
643
|
}
|
|
1401
|
-
|
|
644
|
+
// Does the object qualify as either tested or omitted (but not skipped!)
|
|
645
|
+
function noMissingTestsLogic(testObject, fieldName) {
|
|
1402
646
|
if (nonMatchingFieldName(testObject, fieldName)) {
|
|
1403
647
|
return true;
|
|
1404
648
|
}
|
|
1405
|
-
|
|
649
|
+
/**
|
|
650
|
+
* The reason we're checking for the optional field here and not in "omitOptionalFields"
|
|
651
|
+
* is because that unlike the bool/function check we do there, here it only depends on
|
|
652
|
+
* whether the field was tested alredy or not.
|
|
653
|
+
*
|
|
654
|
+
* We qualify the test as not missing only if it was already run, if it is omitted,
|
|
655
|
+
* or if it is marked as optional, even if the optional check did not apply yet -
|
|
656
|
+
* but the test did not reach its final state.
|
|
657
|
+
*/
|
|
658
|
+
return (optionalTestAwaitsResolution(testObject) ||
|
|
1406
659
|
testObject.isTested() ||
|
|
1407
660
|
testObject.isOmitted());
|
|
1408
661
|
}
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
662
|
+
function optionalTestAwaitsResolution(testObject) {
|
|
663
|
+
// Does the test belong to an optional field,
|
|
664
|
+
// and the test itself is still in an indeterminate state?
|
|
665
|
+
return (useOptionalField(testObject.fieldName).type ===
|
|
666
|
+
OptionalFieldTypes.Delayed && testObject.awaitsResolution());
|
|
1414
667
|
}
|
|
668
|
+
|
|
1415
669
|
/**
|
|
1416
670
|
* Reads the testObjects list and gets full validation result from it.
|
|
1417
671
|
*/
|
|
1418
672
|
function genTestsSummary() {
|
|
1419
673
|
var testObjects = useTestsFlat();
|
|
1420
|
-
var summary = assign(baseStats(), {
|
|
674
|
+
var summary = vestUtils.assign(baseStats(), {
|
|
1421
675
|
groups: {},
|
|
1422
676
|
tests: {},
|
|
1423
677
|
valid: false
|
|
@@ -1494,7 +748,7 @@
|
|
|
1494
748
|
};
|
|
1495
749
|
}
|
|
1496
750
|
function baseTestStats() {
|
|
1497
|
-
return assign(baseStats(), {
|
|
751
|
+
return vestUtils.assign(baseStats(), {
|
|
1498
752
|
errors: [],
|
|
1499
753
|
warnings: []
|
|
1500
754
|
});
|
|
@@ -1514,7 +768,7 @@
|
|
|
1514
768
|
var output = {};
|
|
1515
769
|
var countKey = countKeyBySeverity(severityKey);
|
|
1516
770
|
for (var field in testGroup) {
|
|
1517
|
-
if (isPositive(testGroup[field][countKey])) {
|
|
771
|
+
if (vestUtils.isPositive(testGroup[field][countKey])) {
|
|
1518
772
|
// We will probably never get to the fallback array
|
|
1519
773
|
// leaving it just in case the implementation changes
|
|
1520
774
|
output[field] = testGroup[field][severityKey] || [];
|
|
@@ -1523,118 +777,117 @@
|
|
|
1523
777
|
return output;
|
|
1524
778
|
}
|
|
1525
779
|
|
|
1526
|
-
function
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
780
|
+
// eslint-disable-next-line max-lines-per-function, max-statements
|
|
781
|
+
function suiteSelectors(summary) {
|
|
782
|
+
var selectors = {
|
|
783
|
+
getErrors: getErrors,
|
|
784
|
+
getErrorsByGroup: getErrorsByGroup,
|
|
785
|
+
getWarnings: getWarnings,
|
|
786
|
+
getWarningsByGroup: getWarningsByGroup,
|
|
787
|
+
hasErrors: hasErrors,
|
|
788
|
+
hasErrorsByGroup: hasErrorsByGroup,
|
|
789
|
+
hasWarnings: hasWarnings,
|
|
790
|
+
hasWarningsByGroup: hasWarningsByGroup,
|
|
791
|
+
isValid: isValid,
|
|
792
|
+
isValidByGroup: isValidByGroup
|
|
793
|
+
};
|
|
794
|
+
return selectors;
|
|
795
|
+
// Booleans
|
|
796
|
+
function isValid(fieldName) {
|
|
797
|
+
var _a;
|
|
798
|
+
return fieldName ? Boolean((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.valid) : summary.valid;
|
|
799
|
+
}
|
|
800
|
+
function isValidByGroup(groupName, fieldName) {
|
|
801
|
+
var group = summary.groups[groupName];
|
|
802
|
+
if (!group) {
|
|
803
|
+
return false;
|
|
804
|
+
}
|
|
805
|
+
if (fieldName) {
|
|
806
|
+
return isFieldValid(group, fieldName);
|
|
807
|
+
}
|
|
808
|
+
for (var fieldName_1 in group) {
|
|
809
|
+
if (!isFieldValid(group, fieldName_1)) {
|
|
810
|
+
return false;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
815
|
+
function hasWarnings(fieldName) {
|
|
816
|
+
return hasFailures(summary, SeverityCount.WARN_COUNT, fieldName);
|
|
817
|
+
}
|
|
818
|
+
function hasErrors(fieldName) {
|
|
819
|
+
return hasFailures(summary, SeverityCount.ERROR_COUNT, fieldName);
|
|
820
|
+
}
|
|
821
|
+
function hasWarningsByGroup(groupName, fieldName) {
|
|
822
|
+
return hasFailuresByGroup(summary, SeverityCount.WARN_COUNT, groupName, fieldName);
|
|
823
|
+
}
|
|
824
|
+
function hasErrorsByGroup(groupName, fieldName) {
|
|
825
|
+
return hasFailuresByGroup(summary, SeverityCount.ERROR_COUNT, groupName, fieldName);
|
|
826
|
+
}
|
|
827
|
+
function getWarnings(fieldName) {
|
|
828
|
+
return getFailures(summary, Severity.WARNINGS, fieldName);
|
|
829
|
+
}
|
|
830
|
+
function getErrors(fieldName) {
|
|
831
|
+
return getFailures(summary, Severity.ERRORS, fieldName);
|
|
832
|
+
}
|
|
833
|
+
function getErrorsByGroup(groupName, fieldName) {
|
|
834
|
+
return getFailuresByGroup(summary, Severity.ERRORS, groupName, fieldName);
|
|
835
|
+
}
|
|
836
|
+
function getWarningsByGroup(groupName, fieldName) {
|
|
837
|
+
return getFailuresByGroup(summary, Severity.WARNINGS, groupName, fieldName);
|
|
838
|
+
}
|
|
1531
839
|
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
function getFailures(severityKey, fieldName) {
|
|
1536
|
-
var summary = useSummary();
|
|
840
|
+
// Gathers all failures of a given severity
|
|
841
|
+
// With a fieldName, it will only gather failures for that field
|
|
842
|
+
function getFailures(summary, severityKey, fieldName) {
|
|
1537
843
|
return gatherFailures(summary.tests, severityKey, fieldName);
|
|
1538
844
|
}
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
}
|
|
1543
|
-
function getWarningsByGroup(groupName, fieldName) {
|
|
1544
|
-
return getFailuresByGroup(groupName, Severity.WARNINGS, fieldName);
|
|
1545
|
-
}
|
|
1546
|
-
function getFailuresByGroup(groupName, severityKey, fieldName) {
|
|
1547
|
-
var summary = useSummary();
|
|
845
|
+
// Gathers all failures of a given severity within a group
|
|
846
|
+
// With a fieldName, it will only gather failures for that field
|
|
847
|
+
function getFailuresByGroup(summary, severityKey, groupName, fieldName) {
|
|
1548
848
|
return gatherFailures(summary.groups[groupName], severityKey, fieldName);
|
|
1549
849
|
}
|
|
1550
|
-
|
|
1551
|
-
function
|
|
1552
|
-
return hasFailures(SeverityCount.ERROR_COUNT, fieldName);
|
|
1553
|
-
}
|
|
1554
|
-
function hasWarnings(fieldName) {
|
|
1555
|
-
return hasFailures(SeverityCount.WARN_COUNT, fieldName);
|
|
1556
|
-
}
|
|
1557
|
-
function hasFailures(severityCount, fieldName) {
|
|
850
|
+
// Checks if a field is valid within a container object - can be within a group or top level
|
|
851
|
+
function isFieldValid(testContainer, fieldName) {
|
|
1558
852
|
var _a;
|
|
1559
|
-
|
|
1560
|
-
if (fieldName) {
|
|
1561
|
-
return isPositive((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
1562
|
-
}
|
|
1563
|
-
return isPositive(summary[severityCount]);
|
|
1564
|
-
}
|
|
1565
|
-
|
|
1566
|
-
function hasErrorsByGroup(groupName, fieldName) {
|
|
1567
|
-
return hasFailuresByGroup(Severity.ERRORS, groupName, fieldName);
|
|
1568
|
-
}
|
|
1569
|
-
function hasWarningsByGroup(groupName, fieldName) {
|
|
1570
|
-
return hasFailuresByGroup(Severity.WARNINGS, groupName, fieldName);
|
|
853
|
+
return !!((_a = testContainer[fieldName]) === null || _a === void 0 ? void 0 : _a.valid);
|
|
1571
854
|
}
|
|
1572
|
-
//
|
|
1573
|
-
|
|
855
|
+
// Checks if a there are any failures of a given severity within a group
|
|
856
|
+
// If a fieldName is provided, it will only check for failures within that field
|
|
857
|
+
function hasFailuresByGroup(summary, severityCount, groupName, fieldName) {
|
|
1574
858
|
var _a, _b;
|
|
1575
|
-
var summary = useSummary();
|
|
1576
|
-
var severityCount = countKeyBySeverity(severityKey);
|
|
1577
859
|
var group = summary.groups[groupName];
|
|
1578
860
|
if (!group) {
|
|
1579
861
|
return false;
|
|
1580
862
|
}
|
|
1581
863
|
if (fieldName) {
|
|
1582
|
-
return isPositive((_a = group[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
864
|
+
return vestUtils.isPositive((_a = group[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
1583
865
|
}
|
|
1584
866
|
for (var field in group) {
|
|
1585
|
-
if (isPositive((_b = group[field]) === null || _b === void 0 ? void 0 : _b[severityCount])) {
|
|
867
|
+
if (vestUtils.isPositive((_b = group[field]) === null || _b === void 0 ? void 0 : _b[severityCount])) {
|
|
1586
868
|
return true;
|
|
1587
869
|
}
|
|
1588
870
|
}
|
|
1589
871
|
return false;
|
|
1590
872
|
}
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
return fieldName
|
|
1595
|
-
? Boolean(isFieldValid(summary.tests, fieldName))
|
|
1596
|
-
: summary.valid;
|
|
1597
|
-
}
|
|
1598
|
-
function isValidByGroup(groupName, fieldName) {
|
|
1599
|
-
var summary = useSummary();
|
|
1600
|
-
var group = summary.groups[groupName];
|
|
1601
|
-
if (!group) {
|
|
1602
|
-
return false;
|
|
1603
|
-
}
|
|
1604
|
-
if (fieldName) {
|
|
1605
|
-
return isFieldValid(group, fieldName);
|
|
1606
|
-
}
|
|
1607
|
-
for (var fieldName_1 in group) {
|
|
1608
|
-
if (!isFieldValid(group, fieldName_1)) {
|
|
1609
|
-
return false;
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
return true;
|
|
1613
|
-
}
|
|
1614
|
-
function isFieldValid(testContainer, fieldName) {
|
|
873
|
+
// Checks if there are any failures of a given severity
|
|
874
|
+
// If a fieldName is provided, it will only check for failures within that field
|
|
875
|
+
function hasFailures(summary, countKey, fieldName) {
|
|
1615
876
|
var _a;
|
|
1616
|
-
|
|
877
|
+
var failureCount = fieldName
|
|
878
|
+
? (_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[countKey]
|
|
879
|
+
: summary[countKey] || 0;
|
|
880
|
+
return vestUtils.isPositive(failureCount);
|
|
1617
881
|
}
|
|
1618
882
|
|
|
1619
|
-
var cache$1 =
|
|
883
|
+
var cache$1 = vestUtils.cache(1);
|
|
1620
884
|
function produceSuiteResult() {
|
|
1621
885
|
var testObjects = useTestsFlat();
|
|
1622
886
|
var ctxRef = { stateRef: useStateRef() };
|
|
1623
887
|
return cache$1([testObjects], context.bind(ctxRef, function () {
|
|
1624
888
|
var summary = genTestsSummary();
|
|
1625
889
|
var suiteName = useSuiteName();
|
|
1626
|
-
|
|
1627
|
-
return assign(summary, {
|
|
1628
|
-
getErrors: context.bind(ref, getErrors),
|
|
1629
|
-
getErrorsByGroup: context.bind(ref, getErrorsByGroup),
|
|
1630
|
-
getWarnings: context.bind(ref, getWarnings),
|
|
1631
|
-
getWarningsByGroup: context.bind(ref, getWarningsByGroup),
|
|
1632
|
-
hasErrors: context.bind(ref, hasErrors),
|
|
1633
|
-
hasErrorsByGroup: context.bind(ref, hasErrorsByGroup),
|
|
1634
|
-
hasWarnings: context.bind(ref, hasWarnings),
|
|
1635
|
-
hasWarningsByGroup: context.bind(ref, hasWarningsByGroup),
|
|
1636
|
-
isValid: context.bind(ref, isValid),
|
|
1637
|
-
isValidByGroup: context.bind(ref, isValidByGroup),
|
|
890
|
+
return vestUtils.assign(summary, suiteSelectors(summary), {
|
|
1638
891
|
suiteName: suiteName
|
|
1639
892
|
});
|
|
1640
893
|
}));
|
|
@@ -1645,7 +898,7 @@
|
|
|
1645
898
|
*/
|
|
1646
899
|
function hasRemainingTests(fieldName) {
|
|
1647
900
|
var allIncomplete = useAllIncomplete();
|
|
1648
|
-
if (isEmpty(allIncomplete)) {
|
|
901
|
+
if (vestUtils.isEmpty(allIncomplete)) {
|
|
1649
902
|
return false;
|
|
1650
903
|
}
|
|
1651
904
|
if (fieldName) {
|
|
@@ -1653,15 +906,15 @@
|
|
|
1653
906
|
return matchingFieldName(testObject, fieldName);
|
|
1654
907
|
});
|
|
1655
908
|
}
|
|
1656
|
-
return
|
|
909
|
+
return true;
|
|
1657
910
|
}
|
|
1658
911
|
|
|
1659
|
-
var cache =
|
|
912
|
+
var cache = vestUtils.cache(20);
|
|
1660
913
|
function produceFullResult() {
|
|
1661
914
|
var testObjects = useTestsFlat();
|
|
1662
915
|
var ctxRef = { stateRef: useStateRef() };
|
|
1663
916
|
return cache([testObjects], context.bind(ctxRef, function () {
|
|
1664
|
-
return assign({}, produceSuiteResult(), {
|
|
917
|
+
return vestUtils.assign({}, produceSuiteResult(), {
|
|
1665
918
|
done: context.bind(ctxRef, done)
|
|
1666
919
|
});
|
|
1667
920
|
}));
|
|
@@ -1670,10 +923,10 @@
|
|
|
1670
923
|
* DONE is here and not in its own module to prevent circular dependency issues.
|
|
1671
924
|
*/
|
|
1672
925
|
function shouldSkipDoneRegistration(callback, fieldName, output) {
|
|
926
|
+
var _a;
|
|
1673
927
|
// If we do not have any test runs for the current field
|
|
1674
|
-
return !!(!isFunction(callback) ||
|
|
1675
|
-
(fieldName &&
|
|
1676
|
-
(!output.tests[fieldName] || isEmpty(output.tests[fieldName].testCount))));
|
|
928
|
+
return !!(!vestUtils.isFunction(callback) ||
|
|
929
|
+
(fieldName && vestUtils.numberEquals((_a = output.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.testCount, 0)));
|
|
1677
930
|
}
|
|
1678
931
|
function shouldRunDoneCallback(fieldName) {
|
|
1679
932
|
// is suite finished || field name exists, and test is finished;
|
|
@@ -1715,34 +968,48 @@
|
|
|
1715
968
|
});
|
|
1716
969
|
}
|
|
1717
970
|
|
|
971
|
+
/**
|
|
972
|
+
* This module gets triggered once the suite is done running its sync tests.
|
|
973
|
+
*
|
|
974
|
+
* It goes over all the tests in the state, and checks if they need to be omitted.
|
|
975
|
+
*/
|
|
1718
976
|
function omitOptionalFields() {
|
|
1719
977
|
var optionalFields = useOptionalFields()[0];
|
|
1720
|
-
|
|
978
|
+
// If there are no optional fields, we don't need to do anything
|
|
979
|
+
if (vestUtils.isEmpty(optionalFields)) {
|
|
1721
980
|
return;
|
|
1722
981
|
}
|
|
982
|
+
// Create an object to store the fields that need to be omitted
|
|
1723
983
|
var shouldOmit = {};
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
984
|
+
// iterate over each of the tests in the state
|
|
985
|
+
useTestsFlat().forEach(function (testObject) {
|
|
986
|
+
// If we already added the current field (not this test specifically)
|
|
987
|
+
// no need for further checks, go and omit the test
|
|
988
|
+
if (vestUtils.hasOwnProperty(shouldOmit, testObject.fieldName)) {
|
|
989
|
+
verifyAndOmit(testObject);
|
|
990
|
+
}
|
|
991
|
+
else {
|
|
992
|
+
// check if the field has an optional function
|
|
993
|
+
// if so, run it and verify/omit the test
|
|
994
|
+
runOptionalConfig(testObject);
|
|
995
|
+
}
|
|
1735
996
|
});
|
|
997
|
+
// refresh the tests in the state so that the omitted fields are applied
|
|
998
|
+
useRefreshTestObjects();
|
|
1736
999
|
function verifyAndOmit(testObject) {
|
|
1737
1000
|
if (shouldOmit[testObject.fieldName]) {
|
|
1738
1001
|
testObject.omit();
|
|
1739
|
-
useSetOptionalField(testObject.fieldName, function (
|
|
1002
|
+
useSetOptionalField(testObject.fieldName, function () { return ({
|
|
1003
|
+
applied: true
|
|
1004
|
+
}); });
|
|
1740
1005
|
}
|
|
1741
1006
|
}
|
|
1742
1007
|
function runOptionalConfig(testObject) {
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1008
|
+
// Ge the optional configuration for the given field
|
|
1009
|
+
var optionalConfig = useOptionalField(testObject.fieldName);
|
|
1010
|
+
// If the optional was set to a function or a boolean, run it and verify/omit the test
|
|
1011
|
+
if (optionalConfig.type === OptionalFieldTypes.Immediate) {
|
|
1012
|
+
shouldOmit[testObject.fieldName] = vestUtils.optionalFunctionValue(optionalConfig.rule);
|
|
1746
1013
|
verifyAndOmit(testObject);
|
|
1747
1014
|
}
|
|
1748
1015
|
}
|
|
@@ -1753,7 +1020,7 @@
|
|
|
1753
1020
|
*/
|
|
1754
1021
|
function removeTestFromState (testObject) {
|
|
1755
1022
|
useSetTests(function (tests) {
|
|
1756
|
-
return transform(tests, function (test) { return (testObject !== test ? test : null); });
|
|
1023
|
+
return vestUtils.nestedArray.transform(tests, function (test) { return (testObject !== test ? test : null); });
|
|
1757
1024
|
});
|
|
1758
1025
|
}
|
|
1759
1026
|
|
|
@@ -1764,8 +1031,8 @@
|
|
|
1764
1031
|
var fieldCallbacks = useTestCallbacks()[0].fieldCallbacks;
|
|
1765
1032
|
if (fieldName &&
|
|
1766
1033
|
!hasRemainingTests(fieldName) &&
|
|
1767
|
-
isArray(fieldCallbacks[fieldName])) {
|
|
1768
|
-
callEach(fieldCallbacks[fieldName]);
|
|
1034
|
+
vestUtils.isArray(fieldCallbacks[fieldName])) {
|
|
1035
|
+
vestUtils.callEach(fieldCallbacks[fieldName]);
|
|
1769
1036
|
}
|
|
1770
1037
|
}
|
|
1771
1038
|
/**
|
|
@@ -1773,12 +1040,12 @@
|
|
|
1773
1040
|
*/
|
|
1774
1041
|
function runDoneCallbacks() {
|
|
1775
1042
|
var doneCallbacks = useTestCallbacks()[0].doneCallbacks;
|
|
1776
|
-
callEach(doneCallbacks);
|
|
1043
|
+
vestUtils.callEach(doneCallbacks);
|
|
1777
1044
|
}
|
|
1778
1045
|
|
|
1779
1046
|
// eslint-disable-next-line max-lines-per-function
|
|
1780
1047
|
function initBus() {
|
|
1781
|
-
var vestBus = createBus();
|
|
1048
|
+
var vestBus = vestUtils.bus.createBus();
|
|
1782
1049
|
// Report a the completion of a test. There may be other tests with the same
|
|
1783
1050
|
// name that are still running, or not yet started.
|
|
1784
1051
|
vestBus.on(Events.TEST_COMPLETED, function (testObject) {
|
|
@@ -1823,7 +1090,7 @@
|
|
|
1823
1090
|
}
|
|
1824
1091
|
function useBus() {
|
|
1825
1092
|
var context$1 = context.useX();
|
|
1826
|
-
invariant(context$1.bus);
|
|
1093
|
+
vestUtils.invariant(context$1.bus);
|
|
1827
1094
|
return context$1.bus;
|
|
1828
1095
|
}
|
|
1829
1096
|
var Events;
|
|
@@ -1842,16 +1109,16 @@
|
|
|
1842
1109
|
args[_i] = arguments[_i];
|
|
1843
1110
|
}
|
|
1844
1111
|
var _a = args.reverse(), suiteCallback = _a[0], suiteName = _a[1];
|
|
1845
|
-
invariant(isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
|
|
1112
|
+
vestUtils.invariant(vestUtils.isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
|
|
1846
1113
|
// Event bus initialization
|
|
1847
1114
|
var bus = initBus();
|
|
1848
1115
|
// State initialization
|
|
1849
1116
|
var state = createState();
|
|
1850
1117
|
// State reference - this holds the actual state values
|
|
1851
|
-
var stateRef = createStateRef(state, { suiteId:
|
|
1118
|
+
var stateRef = createStateRef(state, { suiteId: vestUtils.seq(), suiteName: suiteName });
|
|
1852
1119
|
// Create base context reference. All hooks will derive their data from this
|
|
1853
1120
|
var ctxRef = { stateRef: stateRef, bus: bus };
|
|
1854
|
-
var suite = assign(
|
|
1121
|
+
var suite = vestUtils.assign(
|
|
1855
1122
|
// Bind the suite body to the context
|
|
1856
1123
|
context.bind(ctxRef, function () {
|
|
1857
1124
|
var args = [];
|
|
@@ -1897,7 +1164,7 @@
|
|
|
1897
1164
|
* })
|
|
1898
1165
|
*/
|
|
1899
1166
|
function each(list, callback) {
|
|
1900
|
-
invariant(isFunction(callback), 'each callback must be a function');
|
|
1167
|
+
vestUtils.invariant(vestUtils.isFunction(callback), 'each callback must be a function');
|
|
1901
1168
|
isolate({ type: IsolateTypes.EACH }, function () {
|
|
1902
1169
|
list.forEach(function (arg, index) {
|
|
1903
1170
|
callback(arg, index);
|
|
@@ -1927,7 +1194,7 @@
|
|
|
1927
1194
|
// we should skip the test if the parent conditional is true.
|
|
1928
1195
|
isExcludedIndividually() ||
|
|
1929
1196
|
// Otherwise, we should skip the test if the conditional is true.
|
|
1930
|
-
optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
|
|
1197
|
+
vestUtils.optionalFunctionValue(conditional, vestUtils.optionalFunctionValue(produceSuiteResult))
|
|
1931
1198
|
}, function () { return callback(); });
|
|
1932
1199
|
});
|
|
1933
1200
|
}
|
|
@@ -1962,7 +1229,7 @@
|
|
|
1962
1229
|
return addTo(1 /* ExclusionGroup.SKIP */, 'groups', item);
|
|
1963
1230
|
};
|
|
1964
1231
|
//Checks whether a certain test profile excluded by any of the exclusion groups.
|
|
1965
|
-
// eslint-disable-next-line complexity, max-statements
|
|
1232
|
+
// eslint-disable-next-line complexity, max-statements
|
|
1966
1233
|
function isExcluded(testObject) {
|
|
1967
1234
|
var fieldName = testObject.fieldName, groupName = testObject.groupName;
|
|
1968
1235
|
if (isExcludedIndividually())
|
|
@@ -2003,7 +1270,7 @@
|
|
|
2003
1270
|
// Check if inclusion rules for this field (`include` hook)
|
|
2004
1271
|
// TODO: Check if this may need to be moved outside of the condition.
|
|
2005
1272
|
// What if there are no included tests? This shouldn't run then?
|
|
2006
|
-
return !optionalFunctionValue(inclusion[fieldName]);
|
|
1273
|
+
return !vestUtils.optionalFunctionValue(inclusion[fieldName]);
|
|
2007
1274
|
}
|
|
2008
1275
|
// We're done here. This field is not excluded
|
|
2009
1276
|
return false;
|
|
@@ -2015,7 +1282,7 @@
|
|
|
2015
1282
|
var context$1 = context.useX();
|
|
2016
1283
|
var exclusion = context$1.exclusion;
|
|
2017
1284
|
var keyGroups = exclusion.groups;
|
|
2018
|
-
var groupPresent = hasOwnProperty(keyGroups, groupName);
|
|
1285
|
+
var groupPresent = vestUtils.hasOwnProperty(keyGroups, groupName);
|
|
2019
1286
|
// When group is either only'ed or skipped
|
|
2020
1287
|
if (groupPresent) {
|
|
2021
1288
|
// Return true if group is skipped and false if only'ed
|
|
@@ -2033,8 +1300,8 @@
|
|
|
2033
1300
|
if (!item) {
|
|
2034
1301
|
return;
|
|
2035
1302
|
}
|
|
2036
|
-
asArray(item).forEach(function (itemName) {
|
|
2037
|
-
if (!isStringValue(itemName)) {
|
|
1303
|
+
vestUtils.asArray(item).forEach(function (itemName) {
|
|
1304
|
+
if (!vestUtils.isStringValue(itemName)) {
|
|
2038
1305
|
return;
|
|
2039
1306
|
}
|
|
2040
1307
|
context$1.exclusion[itemType][itemName] =
|
|
@@ -2081,8 +1348,8 @@
|
|
|
2081
1348
|
* });
|
|
2082
1349
|
*/
|
|
2083
1350
|
function group(groupName, tests) {
|
|
2084
|
-
invariant(isStringValue(groupName), groupErrorMsg('name must be a string'));
|
|
2085
|
-
invariant(isFunction(tests), groupErrorMsg('callback must be a function'));
|
|
1351
|
+
vestUtils.invariant(vestUtils.isStringValue(groupName), groupErrorMsg('name must be a string'));
|
|
1352
|
+
vestUtils.invariant(vestUtils.isFunction(tests), groupErrorMsg('callback must be a function'));
|
|
2086
1353
|
// Running with the context applied
|
|
2087
1354
|
isolate({ type: IsolateTypes.GROUP }, function () {
|
|
2088
1355
|
context.run({ groupName: groupName }, tests);
|
|
@@ -2095,24 +1362,24 @@
|
|
|
2095
1362
|
function include(fieldName) {
|
|
2096
1363
|
var context$1 = context.useX();
|
|
2097
1364
|
var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
|
|
2098
|
-
invariant(isStringValue(fieldName));
|
|
2099
|
-
inclusion[fieldName] = defaultTo(exclusion.tests[fieldName], true);
|
|
1365
|
+
vestUtils.invariant(vestUtils.isStringValue(fieldName));
|
|
1366
|
+
inclusion[fieldName] = vestUtils.defaultTo(exclusion.tests[fieldName], true);
|
|
2100
1367
|
return { when: when };
|
|
2101
1368
|
function when(condition) {
|
|
2102
1369
|
var context$1 = context.useX();
|
|
2103
1370
|
var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
|
|
2104
1371
|
// This callback will run as part of the "isExcluded" series of checks
|
|
2105
1372
|
inclusion[fieldName] = function () {
|
|
2106
|
-
if (hasOwnProperty(exclusion.tests, fieldName)) {
|
|
1373
|
+
if (vestUtils.hasOwnProperty(exclusion.tests, fieldName)) {
|
|
2107
1374
|
// I suspect this code is technically unreachable because
|
|
2108
1375
|
// if there are any skip/only rules applied to the current
|
|
2109
1376
|
// field, the "isExcluded" function will have already bailed
|
|
2110
|
-
return defaultTo(exclusion.tests[fieldName], true);
|
|
1377
|
+
return vestUtils.defaultTo(exclusion.tests[fieldName], true);
|
|
2111
1378
|
}
|
|
2112
|
-
if (isStringValue(condition)) {
|
|
1379
|
+
if (vestUtils.isStringValue(condition)) {
|
|
2113
1380
|
return Boolean(exclusion.tests[condition]);
|
|
2114
1381
|
}
|
|
2115
|
-
return optionalFunctionValue(condition, optionalFunctionValue(produceSuiteResult));
|
|
1382
|
+
return vestUtils.optionalFunctionValue(condition, vestUtils.optionalFunctionValue(produceSuiteResult));
|
|
2116
1383
|
};
|
|
2117
1384
|
}
|
|
2118
1385
|
}
|
|
@@ -2166,42 +1433,39 @@
|
|
|
2166
1433
|
function omitWhen(conditional, callback) {
|
|
2167
1434
|
isolate({ type: IsolateTypes.OMIT_WHEN }, function () {
|
|
2168
1435
|
context.run({
|
|
2169
|
-
omitted:
|
|
2170
|
-
optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
|
|
1436
|
+
omitted: inActiveOmitWhen() ||
|
|
1437
|
+
vestUtils.optionalFunctionValue(conditional, vestUtils.optionalFunctionValue(produceSuiteResult))
|
|
2171
1438
|
}, function () { return callback(); });
|
|
2172
1439
|
});
|
|
2173
1440
|
}
|
|
2174
|
-
|
|
1441
|
+
// Checks that we're currently in an active omitWhen block
|
|
1442
|
+
function inActiveOmitWhen() {
|
|
2175
1443
|
return !!context.useX().omitted;
|
|
2176
1444
|
}
|
|
2177
1445
|
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
var predicate = optionalFunctions[field];
|
|
2202
|
-
useSetOptionalField(field, [predicate, false]);
|
|
2203
|
-
}
|
|
2204
|
-
}
|
|
1446
|
+
/******************************************************************************
|
|
1447
|
+
Copyright (c) Microsoft Corporation.
|
|
1448
|
+
|
|
1449
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
1450
|
+
purpose with or without fee is hereby granted.
|
|
1451
|
+
|
|
1452
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1453
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1454
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1455
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1456
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1457
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1458
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
1459
|
+
***************************************************************************** */
|
|
1460
|
+
|
|
1461
|
+
function __spreadArray(to, from, pack) {
|
|
1462
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
1463
|
+
if (ar || !(i in from)) {
|
|
1464
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
1465
|
+
ar[i] = from[i];
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
2205
1469
|
}
|
|
2206
1470
|
|
|
2207
1471
|
function isSameProfileTest(testObject1, testObject2) {
|
|
@@ -2222,7 +1486,7 @@
|
|
|
2222
1486
|
*/
|
|
2223
1487
|
function runAsyncTest(testObject) {
|
|
2224
1488
|
var asyncTest = testObject.asyncTest, message = testObject.message;
|
|
2225
|
-
if (!isPromise(asyncTest))
|
|
1489
|
+
if (!vestUtils.isPromise(asyncTest))
|
|
2226
1490
|
return;
|
|
2227
1491
|
var emit = useBus().emit;
|
|
2228
1492
|
var stateRef = useStateRef();
|
|
@@ -2235,7 +1499,7 @@
|
|
|
2235
1499
|
if (testObject.isCanceled()) {
|
|
2236
1500
|
return;
|
|
2237
1501
|
}
|
|
2238
|
-
testObject.message = isStringValue(rejectionMessage)
|
|
1502
|
+
testObject.message = vestUtils.isStringValue(rejectionMessage)
|
|
2239
1503
|
? rejectionMessage
|
|
2240
1504
|
: message;
|
|
2241
1505
|
testObject.fail();
|
|
@@ -2270,7 +1534,7 @@
|
|
|
2270
1534
|
try {
|
|
2271
1535
|
// try catch for safe property access
|
|
2272
1536
|
// in case object is an enforce chain
|
|
2273
|
-
if (isPromise(result)) {
|
|
1537
|
+
if (vestUtils.isPromise(result)) {
|
|
2274
1538
|
testObject.asyncTest = result;
|
|
2275
1539
|
testObject.setPending();
|
|
2276
1540
|
runAsyncTest(testObject);
|
|
@@ -2297,12 +1561,12 @@
|
|
|
2297
1561
|
function useTestAtCursor(newTestObject) {
|
|
2298
1562
|
var testObjects = useTestObjects()[0];
|
|
2299
1563
|
var prevTests = testObjects.prev;
|
|
2300
|
-
if (isEmpty(prevTests)) {
|
|
1564
|
+
if (vestUtils.isEmpty(prevTests)) {
|
|
2301
1565
|
useSetTestAtCursor(newTestObject);
|
|
2302
1566
|
return newTestObject;
|
|
2303
1567
|
}
|
|
2304
1568
|
var prevTest = useGetTestAtCursor(prevTests);
|
|
2305
|
-
if (!isNullish(newTestObject.key)) {
|
|
1569
|
+
if (!vestUtils.isNullish(newTestObject.key)) {
|
|
2306
1570
|
var nextTest_1 = handleKeyTest(newTestObject.key, newTestObject);
|
|
2307
1571
|
useSetTestAtCursor(nextTest_1);
|
|
2308
1572
|
return nextTest_1;
|
|
@@ -2313,7 +1577,7 @@
|
|
|
2313
1577
|
// Need to see if this has any effect at all.
|
|
2314
1578
|
prevTest = null;
|
|
2315
1579
|
}
|
|
2316
|
-
var nextTest = defaultTo(prevTest, newTestObject);
|
|
1580
|
+
var nextTest = vestUtils.defaultTo(prevTest, newTestObject);
|
|
2317
1581
|
useSetTestAtCursor(nextTest);
|
|
2318
1582
|
return nextTest;
|
|
2319
1583
|
}
|
|
@@ -2330,21 +1594,21 @@
|
|
|
2330
1594
|
function useSetTestAtCursor(testObject) {
|
|
2331
1595
|
var cursorPath = useCurrentPath();
|
|
2332
1596
|
useSetTests(function (tests) {
|
|
2333
|
-
return setValueAtPath(tests, cursorPath, testObject);
|
|
1597
|
+
return vestUtils.nestedArray.setValueAtPath(tests, cursorPath, testObject);
|
|
2334
1598
|
});
|
|
2335
1599
|
}
|
|
2336
1600
|
function useGetTestAtCursor(tests) {
|
|
2337
1601
|
var cursorPath = useCurrentPath();
|
|
2338
|
-
return valueAtPath(tests, cursorPath);
|
|
1602
|
+
return vestUtils.nestedArray.valueAtPath(tests, cursorPath);
|
|
2339
1603
|
}
|
|
2340
1604
|
function testReorderDetected(prevTest, newTest) {
|
|
2341
|
-
return isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
|
|
1605
|
+
return vestUtils.isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
|
|
2342
1606
|
}
|
|
2343
1607
|
function throwTestOrderError(prevTest, newTestObject) {
|
|
2344
1608
|
if (shouldAllowReorder()) {
|
|
2345
1609
|
return;
|
|
2346
1610
|
}
|
|
2347
|
-
deferThrow("Vest Critical Error: Tests called in different order than previous run.\n expected: ".concat(prevTest.fieldName, "\n received: ").concat(newTestObject.fieldName, "\n This can happen on one of two reasons:\n 1. You're using if/else statements to conditionally select tests. Instead, use \"skipWhen\".\n 2. You are iterating over a list of tests, and their order changed. Use \"each\" and a custom key prop so that Vest retains their state."));
|
|
1611
|
+
vestUtils.deferThrow("Vest Critical Error: Tests called in different order than previous run.\n expected: ".concat(prevTest.fieldName, "\n received: ").concat(newTestObject.fieldName, "\n This can happen on one of two reasons:\n 1. You're using if/else statements to conditionally select tests. Instead, use \"skipWhen\".\n 2. You are iterating over a list of tests, and their order changed. Use \"each\" and a custom key prop so that Vest retains their state."));
|
|
2348
1612
|
}
|
|
2349
1613
|
function handleKeyTest(key, newTestObject) {
|
|
2350
1614
|
var prevTestByKey = usePrevTestByKey(key);
|
|
@@ -2366,7 +1630,7 @@
|
|
|
2366
1630
|
return testObject;
|
|
2367
1631
|
}
|
|
2368
1632
|
var prevRunTest = useTestAtCursor(testObject);
|
|
2369
|
-
if (
|
|
1633
|
+
if (inActiveOmitWhen() || optionalFiedIsApplied(testObject.fieldName)) {
|
|
2370
1634
|
prevRunTest.omit();
|
|
2371
1635
|
cursor.next();
|
|
2372
1636
|
return prevRunTest;
|
|
@@ -2390,16 +1654,15 @@
|
|
|
2390
1654
|
if (testObject.isUntested()) {
|
|
2391
1655
|
registerTest(testObject);
|
|
2392
1656
|
}
|
|
2393
|
-
else if (isPromise(testObject.asyncTest)) {
|
|
1657
|
+
else if (vestUtils.isPromise(testObject.asyncTest)) {
|
|
2394
1658
|
testObject.setPending();
|
|
2395
1659
|
runAsyncTest(testObject);
|
|
2396
1660
|
}
|
|
2397
1661
|
}
|
|
2398
1662
|
|
|
2399
1663
|
/* eslint-disable jest/valid-title */
|
|
2400
|
-
// eslint-disable-next-line max-lines-per-function
|
|
2401
1664
|
function bindTestMemo(test) {
|
|
2402
|
-
var cache =
|
|
1665
|
+
var cache = vestUtils.cache(10); // arbitrary cache size
|
|
2403
1666
|
// eslint-disable-next-line max-statements
|
|
2404
1667
|
function memo(fieldName) {
|
|
2405
1668
|
var args = [];
|
|
@@ -2411,7 +1674,7 @@
|
|
|
2411
1674
|
// Implicit dependency for more specificity
|
|
2412
1675
|
var dependencies = [useSuiteId(), fieldName, cursorAt].concat(deps);
|
|
2413
1676
|
var cached = cache.get(dependencies);
|
|
2414
|
-
if (isNull(cached)) {
|
|
1677
|
+
if (vestUtils.isNull(cached)) {
|
|
2415
1678
|
// cache miss
|
|
2416
1679
|
return cache(dependencies, function () { return test(fieldName, msg, testFn); });
|
|
2417
1680
|
}
|
|
@@ -2430,9 +1693,9 @@
|
|
|
2430
1693
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
2431
1694
|
args[_i - 1] = arguments[_i];
|
|
2432
1695
|
}
|
|
2433
|
-
var _a = (isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
|
|
2434
|
-
invariant(isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
|
|
2435
|
-
invariant(isFunction(testFn), incompatibleParamsError('Test callback', 'function'));
|
|
1696
|
+
var _a = (vestUtils.isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
|
|
1697
|
+
vestUtils.invariant(vestUtils.isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
|
|
1698
|
+
vestUtils.invariant(vestUtils.isFunction(testFn), incompatibleParamsError('Test callback', 'function'));
|
|
2436
1699
|
var context$1 = context.useX();
|
|
2437
1700
|
var testObject = new VestTest(fieldName, testFn, {
|
|
2438
1701
|
message: message,
|
|
@@ -2450,7 +1713,7 @@
|
|
|
2450
1713
|
* enforce(data.username).isNotBlank();
|
|
2451
1714
|
* });
|
|
2452
1715
|
*/
|
|
2453
|
-
var test = assign(testBase, {
|
|
1716
|
+
var test = vestUtils.assign(testBase, {
|
|
2454
1717
|
memo: bindTestMemo(testBase)
|
|
2455
1718
|
});
|
|
2456
1719
|
function incompatibleParamsError(name, expected) {
|
|
@@ -2464,18 +1727,23 @@
|
|
|
2464
1727
|
*/
|
|
2465
1728
|
function warn() {
|
|
2466
1729
|
var ctx = context.useX('warn ' + ERROR_HOOK_CALLED_OUTSIDE);
|
|
2467
|
-
invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
|
|
1730
|
+
vestUtils.invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
|
|
2468
1731
|
ctx.currentTest.warn();
|
|
2469
1732
|
}
|
|
2470
1733
|
|
|
2471
|
-
var VERSION = "4.
|
|
1734
|
+
var VERSION = "4.6.0";
|
|
2472
1735
|
|
|
1736
|
+
Object.defineProperty(exports, 'enforce', {
|
|
1737
|
+
enumerable: true,
|
|
1738
|
+
get: function () {
|
|
1739
|
+
return n4s.enforce;
|
|
1740
|
+
}
|
|
1741
|
+
});
|
|
2473
1742
|
exports.VERSION = VERSION;
|
|
2474
1743
|
exports.context = context;
|
|
2475
1744
|
exports.create = create;
|
|
2476
1745
|
exports.each = each;
|
|
2477
1746
|
exports.eager = eager;
|
|
2478
|
-
exports.enforce = enforce;
|
|
2479
1747
|
exports.group = group;
|
|
2480
1748
|
exports.include = include;
|
|
2481
1749
|
exports.omitWhen = omitWhen;
|
|
@@ -2483,6 +1751,7 @@
|
|
|
2483
1751
|
exports.optional = optional;
|
|
2484
1752
|
exports.skip = skip;
|
|
2485
1753
|
exports.skipWhen = skipWhen;
|
|
1754
|
+
exports.suiteSelectors = suiteSelectors;
|
|
2486
1755
|
exports.test = test;
|
|
2487
1756
|
exports.warn = warn;
|
|
2488
1757
|
|