vest 4.4.2 → 4.4.3-dev-c786f7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/classnames.development.js +9 -60
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/enforce/compose.development.js +5 -58
- package/dist/cjs/enforce/compose.production.js +1 -1
- package/dist/cjs/enforce/compounds.development.js +8 -51
- package/dist/cjs/enforce/compounds.production.js +1 -1
- package/dist/cjs/enforce/schema.development.js +5 -57
- package/dist/cjs/enforce/schema.production.js +1 -1
- package/dist/cjs/parser.development.js +8 -59
- package/dist/cjs/parser.production.js +1 -1
- package/dist/cjs/promisify.development.js +2 -26
- package/dist/cjs/promisify.production.js +1 -1
- package/dist/cjs/vest.development.js +119 -368
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +1 -52
- package/dist/es/classnames.production.js +1 -1
- package/dist/es/enforce/compose.development.js +1 -54
- package/dist/es/enforce/compose.production.js +1 -1
- package/dist/es/enforce/compounds.development.js +2 -45
- package/dist/es/enforce/compounds.production.js +1 -1
- package/dist/es/enforce/schema.development.js +1 -53
- package/dist/es/enforce/schema.production.js +1 -1
- package/dist/es/parser.development.js +1 -52
- package/dist/es/parser.production.js +1 -1
- package/dist/es/promisify.development.js +1 -25
- package/dist/es/promisify.production.js +1 -1
- package/dist/es/vest.development.js +44 -293
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +11 -11
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +94 -94
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +117 -117
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +117 -117
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/parser.development.js +11 -11
- package/dist/umd/parser.production.js +1 -1
- package/dist/umd/vest.development.js +296 -295
- package/dist/umd/vest.production.js +1 -1
- package/package.json +4 -3
- package/testUtils/__tests__/partition.test.ts +21 -0
- package/testUtils/mockThrowError.ts +2 -1
- package/testUtils/partition.ts +13 -0
- package/testUtils/suiteDummy.ts +1 -1
- package/types/enforce/compose.d.ts +15 -31
- package/types/enforce/compounds.d.ts +15 -31
- package/types/enforce/schema.d.ts +15 -31
- package/types/vest.d.ts +1 -1
|
@@ -3,181 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var n4s = require('n4s');
|
|
6
|
+
var vestUtils = require('vest-utils');
|
|
6
7
|
var context$1 = require('context');
|
|
7
8
|
|
|
8
|
-
/**
|
|
9
|
-
* @returns a unique numeric id.
|
|
10
|
-
*/
|
|
11
|
-
var genId = (function (n) { return function () {
|
|
12
|
-
return "".concat(n++);
|
|
13
|
-
}; })(0);
|
|
14
|
-
|
|
15
|
-
function isStringValue(v) {
|
|
16
|
-
return String(v) === v;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function bindNot(fn) {
|
|
20
|
-
return function () {
|
|
21
|
-
var args = [];
|
|
22
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
23
|
-
args[_i] = arguments[_i];
|
|
24
|
-
}
|
|
25
|
-
return !fn.apply(void 0, args);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function isUndefined(value) {
|
|
30
|
-
return value === undefined;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
9
|
function shouldUseErrorAsMessage(message, error) {
|
|
34
10
|
// kind of cheating with this safe guard, but it does the job
|
|
35
|
-
return isUndefined(message) && isStringValue(error);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function asArray(possibleArg) {
|
|
39
|
-
return [].concat(possibleArg);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
var assign = Object.assign;
|
|
43
|
-
|
|
44
|
-
function isNumeric(value) {
|
|
45
|
-
var str = String(value);
|
|
46
|
-
var num = Number(value);
|
|
47
|
-
var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
|
|
48
|
-
return Boolean(result);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function numberEquals(value, eq) {
|
|
52
|
-
return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function lengthEquals(value, arg1) {
|
|
56
|
-
return numberEquals(value.length, arg1);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function greaterThan(value, gt) {
|
|
60
|
-
return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function longerThan(value, arg1) {
|
|
64
|
-
return greaterThan(value.length, arg1);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Creates a cache function
|
|
69
|
-
*/
|
|
70
|
-
function createCache(maxSize) {
|
|
71
|
-
if (maxSize === void 0) { maxSize = 1; }
|
|
72
|
-
var cacheStorage = [];
|
|
73
|
-
var cache = function (deps, cacheAction) {
|
|
74
|
-
var cacheHit = cache.get(deps);
|
|
75
|
-
// cache hit is not null
|
|
76
|
-
if (cacheHit)
|
|
77
|
-
return cacheHit[1];
|
|
78
|
-
var result = cacheAction();
|
|
79
|
-
cacheStorage.unshift([deps.concat(), result]);
|
|
80
|
-
if (longerThan(cacheStorage, maxSize))
|
|
81
|
-
cacheStorage.length = maxSize;
|
|
82
|
-
return result;
|
|
83
|
-
};
|
|
84
|
-
// invalidate an item in the cache by its dependencies
|
|
85
|
-
cache.invalidate = function (deps) {
|
|
86
|
-
var index = findIndex(deps);
|
|
87
|
-
if (index > -1)
|
|
88
|
-
cacheStorage.splice(index, 1);
|
|
89
|
-
};
|
|
90
|
-
// Retrieves an item from the cache.
|
|
91
|
-
cache.get = function (deps) {
|
|
92
|
-
return cacheStorage[findIndex(deps)] || null;
|
|
93
|
-
};
|
|
94
|
-
return cache;
|
|
95
|
-
function findIndex(deps) {
|
|
96
|
-
return cacheStorage.findIndex(function (_a) {
|
|
97
|
-
var cachedDeps = _a[0];
|
|
98
|
-
return lengthEquals(deps, cachedDeps.length) &&
|
|
99
|
-
deps.every(function (dep, i) { return dep === cachedDeps[i]; });
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// The module is named "isArrayValue" since it
|
|
105
|
-
// is conflicting with a nested npm dependency.
|
|
106
|
-
// We may need to revisit this in the future.
|
|
107
|
-
function isArray(value) {
|
|
108
|
-
return Boolean(Array.isArray(value));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function isNull(value) {
|
|
112
|
-
return value === null;
|
|
113
|
-
}
|
|
114
|
-
var isNotNull = bindNot(isNull);
|
|
115
|
-
|
|
116
|
-
function isFunction(value) {
|
|
117
|
-
return typeof value === 'function';
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function optionalFunctionValue(value) {
|
|
121
|
-
var args = [];
|
|
122
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
123
|
-
args[_i - 1] = arguments[_i];
|
|
124
|
-
}
|
|
125
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function defaultTo(value, defaultValue) {
|
|
129
|
-
var _a;
|
|
130
|
-
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function last(values) {
|
|
134
|
-
var valuesArray = asArray(values);
|
|
135
|
-
return valuesArray[valuesArray.length - 1];
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// This is kind of a map/filter in one function.
|
|
139
|
-
// Normally, behaves like a nested-array map,
|
|
140
|
-
// but returning `null` will drop the element from the array
|
|
141
|
-
function transform(array, cb) {
|
|
142
|
-
var res = [];
|
|
143
|
-
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
|
|
144
|
-
var v = array_1[_i];
|
|
145
|
-
if (isArray(v)) {
|
|
146
|
-
res.push(transform(v, cb));
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
var output = cb(v);
|
|
150
|
-
if (isNotNull(output)) {
|
|
151
|
-
res.push(output);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return res;
|
|
156
|
-
}
|
|
157
|
-
function valueAtPath(array, path) {
|
|
158
|
-
return getCurrent(array, path)[last(path)];
|
|
159
|
-
}
|
|
160
|
-
function setValueAtPath(array, path, value) {
|
|
161
|
-
var current = getCurrent(array, path);
|
|
162
|
-
current[last(path)] = value;
|
|
163
|
-
return array;
|
|
164
|
-
}
|
|
165
|
-
function flatten(values) {
|
|
166
|
-
return asArray(values).reduce(function (acc, value) {
|
|
167
|
-
if (isArray(value)) {
|
|
168
|
-
return acc.concat(flatten(value));
|
|
169
|
-
}
|
|
170
|
-
return asArray(acc).concat(value);
|
|
171
|
-
}, []);
|
|
172
|
-
}
|
|
173
|
-
function getCurrent(array, path) {
|
|
174
|
-
var current = array;
|
|
175
|
-
for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) {
|
|
176
|
-
var p = _a[_i];
|
|
177
|
-
current[p] = defaultTo(current[p], []);
|
|
178
|
-
current = current[p];
|
|
179
|
-
}
|
|
180
|
-
return current;
|
|
11
|
+
return vestUtils.isUndefined(message) && vestUtils.isStringValue(error);
|
|
181
12
|
}
|
|
182
13
|
|
|
183
14
|
var IsolateTypes;
|
|
@@ -234,7 +65,7 @@ function generateIsolate(type, path) {
|
|
|
234
65
|
var context = context$1.createContext(function (ctxRef, parentContext) {
|
|
235
66
|
return parentContext
|
|
236
67
|
? null
|
|
237
|
-
: assign({}, {
|
|
68
|
+
: vestUtils.assign({}, {
|
|
238
69
|
exclusion: {
|
|
239
70
|
tests: {},
|
|
240
71
|
groups: {}
|
|
@@ -272,8 +103,8 @@ function useSetOptionalField(fieldName, setter) {
|
|
|
272
103
|
var _a = useOptionalFields(), setOptionalFields = _a[1];
|
|
273
104
|
setOptionalFields(function (optionalFields) {
|
|
274
105
|
var _a;
|
|
275
|
-
return assign(optionalFields, (_a = {},
|
|
276
|
-
_a[fieldName] = optionalFunctionValue(setter, optionalFields[fieldName]),
|
|
106
|
+
return vestUtils.assign(optionalFields, (_a = {},
|
|
107
|
+
_a[fieldName] = vestUtils.optionalFunctionValue(setter, optionalFields[fieldName]),
|
|
277
108
|
_a));
|
|
278
109
|
});
|
|
279
110
|
}
|
|
@@ -298,7 +129,7 @@ function useSetTests(handler) {
|
|
|
298
129
|
var current = _a.current, prev = _a.prev;
|
|
299
130
|
return ({
|
|
300
131
|
prev: prev,
|
|
301
|
-
current: asArray(handler(current))
|
|
132
|
+
current: vestUtils.asArray(handler(current))
|
|
302
133
|
});
|
|
303
134
|
});
|
|
304
135
|
}
|
|
@@ -306,10 +137,10 @@ function useSetTests(handler) {
|
|
|
306
137
|
function useAllIncomplete() {
|
|
307
138
|
return useTestsFlat().filter(function (test) { return test.isPending(); });
|
|
308
139
|
}
|
|
309
|
-
var flatCache =
|
|
140
|
+
var flatCache = vestUtils.cache();
|
|
310
141
|
function useTestsFlat() {
|
|
311
142
|
var current = useTestObjects()[0].current;
|
|
312
|
-
return flatCache([current], function () { return flatten(current); });
|
|
143
|
+
return flatCache([current], function () { return vestUtils.nestedArray.flatten(current); });
|
|
313
144
|
}
|
|
314
145
|
function useEachTestObject(handler) {
|
|
315
146
|
var testObjects = useTestsFlat();
|
|
@@ -325,7 +156,7 @@ var VestTest = /** @class */ (function () {
|
|
|
325
156
|
function VestTest(fieldName, testFn, _a) {
|
|
326
157
|
var _b = _a === void 0 ? {} : _a, message = _b.message, groupName = _b.groupName, key = _b.key;
|
|
327
158
|
this.key = null;
|
|
328
|
-
this.id = genId();
|
|
159
|
+
this.id = vestUtils.genId();
|
|
329
160
|
this.severity = TestSeverity.Error;
|
|
330
161
|
this.status = STATUS_UNTESTED;
|
|
331
162
|
this.fieldName = fieldName;
|
|
@@ -460,20 +291,6 @@ var STATUS_PENDING = 'PENDING';
|
|
|
460
291
|
var STATUS_CANCELED = 'CANCELED';
|
|
461
292
|
var STATUS_OMITTED = 'OMITTED';
|
|
462
293
|
|
|
463
|
-
function invariant(condition,
|
|
464
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
465
|
-
message) {
|
|
466
|
-
if (condition) {
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
// If message is a string object (rather than string literal)
|
|
470
|
-
// Throw the value directly as a string
|
|
471
|
-
// Alternatively, throw an error with the message
|
|
472
|
-
throw message instanceof String
|
|
473
|
-
? message.valueOf()
|
|
474
|
-
: new Error(message ? optionalFunctionValue(message) : message);
|
|
475
|
-
}
|
|
476
|
-
|
|
477
294
|
// eslint-disable-next-line max-lines-per-function
|
|
478
295
|
function createState(onStateChange) {
|
|
479
296
|
var state = {
|
|
@@ -512,12 +329,12 @@ function createState(onStateChange) {
|
|
|
512
329
|
}
|
|
513
330
|
function initKey(key, initialState, prevState) {
|
|
514
331
|
current().push();
|
|
515
|
-
set(key, optionalFunctionValue(initialState, prevState));
|
|
332
|
+
set(key, vestUtils.optionalFunctionValue(initialState, prevState));
|
|
516
333
|
return function useStateKey() {
|
|
517
334
|
return [
|
|
518
335
|
current()[key],
|
|
519
336
|
function (nextState) {
|
|
520
|
-
return set(key, optionalFunctionValue(nextState, current()[key]));
|
|
337
|
+
return set(key, vestUtils.optionalFunctionValue(nextState, current()[key]));
|
|
521
338
|
},
|
|
522
339
|
];
|
|
523
340
|
};
|
|
@@ -529,10 +346,10 @@ function createState(onStateChange) {
|
|
|
529
346
|
var prevValue = state.references[index];
|
|
530
347
|
state.references[index] = value;
|
|
531
348
|
var _a = registrations[index], onUpdate = _a[1];
|
|
532
|
-
if (isFunction(onUpdate)) {
|
|
349
|
+
if (vestUtils.isFunction(onUpdate)) {
|
|
533
350
|
onUpdate(value, prevValue);
|
|
534
351
|
}
|
|
535
|
-
if (isFunction(onStateChange)) {
|
|
352
|
+
if (vestUtils.isFunction(onStateChange)) {
|
|
536
353
|
onStateChange();
|
|
537
354
|
}
|
|
538
355
|
}
|
|
@@ -557,23 +374,33 @@ function createStateRef(state, _a) {
|
|
|
557
374
|
};
|
|
558
375
|
}
|
|
559
376
|
|
|
560
|
-
|
|
561
|
-
|
|
377
|
+
/**
|
|
378
|
+
* @returns {Isolate} The current isolate layer
|
|
379
|
+
*/
|
|
380
|
+
function useIsolate() {
|
|
381
|
+
return context.useX().isolate;
|
|
562
382
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
383
|
+
/**
|
|
384
|
+
* @returns {number[]} The current cursor path of the isolate tree
|
|
385
|
+
*/
|
|
386
|
+
function useCurrentPath() {
|
|
387
|
+
var isolate = useIsolate();
|
|
388
|
+
return isolate.path.concat(isolate.cursor.current());
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* @returns {IsolateCursor} The cursor object for the current isolate
|
|
392
|
+
*/
|
|
393
|
+
function useCursor() {
|
|
394
|
+
return useIsolate().cursor;
|
|
568
395
|
}
|
|
569
396
|
|
|
570
397
|
function usePrevKeys() {
|
|
571
398
|
var prev = useTestObjects()[0].prev;
|
|
572
|
-
return asArray(getCurrent(prev, useCurrentPath())).reduce(function (prevKeys, testObject) {
|
|
399
|
+
return vestUtils.asArray(vestUtils.nestedArray.getCurrent(prev, useCurrentPath())).reduce(function (prevKeys, testObject) {
|
|
573
400
|
if (!(testObject instanceof VestTest)) {
|
|
574
401
|
return prevKeys;
|
|
575
402
|
}
|
|
576
|
-
if (isNullish(testObject.key)) {
|
|
403
|
+
if (vestUtils.isNullish(testObject.key)) {
|
|
577
404
|
return prevKeys;
|
|
578
405
|
}
|
|
579
406
|
prevKeys[testObject.key] = testObject;
|
|
@@ -586,22 +413,22 @@ function usePrevTestByKey(key) {
|
|
|
586
413
|
}
|
|
587
414
|
function useRetainTestKey(key, testObject) {
|
|
588
415
|
var current = useIsolate().keys.current;
|
|
589
|
-
if (isNullish(current[key])) {
|
|
416
|
+
if (vestUtils.isNullish(current[key])) {
|
|
590
417
|
current[key] = testObject;
|
|
591
418
|
}
|
|
592
419
|
else {
|
|
593
|
-
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."));
|
|
420
|
+
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."));
|
|
594
421
|
}
|
|
595
422
|
}
|
|
596
423
|
|
|
597
424
|
function isolate(_a, callback) {
|
|
598
425
|
var _b = _a.type, type = _b === void 0 ? IsolateTypes.DEFAULT : _b;
|
|
599
|
-
invariant(isFunction(callback));
|
|
426
|
+
vestUtils.invariant(vestUtils.isFunction(callback));
|
|
600
427
|
// Generate a new Isolate layer, with its own cursor
|
|
601
428
|
var isolate = generateIsolate(type, useCurrentPath());
|
|
602
429
|
var output = context.run({ isolate: isolate }, function () {
|
|
603
430
|
isolate.keys.prev = usePrevKeys();
|
|
604
|
-
useSetTests(function (tests) { return setValueAtPath(tests, isolate.path, []); });
|
|
431
|
+
useSetTests(function (tests) { return vestUtils.nestedArray.setValueAtPath(tests, isolate.path, []); });
|
|
605
432
|
var res = callback();
|
|
606
433
|
return res;
|
|
607
434
|
});
|
|
@@ -609,31 +436,12 @@ function isolate(_a, callback) {
|
|
|
609
436
|
useCursor().next();
|
|
610
437
|
return output;
|
|
611
438
|
}
|
|
612
|
-
/**
|
|
613
|
-
* @returns {Isolate} The current isolate layer
|
|
614
|
-
*/
|
|
615
|
-
function useIsolate() {
|
|
616
|
-
return context.useX().isolate;
|
|
617
|
-
}
|
|
618
439
|
/**
|
|
619
440
|
* @returns {boolean} Whether or not the current isolate allows tests to be reordered
|
|
620
441
|
*/
|
|
621
442
|
function shouldAllowReorder() {
|
|
622
443
|
return useIsolate().type === IsolateTypes.EACH;
|
|
623
444
|
}
|
|
624
|
-
/**
|
|
625
|
-
* @returns {number[]} The current cursor path of the isolate tree
|
|
626
|
-
*/
|
|
627
|
-
function useCurrentPath() {
|
|
628
|
-
var isolate = useIsolate();
|
|
629
|
-
return isolate.path.concat(isolate.cursor.current());
|
|
630
|
-
}
|
|
631
|
-
/**
|
|
632
|
-
* @returns {IsolateCursor} The cursor object for the current isolate
|
|
633
|
-
*/
|
|
634
|
-
function useCursor() {
|
|
635
|
-
return useIsolate().cursor;
|
|
636
|
-
}
|
|
637
445
|
|
|
638
446
|
var Severity;
|
|
639
447
|
(function (Severity) {
|
|
@@ -651,27 +459,6 @@ function countKeyBySeverity(severity) {
|
|
|
651
459
|
: SeverityCount.WARN_COUNT;
|
|
652
460
|
}
|
|
653
461
|
|
|
654
|
-
/**
|
|
655
|
-
* A safe hasOwnProperty access
|
|
656
|
-
*/
|
|
657
|
-
function hasOwnProperty(obj, key) {
|
|
658
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
function isEmpty(value) {
|
|
662
|
-
if (!value) {
|
|
663
|
-
return true;
|
|
664
|
-
}
|
|
665
|
-
else if (hasOwnProperty(value, 'length')) {
|
|
666
|
-
return lengthEquals(value, 0);
|
|
667
|
-
}
|
|
668
|
-
else if (typeof value === 'object') {
|
|
669
|
-
return lengthEquals(Object.keys(value), 0);
|
|
670
|
-
}
|
|
671
|
-
return false;
|
|
672
|
-
}
|
|
673
|
-
var isNotEmpty = bindNot(isEmpty);
|
|
674
|
-
|
|
675
462
|
function nonMatchingFieldName(testObject, fieldName) {
|
|
676
463
|
return !!fieldName && !matchingFieldName(testObject, fieldName);
|
|
677
464
|
}
|
|
@@ -679,20 +466,16 @@ function matchingFieldName(testObject, fieldName) {
|
|
|
679
466
|
return !!(fieldName && testObject.fieldName === fieldName);
|
|
680
467
|
}
|
|
681
468
|
|
|
682
|
-
var nonMatchingGroupName = bindNot(matchingGroupName);
|
|
469
|
+
var nonMatchingGroupName = vestUtils.bindNot(matchingGroupName);
|
|
683
470
|
function matchingGroupName(testObject, groupName) {
|
|
684
471
|
return testObject.groupName === groupName;
|
|
685
472
|
}
|
|
686
473
|
|
|
687
|
-
function either(a, b) {
|
|
688
|
-
return !!a !== !!b;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
474
|
/**
|
|
692
475
|
* Checks that a given test object matches the currently specified severity level
|
|
693
476
|
*/
|
|
694
477
|
function nonMatchingSeverityProfile(severity, testObject) {
|
|
695
|
-
return either(severity === Severity.WARNINGS, testObject.warns());
|
|
478
|
+
return vestUtils.either(severity === Severity.WARNINGS, testObject.warns());
|
|
696
479
|
}
|
|
697
480
|
|
|
698
481
|
/**
|
|
@@ -742,7 +525,7 @@ function shouldAddValidProperty(fieldName) {
|
|
|
742
525
|
return false;
|
|
743
526
|
}
|
|
744
527
|
var testObjects = useTestsFlat();
|
|
745
|
-
if (isEmpty(testObjects)) {
|
|
528
|
+
if (vestUtils.isEmpty(testObjects)) {
|
|
746
529
|
return false;
|
|
747
530
|
}
|
|
748
531
|
// Does the given field have any pending tests that are not optional?
|
|
@@ -772,13 +555,13 @@ function fieldIsOmitted(fieldName) {
|
|
|
772
555
|
}
|
|
773
556
|
// Does the given field have any pending tests that are not optional?
|
|
774
557
|
function hasNonOptionalIncomplete(fieldName) {
|
|
775
|
-
return isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
558
|
+
return vestUtils.isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
776
559
|
return isOptionalFieldIncomplete(testObject, fieldName);
|
|
777
560
|
}));
|
|
778
561
|
}
|
|
779
562
|
// Do the given group/field have any pending tests that are not optional?
|
|
780
563
|
function hasNonOptionalIncompleteByGroup(groupName, fieldName) {
|
|
781
|
-
return isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
564
|
+
return vestUtils.isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
782
565
|
if (nonMatchingGroupName(testObject, groupName)) {
|
|
783
566
|
return false;
|
|
784
567
|
}
|
|
@@ -820,7 +603,7 @@ function missingTestsLogic(testObject, fieldName) {
|
|
|
820
603
|
|
|
821
604
|
function useSummary() {
|
|
822
605
|
var summary = context.useX().summary;
|
|
823
|
-
invariant(summary);
|
|
606
|
+
vestUtils.invariant(summary);
|
|
824
607
|
return summary;
|
|
825
608
|
}
|
|
826
609
|
/**
|
|
@@ -828,7 +611,7 @@ function useSummary() {
|
|
|
828
611
|
*/
|
|
829
612
|
function genTestsSummary() {
|
|
830
613
|
var testObjects = useTestsFlat();
|
|
831
|
-
var summary = assign(baseStats(), {
|
|
614
|
+
var summary = vestUtils.assign(baseStats(), {
|
|
832
615
|
groups: {},
|
|
833
616
|
tests: {},
|
|
834
617
|
valid: false
|
|
@@ -905,16 +688,12 @@ function baseStats() {
|
|
|
905
688
|
};
|
|
906
689
|
}
|
|
907
690
|
function baseTestStats() {
|
|
908
|
-
return assign(baseStats(), {
|
|
691
|
+
return vestUtils.assign(baseStats(), {
|
|
909
692
|
errors: [],
|
|
910
693
|
warnings: []
|
|
911
694
|
});
|
|
912
695
|
}
|
|
913
696
|
|
|
914
|
-
function isPositive(value) {
|
|
915
|
-
return greaterThan(value, 0);
|
|
916
|
-
}
|
|
917
|
-
|
|
918
697
|
// calls collectAll or getByFieldName depending on whether fieldName is provided
|
|
919
698
|
function gatherFailures(testGroup, severityKey, fieldName) {
|
|
920
699
|
return fieldName
|
|
@@ -929,7 +708,7 @@ function collectAll(testGroup, severityKey) {
|
|
|
929
708
|
var output = {};
|
|
930
709
|
var countKey = countKeyBySeverity(severityKey);
|
|
931
710
|
for (var field in testGroup) {
|
|
932
|
-
if (isPositive(testGroup[field][countKey])) {
|
|
711
|
+
if (vestUtils.isPositive(testGroup[field][countKey])) {
|
|
933
712
|
// We will probably never get to the fallback array
|
|
934
713
|
// leaving it just in case the implementation changes
|
|
935
714
|
output[field] = testGroup[field][severityKey] || [];
|
|
@@ -973,9 +752,9 @@ function hasFailures(severityCount, fieldName) {
|
|
|
973
752
|
var _a;
|
|
974
753
|
var summary = useSummary();
|
|
975
754
|
if (fieldName) {
|
|
976
|
-
return isPositive((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
755
|
+
return vestUtils.isPositive((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
977
756
|
}
|
|
978
|
-
return isPositive(summary[severityCount]);
|
|
757
|
+
return vestUtils.isPositive(summary[severityCount]);
|
|
979
758
|
}
|
|
980
759
|
|
|
981
760
|
function hasErrorsByGroup(groupName, fieldName) {
|
|
@@ -994,10 +773,10 @@ function hasFailuresByGroup(severityKey, groupName, fieldName) {
|
|
|
994
773
|
return false;
|
|
995
774
|
}
|
|
996
775
|
if (fieldName) {
|
|
997
|
-
return isPositive((_a = group[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
776
|
+
return vestUtils.isPositive((_a = group[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
998
777
|
}
|
|
999
778
|
for (var field in group) {
|
|
1000
|
-
if (isPositive((_b = group[field]) === null || _b === void 0 ? void 0 : _b[severityCount])) {
|
|
779
|
+
if (vestUtils.isPositive((_b = group[field]) === null || _b === void 0 ? void 0 : _b[severityCount])) {
|
|
1001
780
|
return true;
|
|
1002
781
|
}
|
|
1003
782
|
}
|
|
@@ -1031,7 +810,7 @@ function isFieldValid(testContainer, fieldName) {
|
|
|
1031
810
|
return !!((_a = testContainer[fieldName]) === null || _a === void 0 ? void 0 : _a.valid);
|
|
1032
811
|
}
|
|
1033
812
|
|
|
1034
|
-
var cache$1 =
|
|
813
|
+
var cache$1 = vestUtils.cache(1);
|
|
1035
814
|
function produceSuiteResult() {
|
|
1036
815
|
var testObjects = useTestsFlat();
|
|
1037
816
|
var ctxRef = { stateRef: useStateRef() };
|
|
@@ -1039,7 +818,7 @@ function produceSuiteResult() {
|
|
|
1039
818
|
var summary = genTestsSummary();
|
|
1040
819
|
var suiteName = useSuiteName();
|
|
1041
820
|
var ref = { summary: summary };
|
|
1042
|
-
return assign(summary, {
|
|
821
|
+
return vestUtils.assign(summary, {
|
|
1043
822
|
getErrors: context.bind(ref, getErrors),
|
|
1044
823
|
getErrorsByGroup: context.bind(ref, getErrorsByGroup),
|
|
1045
824
|
getWarnings: context.bind(ref, getWarnings),
|
|
@@ -1060,7 +839,7 @@ function produceSuiteResult() {
|
|
|
1060
839
|
*/
|
|
1061
840
|
function hasRemainingTests(fieldName) {
|
|
1062
841
|
var allIncomplete = useAllIncomplete();
|
|
1063
|
-
if (isEmpty(allIncomplete)) {
|
|
842
|
+
if (vestUtils.isEmpty(allIncomplete)) {
|
|
1064
843
|
return false;
|
|
1065
844
|
}
|
|
1066
845
|
if (fieldName) {
|
|
@@ -1068,15 +847,15 @@ function hasRemainingTests(fieldName) {
|
|
|
1068
847
|
return matchingFieldName(testObject, fieldName);
|
|
1069
848
|
});
|
|
1070
849
|
}
|
|
1071
|
-
return isNotEmpty(allIncomplete);
|
|
850
|
+
return vestUtils.isNotEmpty(allIncomplete);
|
|
1072
851
|
}
|
|
1073
852
|
|
|
1074
|
-
var cache =
|
|
853
|
+
var cache = vestUtils.cache(20);
|
|
1075
854
|
function produceFullResult() {
|
|
1076
855
|
var testObjects = useTestsFlat();
|
|
1077
856
|
var ctxRef = { stateRef: useStateRef() };
|
|
1078
857
|
return cache([testObjects], context.bind(ctxRef, function () {
|
|
1079
|
-
return assign({}, produceSuiteResult(), {
|
|
858
|
+
return vestUtils.assign({}, produceSuiteResult(), {
|
|
1080
859
|
done: context.bind(ctxRef, done)
|
|
1081
860
|
});
|
|
1082
861
|
}));
|
|
@@ -1086,9 +865,9 @@ function produceFullResult() {
|
|
|
1086
865
|
*/
|
|
1087
866
|
function shouldSkipDoneRegistration(callback, fieldName, output) {
|
|
1088
867
|
// If we do not have any test runs for the current field
|
|
1089
|
-
return !!(!isFunction(callback) ||
|
|
868
|
+
return !!(!vestUtils.isFunction(callback) ||
|
|
1090
869
|
(fieldName &&
|
|
1091
|
-
(!output.tests[fieldName] || isEmpty(output.tests[fieldName].testCount))));
|
|
870
|
+
(!output.tests[fieldName] || vestUtils.isEmpty(output.tests[fieldName].testCount))));
|
|
1092
871
|
}
|
|
1093
872
|
function shouldRunDoneCallback(fieldName) {
|
|
1094
873
|
// is suite finished || field name exists, and test is finished;
|
|
@@ -1130,38 +909,16 @@ function deferDoneCallback(doneCallback, fieldName) {
|
|
|
1130
909
|
});
|
|
1131
910
|
}
|
|
1132
911
|
|
|
1133
|
-
function createBus() {
|
|
1134
|
-
var listeners = {};
|
|
1135
|
-
return {
|
|
1136
|
-
emit: function (event, data) {
|
|
1137
|
-
listener(event).forEach(function (handler) {
|
|
1138
|
-
handler(data);
|
|
1139
|
-
});
|
|
1140
|
-
},
|
|
1141
|
-
on: function (event, handler) {
|
|
1142
|
-
listeners[event] = listener(event).concat(handler);
|
|
1143
|
-
return {
|
|
1144
|
-
off: function () {
|
|
1145
|
-
listeners[event] = listener(event).filter(function (h) { return h !== handler; });
|
|
1146
|
-
}
|
|
1147
|
-
};
|
|
1148
|
-
}
|
|
1149
|
-
};
|
|
1150
|
-
function listener(event) {
|
|
1151
|
-
return listeners[event] || [];
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
912
|
function omitOptionalFields() {
|
|
1156
913
|
var optionalFields = useOptionalFields()[0];
|
|
1157
|
-
if (isEmpty(optionalFields)) {
|
|
914
|
+
if (vestUtils.isEmpty(optionalFields)) {
|
|
1158
915
|
return;
|
|
1159
916
|
}
|
|
1160
917
|
var shouldOmit = {};
|
|
1161
918
|
useSetTests(function (tests) {
|
|
1162
|
-
return transform(tests, function (testObject) {
|
|
919
|
+
return vestUtils.nestedArray.transform(tests, function (testObject) {
|
|
1163
920
|
var fieldName = testObject.fieldName;
|
|
1164
|
-
if (hasOwnProperty(shouldOmit, fieldName)) {
|
|
921
|
+
if (vestUtils.hasOwnProperty(shouldOmit, fieldName)) {
|
|
1165
922
|
verifyAndOmit(testObject);
|
|
1166
923
|
}
|
|
1167
924
|
else {
|
|
@@ -1178,7 +935,7 @@ function omitOptionalFields() {
|
|
|
1178
935
|
}
|
|
1179
936
|
function runOptionalConfig(testObject) {
|
|
1180
937
|
var optionalConfig = useOptionalFieldConfig(testObject.fieldName);
|
|
1181
|
-
if (isFunction(optionalConfig)) {
|
|
938
|
+
if (vestUtils.isFunction(optionalConfig)) {
|
|
1182
939
|
shouldOmit[testObject.fieldName] = optionalConfig();
|
|
1183
940
|
verifyAndOmit(testObject);
|
|
1184
941
|
}
|
|
@@ -1190,14 +947,10 @@ function omitOptionalFields() {
|
|
|
1190
947
|
*/
|
|
1191
948
|
function removeTestFromState (testObject) {
|
|
1192
949
|
useSetTests(function (tests) {
|
|
1193
|
-
return transform(tests, function (test) { return (testObject !== test ? test : null); });
|
|
950
|
+
return vestUtils.nestedArray.transform(tests, function (test) { return (testObject !== test ? test : null); });
|
|
1194
951
|
});
|
|
1195
952
|
}
|
|
1196
953
|
|
|
1197
|
-
function callEach(arr) {
|
|
1198
|
-
return arr.forEach(function (fn) { return fn(); });
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
954
|
/**
|
|
1202
955
|
* Runs done callback per field when async tests are finished running.
|
|
1203
956
|
*/
|
|
@@ -1205,8 +958,8 @@ function runFieldCallbacks(fieldName) {
|
|
|
1205
958
|
var fieldCallbacks = useTestCallbacks()[0].fieldCallbacks;
|
|
1206
959
|
if (fieldName &&
|
|
1207
960
|
!hasRemainingTests(fieldName) &&
|
|
1208
|
-
isArray(fieldCallbacks[fieldName])) {
|
|
1209
|
-
callEach(fieldCallbacks[fieldName]);
|
|
961
|
+
vestUtils.isArray(fieldCallbacks[fieldName])) {
|
|
962
|
+
vestUtils.callEach(fieldCallbacks[fieldName]);
|
|
1210
963
|
}
|
|
1211
964
|
}
|
|
1212
965
|
/**
|
|
@@ -1214,15 +967,15 @@ function runFieldCallbacks(fieldName) {
|
|
|
1214
967
|
*/
|
|
1215
968
|
function runDoneCallbacks() {
|
|
1216
969
|
var doneCallbacks = useTestCallbacks()[0].doneCallbacks;
|
|
1217
|
-
callEach(doneCallbacks);
|
|
970
|
+
vestUtils.callEach(doneCallbacks);
|
|
1218
971
|
}
|
|
1219
972
|
|
|
1220
973
|
// eslint-disable-next-line max-lines-per-function
|
|
1221
974
|
function initBus() {
|
|
1222
|
-
var
|
|
975
|
+
var vestBus = vestUtils.bus.createBus();
|
|
1223
976
|
// Report a the completion of a test. There may be other tests with the same
|
|
1224
977
|
// name that are still running, or not yet started.
|
|
1225
|
-
|
|
978
|
+
vestBus.on(Events.TEST_COMPLETED, function (testObject) {
|
|
1226
979
|
if (testObject.isCanceled()) {
|
|
1227
980
|
return;
|
|
1228
981
|
}
|
|
@@ -1230,21 +983,21 @@ function initBus() {
|
|
|
1230
983
|
runFieldCallbacks(testObject.fieldName);
|
|
1231
984
|
if (!hasRemainingTests()) {
|
|
1232
985
|
// When no more tests are running, emit the done event
|
|
1233
|
-
|
|
986
|
+
vestBus.emit(Events.ALL_RUNNING_TESTS_FINISHED);
|
|
1234
987
|
}
|
|
1235
988
|
});
|
|
1236
989
|
// Report that the suite completed its synchronous test run.
|
|
1237
990
|
// Async operations may still be running.
|
|
1238
|
-
|
|
991
|
+
vestBus.on(Events.SUITE_CALLBACK_DONE_RUNNING, function () {
|
|
1239
992
|
// Remove tests that are optional and need to be omitted
|
|
1240
993
|
omitOptionalFields();
|
|
1241
994
|
});
|
|
1242
995
|
// Called when all the tests, including async, are done running
|
|
1243
|
-
|
|
996
|
+
vestBus.on(Events.ALL_RUNNING_TESTS_FINISHED, function () {
|
|
1244
997
|
runDoneCallbacks();
|
|
1245
998
|
});
|
|
1246
999
|
// Removes a certain field from the state.
|
|
1247
|
-
|
|
1000
|
+
vestBus.on(Events.REMOVE_FIELD, function (fieldName) {
|
|
1248
1001
|
useEachTestObject(function (testObject) {
|
|
1249
1002
|
if (matchingFieldName(testObject, fieldName)) {
|
|
1250
1003
|
testObject.cancel();
|
|
@@ -1253,18 +1006,18 @@ function initBus() {
|
|
|
1253
1006
|
});
|
|
1254
1007
|
});
|
|
1255
1008
|
// Resets a certain field in the state.
|
|
1256
|
-
|
|
1009
|
+
vestBus.on(Events.RESET_FIELD, function (fieldName) {
|
|
1257
1010
|
useEachTestObject(function (testObject) {
|
|
1258
1011
|
if (matchingFieldName(testObject, fieldName)) {
|
|
1259
1012
|
testObject.reset();
|
|
1260
1013
|
}
|
|
1261
1014
|
});
|
|
1262
1015
|
});
|
|
1263
|
-
return
|
|
1016
|
+
return vestBus;
|
|
1264
1017
|
}
|
|
1265
1018
|
function useBus() {
|
|
1266
1019
|
var context$1 = context.useX();
|
|
1267
|
-
invariant(context$1.bus);
|
|
1020
|
+
vestUtils.invariant(context$1.bus);
|
|
1268
1021
|
return context$1.bus;
|
|
1269
1022
|
}
|
|
1270
1023
|
var Events;
|
|
@@ -1283,16 +1036,16 @@ function create() {
|
|
|
1283
1036
|
args[_i] = arguments[_i];
|
|
1284
1037
|
}
|
|
1285
1038
|
var _a = args.reverse(), suiteCallback = _a[0], suiteName = _a[1];
|
|
1286
|
-
invariant(isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
|
|
1039
|
+
vestUtils.invariant(vestUtils.isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
|
|
1287
1040
|
// Event bus initialization
|
|
1288
1041
|
var bus = initBus();
|
|
1289
1042
|
// State initialization
|
|
1290
1043
|
var state = createState();
|
|
1291
1044
|
// State reference - this holds the actual state values
|
|
1292
|
-
var stateRef = createStateRef(state, { suiteId: genId(), suiteName: suiteName });
|
|
1045
|
+
var stateRef = createStateRef(state, { suiteId: vestUtils.genId(), suiteName: suiteName });
|
|
1293
1046
|
// Create base context reference. All hooks will derive their data from this
|
|
1294
1047
|
var ctxRef = { stateRef: stateRef, bus: bus };
|
|
1295
|
-
var suite = assign(
|
|
1048
|
+
var suite = vestUtils.assign(
|
|
1296
1049
|
// Bind the suite body to the context
|
|
1297
1050
|
context.bind(ctxRef, function () {
|
|
1298
1051
|
var args = [];
|
|
@@ -1338,7 +1091,7 @@ function create() {
|
|
|
1338
1091
|
* })
|
|
1339
1092
|
*/
|
|
1340
1093
|
function each(list, callback) {
|
|
1341
|
-
invariant(isFunction(callback), 'each callback must be a function');
|
|
1094
|
+
vestUtils.invariant(vestUtils.isFunction(callback), 'each callback must be a function');
|
|
1342
1095
|
isolate({ type: IsolateTypes.EACH }, function () {
|
|
1343
1096
|
list.forEach(function (arg, index) {
|
|
1344
1097
|
callback(arg, index);
|
|
@@ -1368,7 +1121,7 @@ function skipWhen(conditional, callback) {
|
|
|
1368
1121
|
// we should skip the test if the parent conditional is true.
|
|
1369
1122
|
isExcludedIndividually() ||
|
|
1370
1123
|
// Otherwise, we should skip the test if the conditional is true.
|
|
1371
|
-
optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
|
|
1124
|
+
vestUtils.optionalFunctionValue(conditional, vestUtils.optionalFunctionValue(produceSuiteResult))
|
|
1372
1125
|
}, function () { return callback(); });
|
|
1373
1126
|
});
|
|
1374
1127
|
}
|
|
@@ -1384,10 +1137,10 @@ function isExcludedIndividually() {
|
|
|
1384
1137
|
* only('username');
|
|
1385
1138
|
*/
|
|
1386
1139
|
function only(item) {
|
|
1387
|
-
return addTo(0 /* ONLY */, 'tests', item);
|
|
1140
|
+
return addTo(0 /* ExclusionGroup.ONLY */, 'tests', item);
|
|
1388
1141
|
}
|
|
1389
1142
|
only.group = function (item) {
|
|
1390
|
-
return addTo(0 /* ONLY */, 'groups', item);
|
|
1143
|
+
return addTo(0 /* ExclusionGroup.ONLY */, 'groups', item);
|
|
1391
1144
|
};
|
|
1392
1145
|
/**
|
|
1393
1146
|
* Adds a field or a list of fields into the exclusion list
|
|
@@ -1397,10 +1150,10 @@ only.group = function (item) {
|
|
|
1397
1150
|
* skip('username');
|
|
1398
1151
|
*/
|
|
1399
1152
|
function skip(item) {
|
|
1400
|
-
return addTo(1 /* SKIP */, 'tests', item);
|
|
1153
|
+
return addTo(1 /* ExclusionGroup.SKIP */, 'tests', item);
|
|
1401
1154
|
}
|
|
1402
1155
|
skip.group = function (item) {
|
|
1403
|
-
return addTo(1 /* SKIP */, 'groups', item);
|
|
1156
|
+
return addTo(1 /* ExclusionGroup.SKIP */, 'groups', item);
|
|
1404
1157
|
};
|
|
1405
1158
|
//Checks whether a certain test profile excluded by any of the exclusion groups.
|
|
1406
1159
|
// eslint-disable-next-line complexity, max-statements, max-lines-per-function
|
|
@@ -1444,7 +1197,7 @@ function isExcluded(testObject) {
|
|
|
1444
1197
|
// Check if inclusion rules for this field (`include` hook)
|
|
1445
1198
|
// TODO: Check if this may need to be moved outside of the condition.
|
|
1446
1199
|
// What if there are no included tests? This shouldn't run then?
|
|
1447
|
-
return !optionalFunctionValue(inclusion[fieldName]);
|
|
1200
|
+
return !vestUtils.optionalFunctionValue(inclusion[fieldName]);
|
|
1448
1201
|
}
|
|
1449
1202
|
// We're done here. This field is not excluded
|
|
1450
1203
|
return false;
|
|
@@ -1456,7 +1209,7 @@ function isGroupExcluded(groupName) {
|
|
|
1456
1209
|
var context$1 = context.useX();
|
|
1457
1210
|
var exclusion = context$1.exclusion;
|
|
1458
1211
|
var keyGroups = exclusion.groups;
|
|
1459
|
-
var groupPresent = hasOwnProperty(keyGroups, groupName);
|
|
1212
|
+
var groupPresent = vestUtils.hasOwnProperty(keyGroups, groupName);
|
|
1460
1213
|
// When group is either only'ed or skipped
|
|
1461
1214
|
if (groupPresent) {
|
|
1462
1215
|
// Return true if group is skipped and false if only'ed
|
|
@@ -1474,12 +1227,12 @@ function addTo(exclusionGroup, itemType, item) {
|
|
|
1474
1227
|
if (!item) {
|
|
1475
1228
|
return;
|
|
1476
1229
|
}
|
|
1477
|
-
asArray(item).forEach(function (itemName) {
|
|
1478
|
-
if (!isStringValue(itemName)) {
|
|
1230
|
+
vestUtils.asArray(item).forEach(function (itemName) {
|
|
1231
|
+
if (!vestUtils.isStringValue(itemName)) {
|
|
1479
1232
|
return;
|
|
1480
1233
|
}
|
|
1481
1234
|
context$1.exclusion[itemType][itemName] =
|
|
1482
|
-
exclusionGroup === 0 /* ONLY */;
|
|
1235
|
+
exclusionGroup === 0 /* ExclusionGroup.ONLY */;
|
|
1483
1236
|
});
|
|
1484
1237
|
}
|
|
1485
1238
|
/**
|
|
@@ -1522,8 +1275,8 @@ function hasIncludedGroups() {
|
|
|
1522
1275
|
* });
|
|
1523
1276
|
*/
|
|
1524
1277
|
function group(groupName, tests) {
|
|
1525
|
-
invariant(isStringValue(groupName), groupErrorMsg('name must be a string'));
|
|
1526
|
-
invariant(isFunction(tests), groupErrorMsg('callback must be a function'));
|
|
1278
|
+
vestUtils.invariant(vestUtils.isStringValue(groupName), groupErrorMsg('name must be a string'));
|
|
1279
|
+
vestUtils.invariant(vestUtils.isFunction(tests), groupErrorMsg('callback must be a function'));
|
|
1527
1280
|
// Running with the context applied
|
|
1528
1281
|
isolate({ type: IsolateTypes.GROUP }, function () {
|
|
1529
1282
|
context.run({ groupName: groupName }, tests);
|
|
@@ -1536,24 +1289,24 @@ function groupErrorMsg(error) {
|
|
|
1536
1289
|
function include(fieldName) {
|
|
1537
1290
|
var context$1 = context.useX();
|
|
1538
1291
|
var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
|
|
1539
|
-
invariant(isStringValue(fieldName));
|
|
1540
|
-
inclusion[fieldName] = defaultTo(exclusion.tests[fieldName], true);
|
|
1292
|
+
vestUtils.invariant(vestUtils.isStringValue(fieldName));
|
|
1293
|
+
inclusion[fieldName] = vestUtils.defaultTo(exclusion.tests[fieldName], true);
|
|
1541
1294
|
return { when: when };
|
|
1542
1295
|
function when(condition) {
|
|
1543
1296
|
var context$1 = context.useX();
|
|
1544
1297
|
var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
|
|
1545
1298
|
// This callback will run as part of the "isExcluded" series of checks
|
|
1546
1299
|
inclusion[fieldName] = function () {
|
|
1547
|
-
if (hasOwnProperty(exclusion.tests, fieldName)) {
|
|
1300
|
+
if (vestUtils.hasOwnProperty(exclusion.tests, fieldName)) {
|
|
1548
1301
|
// I suspect this code is technically unreachable because
|
|
1549
1302
|
// if there are any skip/only rules applied to the current
|
|
1550
1303
|
// field, the "isExcluded" function will have already bailed
|
|
1551
|
-
return defaultTo(exclusion.tests[fieldName], true);
|
|
1304
|
+
return vestUtils.defaultTo(exclusion.tests[fieldName], true);
|
|
1552
1305
|
}
|
|
1553
|
-
if (isStringValue(condition)) {
|
|
1306
|
+
if (vestUtils.isStringValue(condition)) {
|
|
1554
1307
|
return Boolean(exclusion.tests[condition]);
|
|
1555
1308
|
}
|
|
1556
|
-
return optionalFunctionValue(condition, optionalFunctionValue(produceSuiteResult));
|
|
1309
|
+
return vestUtils.optionalFunctionValue(condition, vestUtils.optionalFunctionValue(produceSuiteResult));
|
|
1557
1310
|
};
|
|
1558
1311
|
}
|
|
1559
1312
|
}
|
|
@@ -1608,7 +1361,7 @@ function omitWhen(conditional, callback) {
|
|
|
1608
1361
|
isolate({ type: IsolateTypes.OMIT_WHEN }, function () {
|
|
1609
1362
|
context.run({
|
|
1610
1363
|
omitted: isOmitted() ||
|
|
1611
|
-
optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
|
|
1364
|
+
vestUtils.optionalFunctionValue(conditional, vestUtils.optionalFunctionValue(produceSuiteResult))
|
|
1612
1365
|
}, function () { return callback(); });
|
|
1613
1366
|
});
|
|
1614
1367
|
}
|
|
@@ -1630,8 +1383,8 @@ function isOmitted() {
|
|
|
1630
1383
|
function optional(optionals) {
|
|
1631
1384
|
// When the optional is given as a string or a list of strings
|
|
1632
1385
|
// we just add them to the list of optional fields.
|
|
1633
|
-
if (isArray(optionals) || isStringValue(optionals)) {
|
|
1634
|
-
asArray(optionals).forEach(function (optionalField) {
|
|
1386
|
+
if (vestUtils.isArray(optionals) || vestUtils.isStringValue(optionals)) {
|
|
1387
|
+
vestUtils.asArray(optionals).forEach(function (optionalField) {
|
|
1635
1388
|
useSetOptionalField(optionalField, [true, false]);
|
|
1636
1389
|
});
|
|
1637
1390
|
}
|
|
@@ -1670,9 +1423,7 @@ function __spreadArray(to, from, pack) {
|
|
|
1670
1423
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
1671
1424
|
}
|
|
1672
1425
|
|
|
1673
|
-
|
|
1674
|
-
return value && isFunction(value.then);
|
|
1675
|
-
}
|
|
1426
|
+
vestUtils.bindNot(vestUtils.isStringValue);
|
|
1676
1427
|
|
|
1677
1428
|
function isSameProfileTest(testObject1, testObject2) {
|
|
1678
1429
|
return (testObject1.fieldName === testObject2.fieldName &&
|
|
@@ -1692,7 +1443,7 @@ function cancelOverriddenPendingTest(prevRunTestObject, currentRunTestObject) {
|
|
|
1692
1443
|
*/
|
|
1693
1444
|
function runAsyncTest(testObject) {
|
|
1694
1445
|
var asyncTest = testObject.asyncTest, message = testObject.message;
|
|
1695
|
-
if (!isPromise(asyncTest))
|
|
1446
|
+
if (!vestUtils.isPromise(asyncTest))
|
|
1696
1447
|
return;
|
|
1697
1448
|
var emit = useBus().emit;
|
|
1698
1449
|
var stateRef = useStateRef();
|
|
@@ -1705,7 +1456,7 @@ function runAsyncTest(testObject) {
|
|
|
1705
1456
|
if (testObject.isCanceled()) {
|
|
1706
1457
|
return;
|
|
1707
1458
|
}
|
|
1708
|
-
testObject.message = isStringValue(rejectionMessage)
|
|
1459
|
+
testObject.message = vestUtils.isStringValue(rejectionMessage)
|
|
1709
1460
|
? rejectionMessage
|
|
1710
1461
|
: message;
|
|
1711
1462
|
testObject.fail();
|
|
@@ -1740,7 +1491,7 @@ function registerTest(testObject) {
|
|
|
1740
1491
|
try {
|
|
1741
1492
|
// try catch for safe property access
|
|
1742
1493
|
// in case object is an enforce chain
|
|
1743
|
-
if (isPromise(result)) {
|
|
1494
|
+
if (vestUtils.isPromise(result)) {
|
|
1744
1495
|
testObject.asyncTest = result;
|
|
1745
1496
|
testObject.setPending();
|
|
1746
1497
|
runAsyncTest(testObject);
|
|
@@ -1767,12 +1518,12 @@ function registerTest(testObject) {
|
|
|
1767
1518
|
function useTestAtCursor(newTestObject) {
|
|
1768
1519
|
var testObjects = useTestObjects()[0];
|
|
1769
1520
|
var prevTests = testObjects.prev;
|
|
1770
|
-
if (isEmpty(prevTests)) {
|
|
1521
|
+
if (vestUtils.isEmpty(prevTests)) {
|
|
1771
1522
|
useSetTestAtCursor(newTestObject);
|
|
1772
1523
|
return newTestObject;
|
|
1773
1524
|
}
|
|
1774
1525
|
var prevTest = useGetTestAtCursor(prevTests);
|
|
1775
|
-
if (!isNullish(newTestObject.key)) {
|
|
1526
|
+
if (!vestUtils.isNullish(newTestObject.key)) {
|
|
1776
1527
|
var nextTest_1 = handleKeyTest(newTestObject.key, newTestObject);
|
|
1777
1528
|
useSetTestAtCursor(nextTest_1);
|
|
1778
1529
|
return nextTest_1;
|
|
@@ -1783,7 +1534,7 @@ function useTestAtCursor(newTestObject) {
|
|
|
1783
1534
|
// Need to see if this has any effect at all.
|
|
1784
1535
|
prevTest = null;
|
|
1785
1536
|
}
|
|
1786
|
-
var nextTest = defaultTo(prevTest, newTestObject);
|
|
1537
|
+
var nextTest = vestUtils.defaultTo(prevTest, newTestObject);
|
|
1787
1538
|
useSetTestAtCursor(nextTest);
|
|
1788
1539
|
return nextTest;
|
|
1789
1540
|
}
|
|
@@ -1800,21 +1551,21 @@ function removeAllNextTestsInIsolate() {
|
|
|
1800
1551
|
function useSetTestAtCursor(testObject) {
|
|
1801
1552
|
var cursorPath = useCurrentPath();
|
|
1802
1553
|
useSetTests(function (tests) {
|
|
1803
|
-
return setValueAtPath(tests, cursorPath, testObject);
|
|
1554
|
+
return vestUtils.nestedArray.setValueAtPath(tests, cursorPath, testObject);
|
|
1804
1555
|
});
|
|
1805
1556
|
}
|
|
1806
1557
|
function useGetTestAtCursor(tests) {
|
|
1807
1558
|
var cursorPath = useCurrentPath();
|
|
1808
|
-
return valueAtPath(tests, cursorPath);
|
|
1559
|
+
return vestUtils.nestedArray.valueAtPath(tests, cursorPath);
|
|
1809
1560
|
}
|
|
1810
1561
|
function testReorderDetected(prevTest, newTest) {
|
|
1811
|
-
return isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
|
|
1562
|
+
return vestUtils.isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
|
|
1812
1563
|
}
|
|
1813
1564
|
function throwTestOrderError(prevTest, newTestObject) {
|
|
1814
1565
|
if (shouldAllowReorder()) {
|
|
1815
1566
|
return;
|
|
1816
1567
|
}
|
|
1817
|
-
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."));
|
|
1568
|
+
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."));
|
|
1818
1569
|
}
|
|
1819
1570
|
function handleKeyTest(key, newTestObject) {
|
|
1820
1571
|
var prevTestByKey = usePrevTestByKey(key);
|
|
@@ -1860,7 +1611,7 @@ function registerTestObjectByTier(testObject) {
|
|
|
1860
1611
|
if (testObject.isUntested()) {
|
|
1861
1612
|
registerTest(testObject);
|
|
1862
1613
|
}
|
|
1863
|
-
else if (isPromise(testObject.asyncTest)) {
|
|
1614
|
+
else if (vestUtils.isPromise(testObject.asyncTest)) {
|
|
1864
1615
|
testObject.setPending();
|
|
1865
1616
|
runAsyncTest(testObject);
|
|
1866
1617
|
}
|
|
@@ -1869,7 +1620,7 @@ function registerTestObjectByTier(testObject) {
|
|
|
1869
1620
|
/* eslint-disable jest/valid-title */
|
|
1870
1621
|
// eslint-disable-next-line max-lines-per-function
|
|
1871
1622
|
function bindTestMemo(test) {
|
|
1872
|
-
var cache =
|
|
1623
|
+
var cache = vestUtils.cache(10); // arbitrary cache size
|
|
1873
1624
|
// eslint-disable-next-line max-statements
|
|
1874
1625
|
function memo(fieldName) {
|
|
1875
1626
|
var args = [];
|
|
@@ -1881,7 +1632,7 @@ function bindTestMemo(test) {
|
|
|
1881
1632
|
// Implicit dependency for more specificity
|
|
1882
1633
|
var dependencies = [useSuiteId(), fieldName, cursorAt].concat(deps);
|
|
1883
1634
|
var cached = cache.get(dependencies);
|
|
1884
|
-
if (isNull(cached)) {
|
|
1635
|
+
if (vestUtils.isNull(cached)) {
|
|
1885
1636
|
// cache miss
|
|
1886
1637
|
return cache(dependencies, function () { return test(fieldName, msg, testFn); });
|
|
1887
1638
|
}
|
|
@@ -1900,9 +1651,9 @@ function testBase(fieldName) {
|
|
|
1900
1651
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1901
1652
|
args[_i - 1] = arguments[_i];
|
|
1902
1653
|
}
|
|
1903
|
-
var _a = (isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
|
|
1904
|
-
invariant(isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
|
|
1905
|
-
invariant(isFunction(testFn), incompatibleParamsError('Test callback', 'function'));
|
|
1654
|
+
var _a = (vestUtils.isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
|
|
1655
|
+
vestUtils.invariant(vestUtils.isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
|
|
1656
|
+
vestUtils.invariant(vestUtils.isFunction(testFn), incompatibleParamsError('Test callback', 'function'));
|
|
1906
1657
|
var context$1 = context.useX();
|
|
1907
1658
|
var testObject = new VestTest(fieldName, testFn, {
|
|
1908
1659
|
message: message,
|
|
@@ -1920,7 +1671,7 @@ function testBase(fieldName) {
|
|
|
1920
1671
|
* enforce(data.username).isNotBlank();
|
|
1921
1672
|
* });
|
|
1922
1673
|
*/
|
|
1923
|
-
var test = assign(testBase, {
|
|
1674
|
+
var test = vestUtils.assign(testBase, {
|
|
1924
1675
|
memo: bindTestMemo(testBase)
|
|
1925
1676
|
});
|
|
1926
1677
|
function incompatibleParamsError(name, expected) {
|
|
@@ -1934,11 +1685,11 @@ var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won
|
|
|
1934
1685
|
*/
|
|
1935
1686
|
function warn() {
|
|
1936
1687
|
var ctx = context.useX('warn ' + ERROR_HOOK_CALLED_OUTSIDE);
|
|
1937
|
-
invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
|
|
1688
|
+
vestUtils.invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
|
|
1938
1689
|
ctx.currentTest.warn();
|
|
1939
1690
|
}
|
|
1940
1691
|
|
|
1941
|
-
var VERSION = "4.4.
|
|
1692
|
+
var VERSION = "4.4.3-dev-c786f7";
|
|
1942
1693
|
|
|
1943
1694
|
Object.defineProperty(exports, 'enforce', {
|
|
1944
1695
|
enumerable: true,
|