vest 4.4.2 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/classnames.development.js +16 -90
- 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 +15 -89
- 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 +197 -452
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +14 -88
- 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 +14 -88
- 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 +131 -387
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +27 -56
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +111 -94
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +185 -168
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +134 -117
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/parser.development.js +27 -56
- package/dist/umd/parser.production.js +1 -1
- package/dist/umd/vest.development.js +398 -386
- 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 +17 -32
- package/types/enforce/compounds.d.ts +17 -32
- package/types/enforce/schema.d.ts +17 -32
- package/types/parser.d.ts +8 -7
- package/types/promisify.d.ts +20 -35
- package/types/vest.d.ts +45 -60
|
@@ -1,181 +1,12 @@
|
|
|
1
1
|
export { enforce } from 'n4s';
|
|
2
|
+
import { isUndefined, isStringValue, assign, cache as cache$2, optionalFunctionValue, nestedArray, asArray, seq, isFunction, isNullish, deferThrow, invariant, bindNot, either, isEmpty, isNotEmpty, isPositive, numberEquals, hasOwnProperty, isArray, callEach, bus, defaultTo, isPromise, isNull } from 'vest-utils';
|
|
2
3
|
import { createContext } from 'context';
|
|
3
4
|
|
|
4
|
-
/**
|
|
5
|
-
* @returns a unique numeric id.
|
|
6
|
-
*/
|
|
7
|
-
var genId = (function (n) { return function () {
|
|
8
|
-
return "".concat(n++);
|
|
9
|
-
}; })(0);
|
|
10
|
-
|
|
11
|
-
function isStringValue(v) {
|
|
12
|
-
return String(v) === v;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function bindNot(fn) {
|
|
16
|
-
return function () {
|
|
17
|
-
var args = [];
|
|
18
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
19
|
-
args[_i] = arguments[_i];
|
|
20
|
-
}
|
|
21
|
-
return !fn.apply(void 0, args);
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function isUndefined(value) {
|
|
26
|
-
return value === undefined;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
5
|
function shouldUseErrorAsMessage(message, error) {
|
|
30
6
|
// kind of cheating with this safe guard, but it does the job
|
|
31
7
|
return isUndefined(message) && isStringValue(error);
|
|
32
8
|
}
|
|
33
9
|
|
|
34
|
-
function asArray(possibleArg) {
|
|
35
|
-
return [].concat(possibleArg);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var assign = Object.assign;
|
|
39
|
-
|
|
40
|
-
function isNumeric(value) {
|
|
41
|
-
var str = String(value);
|
|
42
|
-
var num = Number(value);
|
|
43
|
-
var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
|
|
44
|
-
return Boolean(result);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function numberEquals(value, eq) {
|
|
48
|
-
return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function lengthEquals(value, arg1) {
|
|
52
|
-
return numberEquals(value.length, arg1);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function greaterThan(value, gt) {
|
|
56
|
-
return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function longerThan(value, arg1) {
|
|
60
|
-
return greaterThan(value.length, arg1);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Creates a cache function
|
|
65
|
-
*/
|
|
66
|
-
function createCache(maxSize) {
|
|
67
|
-
if (maxSize === void 0) { maxSize = 1; }
|
|
68
|
-
var cacheStorage = [];
|
|
69
|
-
var cache = function (deps, cacheAction) {
|
|
70
|
-
var cacheHit = cache.get(deps);
|
|
71
|
-
// cache hit is not null
|
|
72
|
-
if (cacheHit)
|
|
73
|
-
return cacheHit[1];
|
|
74
|
-
var result = cacheAction();
|
|
75
|
-
cacheStorage.unshift([deps.concat(), result]);
|
|
76
|
-
if (longerThan(cacheStorage, maxSize))
|
|
77
|
-
cacheStorage.length = maxSize;
|
|
78
|
-
return result;
|
|
79
|
-
};
|
|
80
|
-
// invalidate an item in the cache by its dependencies
|
|
81
|
-
cache.invalidate = function (deps) {
|
|
82
|
-
var index = findIndex(deps);
|
|
83
|
-
if (index > -1)
|
|
84
|
-
cacheStorage.splice(index, 1);
|
|
85
|
-
};
|
|
86
|
-
// Retrieves an item from the cache.
|
|
87
|
-
cache.get = function (deps) {
|
|
88
|
-
return cacheStorage[findIndex(deps)] || null;
|
|
89
|
-
};
|
|
90
|
-
return cache;
|
|
91
|
-
function findIndex(deps) {
|
|
92
|
-
return cacheStorage.findIndex(function (_a) {
|
|
93
|
-
var cachedDeps = _a[0];
|
|
94
|
-
return lengthEquals(deps, cachedDeps.length) &&
|
|
95
|
-
deps.every(function (dep, i) { return dep === cachedDeps[i]; });
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// The module is named "isArrayValue" since it
|
|
101
|
-
// is conflicting with a nested npm dependency.
|
|
102
|
-
// We may need to revisit this in the future.
|
|
103
|
-
function isArray(value) {
|
|
104
|
-
return Boolean(Array.isArray(value));
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function isNull(value) {
|
|
108
|
-
return value === null;
|
|
109
|
-
}
|
|
110
|
-
var isNotNull = bindNot(isNull);
|
|
111
|
-
|
|
112
|
-
function isFunction(value) {
|
|
113
|
-
return typeof value === 'function';
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function optionalFunctionValue(value) {
|
|
117
|
-
var args = [];
|
|
118
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
119
|
-
args[_i - 1] = arguments[_i];
|
|
120
|
-
}
|
|
121
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function defaultTo(value, defaultValue) {
|
|
125
|
-
var _a;
|
|
126
|
-
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function last(values) {
|
|
130
|
-
var valuesArray = asArray(values);
|
|
131
|
-
return valuesArray[valuesArray.length - 1];
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// This is kind of a map/filter in one function.
|
|
135
|
-
// Normally, behaves like a nested-array map,
|
|
136
|
-
// but returning `null` will drop the element from the array
|
|
137
|
-
function transform(array, cb) {
|
|
138
|
-
var res = [];
|
|
139
|
-
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
|
|
140
|
-
var v = array_1[_i];
|
|
141
|
-
if (isArray(v)) {
|
|
142
|
-
res.push(transform(v, cb));
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
var output = cb(v);
|
|
146
|
-
if (isNotNull(output)) {
|
|
147
|
-
res.push(output);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return res;
|
|
152
|
-
}
|
|
153
|
-
function valueAtPath(array, path) {
|
|
154
|
-
return getCurrent(array, path)[last(path)];
|
|
155
|
-
}
|
|
156
|
-
function setValueAtPath(array, path, value) {
|
|
157
|
-
var current = getCurrent(array, path);
|
|
158
|
-
current[last(path)] = value;
|
|
159
|
-
return array;
|
|
160
|
-
}
|
|
161
|
-
function flatten(values) {
|
|
162
|
-
return asArray(values).reduce(function (acc, value) {
|
|
163
|
-
if (isArray(value)) {
|
|
164
|
-
return acc.concat(flatten(value));
|
|
165
|
-
}
|
|
166
|
-
return asArray(acc).concat(value);
|
|
167
|
-
}, []);
|
|
168
|
-
}
|
|
169
|
-
function getCurrent(array, path) {
|
|
170
|
-
var current = array;
|
|
171
|
-
for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) {
|
|
172
|
-
var p = _a[_i];
|
|
173
|
-
current[p] = defaultTo(current[p], []);
|
|
174
|
-
current = current[p];
|
|
175
|
-
}
|
|
176
|
-
return current;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
10
|
var IsolateTypes;
|
|
180
11
|
(function (IsolateTypes) {
|
|
181
12
|
IsolateTypes[IsolateTypes["DEFAULT"] = 0] = "DEFAULT";
|
|
@@ -230,7 +61,7 @@ function generateIsolate(type, path) {
|
|
|
230
61
|
var context = createContext(function (ctxRef, parentContext) {
|
|
231
62
|
return parentContext
|
|
232
63
|
? null
|
|
233
|
-
: assign({
|
|
64
|
+
: assign({
|
|
234
65
|
exclusion: {
|
|
235
66
|
tests: {},
|
|
236
67
|
groups: {}
|
|
@@ -302,10 +133,10 @@ function useSetTests(handler) {
|
|
|
302
133
|
function useAllIncomplete() {
|
|
303
134
|
return useTestsFlat().filter(function (test) { return test.isPending(); });
|
|
304
135
|
}
|
|
305
|
-
var flatCache =
|
|
136
|
+
var flatCache = cache$2();
|
|
306
137
|
function useTestsFlat() {
|
|
307
138
|
var current = useTestObjects()[0].current;
|
|
308
|
-
return flatCache([current], function () { return flatten(current); });
|
|
139
|
+
return flatCache([current], function () { return nestedArray.flatten(current); });
|
|
309
140
|
}
|
|
310
141
|
function useEachTestObject(handler) {
|
|
311
142
|
var testObjects = useTestsFlat();
|
|
@@ -321,7 +152,7 @@ var VestTest = /** @class */ (function () {
|
|
|
321
152
|
function VestTest(fieldName, testFn, _a) {
|
|
322
153
|
var _b = _a === void 0 ? {} : _a, message = _b.message, groupName = _b.groupName, key = _b.key;
|
|
323
154
|
this.key = null;
|
|
324
|
-
this.id =
|
|
155
|
+
this.id = seq();
|
|
325
156
|
this.severity = TestSeverity.Error;
|
|
326
157
|
this.status = STATUS_UNTESTED;
|
|
327
158
|
this.fieldName = fieldName;
|
|
@@ -456,20 +287,6 @@ var STATUS_PENDING = 'PENDING';
|
|
|
456
287
|
var STATUS_CANCELED = 'CANCELED';
|
|
457
288
|
var STATUS_OMITTED = 'OMITTED';
|
|
458
289
|
|
|
459
|
-
function invariant(condition,
|
|
460
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
461
|
-
message) {
|
|
462
|
-
if (condition) {
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
// If message is a string object (rather than string literal)
|
|
466
|
-
// Throw the value directly as a string
|
|
467
|
-
// Alternatively, throw an error with the message
|
|
468
|
-
throw message instanceof String
|
|
469
|
-
? message.valueOf()
|
|
470
|
-
: new Error(message ? optionalFunctionValue(message) : message);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
290
|
// eslint-disable-next-line max-lines-per-function
|
|
474
291
|
function createState(onStateChange) {
|
|
475
292
|
var state = {
|
|
@@ -553,19 +370,29 @@ function createStateRef(state, _a) {
|
|
|
553
370
|
};
|
|
554
371
|
}
|
|
555
372
|
|
|
556
|
-
|
|
557
|
-
|
|
373
|
+
/**
|
|
374
|
+
* @returns {Isolate} The current isolate layer
|
|
375
|
+
*/
|
|
376
|
+
function useIsolate() {
|
|
377
|
+
return context.useX().isolate;
|
|
558
378
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
379
|
+
/**
|
|
380
|
+
* @returns {number[]} The current cursor path of the isolate tree
|
|
381
|
+
*/
|
|
382
|
+
function useCurrentPath() {
|
|
383
|
+
var isolate = useIsolate();
|
|
384
|
+
return isolate.path.concat(isolate.cursor.current());
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* @returns {IsolateCursor} The cursor object for the current isolate
|
|
388
|
+
*/
|
|
389
|
+
function useCursor() {
|
|
390
|
+
return useIsolate().cursor;
|
|
564
391
|
}
|
|
565
392
|
|
|
566
393
|
function usePrevKeys() {
|
|
567
394
|
var prev = useTestObjects()[0].prev;
|
|
568
|
-
return asArray(getCurrent(prev, useCurrentPath())).reduce(function (prevKeys, testObject) {
|
|
395
|
+
return asArray(nestedArray.getCurrent(prev, useCurrentPath())).reduce(function (prevKeys, testObject) {
|
|
569
396
|
if (!(testObject instanceof VestTest)) {
|
|
570
397
|
return prevKeys;
|
|
571
398
|
}
|
|
@@ -597,7 +424,7 @@ function isolate(_a, callback) {
|
|
|
597
424
|
var isolate = generateIsolate(type, useCurrentPath());
|
|
598
425
|
var output = context.run({ isolate: isolate }, function () {
|
|
599
426
|
isolate.keys.prev = usePrevKeys();
|
|
600
|
-
useSetTests(function (tests) { return setValueAtPath(tests, isolate.path, []); });
|
|
427
|
+
useSetTests(function (tests) { return nestedArray.setValueAtPath(tests, isolate.path, []); });
|
|
601
428
|
var res = callback();
|
|
602
429
|
return res;
|
|
603
430
|
});
|
|
@@ -605,31 +432,12 @@ function isolate(_a, callback) {
|
|
|
605
432
|
useCursor().next();
|
|
606
433
|
return output;
|
|
607
434
|
}
|
|
608
|
-
/**
|
|
609
|
-
* @returns {Isolate} The current isolate layer
|
|
610
|
-
*/
|
|
611
|
-
function useIsolate() {
|
|
612
|
-
return context.useX().isolate;
|
|
613
|
-
}
|
|
614
435
|
/**
|
|
615
436
|
* @returns {boolean} Whether or not the current isolate allows tests to be reordered
|
|
616
437
|
*/
|
|
617
438
|
function shouldAllowReorder() {
|
|
618
439
|
return useIsolate().type === IsolateTypes.EACH;
|
|
619
440
|
}
|
|
620
|
-
/**
|
|
621
|
-
* @returns {number[]} The current cursor path of the isolate tree
|
|
622
|
-
*/
|
|
623
|
-
function useCurrentPath() {
|
|
624
|
-
var isolate = useIsolate();
|
|
625
|
-
return isolate.path.concat(isolate.cursor.current());
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* @returns {IsolateCursor} The cursor object for the current isolate
|
|
629
|
-
*/
|
|
630
|
-
function useCursor() {
|
|
631
|
-
return useIsolate().cursor;
|
|
632
|
-
}
|
|
633
441
|
|
|
634
442
|
var Severity;
|
|
635
443
|
(function (Severity) {
|
|
@@ -647,27 +455,6 @@ function countKeyBySeverity(severity) {
|
|
|
647
455
|
: SeverityCount.WARN_COUNT;
|
|
648
456
|
}
|
|
649
457
|
|
|
650
|
-
/**
|
|
651
|
-
* A safe hasOwnProperty access
|
|
652
|
-
*/
|
|
653
|
-
function hasOwnProperty(obj, key) {
|
|
654
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
function isEmpty(value) {
|
|
658
|
-
if (!value) {
|
|
659
|
-
return true;
|
|
660
|
-
}
|
|
661
|
-
else if (hasOwnProperty(value, 'length')) {
|
|
662
|
-
return lengthEquals(value, 0);
|
|
663
|
-
}
|
|
664
|
-
else if (typeof value === 'object') {
|
|
665
|
-
return lengthEquals(Object.keys(value), 0);
|
|
666
|
-
}
|
|
667
|
-
return false;
|
|
668
|
-
}
|
|
669
|
-
var isNotEmpty = bindNot(isEmpty);
|
|
670
|
-
|
|
671
458
|
function nonMatchingFieldName(testObject, fieldName) {
|
|
672
459
|
return !!fieldName && !matchingFieldName(testObject, fieldName);
|
|
673
460
|
}
|
|
@@ -680,10 +467,6 @@ function matchingGroupName(testObject, groupName) {
|
|
|
680
467
|
return testObject.groupName === groupName;
|
|
681
468
|
}
|
|
682
469
|
|
|
683
|
-
function either(a, b) {
|
|
684
|
-
return !!a !== !!b;
|
|
685
|
-
}
|
|
686
|
-
|
|
687
470
|
/**
|
|
688
471
|
* Checks that a given test object matches the currently specified severity level
|
|
689
472
|
*/
|
|
@@ -814,11 +597,6 @@ function missingTestsLogic(testObject, fieldName) {
|
|
|
814
597
|
testObject.isOmitted());
|
|
815
598
|
}
|
|
816
599
|
|
|
817
|
-
function useSummary() {
|
|
818
|
-
var summary = context.useX().summary;
|
|
819
|
-
invariant(summary);
|
|
820
|
-
return summary;
|
|
821
|
-
}
|
|
822
600
|
/**
|
|
823
601
|
* Reads the testObjects list and gets full validation result from it.
|
|
824
602
|
*/
|
|
@@ -907,10 +685,6 @@ function baseTestStats() {
|
|
|
907
685
|
});
|
|
908
686
|
}
|
|
909
687
|
|
|
910
|
-
function isPositive(value) {
|
|
911
|
-
return greaterThan(value, 0);
|
|
912
|
-
}
|
|
913
|
-
|
|
914
688
|
// calls collectAll or getByFieldName depending on whether fieldName is provided
|
|
915
689
|
function gatherFailures(testGroup, severityKey, fieldName) {
|
|
916
690
|
return fieldName
|
|
@@ -934,57 +708,85 @@ function collectAll(testGroup, severityKey) {
|
|
|
934
708
|
return output;
|
|
935
709
|
}
|
|
936
710
|
|
|
937
|
-
function
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
711
|
+
// eslint-disable-next-line max-lines-per-function, max-statements
|
|
712
|
+
function suiteSelectors(summary) {
|
|
713
|
+
var selectors = {
|
|
714
|
+
getErrors: getErrors,
|
|
715
|
+
getErrorsByGroup: getErrorsByGroup,
|
|
716
|
+
getWarnings: getWarnings,
|
|
717
|
+
getWarningsByGroup: getWarningsByGroup,
|
|
718
|
+
hasErrors: hasErrors,
|
|
719
|
+
hasErrorsByGroup: hasErrorsByGroup,
|
|
720
|
+
hasWarnings: hasWarnings,
|
|
721
|
+
hasWarningsByGroup: hasWarningsByGroup,
|
|
722
|
+
isValid: isValid,
|
|
723
|
+
isValidByGroup: isValidByGroup
|
|
724
|
+
};
|
|
725
|
+
return selectors;
|
|
726
|
+
// Booleans
|
|
727
|
+
function isValid(fieldName) {
|
|
728
|
+
var _a;
|
|
729
|
+
return fieldName ? Boolean((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.valid) : summary.valid;
|
|
730
|
+
}
|
|
731
|
+
function isValidByGroup(groupName, fieldName) {
|
|
732
|
+
var group = summary.groups[groupName];
|
|
733
|
+
if (!group) {
|
|
734
|
+
return false;
|
|
735
|
+
}
|
|
736
|
+
if (fieldName) {
|
|
737
|
+
return isFieldValid(group, fieldName);
|
|
738
|
+
}
|
|
739
|
+
for (var fieldName_1 in group) {
|
|
740
|
+
if (!isFieldValid(group, fieldName_1)) {
|
|
741
|
+
return false;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
return true;
|
|
745
|
+
}
|
|
746
|
+
function hasWarnings(fieldName) {
|
|
747
|
+
return hasFailures(summary, SeverityCount.WARN_COUNT, fieldName);
|
|
748
|
+
}
|
|
749
|
+
function hasErrors(fieldName) {
|
|
750
|
+
return hasFailures(summary, SeverityCount.ERROR_COUNT, fieldName);
|
|
751
|
+
}
|
|
752
|
+
function hasWarningsByGroup(groupName, fieldName) {
|
|
753
|
+
return hasFailuresByGroup(summary, SeverityCount.WARN_COUNT, groupName, fieldName);
|
|
754
|
+
}
|
|
755
|
+
function hasErrorsByGroup(groupName, fieldName) {
|
|
756
|
+
return hasFailuresByGroup(summary, SeverityCount.ERROR_COUNT, groupName, fieldName);
|
|
757
|
+
}
|
|
758
|
+
function getWarnings(fieldName) {
|
|
759
|
+
return getFailures(summary, Severity.WARNINGS, fieldName);
|
|
760
|
+
}
|
|
761
|
+
function getErrors(fieldName) {
|
|
762
|
+
return getFailures(summary, Severity.ERRORS, fieldName);
|
|
763
|
+
}
|
|
764
|
+
function getErrorsByGroup(groupName, fieldName) {
|
|
765
|
+
return getFailuresByGroup(summary, Severity.ERRORS, groupName, fieldName);
|
|
766
|
+
}
|
|
767
|
+
function getWarningsByGroup(groupName, fieldName) {
|
|
768
|
+
return getFailuresByGroup(summary, Severity.WARNINGS, groupName, fieldName);
|
|
769
|
+
}
|
|
942
770
|
}
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
function getFailures(severityKey, fieldName) {
|
|
947
|
-
var summary = useSummary();
|
|
771
|
+
// Gathers all failures of a given severity
|
|
772
|
+
// With a fieldName, it will only gather failures for that field
|
|
773
|
+
function getFailures(summary, severityKey, fieldName) {
|
|
948
774
|
return gatherFailures(summary.tests, severityKey, fieldName);
|
|
949
775
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
}
|
|
954
|
-
function getWarningsByGroup(groupName, fieldName) {
|
|
955
|
-
return getFailuresByGroup(groupName, Severity.WARNINGS, fieldName);
|
|
956
|
-
}
|
|
957
|
-
function getFailuresByGroup(groupName, severityKey, fieldName) {
|
|
958
|
-
var summary = useSummary();
|
|
776
|
+
// Gathers all failures of a given severity within a group
|
|
777
|
+
// With a fieldName, it will only gather failures for that field
|
|
778
|
+
function getFailuresByGroup(summary, severityKey, groupName, fieldName) {
|
|
959
779
|
return gatherFailures(summary.groups[groupName], severityKey, fieldName);
|
|
960
780
|
}
|
|
961
|
-
|
|
962
|
-
function
|
|
963
|
-
return hasFailures(SeverityCount.ERROR_COUNT, fieldName);
|
|
964
|
-
}
|
|
965
|
-
function hasWarnings(fieldName) {
|
|
966
|
-
return hasFailures(SeverityCount.WARN_COUNT, fieldName);
|
|
967
|
-
}
|
|
968
|
-
function hasFailures(severityCount, fieldName) {
|
|
781
|
+
// Checks if a field is valid within a container object - can be within a group or top level
|
|
782
|
+
function isFieldValid(testContainer, fieldName) {
|
|
969
783
|
var _a;
|
|
970
|
-
|
|
971
|
-
if (fieldName) {
|
|
972
|
-
return isPositive((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
973
|
-
}
|
|
974
|
-
return isPositive(summary[severityCount]);
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
function hasErrorsByGroup(groupName, fieldName) {
|
|
978
|
-
return hasFailuresByGroup(Severity.ERRORS, groupName, fieldName);
|
|
979
|
-
}
|
|
980
|
-
function hasWarningsByGroup(groupName, fieldName) {
|
|
981
|
-
return hasFailuresByGroup(Severity.WARNINGS, groupName, fieldName);
|
|
784
|
+
return !!((_a = testContainer[fieldName]) === null || _a === void 0 ? void 0 : _a.valid);
|
|
982
785
|
}
|
|
983
|
-
//
|
|
984
|
-
|
|
786
|
+
// Checks if a there are any failures of a given severity within a group
|
|
787
|
+
// If a fieldName is provided, it will only check for failures within that field
|
|
788
|
+
function hasFailuresByGroup(summary, severityCount, groupName, fieldName) {
|
|
985
789
|
var _a, _b;
|
|
986
|
-
var summary = useSummary();
|
|
987
|
-
var severityCount = countKeyBySeverity(severityKey);
|
|
988
790
|
var group = summary.groups[groupName];
|
|
989
791
|
if (!group) {
|
|
990
792
|
return false;
|
|
@@ -999,53 +801,24 @@ function hasFailuresByGroup(severityKey, groupName, fieldName) {
|
|
|
999
801
|
}
|
|
1000
802
|
return false;
|
|
1001
803
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
return fieldName
|
|
1006
|
-
? Boolean(isFieldValid(summary.tests, fieldName))
|
|
1007
|
-
: summary.valid;
|
|
1008
|
-
}
|
|
1009
|
-
function isValidByGroup(groupName, fieldName) {
|
|
1010
|
-
var summary = useSummary();
|
|
1011
|
-
var group = summary.groups[groupName];
|
|
1012
|
-
if (!group) {
|
|
1013
|
-
return false;
|
|
1014
|
-
}
|
|
1015
|
-
if (fieldName) {
|
|
1016
|
-
return isFieldValid(group, fieldName);
|
|
1017
|
-
}
|
|
1018
|
-
for (var fieldName_1 in group) {
|
|
1019
|
-
if (!isFieldValid(group, fieldName_1)) {
|
|
1020
|
-
return false;
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
return true;
|
|
1024
|
-
}
|
|
1025
|
-
function isFieldValid(testContainer, fieldName) {
|
|
804
|
+
// Checks if there are any failures of a given severity
|
|
805
|
+
// If a fieldName is provided, it will only check for failures within that field
|
|
806
|
+
function hasFailures(summary, countKey, fieldName) {
|
|
1026
807
|
var _a;
|
|
1027
|
-
|
|
808
|
+
var failureCount = fieldName
|
|
809
|
+
? (_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[countKey]
|
|
810
|
+
: summary[countKey] || 0;
|
|
811
|
+
return isPositive(failureCount);
|
|
1028
812
|
}
|
|
1029
813
|
|
|
1030
|
-
var cache$1 =
|
|
814
|
+
var cache$1 = cache$2(1);
|
|
1031
815
|
function produceSuiteResult() {
|
|
1032
816
|
var testObjects = useTestsFlat();
|
|
1033
817
|
var ctxRef = { stateRef: useStateRef() };
|
|
1034
818
|
return cache$1([testObjects], context.bind(ctxRef, function () {
|
|
1035
819
|
var summary = genTestsSummary();
|
|
1036
820
|
var suiteName = useSuiteName();
|
|
1037
|
-
|
|
1038
|
-
return assign(summary, {
|
|
1039
|
-
getErrors: context.bind(ref, getErrors),
|
|
1040
|
-
getErrorsByGroup: context.bind(ref, getErrorsByGroup),
|
|
1041
|
-
getWarnings: context.bind(ref, getWarnings),
|
|
1042
|
-
getWarningsByGroup: context.bind(ref, getWarningsByGroup),
|
|
1043
|
-
hasErrors: context.bind(ref, hasErrors),
|
|
1044
|
-
hasErrorsByGroup: context.bind(ref, hasErrorsByGroup),
|
|
1045
|
-
hasWarnings: context.bind(ref, hasWarnings),
|
|
1046
|
-
hasWarningsByGroup: context.bind(ref, hasWarningsByGroup),
|
|
1047
|
-
isValid: context.bind(ref, isValid),
|
|
1048
|
-
isValidByGroup: context.bind(ref, isValidByGroup),
|
|
821
|
+
return assign(summary, suiteSelectors(summary), {
|
|
1049
822
|
suiteName: suiteName
|
|
1050
823
|
});
|
|
1051
824
|
}));
|
|
@@ -1064,10 +837,10 @@ function hasRemainingTests(fieldName) {
|
|
|
1064
837
|
return matchingFieldName(testObject, fieldName);
|
|
1065
838
|
});
|
|
1066
839
|
}
|
|
1067
|
-
return
|
|
840
|
+
return true;
|
|
1068
841
|
}
|
|
1069
842
|
|
|
1070
|
-
var cache =
|
|
843
|
+
var cache = cache$2(20);
|
|
1071
844
|
function produceFullResult() {
|
|
1072
845
|
var testObjects = useTestsFlat();
|
|
1073
846
|
var ctxRef = { stateRef: useStateRef() };
|
|
@@ -1081,10 +854,10 @@ function produceFullResult() {
|
|
|
1081
854
|
* DONE is here and not in its own module to prevent circular dependency issues.
|
|
1082
855
|
*/
|
|
1083
856
|
function shouldSkipDoneRegistration(callback, fieldName, output) {
|
|
857
|
+
var _a;
|
|
1084
858
|
// If we do not have any test runs for the current field
|
|
1085
859
|
return !!(!isFunction(callback) ||
|
|
1086
|
-
(fieldName &&
|
|
1087
|
-
(!output.tests[fieldName] || isEmpty(output.tests[fieldName].testCount))));
|
|
860
|
+
(fieldName && numberEquals((_a = output.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.testCount, 0)));
|
|
1088
861
|
}
|
|
1089
862
|
function shouldRunDoneCallback(fieldName) {
|
|
1090
863
|
// is suite finished || field name exists, and test is finished;
|
|
@@ -1126,28 +899,6 @@ function deferDoneCallback(doneCallback, fieldName) {
|
|
|
1126
899
|
});
|
|
1127
900
|
}
|
|
1128
901
|
|
|
1129
|
-
function createBus() {
|
|
1130
|
-
var listeners = {};
|
|
1131
|
-
return {
|
|
1132
|
-
emit: function (event, data) {
|
|
1133
|
-
listener(event).forEach(function (handler) {
|
|
1134
|
-
handler(data);
|
|
1135
|
-
});
|
|
1136
|
-
},
|
|
1137
|
-
on: function (event, handler) {
|
|
1138
|
-
listeners[event] = listener(event).concat(handler);
|
|
1139
|
-
return {
|
|
1140
|
-
off: function () {
|
|
1141
|
-
listeners[event] = listener(event).filter(function (h) { return h !== handler; });
|
|
1142
|
-
}
|
|
1143
|
-
};
|
|
1144
|
-
}
|
|
1145
|
-
};
|
|
1146
|
-
function listener(event) {
|
|
1147
|
-
return listeners[event] || [];
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
902
|
function omitOptionalFields() {
|
|
1152
903
|
var optionalFields = useOptionalFields()[0];
|
|
1153
904
|
if (isEmpty(optionalFields)) {
|
|
@@ -1155,7 +906,7 @@ function omitOptionalFields() {
|
|
|
1155
906
|
}
|
|
1156
907
|
var shouldOmit = {};
|
|
1157
908
|
useSetTests(function (tests) {
|
|
1158
|
-
return transform(tests, function (testObject) {
|
|
909
|
+
return nestedArray.transform(tests, function (testObject) {
|
|
1159
910
|
var fieldName = testObject.fieldName;
|
|
1160
911
|
if (hasOwnProperty(shouldOmit, fieldName)) {
|
|
1161
912
|
verifyAndOmit(testObject);
|
|
@@ -1186,14 +937,10 @@ function omitOptionalFields() {
|
|
|
1186
937
|
*/
|
|
1187
938
|
function removeTestFromState (testObject) {
|
|
1188
939
|
useSetTests(function (tests) {
|
|
1189
|
-
return transform(tests, function (test) { return (testObject !== test ? test : null); });
|
|
940
|
+
return nestedArray.transform(tests, function (test) { return (testObject !== test ? test : null); });
|
|
1190
941
|
});
|
|
1191
942
|
}
|
|
1192
943
|
|
|
1193
|
-
function callEach(arr) {
|
|
1194
|
-
return arr.forEach(function (fn) { return fn(); });
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
944
|
/**
|
|
1198
945
|
* Runs done callback per field when async tests are finished running.
|
|
1199
946
|
*/
|
|
@@ -1215,10 +962,10 @@ function runDoneCallbacks() {
|
|
|
1215
962
|
|
|
1216
963
|
// eslint-disable-next-line max-lines-per-function
|
|
1217
964
|
function initBus() {
|
|
1218
|
-
var
|
|
965
|
+
var vestBus = bus.createBus();
|
|
1219
966
|
// Report a the completion of a test. There may be other tests with the same
|
|
1220
967
|
// name that are still running, or not yet started.
|
|
1221
|
-
|
|
968
|
+
vestBus.on(Events.TEST_COMPLETED, function (testObject) {
|
|
1222
969
|
if (testObject.isCanceled()) {
|
|
1223
970
|
return;
|
|
1224
971
|
}
|
|
@@ -1226,21 +973,21 @@ function initBus() {
|
|
|
1226
973
|
runFieldCallbacks(testObject.fieldName);
|
|
1227
974
|
if (!hasRemainingTests()) {
|
|
1228
975
|
// When no more tests are running, emit the done event
|
|
1229
|
-
|
|
976
|
+
vestBus.emit(Events.ALL_RUNNING_TESTS_FINISHED);
|
|
1230
977
|
}
|
|
1231
978
|
});
|
|
1232
979
|
// Report that the suite completed its synchronous test run.
|
|
1233
980
|
// Async operations may still be running.
|
|
1234
|
-
|
|
981
|
+
vestBus.on(Events.SUITE_CALLBACK_DONE_RUNNING, function () {
|
|
1235
982
|
// Remove tests that are optional and need to be omitted
|
|
1236
983
|
omitOptionalFields();
|
|
1237
984
|
});
|
|
1238
985
|
// Called when all the tests, including async, are done running
|
|
1239
|
-
|
|
986
|
+
vestBus.on(Events.ALL_RUNNING_TESTS_FINISHED, function () {
|
|
1240
987
|
runDoneCallbacks();
|
|
1241
988
|
});
|
|
1242
989
|
// Removes a certain field from the state.
|
|
1243
|
-
|
|
990
|
+
vestBus.on(Events.REMOVE_FIELD, function (fieldName) {
|
|
1244
991
|
useEachTestObject(function (testObject) {
|
|
1245
992
|
if (matchingFieldName(testObject, fieldName)) {
|
|
1246
993
|
testObject.cancel();
|
|
@@ -1249,14 +996,14 @@ function initBus() {
|
|
|
1249
996
|
});
|
|
1250
997
|
});
|
|
1251
998
|
// Resets a certain field in the state.
|
|
1252
|
-
|
|
999
|
+
vestBus.on(Events.RESET_FIELD, function (fieldName) {
|
|
1253
1000
|
useEachTestObject(function (testObject) {
|
|
1254
1001
|
if (matchingFieldName(testObject, fieldName)) {
|
|
1255
1002
|
testObject.reset();
|
|
1256
1003
|
}
|
|
1257
1004
|
});
|
|
1258
1005
|
});
|
|
1259
|
-
return
|
|
1006
|
+
return vestBus;
|
|
1260
1007
|
}
|
|
1261
1008
|
function useBus() {
|
|
1262
1009
|
var context$1 = context.useX();
|
|
@@ -1285,7 +1032,7 @@ function create() {
|
|
|
1285
1032
|
// State initialization
|
|
1286
1033
|
var state = createState();
|
|
1287
1034
|
// State reference - this holds the actual state values
|
|
1288
|
-
var stateRef = createStateRef(state, { suiteId:
|
|
1035
|
+
var stateRef = createStateRef(state, { suiteId: seq(), suiteName: suiteName });
|
|
1289
1036
|
// Create base context reference. All hooks will derive their data from this
|
|
1290
1037
|
var ctxRef = { stateRef: stateRef, bus: bus };
|
|
1291
1038
|
var suite = assign(
|
|
@@ -1380,10 +1127,10 @@ function isExcludedIndividually() {
|
|
|
1380
1127
|
* only('username');
|
|
1381
1128
|
*/
|
|
1382
1129
|
function only(item) {
|
|
1383
|
-
return addTo(0 /* ONLY */, 'tests', item);
|
|
1130
|
+
return addTo(0 /* ExclusionGroup.ONLY */, 'tests', item);
|
|
1384
1131
|
}
|
|
1385
1132
|
only.group = function (item) {
|
|
1386
|
-
return addTo(0 /* ONLY */, 'groups', item);
|
|
1133
|
+
return addTo(0 /* ExclusionGroup.ONLY */, 'groups', item);
|
|
1387
1134
|
};
|
|
1388
1135
|
/**
|
|
1389
1136
|
* Adds a field or a list of fields into the exclusion list
|
|
@@ -1393,13 +1140,13 @@ only.group = function (item) {
|
|
|
1393
1140
|
* skip('username');
|
|
1394
1141
|
*/
|
|
1395
1142
|
function skip(item) {
|
|
1396
|
-
return addTo(1 /* SKIP */, 'tests', item);
|
|
1143
|
+
return addTo(1 /* ExclusionGroup.SKIP */, 'tests', item);
|
|
1397
1144
|
}
|
|
1398
1145
|
skip.group = function (item) {
|
|
1399
|
-
return addTo(1 /* SKIP */, 'groups', item);
|
|
1146
|
+
return addTo(1 /* ExclusionGroup.SKIP */, 'groups', item);
|
|
1400
1147
|
};
|
|
1401
1148
|
//Checks whether a certain test profile excluded by any of the exclusion groups.
|
|
1402
|
-
// eslint-disable-next-line complexity, max-statements
|
|
1149
|
+
// eslint-disable-next-line complexity, max-statements
|
|
1403
1150
|
function isExcluded(testObject) {
|
|
1404
1151
|
var fieldName = testObject.fieldName, groupName = testObject.groupName;
|
|
1405
1152
|
if (isExcludedIndividually())
|
|
@@ -1475,7 +1222,7 @@ function addTo(exclusionGroup, itemType, item) {
|
|
|
1475
1222
|
return;
|
|
1476
1223
|
}
|
|
1477
1224
|
context$1.exclusion[itemType][itemName] =
|
|
1478
|
-
exclusionGroup === 0 /* ONLY */;
|
|
1225
|
+
exclusionGroup === 0 /* ExclusionGroup.ONLY */;
|
|
1479
1226
|
});
|
|
1480
1227
|
}
|
|
1481
1228
|
/**
|
|
@@ -1666,9 +1413,7 @@ function __spreadArray(to, from, pack) {
|
|
|
1666
1413
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
1667
1414
|
}
|
|
1668
1415
|
|
|
1669
|
-
|
|
1670
|
-
return value && isFunction(value.then);
|
|
1671
|
-
}
|
|
1416
|
+
bindNot(isStringValue);
|
|
1672
1417
|
|
|
1673
1418
|
function isSameProfileTest(testObject1, testObject2) {
|
|
1674
1419
|
return (testObject1.fieldName === testObject2.fieldName &&
|
|
@@ -1796,12 +1541,12 @@ function removeAllNextTestsInIsolate() {
|
|
|
1796
1541
|
function useSetTestAtCursor(testObject) {
|
|
1797
1542
|
var cursorPath = useCurrentPath();
|
|
1798
1543
|
useSetTests(function (tests) {
|
|
1799
|
-
return setValueAtPath(tests, cursorPath, testObject);
|
|
1544
|
+
return nestedArray.setValueAtPath(tests, cursorPath, testObject);
|
|
1800
1545
|
});
|
|
1801
1546
|
}
|
|
1802
1547
|
function useGetTestAtCursor(tests) {
|
|
1803
1548
|
var cursorPath = useCurrentPath();
|
|
1804
|
-
return valueAtPath(tests, cursorPath);
|
|
1549
|
+
return nestedArray.valueAtPath(tests, cursorPath);
|
|
1805
1550
|
}
|
|
1806
1551
|
function testReorderDetected(prevTest, newTest) {
|
|
1807
1552
|
return isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
|
|
@@ -1863,9 +1608,8 @@ function registerTestObjectByTier(testObject) {
|
|
|
1863
1608
|
}
|
|
1864
1609
|
|
|
1865
1610
|
/* eslint-disable jest/valid-title */
|
|
1866
|
-
// eslint-disable-next-line max-lines-per-function
|
|
1867
1611
|
function bindTestMemo(test) {
|
|
1868
|
-
var cache =
|
|
1612
|
+
var cache = cache$2(10); // arbitrary cache size
|
|
1869
1613
|
// eslint-disable-next-line max-statements
|
|
1870
1614
|
function memo(fieldName) {
|
|
1871
1615
|
var args = [];
|
|
@@ -1934,6 +1678,6 @@ function warn() {
|
|
|
1934
1678
|
ctx.currentTest.warn();
|
|
1935
1679
|
}
|
|
1936
1680
|
|
|
1937
|
-
var VERSION = "4.
|
|
1681
|
+
var VERSION = "4.5.0";
|
|
1938
1682
|
|
|
1939
|
-
export { VERSION, context, create, each, eager, group, include, omitWhen, only, optional, skip, skipWhen, test, warn };
|
|
1683
|
+
export { VERSION, context, create, each, eager, group, include, omitWhen, only, optional, skip, skipWhen, suiteSelectors, test, warn };
|