vest 4.5.0 → 5.0.0-dev-781e21
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/enforce/compose.development.js +1 -1
- package/dist/cjs/enforce/compose.production.js +1 -1
- package/dist/cjs/enforce/compounds.development.js +1 -1
- package/dist/cjs/enforce/compounds.production.js +1 -1
- package/dist/cjs/enforce/schema.development.js +1 -1
- package/dist/cjs/enforce/schema.production.js +1 -1
- package/dist/cjs/vest.development.js +146 -95
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/enforce/compose.development.js +1 -1
- package/dist/es/enforce/compose.production.js +1 -1
- package/dist/es/enforce/compounds.development.js +1 -1
- package/dist/es/enforce/compounds.production.js +1 -1
- package/dist/es/enforce/schema.development.js +1 -1
- package/dist/es/enforce/schema.production.js +1 -1
- package/dist/es/vest.development.js +148 -97
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +11 -59
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +9 -682
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +17 -684
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +12 -685
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/parser.development.js +10 -58
- 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 +255 -997
- package/dist/umd/vest.production.js +1 -1
- package/package.json +3 -3
- package/types/enforce/compounds.d.ts +6 -8
- package/types/enforce/schema.d.ts +5 -4
- package/types/vest.d.ts +36 -28
|
@@ -1,837 +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 seq = (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
|
-
// This condition is for when we don't have proxy support (ES5).
|
|
671
|
-
// In this case, we need to manually assign the rules to the target object on runtime.
|
|
672
|
-
// The follow up proxy block is used in case we do have proxy support, and we can assign each rule upon invocation.
|
|
673
|
-
if (!isProxySupported()) {
|
|
674
|
-
// We iterate over each of the rules, and add them to the target object being return by enforce
|
|
675
|
-
eachEnforceRule(function (ruleName, ruleFn) {
|
|
676
|
-
// We then wrap the rule with `genRuleCall` that adds the base enforce behavior
|
|
677
|
-
target[ruleName] = genRuleCall(target, ruleFn, ruleName);
|
|
678
|
-
});
|
|
679
|
-
return target;
|
|
680
|
-
}
|
|
681
|
-
// We create a proxy intercepting access to the target object (which is empty).
|
|
682
|
-
var proxy = new Proxy(target, {
|
|
683
|
-
get: function (_, ruleName) {
|
|
684
|
-
// On property access, we identify if it is a rule or not.
|
|
685
|
-
var rule = getRule(ruleName);
|
|
686
|
-
// If it is a rule, we wrap it with `genRuleCall` that adds the base enforce behavior
|
|
687
|
-
if (rule) {
|
|
688
|
-
return genRuleCall(proxy, rule, ruleName);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
});
|
|
692
|
-
return proxy;
|
|
693
|
-
// This function is used to wrap a rule with the base enforce behavior
|
|
694
|
-
// It takes the target object, the rule function, and the rule name
|
|
695
|
-
// It then returns the rule, in a manner that can be used by enforce
|
|
696
|
-
function genRuleCall(target, rule, ruleName) {
|
|
697
|
-
return function ruleCall() {
|
|
698
|
-
var args = [];
|
|
699
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
700
|
-
args[_i] = arguments[_i];
|
|
701
|
-
}
|
|
702
|
-
// Order of operation:
|
|
703
|
-
// 1. Create a context with the value being enforced
|
|
704
|
-
// 2. Call the rule within the context, and pass over the arguments passed to it
|
|
705
|
-
// 3. Transform the result to the correct output format
|
|
706
|
-
var transformedResult = ctx.run({ value: value }, function () {
|
|
707
|
-
return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args, false)), ruleName, value], args, false));
|
|
708
|
-
});
|
|
709
|
-
// On rule failure (the result is false), we either throw an error
|
|
710
|
-
// or throw a string value if the rule has a message defined in it.
|
|
711
|
-
invariant(transformedResult.pass, isNullish(transformedResult.message)
|
|
712
|
-
? "enforce/".concat(ruleName, " failed with ").concat(JSON.stringify(value))
|
|
713
|
-
: StringObject(transformedResult.message));
|
|
714
|
-
return target;
|
|
715
|
-
};
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
// eslint-disable-next-line max-lines-per-function
|
|
720
|
-
function genEnforceLazy(key) {
|
|
721
|
-
var registeredRules = [];
|
|
722
|
-
var lazyMessage;
|
|
723
|
-
return addLazyRule(key);
|
|
724
|
-
// eslint-disable-next-line max-lines-per-function
|
|
725
|
-
function addLazyRule(ruleName) {
|
|
726
|
-
// eslint-disable-next-line max-lines-per-function
|
|
727
|
-
return function () {
|
|
728
|
-
var args = [];
|
|
729
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
730
|
-
args[_i] = arguments[_i];
|
|
731
|
-
}
|
|
732
|
-
var rule = getRule(ruleName);
|
|
733
|
-
registeredRules.push(function (value) {
|
|
734
|
-
return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args, false)), ruleName, value], args, false));
|
|
735
|
-
});
|
|
736
|
-
var proxy = {
|
|
737
|
-
run: function (value) {
|
|
738
|
-
return defaultToPassing(mapFirst(registeredRules, function (rule, breakout) {
|
|
739
|
-
var _a;
|
|
740
|
-
var res = ctx.run({ value: value }, function () { return rule(value); });
|
|
741
|
-
breakout(!res.pass, ruleReturn(!!res.pass, (_a = optionalFunctionValue(lazyMessage, value, res.message)) !== null && _a !== void 0 ? _a : res.message));
|
|
742
|
-
}));
|
|
743
|
-
},
|
|
744
|
-
test: function (value) { return proxy.run(value).pass; },
|
|
745
|
-
message: function (message) {
|
|
746
|
-
if (message) {
|
|
747
|
-
lazyMessage = message;
|
|
748
|
-
}
|
|
749
|
-
return proxy;
|
|
750
|
-
}
|
|
751
|
-
};
|
|
752
|
-
if (!isProxySupported()) {
|
|
753
|
-
eachEnforceRule(function (ruleName) {
|
|
754
|
-
proxy[ruleName] = addLazyRule(ruleName);
|
|
755
|
-
});
|
|
756
|
-
return proxy;
|
|
757
|
-
}
|
|
758
|
-
// reassigning the proxy here is not pretty
|
|
759
|
-
// but it's a cleaner way of getting `run` and `test` for free
|
|
760
|
-
proxy = new Proxy(proxy, {
|
|
761
|
-
get: function (target, key) {
|
|
762
|
-
if (getRule(key)) {
|
|
763
|
-
return addLazyRule(key);
|
|
764
|
-
}
|
|
765
|
-
return target[key]; // already has `run` and `test` on it
|
|
766
|
-
}
|
|
767
|
-
});
|
|
768
|
-
return proxy;
|
|
769
|
-
};
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
/**
|
|
774
|
-
* Enforce is quite complicated, I want to explain it in detail.
|
|
775
|
-
* It is dynamic in nature, so a lot of proxy objects are involved.
|
|
776
|
-
*
|
|
777
|
-
* Enforce has two main interfaces
|
|
778
|
-
* 1. eager
|
|
779
|
-
* 2. lazy
|
|
780
|
-
*
|
|
781
|
-
* The eager interface is the most commonly used, and the easier to understand.
|
|
782
|
-
* It throws an error when a rule is not satisfied.
|
|
783
|
-
* The eager interface is declared in enforceEager.ts and it is quite simple to understand.
|
|
784
|
-
* enforce is called with a value, and the return value is a proxy object that points back to all the rules.
|
|
785
|
-
* When a rule is called, the value is mapped as its first argument, and if the rule passes, the same
|
|
786
|
-
* proxy object is returned. Otherwise, an error is thrown.
|
|
787
|
-
*
|
|
788
|
-
* The lazy interface works quite differently. It is declared in genEnforceLazy.ts.
|
|
789
|
-
* Rather than calling enforce directly, the lazy interface has all the rules as "methods" (only by proxy).
|
|
790
|
-
* Calling the first function in the chain will initialize an array of calls. It stores the different rule calls
|
|
791
|
-
* and the parameters passed to them. None of the rules are called yet.
|
|
792
|
-
* The rules are only invoked in sequence once either of these chained functions are called:
|
|
793
|
-
* 1. test(value)
|
|
794
|
-
* 2. run(value)
|
|
795
|
-
*
|
|
796
|
-
* Calling run or test will call all the rules in sequence, with the difference that test will only return a boolean value,
|
|
797
|
-
* while run will return an object with the validation result and an optional message created by the rule.
|
|
798
|
-
*/
|
|
799
|
-
function genEnforce() {
|
|
800
|
-
var target = {
|
|
801
|
-
context: function () { return ctx.useX(); },
|
|
802
|
-
extend: function (customRules) {
|
|
803
|
-
assign(baseRules, customRules);
|
|
804
|
-
handleNoProxy(); // TODO: REMOVE when we stop supporting ES5
|
|
805
|
-
}
|
|
806
|
-
};
|
|
807
|
-
handleNoProxy();
|
|
808
|
-
return new Proxy(assign(enforceEager, target), {
|
|
809
|
-
get: function (target, key) {
|
|
810
|
-
if (key in target) {
|
|
811
|
-
return target[key];
|
|
812
|
-
}
|
|
813
|
-
if (!getRule(key)) {
|
|
814
|
-
return;
|
|
815
|
-
}
|
|
816
|
-
// Only on the first rule access - start the chain of calls
|
|
817
|
-
return genEnforceLazy(key);
|
|
818
|
-
}
|
|
819
|
-
});
|
|
820
|
-
function handleNoProxy() {
|
|
821
|
-
if (!isProxySupported()) {
|
|
822
|
-
eachEnforceRule(function (ruleName) {
|
|
823
|
-
// Only on the first rule access - start the chain of calls
|
|
824
|
-
target[ruleName] = genEnforceLazy(ruleName);
|
|
825
|
-
});
|
|
826
|
-
return assign(enforceEager, target);
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
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';
|
|
831
6
|
|
|
832
7
|
function shouldUseErrorAsMessage(message, error) {
|
|
833
8
|
// kind of cheating with this safe guard, but it does the job
|
|
834
|
-
return isUndefined(message) && isStringValue(error);
|
|
9
|
+
return vestUtils.isUndefined(message) && vestUtils.isStringValue(error);
|
|
835
10
|
}
|
|
836
11
|
|
|
837
12
|
var IsolateTypes;
|
|
@@ -885,10 +60,10 @@
|
|
|
885
60
|
};
|
|
886
61
|
}
|
|
887
62
|
|
|
888
|
-
var context =
|
|
63
|
+
var context = context$1.createCascade(function (ctxRef, parentContext) {
|
|
889
64
|
return parentContext
|
|
890
65
|
? null
|
|
891
|
-
: assign({
|
|
66
|
+
: vestUtils.assign({
|
|
892
67
|
exclusion: {
|
|
893
68
|
tests: {},
|
|
894
69
|
groups: {}
|
|
@@ -915,29 +90,22 @@
|
|
|
915
90
|
return useStateRef().testCallbacks();
|
|
916
91
|
}
|
|
917
92
|
// OPTIONAL FIELDS
|
|
918
|
-
function useOptionalField(fieldName) {
|
|
919
|
-
var optionalFields = useOptionalFields()[0];
|
|
920
|
-
return optionalFields[fieldName];
|
|
921
|
-
}
|
|
922
93
|
function useOptionalFields() {
|
|
923
94
|
return useStateRef().optionalFields();
|
|
924
95
|
}
|
|
925
96
|
function useSetOptionalField(fieldName, setter) {
|
|
926
97
|
var _a = useOptionalFields(), setOptionalFields = _a[1];
|
|
927
|
-
setOptionalFields(function (
|
|
98
|
+
setOptionalFields(function (prev) {
|
|
928
99
|
var _a;
|
|
929
|
-
return assign(
|
|
930
|
-
_a[fieldName] =
|
|
100
|
+
return vestUtils.assign(prev, (_a = {},
|
|
101
|
+
_a[fieldName] = vestUtils.assign({}, prev[fieldName], setter(prev[fieldName])),
|
|
931
102
|
_a));
|
|
932
103
|
});
|
|
933
104
|
}
|
|
934
|
-
function
|
|
935
|
-
var _a;
|
|
936
|
-
return (_a = useOptionalField(fieldName)) === null || _a === void 0 ? void 0 : _a[1];
|
|
937
|
-
}
|
|
938
|
-
function useOptionalFieldConfig(fieldName) {
|
|
105
|
+
function useOptionalField(fieldName) {
|
|
939
106
|
var _a;
|
|
940
|
-
|
|
107
|
+
var optionalFields = useOptionalFields()[0];
|
|
108
|
+
return (_a = optionalFields[fieldName]) !== null && _a !== void 0 ? _a : {};
|
|
941
109
|
}
|
|
942
110
|
function useTestObjects() {
|
|
943
111
|
return useStateRef().testObjects();
|
|
@@ -952,7 +120,7 @@
|
|
|
952
120
|
var current = _a.current, prev = _a.prev;
|
|
953
121
|
return ({
|
|
954
122
|
prev: prev,
|
|
955
|
-
current: asArray(handler(current))
|
|
123
|
+
current: vestUtils.asArray(handler(current))
|
|
956
124
|
});
|
|
957
125
|
});
|
|
958
126
|
}
|
|
@@ -960,10 +128,10 @@
|
|
|
960
128
|
function useAllIncomplete() {
|
|
961
129
|
return useTestsFlat().filter(function (test) { return test.isPending(); });
|
|
962
130
|
}
|
|
963
|
-
var flatCache =
|
|
131
|
+
var flatCache = vestUtils.cache();
|
|
964
132
|
function useTestsFlat() {
|
|
965
133
|
var current = useTestObjects()[0].current;
|
|
966
|
-
return flatCache([current], function () { return flatten(current); });
|
|
134
|
+
return flatCache([current], function () { return vestUtils.nestedArray.flatten(current); });
|
|
967
135
|
}
|
|
968
136
|
function useEachTestObject(handler) {
|
|
969
137
|
var testObjects = useTestsFlat();
|
|
@@ -979,7 +147,7 @@
|
|
|
979
147
|
function VestTest(fieldName, testFn, _a) {
|
|
980
148
|
var _b = _a === void 0 ? {} : _a, message = _b.message, groupName = _b.groupName, key = _b.key;
|
|
981
149
|
this.key = null;
|
|
982
|
-
this.id = seq();
|
|
150
|
+
this.id = vestUtils.seq();
|
|
983
151
|
this.severity = TestSeverity.Error;
|
|
984
152
|
this.status = STATUS_UNTESTED;
|
|
985
153
|
this.fieldName = fieldName;
|
|
@@ -1067,18 +235,9 @@
|
|
|
1067
235
|
VestTest.prototype.valueOf = function () {
|
|
1068
236
|
return !this.isFailing();
|
|
1069
237
|
};
|
|
1070
|
-
VestTest.prototype.hasFailures = function () {
|
|
1071
|
-
return this.isFailing() || this.isWarning();
|
|
1072
|
-
};
|
|
1073
|
-
VestTest.prototype.isNonActionable = function () {
|
|
1074
|
-
return this.isSkipped() || this.isOmitted() || this.isCanceled();
|
|
1075
|
-
};
|
|
1076
238
|
VestTest.prototype.isPending = function () {
|
|
1077
239
|
return this.statusEquals(STATUS_PENDING);
|
|
1078
240
|
};
|
|
1079
|
-
VestTest.prototype.isTested = function () {
|
|
1080
|
-
return this.hasFailures() || this.isPassing();
|
|
1081
|
-
};
|
|
1082
241
|
VestTest.prototype.isOmitted = function () {
|
|
1083
242
|
return this.statusEquals(STATUS_OMITTED);
|
|
1084
243
|
};
|
|
@@ -1100,6 +259,20 @@
|
|
|
1100
259
|
VestTest.prototype.isWarning = function () {
|
|
1101
260
|
return this.statusEquals(STATUS_WARNING);
|
|
1102
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
|
+
};
|
|
1103
276
|
VestTest.prototype.statusEquals = function (status) {
|
|
1104
277
|
return this.status === status;
|
|
1105
278
|
};
|
|
@@ -1152,12 +325,12 @@
|
|
|
1152
325
|
}
|
|
1153
326
|
function initKey(key, initialState, prevState) {
|
|
1154
327
|
current().push();
|
|
1155
|
-
set(key, optionalFunctionValue(initialState, prevState));
|
|
328
|
+
set(key, vestUtils.optionalFunctionValue(initialState, prevState));
|
|
1156
329
|
return function useStateKey() {
|
|
1157
330
|
return [
|
|
1158
331
|
current()[key],
|
|
1159
332
|
function (nextState) {
|
|
1160
|
-
return set(key, optionalFunctionValue(nextState, current()[key]));
|
|
333
|
+
return set(key, vestUtils.optionalFunctionValue(nextState, current()[key]));
|
|
1161
334
|
},
|
|
1162
335
|
];
|
|
1163
336
|
};
|
|
@@ -1169,10 +342,10 @@
|
|
|
1169
342
|
var prevValue = state.references[index];
|
|
1170
343
|
state.references[index] = value;
|
|
1171
344
|
var _a = registrations[index], onUpdate = _a[1];
|
|
1172
|
-
if (isFunction(onUpdate)) {
|
|
345
|
+
if (vestUtils.isFunction(onUpdate)) {
|
|
1173
346
|
onUpdate(value, prevValue);
|
|
1174
347
|
}
|
|
1175
|
-
if (isFunction(onStateChange)) {
|
|
348
|
+
if (vestUtils.isFunction(onStateChange)) {
|
|
1176
349
|
onStateChange();
|
|
1177
350
|
}
|
|
1178
351
|
}
|
|
@@ -1219,11 +392,11 @@
|
|
|
1219
392
|
|
|
1220
393
|
function usePrevKeys() {
|
|
1221
394
|
var prev = useTestObjects()[0].prev;
|
|
1222
|
-
return asArray(getCurrent(prev, useCurrentPath())).reduce(function (prevKeys, testObject) {
|
|
395
|
+
return vestUtils.asArray(vestUtils.nestedArray.getCurrent(prev, useCurrentPath())).reduce(function (prevKeys, testObject) {
|
|
1223
396
|
if (!(testObject instanceof VestTest)) {
|
|
1224
397
|
return prevKeys;
|
|
1225
398
|
}
|
|
1226
|
-
if (isNullish(testObject.key)) {
|
|
399
|
+
if (vestUtils.isNullish(testObject.key)) {
|
|
1227
400
|
return prevKeys;
|
|
1228
401
|
}
|
|
1229
402
|
prevKeys[testObject.key] = testObject;
|
|
@@ -1236,22 +409,22 @@
|
|
|
1236
409
|
}
|
|
1237
410
|
function useRetainTestKey(key, testObject) {
|
|
1238
411
|
var current = useIsolate().keys.current;
|
|
1239
|
-
if (isNullish(current[key])) {
|
|
412
|
+
if (vestUtils.isNullish(current[key])) {
|
|
1240
413
|
current[key] = testObject;
|
|
1241
414
|
}
|
|
1242
415
|
else {
|
|
1243
|
-
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."));
|
|
1244
417
|
}
|
|
1245
418
|
}
|
|
1246
419
|
|
|
1247
420
|
function isolate(_a, callback) {
|
|
1248
421
|
var _b = _a.type, type = _b === void 0 ? IsolateTypes.DEFAULT : _b;
|
|
1249
|
-
invariant(isFunction(callback));
|
|
422
|
+
vestUtils.invariant(vestUtils.isFunction(callback));
|
|
1250
423
|
// Generate a new Isolate layer, with its own cursor
|
|
1251
424
|
var isolate = generateIsolate(type, useCurrentPath());
|
|
1252
425
|
var output = context.run({ isolate: isolate }, function () {
|
|
1253
426
|
isolate.keys.prev = usePrevKeys();
|
|
1254
|
-
useSetTests(function (tests) { return setValueAtPath(tests, isolate.path, []); });
|
|
427
|
+
useSetTests(function (tests) { return vestUtils.nestedArray.setValueAtPath(tests, isolate.path, []); });
|
|
1255
428
|
var res = callback();
|
|
1256
429
|
return res;
|
|
1257
430
|
});
|
|
@@ -1289,7 +462,7 @@
|
|
|
1289
462
|
return !!(fieldName && testObject.fieldName === fieldName);
|
|
1290
463
|
}
|
|
1291
464
|
|
|
1292
|
-
var nonMatchingGroupName = bindNot(matchingGroupName);
|
|
465
|
+
var nonMatchingGroupName = vestUtils.bindNot(matchingGroupName);
|
|
1293
466
|
function matchingGroupName(testObject, groupName) {
|
|
1294
467
|
return testObject.groupName === groupName;
|
|
1295
468
|
}
|
|
@@ -1298,7 +471,7 @@
|
|
|
1298
471
|
* Checks that a given test object matches the currently specified severity level
|
|
1299
472
|
*/
|
|
1300
473
|
function nonMatchingSeverityProfile(severity, testObject) {
|
|
1301
|
-
return either(severity === Severity.WARNINGS, testObject.warns());
|
|
474
|
+
return vestUtils.either(severity === Severity.WARNINGS, testObject.warns());
|
|
1302
475
|
}
|
|
1303
476
|
|
|
1304
477
|
/**
|
|
@@ -1339,26 +512,85 @@
|
|
|
1339
512
|
return true;
|
|
1340
513
|
}
|
|
1341
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
|
+
|
|
1342
570
|
// eslint-disable-next-line max-statements, complexity
|
|
1343
571
|
function shouldAddValidProperty(fieldName) {
|
|
1344
|
-
|
|
572
|
+
// Is the field optional, and the optional condition is applied
|
|
573
|
+
if (optionalFiedIsApplied(fieldName)) {
|
|
1345
574
|
return true;
|
|
1346
575
|
}
|
|
1347
|
-
|
|
576
|
+
var testObjects = useTestsFlat();
|
|
577
|
+
// Are there no tests?
|
|
578
|
+
if (vestUtils.isEmpty(testObjects)) {
|
|
1348
579
|
return false;
|
|
1349
580
|
}
|
|
1350
|
-
|
|
1351
|
-
if (
|
|
581
|
+
// Does the field have any tests with errors?
|
|
582
|
+
if (hasErrorsByTestObjects(fieldName)) {
|
|
1352
583
|
return false;
|
|
1353
584
|
}
|
|
1354
585
|
// Does the given field have any pending tests that are not optional?
|
|
1355
586
|
if (hasNonOptionalIncomplete(fieldName)) {
|
|
1356
587
|
return false;
|
|
1357
588
|
}
|
|
589
|
+
// Does the field have no missing tests?
|
|
1358
590
|
return noMissingTests(fieldName);
|
|
1359
591
|
}
|
|
1360
592
|
function shouldAddValidPropertyInGroup(groupName, fieldName) {
|
|
1361
|
-
if (
|
|
593
|
+
if (optionalFiedIsApplied(fieldName)) {
|
|
1362
594
|
return true;
|
|
1363
595
|
}
|
|
1364
596
|
if (hasGroupFailuresByTestObjects(Severity.ERRORS, groupName, fieldName)) {
|
|
@@ -1370,66 +602,76 @@
|
|
|
1370
602
|
}
|
|
1371
603
|
return noMissingTestsByGroup(groupName, fieldName);
|
|
1372
604
|
}
|
|
1373
|
-
function fieldIsOmitted(fieldName) {
|
|
1374
|
-
if (!fieldName) {
|
|
1375
|
-
return false;
|
|
1376
|
-
}
|
|
1377
|
-
return useOptionalFieldApplied(fieldName) === true;
|
|
1378
|
-
}
|
|
1379
605
|
// Does the given field have any pending tests that are not optional?
|
|
1380
606
|
function hasNonOptionalIncomplete(fieldName) {
|
|
1381
|
-
return isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
1382
|
-
return
|
|
607
|
+
return vestUtils.isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
608
|
+
return isTestObjectOptional(testObject, fieldName);
|
|
1383
609
|
}));
|
|
1384
610
|
}
|
|
1385
611
|
// Do the given group/field have any pending tests that are not optional?
|
|
1386
612
|
function hasNonOptionalIncompleteByGroup(groupName, fieldName) {
|
|
1387
|
-
return isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
613
|
+
return vestUtils.isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
1388
614
|
if (nonMatchingGroupName(testObject, groupName)) {
|
|
1389
615
|
return false;
|
|
1390
616
|
}
|
|
1391
|
-
return
|
|
617
|
+
return isTestObjectOptional(testObject, fieldName);
|
|
1392
618
|
}));
|
|
1393
619
|
}
|
|
1394
|
-
function
|
|
620
|
+
function isTestObjectOptional(testObject, fieldName) {
|
|
1395
621
|
if (nonMatchingFieldName(testObject, fieldName)) {
|
|
1396
622
|
return false;
|
|
1397
623
|
}
|
|
1398
|
-
return
|
|
624
|
+
return optionalFiedIsApplied(fieldName);
|
|
1399
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.
|
|
1400
628
|
function noMissingTests(fieldName) {
|
|
1401
629
|
var testObjects = useTestsFlat();
|
|
1402
630
|
return testObjects.every(function (testObject) {
|
|
1403
|
-
|
|
1404
|
-
return true;
|
|
1405
|
-
}
|
|
1406
|
-
return missingTestsLogic(testObject, fieldName);
|
|
631
|
+
return noMissingTestsLogic(testObject, fieldName);
|
|
1407
632
|
});
|
|
1408
633
|
}
|
|
634
|
+
// Does the group have no missing tests?
|
|
1409
635
|
function noMissingTestsByGroup(groupName, fieldName) {
|
|
1410
636
|
var testObjects = useTestsFlat();
|
|
1411
637
|
return testObjects.every(function (testObject) {
|
|
1412
638
|
if (nonMatchingGroupName(testObject, groupName)) {
|
|
1413
639
|
return true;
|
|
1414
640
|
}
|
|
1415
|
-
return
|
|
641
|
+
return noMissingTestsLogic(testObject, fieldName);
|
|
1416
642
|
});
|
|
1417
643
|
}
|
|
1418
|
-
|
|
644
|
+
// Does the object qualify as either tested or omitted (but not skipped!)
|
|
645
|
+
function noMissingTestsLogic(testObject, fieldName) {
|
|
1419
646
|
if (nonMatchingFieldName(testObject, fieldName)) {
|
|
1420
647
|
return true;
|
|
1421
648
|
}
|
|
1422
|
-
|
|
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) ||
|
|
1423
659
|
testObject.isTested() ||
|
|
1424
660
|
testObject.isOmitted());
|
|
1425
661
|
}
|
|
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());
|
|
667
|
+
}
|
|
1426
668
|
|
|
1427
669
|
/**
|
|
1428
670
|
* Reads the testObjects list and gets full validation result from it.
|
|
1429
671
|
*/
|
|
1430
672
|
function genTestsSummary() {
|
|
1431
673
|
var testObjects = useTestsFlat();
|
|
1432
|
-
var summary = assign(baseStats(), {
|
|
674
|
+
var summary = vestUtils.assign(baseStats(), {
|
|
1433
675
|
groups: {},
|
|
1434
676
|
tests: {},
|
|
1435
677
|
valid: false
|
|
@@ -1506,7 +748,7 @@
|
|
|
1506
748
|
};
|
|
1507
749
|
}
|
|
1508
750
|
function baseTestStats() {
|
|
1509
|
-
return assign(baseStats(), {
|
|
751
|
+
return vestUtils.assign(baseStats(), {
|
|
1510
752
|
errors: [],
|
|
1511
753
|
warnings: []
|
|
1512
754
|
});
|
|
@@ -1526,7 +768,7 @@
|
|
|
1526
768
|
var output = {};
|
|
1527
769
|
var countKey = countKeyBySeverity(severityKey);
|
|
1528
770
|
for (var field in testGroup) {
|
|
1529
|
-
if (isPositive(testGroup[field][countKey])) {
|
|
771
|
+
if (vestUtils.isPositive(testGroup[field][countKey])) {
|
|
1530
772
|
// We will probably never get to the fallback array
|
|
1531
773
|
// leaving it just in case the implementation changes
|
|
1532
774
|
output[field] = testGroup[field][severityKey] || [];
|
|
@@ -1619,10 +861,10 @@
|
|
|
1619
861
|
return false;
|
|
1620
862
|
}
|
|
1621
863
|
if (fieldName) {
|
|
1622
|
-
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]);
|
|
1623
865
|
}
|
|
1624
866
|
for (var field in group) {
|
|
1625
|
-
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])) {
|
|
1626
868
|
return true;
|
|
1627
869
|
}
|
|
1628
870
|
}
|
|
@@ -1635,17 +877,17 @@
|
|
|
1635
877
|
var failureCount = fieldName
|
|
1636
878
|
? (_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[countKey]
|
|
1637
879
|
: summary[countKey] || 0;
|
|
1638
|
-
return isPositive(failureCount);
|
|
880
|
+
return vestUtils.isPositive(failureCount);
|
|
1639
881
|
}
|
|
1640
882
|
|
|
1641
|
-
var cache$1 =
|
|
883
|
+
var cache$1 = vestUtils.cache(1);
|
|
1642
884
|
function produceSuiteResult() {
|
|
1643
885
|
var testObjects = useTestsFlat();
|
|
1644
886
|
var ctxRef = { stateRef: useStateRef() };
|
|
1645
887
|
return cache$1([testObjects], context.bind(ctxRef, function () {
|
|
1646
888
|
var summary = genTestsSummary();
|
|
1647
889
|
var suiteName = useSuiteName();
|
|
1648
|
-
return assign(summary, suiteSelectors(summary), {
|
|
890
|
+
return vestUtils.assign(summary, suiteSelectors(summary), {
|
|
1649
891
|
suiteName: suiteName
|
|
1650
892
|
});
|
|
1651
893
|
}));
|
|
@@ -1656,7 +898,7 @@
|
|
|
1656
898
|
*/
|
|
1657
899
|
function hasRemainingTests(fieldName) {
|
|
1658
900
|
var allIncomplete = useAllIncomplete();
|
|
1659
|
-
if (isEmpty(allIncomplete)) {
|
|
901
|
+
if (vestUtils.isEmpty(allIncomplete)) {
|
|
1660
902
|
return false;
|
|
1661
903
|
}
|
|
1662
904
|
if (fieldName) {
|
|
@@ -1667,12 +909,12 @@
|
|
|
1667
909
|
return true;
|
|
1668
910
|
}
|
|
1669
911
|
|
|
1670
|
-
var cache =
|
|
912
|
+
var cache = vestUtils.cache(20);
|
|
1671
913
|
function produceFullResult() {
|
|
1672
914
|
var testObjects = useTestsFlat();
|
|
1673
915
|
var ctxRef = { stateRef: useStateRef() };
|
|
1674
916
|
return cache([testObjects], context.bind(ctxRef, function () {
|
|
1675
|
-
return assign({}, produceSuiteResult(), {
|
|
917
|
+
return vestUtils.assign({}, produceSuiteResult(), {
|
|
1676
918
|
done: context.bind(ctxRef, done)
|
|
1677
919
|
});
|
|
1678
920
|
}));
|
|
@@ -1683,8 +925,8 @@
|
|
|
1683
925
|
function shouldSkipDoneRegistration(callback, fieldName, output) {
|
|
1684
926
|
var _a;
|
|
1685
927
|
// If we do not have any test runs for the current field
|
|
1686
|
-
return !!(!isFunction(callback) ||
|
|
1687
|
-
(fieldName && numberEquals((_a = output.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.testCount, 0)));
|
|
928
|
+
return !!(!vestUtils.isFunction(callback) ||
|
|
929
|
+
(fieldName && vestUtils.numberEquals((_a = output.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.testCount, 0)));
|
|
1688
930
|
}
|
|
1689
931
|
function shouldRunDoneCallback(fieldName) {
|
|
1690
932
|
// is suite finished || field name exists, and test is finished;
|
|
@@ -1726,34 +968,48 @@
|
|
|
1726
968
|
});
|
|
1727
969
|
}
|
|
1728
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
|
+
*/
|
|
1729
976
|
function omitOptionalFields() {
|
|
1730
977
|
var optionalFields = useOptionalFields()[0];
|
|
1731
|
-
|
|
978
|
+
// If there are no optional fields, we don't need to do anything
|
|
979
|
+
if (vestUtils.isEmpty(optionalFields)) {
|
|
1732
980
|
return;
|
|
1733
981
|
}
|
|
982
|
+
// Create an object to store the fields that need to be omitted
|
|
1734
983
|
var shouldOmit = {};
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
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
|
+
}
|
|
1746
996
|
});
|
|
997
|
+
// refresh the tests in the state so that the omitted fields are applied
|
|
998
|
+
useRefreshTestObjects();
|
|
1747
999
|
function verifyAndOmit(testObject) {
|
|
1748
1000
|
if (shouldOmit[testObject.fieldName]) {
|
|
1749
1001
|
testObject.omit();
|
|
1750
|
-
useSetOptionalField(testObject.fieldName, function (
|
|
1002
|
+
useSetOptionalField(testObject.fieldName, function () { return ({
|
|
1003
|
+
applied: true
|
|
1004
|
+
}); });
|
|
1751
1005
|
}
|
|
1752
1006
|
}
|
|
1753
1007
|
function runOptionalConfig(testObject) {
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
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);
|
|
1757
1013
|
verifyAndOmit(testObject);
|
|
1758
1014
|
}
|
|
1759
1015
|
}
|
|
@@ -1764,7 +1020,7 @@
|
|
|
1764
1020
|
*/
|
|
1765
1021
|
function removeTestFromState (testObject) {
|
|
1766
1022
|
useSetTests(function (tests) {
|
|
1767
|
-
return transform(tests, function (test) { return (testObject !== test ? test : null); });
|
|
1023
|
+
return vestUtils.nestedArray.transform(tests, function (test) { return (testObject !== test ? test : null); });
|
|
1768
1024
|
});
|
|
1769
1025
|
}
|
|
1770
1026
|
|
|
@@ -1775,8 +1031,8 @@
|
|
|
1775
1031
|
var fieldCallbacks = useTestCallbacks()[0].fieldCallbacks;
|
|
1776
1032
|
if (fieldName &&
|
|
1777
1033
|
!hasRemainingTests(fieldName) &&
|
|
1778
|
-
isArray(fieldCallbacks[fieldName])) {
|
|
1779
|
-
callEach(fieldCallbacks[fieldName]);
|
|
1034
|
+
vestUtils.isArray(fieldCallbacks[fieldName])) {
|
|
1035
|
+
vestUtils.callEach(fieldCallbacks[fieldName]);
|
|
1780
1036
|
}
|
|
1781
1037
|
}
|
|
1782
1038
|
/**
|
|
@@ -1784,12 +1040,12 @@
|
|
|
1784
1040
|
*/
|
|
1785
1041
|
function runDoneCallbacks() {
|
|
1786
1042
|
var doneCallbacks = useTestCallbacks()[0].doneCallbacks;
|
|
1787
|
-
callEach(doneCallbacks);
|
|
1043
|
+
vestUtils.callEach(doneCallbacks);
|
|
1788
1044
|
}
|
|
1789
1045
|
|
|
1790
1046
|
// eslint-disable-next-line max-lines-per-function
|
|
1791
1047
|
function initBus() {
|
|
1792
|
-
var vestBus = createBus();
|
|
1048
|
+
var vestBus = vestUtils.bus.createBus();
|
|
1793
1049
|
// Report a the completion of a test. There may be other tests with the same
|
|
1794
1050
|
// name that are still running, or not yet started.
|
|
1795
1051
|
vestBus.on(Events.TEST_COMPLETED, function (testObject) {
|
|
@@ -1834,7 +1090,7 @@
|
|
|
1834
1090
|
}
|
|
1835
1091
|
function useBus() {
|
|
1836
1092
|
var context$1 = context.useX();
|
|
1837
|
-
invariant(context$1.bus);
|
|
1093
|
+
vestUtils.invariant(context$1.bus);
|
|
1838
1094
|
return context$1.bus;
|
|
1839
1095
|
}
|
|
1840
1096
|
var Events;
|
|
@@ -1853,16 +1109,16 @@
|
|
|
1853
1109
|
args[_i] = arguments[_i];
|
|
1854
1110
|
}
|
|
1855
1111
|
var _a = args.reverse(), suiteCallback = _a[0], suiteName = _a[1];
|
|
1856
|
-
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.');
|
|
1857
1113
|
// Event bus initialization
|
|
1858
1114
|
var bus = initBus();
|
|
1859
1115
|
// State initialization
|
|
1860
1116
|
var state = createState();
|
|
1861
1117
|
// State reference - this holds the actual state values
|
|
1862
|
-
var stateRef = createStateRef(state, { suiteId: seq(), suiteName: suiteName });
|
|
1118
|
+
var stateRef = createStateRef(state, { suiteId: vestUtils.seq(), suiteName: suiteName });
|
|
1863
1119
|
// Create base context reference. All hooks will derive their data from this
|
|
1864
1120
|
var ctxRef = { stateRef: stateRef, bus: bus };
|
|
1865
|
-
var suite = assign(
|
|
1121
|
+
var suite = vestUtils.assign(
|
|
1866
1122
|
// Bind the suite body to the context
|
|
1867
1123
|
context.bind(ctxRef, function () {
|
|
1868
1124
|
var args = [];
|
|
@@ -1908,7 +1164,7 @@
|
|
|
1908
1164
|
* })
|
|
1909
1165
|
*/
|
|
1910
1166
|
function each(list, callback) {
|
|
1911
|
-
invariant(isFunction(callback), 'each callback must be a function');
|
|
1167
|
+
vestUtils.invariant(vestUtils.isFunction(callback), 'each callback must be a function');
|
|
1912
1168
|
isolate({ type: IsolateTypes.EACH }, function () {
|
|
1913
1169
|
list.forEach(function (arg, index) {
|
|
1914
1170
|
callback(arg, index);
|
|
@@ -1938,7 +1194,7 @@
|
|
|
1938
1194
|
// we should skip the test if the parent conditional is true.
|
|
1939
1195
|
isExcludedIndividually() ||
|
|
1940
1196
|
// Otherwise, we should skip the test if the conditional is true.
|
|
1941
|
-
optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
|
|
1197
|
+
vestUtils.optionalFunctionValue(conditional, vestUtils.optionalFunctionValue(produceSuiteResult))
|
|
1942
1198
|
}, function () { return callback(); });
|
|
1943
1199
|
});
|
|
1944
1200
|
}
|
|
@@ -2014,7 +1270,7 @@
|
|
|
2014
1270
|
// Check if inclusion rules for this field (`include` hook)
|
|
2015
1271
|
// TODO: Check if this may need to be moved outside of the condition.
|
|
2016
1272
|
// What if there are no included tests? This shouldn't run then?
|
|
2017
|
-
return !optionalFunctionValue(inclusion[fieldName]);
|
|
1273
|
+
return !vestUtils.optionalFunctionValue(inclusion[fieldName]);
|
|
2018
1274
|
}
|
|
2019
1275
|
// We're done here. This field is not excluded
|
|
2020
1276
|
return false;
|
|
@@ -2026,7 +1282,7 @@
|
|
|
2026
1282
|
var context$1 = context.useX();
|
|
2027
1283
|
var exclusion = context$1.exclusion;
|
|
2028
1284
|
var keyGroups = exclusion.groups;
|
|
2029
|
-
var groupPresent = hasOwnProperty(keyGroups, groupName);
|
|
1285
|
+
var groupPresent = vestUtils.hasOwnProperty(keyGroups, groupName);
|
|
2030
1286
|
// When group is either only'ed or skipped
|
|
2031
1287
|
if (groupPresent) {
|
|
2032
1288
|
// Return true if group is skipped and false if only'ed
|
|
@@ -2044,8 +1300,8 @@
|
|
|
2044
1300
|
if (!item) {
|
|
2045
1301
|
return;
|
|
2046
1302
|
}
|
|
2047
|
-
asArray(item).forEach(function (itemName) {
|
|
2048
|
-
if (!isStringValue(itemName)) {
|
|
1303
|
+
vestUtils.asArray(item).forEach(function (itemName) {
|
|
1304
|
+
if (!vestUtils.isStringValue(itemName)) {
|
|
2049
1305
|
return;
|
|
2050
1306
|
}
|
|
2051
1307
|
context$1.exclusion[itemType][itemName] =
|
|
@@ -2092,8 +1348,8 @@
|
|
|
2092
1348
|
* });
|
|
2093
1349
|
*/
|
|
2094
1350
|
function group(groupName, tests) {
|
|
2095
|
-
invariant(isStringValue(groupName), groupErrorMsg('name must be a string'));
|
|
2096
|
-
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'));
|
|
2097
1353
|
// Running with the context applied
|
|
2098
1354
|
isolate({ type: IsolateTypes.GROUP }, function () {
|
|
2099
1355
|
context.run({ groupName: groupName }, tests);
|
|
@@ -2106,24 +1362,24 @@
|
|
|
2106
1362
|
function include(fieldName) {
|
|
2107
1363
|
var context$1 = context.useX();
|
|
2108
1364
|
var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
|
|
2109
|
-
invariant(isStringValue(fieldName));
|
|
2110
|
-
inclusion[fieldName] = defaultTo(exclusion.tests[fieldName], true);
|
|
1365
|
+
vestUtils.invariant(vestUtils.isStringValue(fieldName));
|
|
1366
|
+
inclusion[fieldName] = vestUtils.defaultTo(exclusion.tests[fieldName], true);
|
|
2111
1367
|
return { when: when };
|
|
2112
1368
|
function when(condition) {
|
|
2113
1369
|
var context$1 = context.useX();
|
|
2114
1370
|
var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
|
|
2115
1371
|
// This callback will run as part of the "isExcluded" series of checks
|
|
2116
1372
|
inclusion[fieldName] = function () {
|
|
2117
|
-
if (hasOwnProperty(exclusion.tests, fieldName)) {
|
|
1373
|
+
if (vestUtils.hasOwnProperty(exclusion.tests, fieldName)) {
|
|
2118
1374
|
// I suspect this code is technically unreachable because
|
|
2119
1375
|
// if there are any skip/only rules applied to the current
|
|
2120
1376
|
// field, the "isExcluded" function will have already bailed
|
|
2121
|
-
return defaultTo(exclusion.tests[fieldName], true);
|
|
1377
|
+
return vestUtils.defaultTo(exclusion.tests[fieldName], true);
|
|
2122
1378
|
}
|
|
2123
|
-
if (isStringValue(condition)) {
|
|
1379
|
+
if (vestUtils.isStringValue(condition)) {
|
|
2124
1380
|
return Boolean(exclusion.tests[condition]);
|
|
2125
1381
|
}
|
|
2126
|
-
return optionalFunctionValue(condition, optionalFunctionValue(produceSuiteResult));
|
|
1382
|
+
return vestUtils.optionalFunctionValue(condition, vestUtils.optionalFunctionValue(produceSuiteResult));
|
|
2127
1383
|
};
|
|
2128
1384
|
}
|
|
2129
1385
|
}
|
|
@@ -2177,42 +1433,39 @@
|
|
|
2177
1433
|
function omitWhen(conditional, callback) {
|
|
2178
1434
|
isolate({ type: IsolateTypes.OMIT_WHEN }, function () {
|
|
2179
1435
|
context.run({
|
|
2180
|
-
omitted:
|
|
2181
|
-
optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
|
|
1436
|
+
omitted: inActiveOmitWhen() ||
|
|
1437
|
+
vestUtils.optionalFunctionValue(conditional, vestUtils.optionalFunctionValue(produceSuiteResult))
|
|
2182
1438
|
}, function () { return callback(); });
|
|
2183
1439
|
});
|
|
2184
1440
|
}
|
|
2185
|
-
|
|
1441
|
+
// Checks that we're currently in an active omitWhen block
|
|
1442
|
+
function inActiveOmitWhen() {
|
|
2186
1443
|
return !!context.useX().omitted;
|
|
2187
1444
|
}
|
|
2188
1445
|
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
var predicate = optionalFunctions[field];
|
|
2213
|
-
useSetOptionalField(field, [predicate, false]);
|
|
2214
|
-
}
|
|
2215
|
-
}
|
|
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));
|
|
2216
1469
|
}
|
|
2217
1470
|
|
|
2218
1471
|
function isSameProfileTest(testObject1, testObject2) {
|
|
@@ -2233,7 +1486,7 @@
|
|
|
2233
1486
|
*/
|
|
2234
1487
|
function runAsyncTest(testObject) {
|
|
2235
1488
|
var asyncTest = testObject.asyncTest, message = testObject.message;
|
|
2236
|
-
if (!isPromise(asyncTest))
|
|
1489
|
+
if (!vestUtils.isPromise(asyncTest))
|
|
2237
1490
|
return;
|
|
2238
1491
|
var emit = useBus().emit;
|
|
2239
1492
|
var stateRef = useStateRef();
|
|
@@ -2246,7 +1499,7 @@
|
|
|
2246
1499
|
if (testObject.isCanceled()) {
|
|
2247
1500
|
return;
|
|
2248
1501
|
}
|
|
2249
|
-
testObject.message = isStringValue(rejectionMessage)
|
|
1502
|
+
testObject.message = vestUtils.isStringValue(rejectionMessage)
|
|
2250
1503
|
? rejectionMessage
|
|
2251
1504
|
: message;
|
|
2252
1505
|
testObject.fail();
|
|
@@ -2281,7 +1534,7 @@
|
|
|
2281
1534
|
try {
|
|
2282
1535
|
// try catch for safe property access
|
|
2283
1536
|
// in case object is an enforce chain
|
|
2284
|
-
if (isPromise(result)) {
|
|
1537
|
+
if (vestUtils.isPromise(result)) {
|
|
2285
1538
|
testObject.asyncTest = result;
|
|
2286
1539
|
testObject.setPending();
|
|
2287
1540
|
runAsyncTest(testObject);
|
|
@@ -2308,12 +1561,12 @@
|
|
|
2308
1561
|
function useTestAtCursor(newTestObject) {
|
|
2309
1562
|
var testObjects = useTestObjects()[0];
|
|
2310
1563
|
var prevTests = testObjects.prev;
|
|
2311
|
-
if (isEmpty(prevTests)) {
|
|
1564
|
+
if (vestUtils.isEmpty(prevTests)) {
|
|
2312
1565
|
useSetTestAtCursor(newTestObject);
|
|
2313
1566
|
return newTestObject;
|
|
2314
1567
|
}
|
|
2315
1568
|
var prevTest = useGetTestAtCursor(prevTests);
|
|
2316
|
-
if (!isNullish(newTestObject.key)) {
|
|
1569
|
+
if (!vestUtils.isNullish(newTestObject.key)) {
|
|
2317
1570
|
var nextTest_1 = handleKeyTest(newTestObject.key, newTestObject);
|
|
2318
1571
|
useSetTestAtCursor(nextTest_1);
|
|
2319
1572
|
return nextTest_1;
|
|
@@ -2324,7 +1577,7 @@
|
|
|
2324
1577
|
// Need to see if this has any effect at all.
|
|
2325
1578
|
prevTest = null;
|
|
2326
1579
|
}
|
|
2327
|
-
var nextTest = defaultTo(prevTest, newTestObject);
|
|
1580
|
+
var nextTest = vestUtils.defaultTo(prevTest, newTestObject);
|
|
2328
1581
|
useSetTestAtCursor(nextTest);
|
|
2329
1582
|
return nextTest;
|
|
2330
1583
|
}
|
|
@@ -2341,21 +1594,21 @@
|
|
|
2341
1594
|
function useSetTestAtCursor(testObject) {
|
|
2342
1595
|
var cursorPath = useCurrentPath();
|
|
2343
1596
|
useSetTests(function (tests) {
|
|
2344
|
-
return setValueAtPath(tests, cursorPath, testObject);
|
|
1597
|
+
return vestUtils.nestedArray.setValueAtPath(tests, cursorPath, testObject);
|
|
2345
1598
|
});
|
|
2346
1599
|
}
|
|
2347
1600
|
function useGetTestAtCursor(tests) {
|
|
2348
1601
|
var cursorPath = useCurrentPath();
|
|
2349
|
-
return valueAtPath(tests, cursorPath);
|
|
1602
|
+
return vestUtils.nestedArray.valueAtPath(tests, cursorPath);
|
|
2350
1603
|
}
|
|
2351
1604
|
function testReorderDetected(prevTest, newTest) {
|
|
2352
|
-
return isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
|
|
1605
|
+
return vestUtils.isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
|
|
2353
1606
|
}
|
|
2354
1607
|
function throwTestOrderError(prevTest, newTestObject) {
|
|
2355
1608
|
if (shouldAllowReorder()) {
|
|
2356
1609
|
return;
|
|
2357
1610
|
}
|
|
2358
|
-
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."));
|
|
2359
1612
|
}
|
|
2360
1613
|
function handleKeyTest(key, newTestObject) {
|
|
2361
1614
|
var prevTestByKey = usePrevTestByKey(key);
|
|
@@ -2377,7 +1630,7 @@
|
|
|
2377
1630
|
return testObject;
|
|
2378
1631
|
}
|
|
2379
1632
|
var prevRunTest = useTestAtCursor(testObject);
|
|
2380
|
-
if (
|
|
1633
|
+
if (inActiveOmitWhen() || optionalFiedIsApplied(testObject.fieldName)) {
|
|
2381
1634
|
prevRunTest.omit();
|
|
2382
1635
|
cursor.next();
|
|
2383
1636
|
return prevRunTest;
|
|
@@ -2401,7 +1654,7 @@
|
|
|
2401
1654
|
if (testObject.isUntested()) {
|
|
2402
1655
|
registerTest(testObject);
|
|
2403
1656
|
}
|
|
2404
|
-
else if (isPromise(testObject.asyncTest)) {
|
|
1657
|
+
else if (vestUtils.isPromise(testObject.asyncTest)) {
|
|
2405
1658
|
testObject.setPending();
|
|
2406
1659
|
runAsyncTest(testObject);
|
|
2407
1660
|
}
|
|
@@ -2409,7 +1662,7 @@
|
|
|
2409
1662
|
|
|
2410
1663
|
/* eslint-disable jest/valid-title */
|
|
2411
1664
|
function bindTestMemo(test) {
|
|
2412
|
-
var cache =
|
|
1665
|
+
var cache = vestUtils.cache(10); // arbitrary cache size
|
|
2413
1666
|
// eslint-disable-next-line max-statements
|
|
2414
1667
|
function memo(fieldName) {
|
|
2415
1668
|
var args = [];
|
|
@@ -2421,7 +1674,7 @@
|
|
|
2421
1674
|
// Implicit dependency for more specificity
|
|
2422
1675
|
var dependencies = [useSuiteId(), fieldName, cursorAt].concat(deps);
|
|
2423
1676
|
var cached = cache.get(dependencies);
|
|
2424
|
-
if (isNull(cached)) {
|
|
1677
|
+
if (vestUtils.isNull(cached)) {
|
|
2425
1678
|
// cache miss
|
|
2426
1679
|
return cache(dependencies, function () { return test(fieldName, msg, testFn); });
|
|
2427
1680
|
}
|
|
@@ -2440,9 +1693,9 @@
|
|
|
2440
1693
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
2441
1694
|
args[_i - 1] = arguments[_i];
|
|
2442
1695
|
}
|
|
2443
|
-
var _a = (isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
|
|
2444
|
-
invariant(isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
|
|
2445
|
-
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'));
|
|
2446
1699
|
var context$1 = context.useX();
|
|
2447
1700
|
var testObject = new VestTest(fieldName, testFn, {
|
|
2448
1701
|
message: message,
|
|
@@ -2460,7 +1713,7 @@
|
|
|
2460
1713
|
* enforce(data.username).isNotBlank();
|
|
2461
1714
|
* });
|
|
2462
1715
|
*/
|
|
2463
|
-
var test = assign(testBase, {
|
|
1716
|
+
var test = vestUtils.assign(testBase, {
|
|
2464
1717
|
memo: bindTestMemo(testBase)
|
|
2465
1718
|
});
|
|
2466
1719
|
function incompatibleParamsError(name, expected) {
|
|
@@ -2474,18 +1727,23 @@
|
|
|
2474
1727
|
*/
|
|
2475
1728
|
function warn() {
|
|
2476
1729
|
var ctx = context.useX('warn ' + ERROR_HOOK_CALLED_OUTSIDE);
|
|
2477
|
-
invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
|
|
1730
|
+
vestUtils.invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
|
|
2478
1731
|
ctx.currentTest.warn();
|
|
2479
1732
|
}
|
|
2480
1733
|
|
|
2481
|
-
var VERSION = "
|
|
1734
|
+
var VERSION = "5.0.0-dev-781e21";
|
|
2482
1735
|
|
|
1736
|
+
Object.defineProperty(exports, 'enforce', {
|
|
1737
|
+
enumerable: true,
|
|
1738
|
+
get: function () {
|
|
1739
|
+
return n4s.enforce;
|
|
1740
|
+
}
|
|
1741
|
+
});
|
|
2483
1742
|
exports.VERSION = VERSION;
|
|
2484
1743
|
exports.context = context;
|
|
2485
1744
|
exports.create = create;
|
|
2486
1745
|
exports.each = each;
|
|
2487
1746
|
exports.eager = eager;
|
|
2488
|
-
exports.enforce = enforce;
|
|
2489
1747
|
exports.group = group;
|
|
2490
1748
|
exports.include = include;
|
|
2491
1749
|
exports.omitWhen = omitWhen;
|