vest 4.5.0 → 4.6.2-dev-fcaa09
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 +2 -0
- package/dist/cjs/enforce_compose.js +7 -0
- package/dist/cjs/enforce_compose.production.js +1 -0
- package/dist/cjs/enforce_compounds.development.js +4 -0
- package/dist/cjs/enforce_compounds.js +7 -0
- package/dist/cjs/enforce_compounds.production.js +1 -0
- package/dist/cjs/enforce_schema.development.js +4 -0
- package/dist/cjs/enforce_schema.js +7 -0
- package/dist/cjs/enforce_schema.production.js +1 -0
- package/dist/cjs/vest.development.js +149 -168
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/enforce_compose.development.js +1 -0
- package/dist/es/enforce_compose.production.js +1 -0
- package/dist/es/enforce_compounds.development.js +1 -0
- package/dist/es/enforce_compounds.production.js +1 -0
- package/dist/es/enforce_schema.development.js +1 -0
- package/dist/es/enforce_schema.production.js +1 -0
- package/dist/es/vest.development.js +150 -169
- 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 +8 -0
- package/dist/umd/enforce_compose.production.js +1 -0
- package/dist/umd/enforce_compounds.development.js +8 -0
- package/dist/umd/enforce_compounds.production.js +1 -0
- package/dist/umd/enforce_schema.development.js +8 -0
- package/dist/umd/enforce_schema.production.js +1 -0
- 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 +253 -1066
- package/dist/umd/vest.production.js +1 -1
- package/enforce_compose/package.json +9 -0
- package/enforce_compounds/package.json +9 -0
- package/enforce_schema/package.json +9 -0
- package/package.json +80 -79
- package/tsconfig.json +85 -1
- package/types/classnames.d.ts +1 -0
- package/types/classnames.d.ts.map +1 -0
- package/types/enforce_compose.d.ts +2 -0
- package/types/enforce_compose.d.ts.map +1 -0
- package/types/enforce_compounds.d.ts +2 -0
- package/types/enforce_compounds.d.ts.map +1 -0
- package/types/enforce_schema.d.ts +2 -0
- package/types/enforce_schema.d.ts.map +1 -0
- package/types/parser.d.ts +1 -0
- package/types/parser.d.ts.map +1 -0
- package/types/promisify.d.ts +1 -0
- package/types/promisify.d.ts.map +1 -0
- package/types/vest.d.ts +40 -37
- package/types/vest.d.ts.map +1 -0
- package/dist/cjs/compose.js +0 -7
- package/dist/cjs/compounds.js +0 -7
- package/dist/cjs/enforce/compose.development.js +0 -60
- package/dist/cjs/enforce/compose.production.js +0 -1
- package/dist/cjs/enforce/compounds.development.js +0 -92
- package/dist/cjs/enforce/compounds.production.js +0 -1
- package/dist/cjs/enforce/package.json +0 -1
- package/dist/cjs/enforce/schema.development.js +0 -92
- package/dist/cjs/enforce/schema.production.js +0 -1
- package/dist/cjs/schema.js +0 -7
- package/dist/es/enforce/compose.development.js +0 -58
- package/dist/es/enforce/compose.production.js +0 -1
- package/dist/es/enforce/compounds.development.js +0 -90
- package/dist/es/enforce/compounds.production.js +0 -1
- package/dist/es/enforce/package.json +0 -1
- package/dist/es/enforce/schema.development.js +0 -88
- package/dist/es/enforce/schema.production.js +0 -1
- package/dist/umd/enforce/compose.development.js +0 -736
- package/dist/umd/enforce/compose.production.js +0 -1
- package/dist/umd/enforce/compounds.development.js +0 -762
- package/dist/umd/enforce/compounds.production.js +0 -1
- package/dist/umd/enforce/schema.development.js +0 -768
- package/dist/umd/enforce/schema.production.js +0 -1
- package/enforce/compose/package.json +0 -9
- package/enforce/compounds/package.json +0 -9
- package/enforce/schema/package.json +0 -9
- package/types/enforce/compose.d.ts +0 -126
- package/types/enforce/compounds.d.ts +0 -138
- package/types/enforce/schema.d.ts +0 -143
|
@@ -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'), require('vast')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'n4s', 'vest-utils', 'context', 'vast'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vest = {}, global.n4s, global['vest-utils'], global.context, global.vast));
|
|
5
|
+
}(this, (function (exports, n4s, vestUtils, context$1, vast) { '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
|
};
|
|
@@ -1114,70 +287,6 @@
|
|
|
1114
287
|
var STATUS_CANCELED = 'CANCELED';
|
|
1115
288
|
var STATUS_OMITTED = 'OMITTED';
|
|
1116
289
|
|
|
1117
|
-
// eslint-disable-next-line max-lines-per-function
|
|
1118
|
-
function createState(onStateChange) {
|
|
1119
|
-
var state = {
|
|
1120
|
-
references: []
|
|
1121
|
-
};
|
|
1122
|
-
var registrations = [];
|
|
1123
|
-
return {
|
|
1124
|
-
registerStateKey: registerStateKey,
|
|
1125
|
-
reset: reset
|
|
1126
|
-
};
|
|
1127
|
-
/**
|
|
1128
|
-
* Registers a new key in the state, takes the initial value (may be a function that returns the initial value), returns a function.
|
|
1129
|
-
*
|
|
1130
|
-
* @example
|
|
1131
|
-
*
|
|
1132
|
-
* const useColor = state.registerStateKey("blue");
|
|
1133
|
-
*
|
|
1134
|
-
* let [color, setColor] = useColor(); // -> ["blue", Function]
|
|
1135
|
-
*
|
|
1136
|
-
* setColor("green");
|
|
1137
|
-
*
|
|
1138
|
-
* useColor()[0]; -> "green"
|
|
1139
|
-
*/
|
|
1140
|
-
function registerStateKey(initialState, onUpdate) {
|
|
1141
|
-
var key = registrations.length;
|
|
1142
|
-
registrations.push([initialState, onUpdate]);
|
|
1143
|
-
return initKey(key, initialState);
|
|
1144
|
-
}
|
|
1145
|
-
function reset() {
|
|
1146
|
-
var prev = current();
|
|
1147
|
-
state.references = [];
|
|
1148
|
-
registrations.forEach(function (_a, index) {
|
|
1149
|
-
var initialValue = _a[0];
|
|
1150
|
-
return initKey(index, initialValue, prev[index]);
|
|
1151
|
-
});
|
|
1152
|
-
}
|
|
1153
|
-
function initKey(key, initialState, prevState) {
|
|
1154
|
-
current().push();
|
|
1155
|
-
set(key, optionalFunctionValue(initialState, prevState));
|
|
1156
|
-
return function useStateKey() {
|
|
1157
|
-
return [
|
|
1158
|
-
current()[key],
|
|
1159
|
-
function (nextState) {
|
|
1160
|
-
return set(key, optionalFunctionValue(nextState, current()[key]));
|
|
1161
|
-
},
|
|
1162
|
-
];
|
|
1163
|
-
};
|
|
1164
|
-
}
|
|
1165
|
-
function current() {
|
|
1166
|
-
return state.references;
|
|
1167
|
-
}
|
|
1168
|
-
function set(index, value) {
|
|
1169
|
-
var prevValue = state.references[index];
|
|
1170
|
-
state.references[index] = value;
|
|
1171
|
-
var _a = registrations[index], onUpdate = _a[1];
|
|
1172
|
-
if (isFunction(onUpdate)) {
|
|
1173
|
-
onUpdate(value, prevValue);
|
|
1174
|
-
}
|
|
1175
|
-
if (isFunction(onStateChange)) {
|
|
1176
|
-
onStateChange();
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
290
|
function createStateRef(state, _a) {
|
|
1182
291
|
var suiteId = _a.suiteId, suiteName = _a.suiteName;
|
|
1183
292
|
return {
|
|
@@ -1219,11 +328,11 @@
|
|
|
1219
328
|
|
|
1220
329
|
function usePrevKeys() {
|
|
1221
330
|
var prev = useTestObjects()[0].prev;
|
|
1222
|
-
return asArray(getCurrent(prev, useCurrentPath())).reduce(function (prevKeys, testObject) {
|
|
331
|
+
return vestUtils.asArray(vestUtils.nestedArray.getCurrent(prev, useCurrentPath())).reduce(function (prevKeys, testObject) {
|
|
1223
332
|
if (!(testObject instanceof VestTest)) {
|
|
1224
333
|
return prevKeys;
|
|
1225
334
|
}
|
|
1226
|
-
if (isNullish(testObject.key)) {
|
|
335
|
+
if (vestUtils.isNullish(testObject.key)) {
|
|
1227
336
|
return prevKeys;
|
|
1228
337
|
}
|
|
1229
338
|
prevKeys[testObject.key] = testObject;
|
|
@@ -1236,22 +345,22 @@
|
|
|
1236
345
|
}
|
|
1237
346
|
function useRetainTestKey(key, testObject) {
|
|
1238
347
|
var current = useIsolate().keys.current;
|
|
1239
|
-
if (isNullish(current[key])) {
|
|
348
|
+
if (vestUtils.isNullish(current[key])) {
|
|
1240
349
|
current[key] = testObject;
|
|
1241
350
|
}
|
|
1242
351
|
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."));
|
|
352
|
+
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
353
|
}
|
|
1245
354
|
}
|
|
1246
355
|
|
|
1247
356
|
function isolate(_a, callback) {
|
|
1248
357
|
var _b = _a.type, type = _b === void 0 ? IsolateTypes.DEFAULT : _b;
|
|
1249
|
-
invariant(isFunction(callback));
|
|
358
|
+
vestUtils.invariant(vestUtils.isFunction(callback));
|
|
1250
359
|
// Generate a new Isolate layer, with its own cursor
|
|
1251
360
|
var isolate = generateIsolate(type, useCurrentPath());
|
|
1252
361
|
var output = context.run({ isolate: isolate }, function () {
|
|
1253
362
|
isolate.keys.prev = usePrevKeys();
|
|
1254
|
-
useSetTests(function (tests) { return setValueAtPath(tests, isolate.path, []); });
|
|
363
|
+
useSetTests(function (tests) { return vestUtils.nestedArray.setValueAtPath(tests, isolate.path, []); });
|
|
1255
364
|
var res = callback();
|
|
1256
365
|
return res;
|
|
1257
366
|
});
|
|
@@ -1289,7 +398,7 @@
|
|
|
1289
398
|
return !!(fieldName && testObject.fieldName === fieldName);
|
|
1290
399
|
}
|
|
1291
400
|
|
|
1292
|
-
var nonMatchingGroupName = bindNot(matchingGroupName);
|
|
401
|
+
var nonMatchingGroupName = vestUtils.bindNot(matchingGroupName);
|
|
1293
402
|
function matchingGroupName(testObject, groupName) {
|
|
1294
403
|
return testObject.groupName === groupName;
|
|
1295
404
|
}
|
|
@@ -1298,7 +407,7 @@
|
|
|
1298
407
|
* Checks that a given test object matches the currently specified severity level
|
|
1299
408
|
*/
|
|
1300
409
|
function nonMatchingSeverityProfile(severity, testObject) {
|
|
1301
|
-
return either(severity === Severity.WARNINGS, testObject.warns());
|
|
410
|
+
return vestUtils.either(severity === Severity.WARNINGS, testObject.warns());
|
|
1302
411
|
}
|
|
1303
412
|
|
|
1304
413
|
/**
|
|
@@ -1339,26 +448,85 @@
|
|
|
1339
448
|
return true;
|
|
1340
449
|
}
|
|
1341
450
|
|
|
451
|
+
/**
|
|
452
|
+
* Marks a field as optional, either just by name, or by a given condition.
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
*
|
|
456
|
+
* optional('field_name');
|
|
457
|
+
*
|
|
458
|
+
* optional({
|
|
459
|
+
* username: () => allowUsernameEmpty,
|
|
460
|
+
* });
|
|
461
|
+
*/
|
|
462
|
+
function optional(optionals) {
|
|
463
|
+
// There are two types of optional field declarations:
|
|
464
|
+
// 1. Delayed: A string, which is the name of the field to be optional.
|
|
465
|
+
// We will only determine whether to omit the test after the suite is done running
|
|
466
|
+
//
|
|
467
|
+
// 2. Immediate: Either a boolean or a function, which is used to determine
|
|
468
|
+
// if the field should be optional.
|
|
469
|
+
// Delayed case (field name)
|
|
470
|
+
if (vestUtils.isArray(optionals) || vestUtils.isStringValue(optionals)) {
|
|
471
|
+
vestUtils.asArray(optionals).forEach(function (optionalField) {
|
|
472
|
+
useSetOptionalField(optionalField, function () { return ({
|
|
473
|
+
type: OptionalFieldTypes.Delayed,
|
|
474
|
+
applied: false,
|
|
475
|
+
rule: null
|
|
476
|
+
}); });
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
var _loop_1 = function (field) {
|
|
481
|
+
var value = optionals[field];
|
|
482
|
+
useSetOptionalField(field, function () { return ({
|
|
483
|
+
type: OptionalFieldTypes.Immediate,
|
|
484
|
+
rule: value,
|
|
485
|
+
applied: vestUtils.optionalFunctionValue(value)
|
|
486
|
+
}); });
|
|
487
|
+
};
|
|
488
|
+
// Immediately case (function or boolean)
|
|
489
|
+
for (var field in optionals) {
|
|
490
|
+
_loop_1(field);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
function optionalFiedIsApplied(fieldName) {
|
|
495
|
+
if (!fieldName) {
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
498
|
+
return useOptionalField(fieldName).applied;
|
|
499
|
+
}
|
|
500
|
+
var OptionalFieldTypes;
|
|
501
|
+
(function (OptionalFieldTypes) {
|
|
502
|
+
OptionalFieldTypes[OptionalFieldTypes["Immediate"] = 0] = "Immediate";
|
|
503
|
+
OptionalFieldTypes[OptionalFieldTypes["Delayed"] = 1] = "Delayed";
|
|
504
|
+
})(OptionalFieldTypes || (OptionalFieldTypes = {}));
|
|
505
|
+
|
|
1342
506
|
// eslint-disable-next-line max-statements, complexity
|
|
1343
507
|
function shouldAddValidProperty(fieldName) {
|
|
1344
|
-
|
|
508
|
+
// Is the field optional, and the optional condition is applied
|
|
509
|
+
if (optionalFiedIsApplied(fieldName)) {
|
|
1345
510
|
return true;
|
|
1346
511
|
}
|
|
1347
|
-
|
|
512
|
+
var testObjects = useTestsFlat();
|
|
513
|
+
// Are there no tests?
|
|
514
|
+
if (vestUtils.isEmpty(testObjects)) {
|
|
1348
515
|
return false;
|
|
1349
516
|
}
|
|
1350
|
-
|
|
1351
|
-
if (
|
|
517
|
+
// Does the field have any tests with errors?
|
|
518
|
+
if (hasErrorsByTestObjects(fieldName)) {
|
|
1352
519
|
return false;
|
|
1353
520
|
}
|
|
1354
521
|
// Does the given field have any pending tests that are not optional?
|
|
1355
522
|
if (hasNonOptionalIncomplete(fieldName)) {
|
|
1356
523
|
return false;
|
|
1357
524
|
}
|
|
525
|
+
// Does the field have no missing tests?
|
|
1358
526
|
return noMissingTests(fieldName);
|
|
1359
527
|
}
|
|
1360
528
|
function shouldAddValidPropertyInGroup(groupName, fieldName) {
|
|
1361
|
-
if (
|
|
529
|
+
if (optionalFiedIsApplied(fieldName)) {
|
|
1362
530
|
return true;
|
|
1363
531
|
}
|
|
1364
532
|
if (hasGroupFailuresByTestObjects(Severity.ERRORS, groupName, fieldName)) {
|
|
@@ -1370,66 +538,76 @@
|
|
|
1370
538
|
}
|
|
1371
539
|
return noMissingTestsByGroup(groupName, fieldName);
|
|
1372
540
|
}
|
|
1373
|
-
function fieldIsOmitted(fieldName) {
|
|
1374
|
-
if (!fieldName) {
|
|
1375
|
-
return false;
|
|
1376
|
-
}
|
|
1377
|
-
return useOptionalFieldApplied(fieldName) === true;
|
|
1378
|
-
}
|
|
1379
541
|
// Does the given field have any pending tests that are not optional?
|
|
1380
542
|
function hasNonOptionalIncomplete(fieldName) {
|
|
1381
|
-
return isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
1382
|
-
return
|
|
543
|
+
return vestUtils.isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
544
|
+
return isTestObjectOptional(testObject, fieldName);
|
|
1383
545
|
}));
|
|
1384
546
|
}
|
|
1385
547
|
// Do the given group/field have any pending tests that are not optional?
|
|
1386
548
|
function hasNonOptionalIncompleteByGroup(groupName, fieldName) {
|
|
1387
|
-
return isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
549
|
+
return vestUtils.isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
1388
550
|
if (nonMatchingGroupName(testObject, groupName)) {
|
|
1389
551
|
return false;
|
|
1390
552
|
}
|
|
1391
|
-
return
|
|
553
|
+
return isTestObjectOptional(testObject, fieldName);
|
|
1392
554
|
}));
|
|
1393
555
|
}
|
|
1394
|
-
function
|
|
556
|
+
function isTestObjectOptional(testObject, fieldName) {
|
|
1395
557
|
if (nonMatchingFieldName(testObject, fieldName)) {
|
|
1396
558
|
return false;
|
|
1397
559
|
}
|
|
1398
|
-
return
|
|
560
|
+
return optionalFiedIsApplied(fieldName);
|
|
1399
561
|
}
|
|
562
|
+
// Did all of the tests for the provided field run/omit?
|
|
563
|
+
// This makes sure that the fields are not skipped or pending.
|
|
1400
564
|
function noMissingTests(fieldName) {
|
|
1401
565
|
var testObjects = useTestsFlat();
|
|
1402
566
|
return testObjects.every(function (testObject) {
|
|
1403
|
-
|
|
1404
|
-
return true;
|
|
1405
|
-
}
|
|
1406
|
-
return missingTestsLogic(testObject, fieldName);
|
|
567
|
+
return noMissingTestsLogic(testObject, fieldName);
|
|
1407
568
|
});
|
|
1408
569
|
}
|
|
570
|
+
// Does the group have no missing tests?
|
|
1409
571
|
function noMissingTestsByGroup(groupName, fieldName) {
|
|
1410
572
|
var testObjects = useTestsFlat();
|
|
1411
573
|
return testObjects.every(function (testObject) {
|
|
1412
574
|
if (nonMatchingGroupName(testObject, groupName)) {
|
|
1413
575
|
return true;
|
|
1414
576
|
}
|
|
1415
|
-
return
|
|
577
|
+
return noMissingTestsLogic(testObject, fieldName);
|
|
1416
578
|
});
|
|
1417
579
|
}
|
|
1418
|
-
|
|
580
|
+
// Does the object qualify as either tested or omitted (but not skipped!)
|
|
581
|
+
function noMissingTestsLogic(testObject, fieldName) {
|
|
1419
582
|
if (nonMatchingFieldName(testObject, fieldName)) {
|
|
1420
583
|
return true;
|
|
1421
584
|
}
|
|
1422
|
-
|
|
585
|
+
/**
|
|
586
|
+
* The reason we're checking for the optional field here and not in "omitOptionalFields"
|
|
587
|
+
* is because that unlike the bool/function check we do there, here it only depends on
|
|
588
|
+
* whether the field was tested alredy or not.
|
|
589
|
+
*
|
|
590
|
+
* We qualify the test as not missing only if it was already run, if it is omitted,
|
|
591
|
+
* or if it is marked as optional, even if the optional check did not apply yet -
|
|
592
|
+
* but the test did not reach its final state.
|
|
593
|
+
*/
|
|
594
|
+
return (optionalTestAwaitsResolution(testObject) ||
|
|
1423
595
|
testObject.isTested() ||
|
|
1424
596
|
testObject.isOmitted());
|
|
1425
597
|
}
|
|
598
|
+
function optionalTestAwaitsResolution(testObject) {
|
|
599
|
+
// Does the test belong to an optional field,
|
|
600
|
+
// and the test itself is still in an indeterminate state?
|
|
601
|
+
return (useOptionalField(testObject.fieldName).type ===
|
|
602
|
+
OptionalFieldTypes.Delayed && testObject.awaitsResolution());
|
|
603
|
+
}
|
|
1426
604
|
|
|
1427
605
|
/**
|
|
1428
606
|
* Reads the testObjects list and gets full validation result from it.
|
|
1429
607
|
*/
|
|
1430
608
|
function genTestsSummary() {
|
|
1431
609
|
var testObjects = useTestsFlat();
|
|
1432
|
-
var summary = assign(baseStats(), {
|
|
610
|
+
var summary = vestUtils.assign(baseStats(), {
|
|
1433
611
|
groups: {},
|
|
1434
612
|
tests: {},
|
|
1435
613
|
valid: false
|
|
@@ -1506,7 +684,7 @@
|
|
|
1506
684
|
};
|
|
1507
685
|
}
|
|
1508
686
|
function baseTestStats() {
|
|
1509
|
-
return assign(baseStats(), {
|
|
687
|
+
return vestUtils.assign(baseStats(), {
|
|
1510
688
|
errors: [],
|
|
1511
689
|
warnings: []
|
|
1512
690
|
});
|
|
@@ -1526,7 +704,7 @@
|
|
|
1526
704
|
var output = {};
|
|
1527
705
|
var countKey = countKeyBySeverity(severityKey);
|
|
1528
706
|
for (var field in testGroup) {
|
|
1529
|
-
if (isPositive(testGroup[field][countKey])) {
|
|
707
|
+
if (vestUtils.isPositive(testGroup[field][countKey])) {
|
|
1530
708
|
// We will probably never get to the fallback array
|
|
1531
709
|
// leaving it just in case the implementation changes
|
|
1532
710
|
output[field] = testGroup[field][severityKey] || [];
|
|
@@ -1619,10 +797,10 @@
|
|
|
1619
797
|
return false;
|
|
1620
798
|
}
|
|
1621
799
|
if (fieldName) {
|
|
1622
|
-
return isPositive((_a = group[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
800
|
+
return vestUtils.isPositive((_a = group[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
1623
801
|
}
|
|
1624
802
|
for (var field in group) {
|
|
1625
|
-
if (isPositive((_b = group[field]) === null || _b === void 0 ? void 0 : _b[severityCount])) {
|
|
803
|
+
if (vestUtils.isPositive((_b = group[field]) === null || _b === void 0 ? void 0 : _b[severityCount])) {
|
|
1626
804
|
return true;
|
|
1627
805
|
}
|
|
1628
806
|
}
|
|
@@ -1635,17 +813,17 @@
|
|
|
1635
813
|
var failureCount = fieldName
|
|
1636
814
|
? (_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[countKey]
|
|
1637
815
|
: summary[countKey] || 0;
|
|
1638
|
-
return isPositive(failureCount);
|
|
816
|
+
return vestUtils.isPositive(failureCount);
|
|
1639
817
|
}
|
|
1640
818
|
|
|
1641
|
-
var cache$1 =
|
|
819
|
+
var cache$1 = vestUtils.cache(1);
|
|
1642
820
|
function produceSuiteResult() {
|
|
1643
821
|
var testObjects = useTestsFlat();
|
|
1644
822
|
var ctxRef = { stateRef: useStateRef() };
|
|
1645
823
|
return cache$1([testObjects], context.bind(ctxRef, function () {
|
|
1646
824
|
var summary = genTestsSummary();
|
|
1647
825
|
var suiteName = useSuiteName();
|
|
1648
|
-
return assign(summary, suiteSelectors(summary), {
|
|
826
|
+
return vestUtils.assign(summary, suiteSelectors(summary), {
|
|
1649
827
|
suiteName: suiteName
|
|
1650
828
|
});
|
|
1651
829
|
}));
|
|
@@ -1656,7 +834,7 @@
|
|
|
1656
834
|
*/
|
|
1657
835
|
function hasRemainingTests(fieldName) {
|
|
1658
836
|
var allIncomplete = useAllIncomplete();
|
|
1659
|
-
if (isEmpty(allIncomplete)) {
|
|
837
|
+
if (vestUtils.isEmpty(allIncomplete)) {
|
|
1660
838
|
return false;
|
|
1661
839
|
}
|
|
1662
840
|
if (fieldName) {
|
|
@@ -1667,12 +845,12 @@
|
|
|
1667
845
|
return true;
|
|
1668
846
|
}
|
|
1669
847
|
|
|
1670
|
-
var cache =
|
|
848
|
+
var cache = vestUtils.cache(20);
|
|
1671
849
|
function produceFullResult() {
|
|
1672
850
|
var testObjects = useTestsFlat();
|
|
1673
851
|
var ctxRef = { stateRef: useStateRef() };
|
|
1674
852
|
return cache([testObjects], context.bind(ctxRef, function () {
|
|
1675
|
-
return assign({}, produceSuiteResult(), {
|
|
853
|
+
return vestUtils.assign({}, produceSuiteResult(), {
|
|
1676
854
|
done: context.bind(ctxRef, done)
|
|
1677
855
|
});
|
|
1678
856
|
}));
|
|
@@ -1683,8 +861,8 @@
|
|
|
1683
861
|
function shouldSkipDoneRegistration(callback, fieldName, output) {
|
|
1684
862
|
var _a;
|
|
1685
863
|
// 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)));
|
|
864
|
+
return !!(!vestUtils.isFunction(callback) ||
|
|
865
|
+
(fieldName && vestUtils.numberEquals((_a = output.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.testCount, 0)));
|
|
1688
866
|
}
|
|
1689
867
|
function shouldRunDoneCallback(fieldName) {
|
|
1690
868
|
// is suite finished || field name exists, and test is finished;
|
|
@@ -1726,34 +904,48 @@
|
|
|
1726
904
|
});
|
|
1727
905
|
}
|
|
1728
906
|
|
|
907
|
+
/**
|
|
908
|
+
* This module gets triggered once the suite is done running its sync tests.
|
|
909
|
+
*
|
|
910
|
+
* It goes over all the tests in the state, and checks if they need to be omitted.
|
|
911
|
+
*/
|
|
1729
912
|
function omitOptionalFields() {
|
|
1730
913
|
var optionalFields = useOptionalFields()[0];
|
|
1731
|
-
|
|
914
|
+
// If there are no optional fields, we don't need to do anything
|
|
915
|
+
if (vestUtils.isEmpty(optionalFields)) {
|
|
1732
916
|
return;
|
|
1733
917
|
}
|
|
918
|
+
// Create an object to store the fields that need to be omitted
|
|
1734
919
|
var shouldOmit = {};
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
920
|
+
// iterate over each of the tests in the state
|
|
921
|
+
useTestsFlat().forEach(function (testObject) {
|
|
922
|
+
// If we already added the current field (not this test specifically)
|
|
923
|
+
// no need for further checks, go and omit the test
|
|
924
|
+
if (vestUtils.hasOwnProperty(shouldOmit, testObject.fieldName)) {
|
|
925
|
+
verifyAndOmit(testObject);
|
|
926
|
+
}
|
|
927
|
+
else {
|
|
928
|
+
// check if the field has an optional function
|
|
929
|
+
// if so, run it and verify/omit the test
|
|
930
|
+
runOptionalConfig(testObject);
|
|
931
|
+
}
|
|
1746
932
|
});
|
|
933
|
+
// refresh the tests in the state so that the omitted fields are applied
|
|
934
|
+
useRefreshTestObjects();
|
|
1747
935
|
function verifyAndOmit(testObject) {
|
|
1748
936
|
if (shouldOmit[testObject.fieldName]) {
|
|
1749
937
|
testObject.omit();
|
|
1750
|
-
useSetOptionalField(testObject.fieldName, function (
|
|
938
|
+
useSetOptionalField(testObject.fieldName, function () { return ({
|
|
939
|
+
applied: true
|
|
940
|
+
}); });
|
|
1751
941
|
}
|
|
1752
942
|
}
|
|
1753
943
|
function runOptionalConfig(testObject) {
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
944
|
+
// Ge the optional configuration for the given field
|
|
945
|
+
var optionalConfig = useOptionalField(testObject.fieldName);
|
|
946
|
+
// If the optional was set to a function or a boolean, run it and verify/omit the test
|
|
947
|
+
if (optionalConfig.type === OptionalFieldTypes.Immediate) {
|
|
948
|
+
shouldOmit[testObject.fieldName] = vestUtils.optionalFunctionValue(optionalConfig.rule);
|
|
1757
949
|
verifyAndOmit(testObject);
|
|
1758
950
|
}
|
|
1759
951
|
}
|
|
@@ -1764,7 +956,7 @@
|
|
|
1764
956
|
*/
|
|
1765
957
|
function removeTestFromState (testObject) {
|
|
1766
958
|
useSetTests(function (tests) {
|
|
1767
|
-
return transform(tests, function (test) { return (testObject !== test ? test : null); });
|
|
959
|
+
return vestUtils.nestedArray.transform(tests, function (test) { return (testObject !== test ? test : null); });
|
|
1768
960
|
});
|
|
1769
961
|
}
|
|
1770
962
|
|
|
@@ -1775,8 +967,8 @@
|
|
|
1775
967
|
var fieldCallbacks = useTestCallbacks()[0].fieldCallbacks;
|
|
1776
968
|
if (fieldName &&
|
|
1777
969
|
!hasRemainingTests(fieldName) &&
|
|
1778
|
-
isArray(fieldCallbacks[fieldName])) {
|
|
1779
|
-
callEach(fieldCallbacks[fieldName]);
|
|
970
|
+
vestUtils.isArray(fieldCallbacks[fieldName])) {
|
|
971
|
+
vestUtils.callEach(fieldCallbacks[fieldName]);
|
|
1780
972
|
}
|
|
1781
973
|
}
|
|
1782
974
|
/**
|
|
@@ -1784,12 +976,12 @@
|
|
|
1784
976
|
*/
|
|
1785
977
|
function runDoneCallbacks() {
|
|
1786
978
|
var doneCallbacks = useTestCallbacks()[0].doneCallbacks;
|
|
1787
|
-
callEach(doneCallbacks);
|
|
979
|
+
vestUtils.callEach(doneCallbacks);
|
|
1788
980
|
}
|
|
1789
981
|
|
|
1790
982
|
// eslint-disable-next-line max-lines-per-function
|
|
1791
983
|
function initBus() {
|
|
1792
|
-
var vestBus = createBus();
|
|
984
|
+
var vestBus = vestUtils.bus.createBus();
|
|
1793
985
|
// Report a the completion of a test. There may be other tests with the same
|
|
1794
986
|
// name that are still running, or not yet started.
|
|
1795
987
|
vestBus.on(Events.TEST_COMPLETED, function (testObject) {
|
|
@@ -1834,7 +1026,7 @@
|
|
|
1834
1026
|
}
|
|
1835
1027
|
function useBus() {
|
|
1836
1028
|
var context$1 = context.useX();
|
|
1837
|
-
invariant(context$1.bus);
|
|
1029
|
+
vestUtils.invariant(context$1.bus);
|
|
1838
1030
|
return context$1.bus;
|
|
1839
1031
|
}
|
|
1840
1032
|
var Events;
|
|
@@ -1853,16 +1045,16 @@
|
|
|
1853
1045
|
args[_i] = arguments[_i];
|
|
1854
1046
|
}
|
|
1855
1047
|
var _a = args.reverse(), suiteCallback = _a[0], suiteName = _a[1];
|
|
1856
|
-
invariant(isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
|
|
1048
|
+
vestUtils.invariant(vestUtils.isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
|
|
1857
1049
|
// Event bus initialization
|
|
1858
1050
|
var bus = initBus();
|
|
1859
1051
|
// State initialization
|
|
1860
|
-
var state = createState();
|
|
1052
|
+
var state = vast.createState();
|
|
1861
1053
|
// State reference - this holds the actual state values
|
|
1862
|
-
var stateRef = createStateRef(state, { suiteId: seq(), suiteName: suiteName });
|
|
1054
|
+
var stateRef = createStateRef(state, { suiteId: vestUtils.seq(), suiteName: suiteName });
|
|
1863
1055
|
// Create base context reference. All hooks will derive their data from this
|
|
1864
1056
|
var ctxRef = { stateRef: stateRef, bus: bus };
|
|
1865
|
-
var suite = assign(
|
|
1057
|
+
var suite = vestUtils.assign(
|
|
1866
1058
|
// Bind the suite body to the context
|
|
1867
1059
|
context.bind(ctxRef, function () {
|
|
1868
1060
|
var args = [];
|
|
@@ -1908,7 +1100,7 @@
|
|
|
1908
1100
|
* })
|
|
1909
1101
|
*/
|
|
1910
1102
|
function each(list, callback) {
|
|
1911
|
-
invariant(isFunction(callback), 'each callback must be a function');
|
|
1103
|
+
vestUtils.invariant(vestUtils.isFunction(callback), 'each callback must be a function');
|
|
1912
1104
|
isolate({ type: IsolateTypes.EACH }, function () {
|
|
1913
1105
|
list.forEach(function (arg, index) {
|
|
1914
1106
|
callback(arg, index);
|
|
@@ -1938,7 +1130,7 @@
|
|
|
1938
1130
|
// we should skip the test if the parent conditional is true.
|
|
1939
1131
|
isExcludedIndividually() ||
|
|
1940
1132
|
// Otherwise, we should skip the test if the conditional is true.
|
|
1941
|
-
optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
|
|
1133
|
+
vestUtils.optionalFunctionValue(conditional, vestUtils.optionalFunctionValue(produceSuiteResult))
|
|
1942
1134
|
}, function () { return callback(); });
|
|
1943
1135
|
});
|
|
1944
1136
|
}
|
|
@@ -2014,7 +1206,7 @@
|
|
|
2014
1206
|
// Check if inclusion rules for this field (`include` hook)
|
|
2015
1207
|
// TODO: Check if this may need to be moved outside of the condition.
|
|
2016
1208
|
// What if there are no included tests? This shouldn't run then?
|
|
2017
|
-
return !optionalFunctionValue(inclusion[fieldName]);
|
|
1209
|
+
return !vestUtils.optionalFunctionValue(inclusion[fieldName]);
|
|
2018
1210
|
}
|
|
2019
1211
|
// We're done here. This field is not excluded
|
|
2020
1212
|
return false;
|
|
@@ -2026,7 +1218,7 @@
|
|
|
2026
1218
|
var context$1 = context.useX();
|
|
2027
1219
|
var exclusion = context$1.exclusion;
|
|
2028
1220
|
var keyGroups = exclusion.groups;
|
|
2029
|
-
var groupPresent = hasOwnProperty(keyGroups, groupName);
|
|
1221
|
+
var groupPresent = vestUtils.hasOwnProperty(keyGroups, groupName);
|
|
2030
1222
|
// When group is either only'ed or skipped
|
|
2031
1223
|
if (groupPresent) {
|
|
2032
1224
|
// Return true if group is skipped and false if only'ed
|
|
@@ -2044,8 +1236,8 @@
|
|
|
2044
1236
|
if (!item) {
|
|
2045
1237
|
return;
|
|
2046
1238
|
}
|
|
2047
|
-
asArray(item).forEach(function (itemName) {
|
|
2048
|
-
if (!isStringValue(itemName)) {
|
|
1239
|
+
vestUtils.asArray(item).forEach(function (itemName) {
|
|
1240
|
+
if (!vestUtils.isStringValue(itemName)) {
|
|
2049
1241
|
return;
|
|
2050
1242
|
}
|
|
2051
1243
|
context$1.exclusion[itemType][itemName] =
|
|
@@ -2092,8 +1284,8 @@
|
|
|
2092
1284
|
* });
|
|
2093
1285
|
*/
|
|
2094
1286
|
function group(groupName, tests) {
|
|
2095
|
-
invariant(isStringValue(groupName), groupErrorMsg('name must be a string'));
|
|
2096
|
-
invariant(isFunction(tests), groupErrorMsg('callback must be a function'));
|
|
1287
|
+
vestUtils.invariant(vestUtils.isStringValue(groupName), groupErrorMsg('name must be a string'));
|
|
1288
|
+
vestUtils.invariant(vestUtils.isFunction(tests), groupErrorMsg('callback must be a function'));
|
|
2097
1289
|
// Running with the context applied
|
|
2098
1290
|
isolate({ type: IsolateTypes.GROUP }, function () {
|
|
2099
1291
|
context.run({ groupName: groupName }, tests);
|
|
@@ -2106,24 +1298,24 @@
|
|
|
2106
1298
|
function include(fieldName) {
|
|
2107
1299
|
var context$1 = context.useX();
|
|
2108
1300
|
var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
|
|
2109
|
-
invariant(isStringValue(fieldName));
|
|
2110
|
-
inclusion[fieldName] = defaultTo(exclusion.tests[fieldName], true);
|
|
1301
|
+
vestUtils.invariant(vestUtils.isStringValue(fieldName));
|
|
1302
|
+
inclusion[fieldName] = vestUtils.defaultTo(exclusion.tests[fieldName], true);
|
|
2111
1303
|
return { when: when };
|
|
2112
1304
|
function when(condition) {
|
|
2113
1305
|
var context$1 = context.useX();
|
|
2114
1306
|
var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
|
|
2115
1307
|
// This callback will run as part of the "isExcluded" series of checks
|
|
2116
1308
|
inclusion[fieldName] = function () {
|
|
2117
|
-
if (hasOwnProperty(exclusion.tests, fieldName)) {
|
|
1309
|
+
if (vestUtils.hasOwnProperty(exclusion.tests, fieldName)) {
|
|
2118
1310
|
// I suspect this code is technically unreachable because
|
|
2119
1311
|
// if there are any skip/only rules applied to the current
|
|
2120
1312
|
// field, the "isExcluded" function will have already bailed
|
|
2121
|
-
return defaultTo(exclusion.tests[fieldName], true);
|
|
1313
|
+
return vestUtils.defaultTo(exclusion.tests[fieldName], true);
|
|
2122
1314
|
}
|
|
2123
|
-
if (isStringValue(condition)) {
|
|
1315
|
+
if (vestUtils.isStringValue(condition)) {
|
|
2124
1316
|
return Boolean(exclusion.tests[condition]);
|
|
2125
1317
|
}
|
|
2126
|
-
return optionalFunctionValue(condition, optionalFunctionValue(produceSuiteResult));
|
|
1318
|
+
return vestUtils.optionalFunctionValue(condition, vestUtils.optionalFunctionValue(produceSuiteResult));
|
|
2127
1319
|
};
|
|
2128
1320
|
}
|
|
2129
1321
|
}
|
|
@@ -2177,42 +1369,39 @@
|
|
|
2177
1369
|
function omitWhen(conditional, callback) {
|
|
2178
1370
|
isolate({ type: IsolateTypes.OMIT_WHEN }, function () {
|
|
2179
1371
|
context.run({
|
|
2180
|
-
omitted:
|
|
2181
|
-
optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
|
|
1372
|
+
omitted: inActiveOmitWhen() ||
|
|
1373
|
+
vestUtils.optionalFunctionValue(conditional, vestUtils.optionalFunctionValue(produceSuiteResult))
|
|
2182
1374
|
}, function () { return callback(); });
|
|
2183
1375
|
});
|
|
2184
1376
|
}
|
|
2185
|
-
|
|
1377
|
+
// Checks that we're currently in an active omitWhen block
|
|
1378
|
+
function inActiveOmitWhen() {
|
|
2186
1379
|
return !!context.useX().omitted;
|
|
2187
1380
|
}
|
|
2188
1381
|
|
|
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
|
-
}
|
|
1382
|
+
/******************************************************************************
|
|
1383
|
+
Copyright (c) Microsoft Corporation.
|
|
1384
|
+
|
|
1385
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
1386
|
+
purpose with or without fee is hereby granted.
|
|
1387
|
+
|
|
1388
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1389
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1390
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1391
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1392
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1393
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1394
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
1395
|
+
***************************************************************************** */
|
|
1396
|
+
|
|
1397
|
+
function __spreadArray(to, from, pack) {
|
|
1398
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
1399
|
+
if (ar || !(i in from)) {
|
|
1400
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
1401
|
+
ar[i] = from[i];
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
2216
1405
|
}
|
|
2217
1406
|
|
|
2218
1407
|
function isSameProfileTest(testObject1, testObject2) {
|
|
@@ -2233,7 +1422,7 @@
|
|
|
2233
1422
|
*/
|
|
2234
1423
|
function runAsyncTest(testObject) {
|
|
2235
1424
|
var asyncTest = testObject.asyncTest, message = testObject.message;
|
|
2236
|
-
if (!isPromise(asyncTest))
|
|
1425
|
+
if (!vestUtils.isPromise(asyncTest))
|
|
2237
1426
|
return;
|
|
2238
1427
|
var emit = useBus().emit;
|
|
2239
1428
|
var stateRef = useStateRef();
|
|
@@ -2246,20 +1435,13 @@
|
|
|
2246
1435
|
if (testObject.isCanceled()) {
|
|
2247
1436
|
return;
|
|
2248
1437
|
}
|
|
2249
|
-
testObject.message = isStringValue(rejectionMessage)
|
|
1438
|
+
testObject.message = vestUtils.isStringValue(rejectionMessage)
|
|
2250
1439
|
? rejectionMessage
|
|
2251
1440
|
: message;
|
|
2252
1441
|
testObject.fail();
|
|
2253
1442
|
done();
|
|
2254
1443
|
});
|
|
2255
|
-
|
|
2256
|
-
asyncTest.then(done, fail);
|
|
2257
|
-
}
|
|
2258
|
-
catch (e) {
|
|
2259
|
-
// We will probably never get here, unless the consumer uses a buggy custom Promise
|
|
2260
|
-
// implementation that behaves differently than the native one, or if they for some
|
|
2261
|
-
fail();
|
|
2262
|
-
}
|
|
1444
|
+
asyncTest.then(done, fail);
|
|
2263
1445
|
}
|
|
2264
1446
|
|
|
2265
1447
|
/**
|
|
@@ -2281,7 +1463,7 @@
|
|
|
2281
1463
|
try {
|
|
2282
1464
|
// try catch for safe property access
|
|
2283
1465
|
// in case object is an enforce chain
|
|
2284
|
-
if (isPromise(result)) {
|
|
1466
|
+
if (vestUtils.isPromise(result)) {
|
|
2285
1467
|
testObject.asyncTest = result;
|
|
2286
1468
|
testObject.setPending();
|
|
2287
1469
|
runAsyncTest(testObject);
|
|
@@ -2308,12 +1490,12 @@
|
|
|
2308
1490
|
function useTestAtCursor(newTestObject) {
|
|
2309
1491
|
var testObjects = useTestObjects()[0];
|
|
2310
1492
|
var prevTests = testObjects.prev;
|
|
2311
|
-
if (isEmpty(prevTests)) {
|
|
1493
|
+
if (vestUtils.isEmpty(prevTests)) {
|
|
2312
1494
|
useSetTestAtCursor(newTestObject);
|
|
2313
1495
|
return newTestObject;
|
|
2314
1496
|
}
|
|
2315
1497
|
var prevTest = useGetTestAtCursor(prevTests);
|
|
2316
|
-
if (!isNullish(newTestObject.key)) {
|
|
1498
|
+
if (!vestUtils.isNullish(newTestObject.key)) {
|
|
2317
1499
|
var nextTest_1 = handleKeyTest(newTestObject.key, newTestObject);
|
|
2318
1500
|
useSetTestAtCursor(nextTest_1);
|
|
2319
1501
|
return nextTest_1;
|
|
@@ -2324,7 +1506,7 @@
|
|
|
2324
1506
|
// Need to see if this has any effect at all.
|
|
2325
1507
|
prevTest = null;
|
|
2326
1508
|
}
|
|
2327
|
-
var nextTest = defaultTo(prevTest, newTestObject);
|
|
1509
|
+
var nextTest = vestUtils.defaultTo(prevTest, newTestObject);
|
|
2328
1510
|
useSetTestAtCursor(nextTest);
|
|
2329
1511
|
return nextTest;
|
|
2330
1512
|
}
|
|
@@ -2341,21 +1523,21 @@
|
|
|
2341
1523
|
function useSetTestAtCursor(testObject) {
|
|
2342
1524
|
var cursorPath = useCurrentPath();
|
|
2343
1525
|
useSetTests(function (tests) {
|
|
2344
|
-
return setValueAtPath(tests, cursorPath, testObject);
|
|
1526
|
+
return vestUtils.nestedArray.setValueAtPath(tests, cursorPath, testObject);
|
|
2345
1527
|
});
|
|
2346
1528
|
}
|
|
2347
1529
|
function useGetTestAtCursor(tests) {
|
|
2348
1530
|
var cursorPath = useCurrentPath();
|
|
2349
|
-
return valueAtPath(tests, cursorPath);
|
|
1531
|
+
return vestUtils.nestedArray.valueAtPath(tests, cursorPath);
|
|
2350
1532
|
}
|
|
2351
1533
|
function testReorderDetected(prevTest, newTest) {
|
|
2352
|
-
return isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
|
|
1534
|
+
return vestUtils.isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
|
|
2353
1535
|
}
|
|
2354
1536
|
function throwTestOrderError(prevTest, newTestObject) {
|
|
2355
1537
|
if (shouldAllowReorder()) {
|
|
2356
1538
|
return;
|
|
2357
1539
|
}
|
|
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."));
|
|
1540
|
+
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
1541
|
}
|
|
2360
1542
|
function handleKeyTest(key, newTestObject) {
|
|
2361
1543
|
var prevTestByKey = usePrevTestByKey(key);
|
|
@@ -2377,7 +1559,7 @@
|
|
|
2377
1559
|
return testObject;
|
|
2378
1560
|
}
|
|
2379
1561
|
var prevRunTest = useTestAtCursor(testObject);
|
|
2380
|
-
if (
|
|
1562
|
+
if (inActiveOmitWhen() || optionalFiedIsApplied(testObject.fieldName)) {
|
|
2381
1563
|
prevRunTest.omit();
|
|
2382
1564
|
cursor.next();
|
|
2383
1565
|
return prevRunTest;
|
|
@@ -2401,7 +1583,7 @@
|
|
|
2401
1583
|
if (testObject.isUntested()) {
|
|
2402
1584
|
registerTest(testObject);
|
|
2403
1585
|
}
|
|
2404
|
-
else if (isPromise(testObject.asyncTest)) {
|
|
1586
|
+
else if (vestUtils.isPromise(testObject.asyncTest)) {
|
|
2405
1587
|
testObject.setPending();
|
|
2406
1588
|
runAsyncTest(testObject);
|
|
2407
1589
|
}
|
|
@@ -2409,7 +1591,7 @@
|
|
|
2409
1591
|
|
|
2410
1592
|
/* eslint-disable jest/valid-title */
|
|
2411
1593
|
function bindTestMemo(test) {
|
|
2412
|
-
var cache =
|
|
1594
|
+
var cache = vestUtils.cache(10); // arbitrary cache size
|
|
2413
1595
|
// eslint-disable-next-line max-statements
|
|
2414
1596
|
function memo(fieldName) {
|
|
2415
1597
|
var args = [];
|
|
@@ -2421,7 +1603,7 @@
|
|
|
2421
1603
|
// Implicit dependency for more specificity
|
|
2422
1604
|
var dependencies = [useSuiteId(), fieldName, cursorAt].concat(deps);
|
|
2423
1605
|
var cached = cache.get(dependencies);
|
|
2424
|
-
if (isNull(cached)) {
|
|
1606
|
+
if (vestUtils.isNull(cached)) {
|
|
2425
1607
|
// cache miss
|
|
2426
1608
|
return cache(dependencies, function () { return test(fieldName, msg, testFn); });
|
|
2427
1609
|
}
|
|
@@ -2440,9 +1622,9 @@
|
|
|
2440
1622
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
2441
1623
|
args[_i - 1] = arguments[_i];
|
|
2442
1624
|
}
|
|
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'));
|
|
1625
|
+
var _a = (vestUtils.isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
|
|
1626
|
+
vestUtils.invariant(vestUtils.isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
|
|
1627
|
+
vestUtils.invariant(vestUtils.isFunction(testFn), incompatibleParamsError('Test callback', 'function'));
|
|
2446
1628
|
var context$1 = context.useX();
|
|
2447
1629
|
var testObject = new VestTest(fieldName, testFn, {
|
|
2448
1630
|
message: message,
|
|
@@ -2460,7 +1642,7 @@
|
|
|
2460
1642
|
* enforce(data.username).isNotBlank();
|
|
2461
1643
|
* });
|
|
2462
1644
|
*/
|
|
2463
|
-
var test = assign(testBase, {
|
|
1645
|
+
var test = vestUtils.assign(testBase, {
|
|
2464
1646
|
memo: bindTestMemo(testBase)
|
|
2465
1647
|
});
|
|
2466
1648
|
function incompatibleParamsError(name, expected) {
|
|
@@ -2474,18 +1656,23 @@
|
|
|
2474
1656
|
*/
|
|
2475
1657
|
function warn() {
|
|
2476
1658
|
var ctx = context.useX('warn ' + ERROR_HOOK_CALLED_OUTSIDE);
|
|
2477
|
-
invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
|
|
1659
|
+
vestUtils.invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
|
|
2478
1660
|
ctx.currentTest.warn();
|
|
2479
1661
|
}
|
|
2480
1662
|
|
|
2481
|
-
var VERSION = "4.
|
|
1663
|
+
var VERSION = "4.6.2-dev-fcaa09";
|
|
2482
1664
|
|
|
1665
|
+
Object.defineProperty(exports, 'enforce', {
|
|
1666
|
+
enumerable: true,
|
|
1667
|
+
get: function () {
|
|
1668
|
+
return n4s.enforce;
|
|
1669
|
+
}
|
|
1670
|
+
});
|
|
2483
1671
|
exports.VERSION = VERSION;
|
|
2484
1672
|
exports.context = context;
|
|
2485
1673
|
exports.create = create;
|
|
2486
1674
|
exports.each = each;
|
|
2487
1675
|
exports.eager = eager;
|
|
2488
|
-
exports.enforce = enforce;
|
|
2489
1676
|
exports.group = group;
|
|
2490
1677
|
exports.include = include;
|
|
2491
1678
|
exports.omitWhen = omitWhen;
|