vest 4.2.3-dev-87ebfa → 4.3.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.
Files changed (33) hide show
  1. package/dist/cjs/classnames.development.js +58 -23
  2. package/dist/cjs/classnames.production.js +1 -1
  3. package/dist/cjs/parser.development.js +84 -22
  4. package/dist/cjs/parser.production.js +1 -1
  5. package/dist/cjs/vest.development.js +447 -440
  6. package/dist/cjs/vest.production.js +1 -1
  7. package/dist/es/classnames.development.js +58 -23
  8. package/dist/es/classnames.production.js +1 -1
  9. package/dist/es/parser.development.js +84 -22
  10. package/dist/es/parser.production.js +1 -1
  11. package/dist/es/vest.development.js +447 -440
  12. package/dist/es/vest.production.js +1 -1
  13. package/dist/umd/classnames.development.js +58 -23
  14. package/dist/umd/classnames.production.js +1 -1
  15. package/dist/umd/enforce/compose.development.js +16 -16
  16. package/dist/umd/enforce/compose.production.js +1 -1
  17. package/dist/umd/enforce/compounds.development.js +16 -16
  18. package/dist/umd/enforce/compounds.production.js +1 -1
  19. package/dist/umd/enforce/schema.development.js +16 -16
  20. package/dist/umd/enforce/schema.production.js +1 -1
  21. package/dist/umd/parser.development.js +84 -22
  22. package/dist/umd/parser.production.js +1 -1
  23. package/dist/umd/vest.development.js +320 -313
  24. package/dist/umd/vest.production.js +1 -1
  25. package/package.json +3 -3
  26. package/testUtils/suiteDummy.ts +5 -1
  27. package/types/classnames.d.ts +13 -55
  28. package/types/enforce/compose.d.ts +2 -1
  29. package/types/enforce/compounds.d.ts +2 -1
  30. package/types/enforce/schema.d.ts +2 -1
  31. package/types/parser.d.ts +12 -54
  32. package/types/promisify.d.ts +12 -10
  33. package/types/vest.d.ts +63 -61
@@ -5,8 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var n4s = require('n4s');
6
6
  var context$1 = require('context');
7
7
 
8
- var assign = Object.assign;
9
-
10
8
  /**
11
9
  * @returns a unique numeric id.
12
10
  */
@@ -14,203 +12,76 @@ var genId = (function (n) { return function () {
14
12
  return "".concat(n++);
15
13
  }; })(0);
16
14
 
17
- function isFunction(value) {
18
- return typeof value === 'function';
19
- }
20
-
21
- function optionalFunctionValue(value) {
22
- var args = [];
23
- for (var _i = 1; _i < arguments.length; _i++) {
24
- args[_i - 1] = arguments[_i];
25
- }
26
- return isFunction(value) ? value.apply(void 0, args) : value;
27
- }
28
-
29
- function invariant(condition,
30
- // eslint-disable-next-line @typescript-eslint/ban-types
31
- message) {
32
- if (condition) {
33
- return;
34
- }
35
- // If message is a string object (rather than string literal)
36
- // Throw the value directly as a string
37
- // Alternatively, throw an error with the message
38
- throw message instanceof String
39
- ? message.valueOf()
40
- : new Error(message ? optionalFunctionValue(message) : message);
15
+ function isStringValue(v) {
16
+ return String(v) === v;
41
17
  }
42
18
 
43
- // eslint-disable-next-line max-lines-per-function
44
- function createState(onStateChange) {
45
- var state = {
46
- references: []
47
- };
48
- var registrations = [];
49
- return {
50
- registerStateKey: registerStateKey,
51
- reset: reset
52
- };
53
- /**
54
- * Registers a new key in the state, takes the initial value (may be a function that returns the initial value), returns a function.
55
- *
56
- * @example
57
- *
58
- * const useColor = state.registerStateKey("blue");
59
- *
60
- * let [color, setColor] = useColor(); // -> ["blue", Function]
61
- *
62
- * setColor("green");
63
- *
64
- * useColor()[0]; -> "green"
65
- */
66
- function registerStateKey(initialState, onUpdate) {
67
- var key = registrations.length;
68
- registrations.push([initialState, onUpdate]);
69
- return initKey(key, initialState);
70
- }
71
- function reset() {
72
- var prev = current();
73
- state.references = [];
74
- registrations.forEach(function (_a, index) {
75
- var initialValue = _a[0];
76
- return initKey(index, initialValue, prev[index]);
77
- });
78
- }
79
- function initKey(key, initialState, prevState) {
80
- current().push();
81
- set(key, optionalFunctionValue(initialState, prevState));
82
- return function useStateKey() {
83
- return [
84
- current()[key],
85
- function (nextState) {
86
- return set(key, optionalFunctionValue(nextState, current()[key]));
87
- },
88
- ];
89
- };
90
- }
91
- function current() {
92
- return state.references;
93
- }
94
- function set(index, value) {
95
- var prevValue = state.references[index];
96
- state.references[index] = value;
97
- var _a = registrations[index], onUpdate = _a[1];
98
- if (isFunction(onUpdate)) {
99
- onUpdate(value, prevValue);
100
- }
101
- if (isFunction(onStateChange)) {
102
- onStateChange();
19
+ function bindNot(fn) {
20
+ return function () {
21
+ var args = [];
22
+ for (var _i = 0; _i < arguments.length; _i++) {
23
+ args[_i] = arguments[_i];
103
24
  }
104
- }
25
+ return !fn.apply(void 0, args);
26
+ };
105
27
  }
106
28
 
107
- var IsolateTypes;
108
- (function (IsolateTypes) {
109
- IsolateTypes[IsolateTypes["DEFAULT"] = 0] = "DEFAULT";
110
- IsolateTypes[IsolateTypes["SUITE"] = 1] = "SUITE";
111
- IsolateTypes[IsolateTypes["EACH"] = 2] = "EACH";
112
- IsolateTypes[IsolateTypes["SKIP_WHEN"] = 3] = "SKIP_WHEN";
113
- IsolateTypes[IsolateTypes["OMIT_WHEN"] = 4] = "OMIT_WHEN";
114
- IsolateTypes[IsolateTypes["GROUP"] = 5] = "GROUP";
115
- })(IsolateTypes || (IsolateTypes = {}));
29
+ function isUndefined(value) {
30
+ return value === undefined;
31
+ }
116
32
 
117
- function createStateRef(state, _a) {
118
- var suiteId = _a.suiteId, suiteName = _a.suiteName;
119
- return {
120
- optionalFields: state.registerStateKey(function () { return ({}); }),
121
- suiteId: state.registerStateKey(suiteId),
122
- suiteName: state.registerStateKey(suiteName),
123
- testCallbacks: state.registerStateKey(function () { return ({
124
- fieldCallbacks: {},
125
- doneCallbacks: []
126
- }); }),
127
- testObjects: state.registerStateKey(function (prev) {
128
- return {
129
- prev: prev ? prev.current : [],
130
- current: []
131
- };
132
- })
133
- };
33
+ function shouldUseErrorAsMessage(message, error) {
34
+ // kind of cheating with this safe guard, but it does the job
35
+ return isUndefined(message) && isStringValue(error);
134
36
  }
135
37
 
136
38
  function asArray(possibleArg) {
137
39
  return [].concat(possibleArg);
138
40
  }
139
41
 
140
- function last(values) {
141
- var valuesArray = asArray(values);
142
- return valuesArray[valuesArray.length - 1];
42
+ function lengthEquals(value, arg1) {
43
+ return value.length === Number(arg1);
143
44
  }
144
45
 
145
- function createCursor() {
146
- var storage = {
147
- cursor: []
148
- };
149
- function addLevel() {
150
- storage.cursor.push(0);
151
- }
152
- function removeLevel() {
153
- storage.cursor.pop();
154
- }
155
- function cursorAt() {
156
- return last(storage.cursor);
157
- }
158
- function getCursor() {
159
- return asArray(storage.cursor);
160
- }
161
- function next() {
162
- storage.cursor[storage.cursor.length - 1]++;
163
- return last(storage.cursor);
164
- }
165
- function reset() {
166
- storage.cursor = [0];
167
- }
168
- reset();
169
- return {
170
- addLevel: addLevel,
171
- cursorAt: cursorAt,
172
- getCursor: getCursor,
173
- next: next,
174
- removeLevel: removeLevel,
175
- reset: reset
176
- };
46
+ function longerThan(value, arg1) {
47
+ return value.length > Number(arg1);
177
48
  }
178
49
 
179
- var Modes;
180
- (function (Modes) {
181
- Modes[Modes["ALL"] = 0] = "ALL";
182
- Modes[Modes["EAGER"] = 1] = "EAGER";
183
- })(Modes || (Modes = {}));
184
-
185
- var context = context$1.createContext(function (ctxRef, parentContext) {
186
- return parentContext
187
- ? null
188
- : assign({}, {
189
- exclusion: {
190
- tests: {},
191
- groups: {}
192
- },
193
- inclusion: {},
194
- isolate: {
195
- type: IsolateTypes.DEFAULT,
196
- keys: {
197
- current: {},
198
- prev: {}
199
- }
200
- },
201
- mode: [Modes.ALL],
202
- testCursor: createCursor()
203
- }, ctxRef);
204
- });
205
-
206
- function bindNot(fn) {
207
- return function () {
208
- var args = [];
209
- for (var _i = 0; _i < arguments.length; _i++) {
210
- args[_i] = arguments[_i];
211
- }
212
- return !fn.apply(void 0, args);
50
+ /**
51
+ * Creates a cache function
52
+ */
53
+ function createCache(maxSize) {
54
+ if (maxSize === void 0) { maxSize = 1; }
55
+ var cacheStorage = [];
56
+ var cache = function (deps, cacheAction) {
57
+ var cacheHit = cache.get(deps);
58
+ // cache hit is not null
59
+ if (cacheHit)
60
+ return cacheHit[1];
61
+ var result = cacheAction();
62
+ cacheStorage.unshift([deps.concat(), result]);
63
+ if (longerThan(cacheStorage, maxSize))
64
+ cacheStorage.length = maxSize;
65
+ return result;
213
66
  };
67
+ // invalidate an item in the cache by its dependencies
68
+ cache.invalidate = function (deps) {
69
+ var index = findIndex(deps);
70
+ if (index > -1)
71
+ cacheStorage.splice(index, 1);
72
+ };
73
+ // Retrieves an item from the cache.
74
+ cache.get = function (deps) {
75
+ return cacheStorage[findIndex(deps)] || null;
76
+ };
77
+ return cache;
78
+ function findIndex(deps) {
79
+ return cacheStorage.findIndex(function (_a) {
80
+ var cachedDeps = _a[0];
81
+ return lengthEquals(deps, cachedDeps.length) &&
82
+ deps.every(function (dep, i) { return dep === cachedDeps[i]; });
83
+ });
84
+ }
214
85
  }
215
86
 
216
87
  // The module is named "isArrayValue" since it
@@ -225,11 +96,28 @@ function isNull(value) {
225
96
  }
226
97
  var isNotNull = bindNot(isNull);
227
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
+
228
111
  function defaultTo(callback, defaultValue) {
229
112
  var _a;
230
113
  return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
231
114
  }
232
115
 
116
+ function last(values) {
117
+ var valuesArray = asArray(values);
118
+ return valuesArray[valuesArray.length - 1];
119
+ }
120
+
233
121
  // This is kind of a map/filter in one function.
234
122
  // Normally, behaves like a nested-array map,
235
123
  // but returning `null` will drop the element from the array
@@ -275,73 +163,78 @@ function getCurrent(array, path) {
275
163
  return current;
276
164
  }
277
165
 
278
- function isUndefined(value) {
279
- return value === undefined;
280
- }
281
-
282
- function isNullish(value) {
283
- return isNull(value) || isUndefined(value);
284
- }
285
-
286
- function deferThrow(message) {
287
- setTimeout(function () {
288
- throw new Error(message);
289
- }, 0);
290
- }
291
-
292
- function isStringValue(v) {
293
- return String(v) === v;
294
- }
166
+ var assign = Object.assign;
295
167
 
296
- function shouldUseErrorAsMessage(message, error) {
297
- // kind of cheating with this safe guard, but it does the job
298
- return isUndefined(message) && isStringValue(error);
168
+ function createCursor() {
169
+ var storage = {
170
+ cursor: []
171
+ };
172
+ function addLevel() {
173
+ storage.cursor.push(0);
174
+ }
175
+ function removeLevel() {
176
+ storage.cursor.pop();
177
+ }
178
+ function cursorAt() {
179
+ return last(storage.cursor);
180
+ }
181
+ function getCursor() {
182
+ return asArray(storage.cursor);
183
+ }
184
+ function next() {
185
+ storage.cursor[storage.cursor.length - 1]++;
186
+ return last(storage.cursor);
187
+ }
188
+ function reset() {
189
+ storage.cursor = [0];
190
+ }
191
+ reset();
192
+ return {
193
+ addLevel: addLevel,
194
+ cursorAt: cursorAt,
195
+ getCursor: getCursor,
196
+ next: next,
197
+ removeLevel: removeLevel,
198
+ reset: reset
199
+ };
299
200
  }
300
201
 
301
- function lengthEquals(value, arg1) {
302
- return value.length === Number(arg1);
303
- }
202
+ var IsolateTypes;
203
+ (function (IsolateTypes) {
204
+ IsolateTypes[IsolateTypes["DEFAULT"] = 0] = "DEFAULT";
205
+ IsolateTypes[IsolateTypes["SUITE"] = 1] = "SUITE";
206
+ IsolateTypes[IsolateTypes["EACH"] = 2] = "EACH";
207
+ IsolateTypes[IsolateTypes["SKIP_WHEN"] = 3] = "SKIP_WHEN";
208
+ IsolateTypes[IsolateTypes["OMIT_WHEN"] = 4] = "OMIT_WHEN";
209
+ IsolateTypes[IsolateTypes["GROUP"] = 5] = "GROUP";
210
+ })(IsolateTypes || (IsolateTypes = {}));
304
211
 
305
- function longerThan(value, arg1) {
306
- return value.length > Number(arg1);
307
- }
212
+ var Modes;
213
+ (function (Modes) {
214
+ Modes[Modes["ALL"] = 0] = "ALL";
215
+ Modes[Modes["EAGER"] = 1] = "EAGER";
216
+ })(Modes || (Modes = {}));
308
217
 
309
- /**
310
- * Creates a cache function
311
- */
312
- function createCache(maxSize) {
313
- if (maxSize === void 0) { maxSize = 1; }
314
- var cacheStorage = [];
315
- var cache = function (deps, cacheAction) {
316
- var cacheHit = cache.get(deps);
317
- // cache hit is not null
318
- if (cacheHit)
319
- return cacheHit[1];
320
- var result = cacheAction();
321
- cacheStorage.unshift([deps.concat(), result]);
322
- if (longerThan(cacheStorage, maxSize))
323
- cacheStorage.length = maxSize;
324
- return result;
325
- };
326
- // invalidate an item in the cache by its dependencies
327
- cache.invalidate = function (deps) {
328
- var index = findIndex(deps);
329
- if (index > -1)
330
- cacheStorage.splice(index, 1);
331
- };
332
- // Retrieves an item from the cache.
333
- cache.get = function (deps) {
334
- return cacheStorage[findIndex(deps)] || null;
335
- };
336
- return cache;
337
- function findIndex(deps) {
338
- return cacheStorage.findIndex(function (_a) {
339
- var cachedDeps = _a[0];
340
- return lengthEquals(deps, cachedDeps.length) &&
341
- deps.every(function (dep, i) { return dep === cachedDeps[i]; });
342
- });
343
- }
344
- }
218
+ var context = context$1.createContext(function (ctxRef, parentContext) {
219
+ return parentContext
220
+ ? null
221
+ : assign({}, {
222
+ exclusion: {
223
+ tests: {},
224
+ groups: {}
225
+ },
226
+ inclusion: {},
227
+ isolate: {
228
+ type: IsolateTypes.DEFAULT,
229
+ keys: {
230
+ current: {},
231
+ prev: {}
232
+ }
233
+ },
234
+ mode: [Modes.ALL],
235
+ testCursor: createCursor()
236
+ }, ctxRef);
237
+ });
345
238
 
346
239
  // STATE REF
347
240
  function useStateRef() {
@@ -558,6 +451,113 @@ var STATUS_PENDING = 'PENDING';
558
451
  var STATUS_CANCELED = 'CANCELED';
559
452
  var STATUS_OMITTED = 'OMITTED';
560
453
 
454
+ function invariant(condition,
455
+ // eslint-disable-next-line @typescript-eslint/ban-types
456
+ message) {
457
+ if (condition) {
458
+ return;
459
+ }
460
+ // If message is a string object (rather than string literal)
461
+ // Throw the value directly as a string
462
+ // Alternatively, throw an error with the message
463
+ throw message instanceof String
464
+ ? message.valueOf()
465
+ : new Error(message ? optionalFunctionValue(message) : message);
466
+ }
467
+
468
+ // eslint-disable-next-line max-lines-per-function
469
+ function createState(onStateChange) {
470
+ var state = {
471
+ references: []
472
+ };
473
+ var registrations = [];
474
+ return {
475
+ registerStateKey: registerStateKey,
476
+ reset: reset
477
+ };
478
+ /**
479
+ * Registers a new key in the state, takes the initial value (may be a function that returns the initial value), returns a function.
480
+ *
481
+ * @example
482
+ *
483
+ * const useColor = state.registerStateKey("blue");
484
+ *
485
+ * let [color, setColor] = useColor(); // -> ["blue", Function]
486
+ *
487
+ * setColor("green");
488
+ *
489
+ * useColor()[0]; -> "green"
490
+ */
491
+ function registerStateKey(initialState, onUpdate) {
492
+ var key = registrations.length;
493
+ registrations.push([initialState, onUpdate]);
494
+ return initKey(key, initialState);
495
+ }
496
+ function reset() {
497
+ var prev = current();
498
+ state.references = [];
499
+ registrations.forEach(function (_a, index) {
500
+ var initialValue = _a[0];
501
+ return initKey(index, initialValue, prev[index]);
502
+ });
503
+ }
504
+ function initKey(key, initialState, prevState) {
505
+ current().push();
506
+ set(key, optionalFunctionValue(initialState, prevState));
507
+ return function useStateKey() {
508
+ return [
509
+ current()[key],
510
+ function (nextState) {
511
+ return set(key, optionalFunctionValue(nextState, current()[key]));
512
+ },
513
+ ];
514
+ };
515
+ }
516
+ function current() {
517
+ return state.references;
518
+ }
519
+ function set(index, value) {
520
+ var prevValue = state.references[index];
521
+ state.references[index] = value;
522
+ var _a = registrations[index], onUpdate = _a[1];
523
+ if (isFunction(onUpdate)) {
524
+ onUpdate(value, prevValue);
525
+ }
526
+ if (isFunction(onStateChange)) {
527
+ onStateChange();
528
+ }
529
+ }
530
+ }
531
+
532
+ function createStateRef(state, _a) {
533
+ var suiteId = _a.suiteId, suiteName = _a.suiteName;
534
+ return {
535
+ optionalFields: state.registerStateKey(function () { return ({}); }),
536
+ suiteId: state.registerStateKey(suiteId),
537
+ suiteName: state.registerStateKey(suiteName),
538
+ testCallbacks: state.registerStateKey(function () { return ({
539
+ fieldCallbacks: {},
540
+ doneCallbacks: []
541
+ }); }),
542
+ testObjects: state.registerStateKey(function (prev) {
543
+ return {
544
+ prev: prev ? prev.current : [],
545
+ current: []
546
+ };
547
+ })
548
+ };
549
+ }
550
+
551
+ function isNullish(value) {
552
+ return isNull(value) || isUndefined(value);
553
+ }
554
+
555
+ function deferThrow(message) {
556
+ setTimeout(function () {
557
+ throw new Error(message);
558
+ }, 0);
559
+ }
560
+
561
561
  function usePath() {
562
562
  var context$1 = context.useX();
563
563
  return context$1.testCursor.getCursor();
@@ -566,81 +566,210 @@ function useCursorAt() {
566
566
  var context$1 = context.useX();
567
567
  return context$1.testCursor.cursorAt();
568
568
  }
569
- function moveForward() {
570
- var context$1 = context.useX();
571
- return context$1.testCursor.next();
569
+ function moveForward() {
570
+ var context$1 = context.useX();
571
+ return context$1.testCursor.next();
572
+ }
573
+ function addLevel() {
574
+ var context$1 = context.useX();
575
+ context$1.testCursor.addLevel();
576
+ }
577
+ function removeLevel() {
578
+ var context$1 = context.useX();
579
+ context$1.testCursor.removeLevel();
580
+ }
581
+
582
+ function usePrevKeys() {
583
+ var prev = useTestObjects()[0].prev;
584
+ return asArray(getCurrent(prev, usePath())).reduce(function (prevKeys, testObject) {
585
+ if (!(testObject instanceof VestTest)) {
586
+ return prevKeys;
587
+ }
588
+ if (isNullish(testObject.key)) {
589
+ return prevKeys;
590
+ }
591
+ prevKeys[testObject.key] = testObject;
592
+ return prevKeys;
593
+ }, {});
594
+ }
595
+ function usePrevTestByKey(key) {
596
+ var prev = context.useX().isolate.keys.prev;
597
+ return prev[key];
598
+ }
599
+ function useRetainTestKey(key, testObject) {
600
+ var context$1 = context.useX();
601
+ var current = context$1.isolate.keys.current;
602
+ if (isNullish(current[key])) {
603
+ current[key] = testObject;
604
+ }
605
+ else {
606
+ 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."));
607
+ }
608
+ }
609
+
610
+ function isolate(_a, callback) {
611
+ var _b = _a.type, type = _b === void 0 ? IsolateTypes.DEFAULT : _b;
612
+ if (!isFunction(callback)) {
613
+ return;
614
+ }
615
+ var keys = {
616
+ current: {},
617
+ prev: {}
618
+ };
619
+ var path = usePath();
620
+ return context.run({ isolate: { type: type, keys: keys } }, function () {
621
+ addLevel();
622
+ keys.prev = usePrevKeys();
623
+ useSetTests(function (tests) { return setValueAtPath(tests, path, []); });
624
+ var res = callback();
625
+ removeLevel();
626
+ moveForward();
627
+ return res;
628
+ });
629
+ }
630
+ function shouldAllowReorder() {
631
+ return context.useX().isolate.type === IsolateTypes.EACH;
632
+ }
633
+
634
+ var Severity;
635
+ (function (Severity) {
636
+ Severity["WARNINGS"] = "warnings";
637
+ Severity["ERRORS"] = "errors";
638
+ })(Severity || (Severity = {}));
639
+ var SeverityCount;
640
+ (function (SeverityCount) {
641
+ SeverityCount["ERROR_COUNT"] = "errorCount";
642
+ SeverityCount["WARN_COUNT"] = "warnCount";
643
+ })(SeverityCount || (SeverityCount = {}));
644
+
645
+ /**
646
+ * A safe hasOwnProperty access
647
+ */
648
+ function hasOwnProperty(obj, key) {
649
+ return Object.prototype.hasOwnProperty.call(obj, key);
650
+ }
651
+
652
+ function isNumber(value) {
653
+ return Boolean(typeof value === 'number');
654
+ }
655
+
656
+ function isEmpty(value) {
657
+ if (!value) {
658
+ return true;
659
+ }
660
+ else if (isNumber(value)) {
661
+ return value === 0;
662
+ }
663
+ else if (hasOwnProperty(value, 'length')) {
664
+ return lengthEquals(value, 0);
665
+ }
666
+ else if (typeof value === 'object') {
667
+ return lengthEquals(Object.keys(value), 0);
668
+ }
669
+ return true;
670
+ }
671
+ var isNotEmpty = bindNot(isEmpty);
672
+
673
+ function nonMatchingFieldName(testObject, fieldName) {
674
+ return !!fieldName && !matchingFieldName(testObject, fieldName);
675
+ }
676
+ function matchingFieldName(testObject, fieldName) {
677
+ return !!(fieldName && testObject.fieldName === fieldName);
678
+ }
679
+
680
+ function either(a, b) {
681
+ return !!a !== !!b;
682
+ }
683
+
684
+ /**
685
+ * Checks that a given test object matches the currently specified severity level
686
+ */
687
+ function nonMatchingSeverityProfile(severity, testObject) {
688
+ return either(severity === Severity.WARNINGS, testObject.warns());
689
+ }
690
+
691
+ /**
692
+ * Determines whether a certain test profile has failures.
693
+ */
694
+ function hasFailuresLogic(testObject, severityKey, fieldName) {
695
+ if (!testObject.hasFailures()) {
696
+ return false;
697
+ }
698
+ if (nonMatchingFieldName(testObject, fieldName)) {
699
+ return false;
700
+ }
701
+ if (nonMatchingSeverityProfile(severityKey, testObject)) {
702
+ return false;
703
+ }
704
+ return true;
705
+ }
706
+
707
+ function hasErrors(fieldName) {
708
+ return has(Severity.ERRORS, fieldName);
572
709
  }
573
- function addLevel() {
574
- var context$1 = context.useX();
575
- context$1.testCursor.addLevel();
710
+ function hasWarnings(fieldName) {
711
+ return has(Severity.WARNINGS, fieldName);
576
712
  }
577
- function removeLevel() {
578
- var context$1 = context.useX();
579
- context$1.testCursor.removeLevel();
713
+ function has(severityKey, fieldName) {
714
+ var testObjects = useTestsFlat();
715
+ return testObjects.some(function (testObject) {
716
+ return hasFailuresLogic(testObject, severityKey, fieldName);
717
+ });
580
718
  }
581
719
 
582
- function usePrevKeys() {
583
- var prev = useTestObjects()[0].prev;
584
- return asArray(getCurrent(prev, usePath())).reduce(function (prevKeys, testObject) {
585
- if (!(testObject instanceof VestTest)) {
586
- return prevKeys;
587
- }
588
- if (isNullish(testObject.key)) {
589
- return prevKeys;
590
- }
591
- prevKeys[testObject.key] = testObject;
592
- return prevKeys;
593
- }, {});
594
- }
595
- function usePrevTestByKey(key) {
596
- var prev = context.useX().isolate.keys.prev;
597
- return prev[key];
598
- }
599
- function useRetainTestKey(key, testObject) {
600
- var context$1 = context.useX();
601
- var current = context$1.isolate.keys.current;
602
- if (isNullish(current[key])) {
603
- current[key] = testObject;
720
+ // eslint-disable-next-line max-statements, complexity
721
+ function isValid(fieldName) {
722
+ if (fieldIsOmitted(fieldName)) {
723
+ return true;
604
724
  }
605
- else {
606
- 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."));
725
+ if (hasErrors(fieldName)) {
726
+ return false;
727
+ }
728
+ var testObjects = useTestsFlat();
729
+ if (isEmpty(testObjects)) {
730
+ return false;
731
+ }
732
+ if (fieldDoesNotExist(fieldName)) {
733
+ return false;
734
+ }
735
+ if (hasNonOptionalIncomplete(fieldName)) {
736
+ return false;
607
737
  }
738
+ return noMissingTests(fieldName);
608
739
  }
609
-
610
- function isolate(_a, callback) {
611
- var _b = _a.type, type = _b === void 0 ? IsolateTypes.DEFAULT : _b;
612
- if (!isFunction(callback)) {
613
- return;
740
+ function fieldIsOmitted(fieldName) {
741
+ var omittedFields = useOmittedFields();
742
+ if (!fieldName) {
743
+ return false;
614
744
  }
615
- var keys = {
616
- current: {},
617
- prev: {}
618
- };
619
- var path = usePath();
620
- return context.run({ isolate: { type: type, keys: keys } }, function () {
621
- addLevel();
622
- keys.prev = usePrevKeys();
623
- useSetTests(function (tests) { return setValueAtPath(tests, path, []); });
624
- var res = callback();
625
- removeLevel();
626
- moveForward();
627
- return res;
628
- });
745
+ return !!omittedFields[fieldName];
629
746
  }
630
- function shouldAllowReorder() {
631
- return context.useX().isolate.type === IsolateTypes.EACH;
747
+ function hasNonOptionalIncomplete(fieldName) {
748
+ var optionalFields = useOptionalFields()[0];
749
+ return isNotEmpty(useAllIncomplete().filter(function (testObject) {
750
+ if (nonMatchingFieldName(testObject, fieldName)) {
751
+ return false;
752
+ }
753
+ return optionalFields[testObject.fieldName] !== true;
754
+ }));
755
+ }
756
+ function fieldDoesNotExist(fieldName) {
757
+ var testObjects = useTestsFlat();
758
+ return (!!fieldName &&
759
+ !testObjects.find(function (testObject) { return testObject.fieldName === fieldName; }));
760
+ }
761
+ function noMissingTests(fieldName) {
762
+ var testObjects = useTestsFlat();
763
+ var optionalFields = useOptionalFields()[0];
764
+ return testObjects.every(function (testObject) {
765
+ if (nonMatchingFieldName(testObject, fieldName)) {
766
+ return true;
767
+ }
768
+ return (optionalFields[testObject.fieldName] === true ||
769
+ testObject.isTested() ||
770
+ testObject.isOmitted());
771
+ });
632
772
  }
633
-
634
- var Severity;
635
- (function (Severity) {
636
- Severity["WARNINGS"] = "warnings";
637
- Severity["ERRORS"] = "errors";
638
- })(Severity || (Severity = {}));
639
- var SeverityCount;
640
- (function (SeverityCount) {
641
- SeverityCount["ERROR_COUNT"] = "errorCount";
642
- SeverityCount["WARN_COUNT"] = "warnCount";
643
- })(SeverityCount || (SeverityCount = {}));
644
773
 
645
774
  /**
646
775
  * Reads the testObjects list and gets full validation result from it.
@@ -649,17 +778,24 @@ function genTestsSummary() {
649
778
  var testObjects = useTestsFlat();
650
779
  var summary = assign(baseStats(), {
651
780
  groups: {},
652
- tests: {}
781
+ tests: {},
782
+ valid: false
653
783
  });
654
784
  testObjects.reduce(function (summary, testObject) {
655
785
  appendToTest(summary.tests, testObject);
656
786
  appendToGroup(summary.groups, testObject);
657
787
  return summary;
658
788
  }, summary);
789
+ summary.valid = isValid();
659
790
  return countFailures(summary);
660
791
  }
661
792
  function appendToTest(tests, testObject) {
662
793
  tests[testObject.fieldName] = appendTestObject(tests, testObject);
794
+ // If `valid` is false to begin with, keep it that way. Otherwise, assess.
795
+ tests[testObject.fieldName].valid =
796
+ tests[testObject.fieldName].valid === false
797
+ ? false
798
+ : isValid(testObject.fieldName);
663
799
  }
664
800
  /**
665
801
  * Appends to a group object if within a group
@@ -758,24 +894,6 @@ function __spreadArray(to, from, pack) {
758
894
  return to.concat(ar || Array.prototype.slice.call(from));
759
895
  }
760
896
 
761
- function nonMatchingFieldName(testObject, fieldName) {
762
- return !!fieldName && !matchingFieldName(testObject, fieldName);
763
- }
764
- function matchingFieldName(testObject, fieldName) {
765
- return !!(fieldName && testObject.fieldName === fieldName);
766
- }
767
-
768
- function either(a, b) {
769
- return !!a !== !!b;
770
- }
771
-
772
- /**
773
- * Checks that a given test object matches the currently specified severity level
774
- */
775
- function nonMatchingSeverityProfile(severity, testObject) {
776
- return either(severity === Severity.WARNINGS, testObject.warns());
777
- }
778
-
779
897
  function collectFailureMessages(severity, testObjects, options) {
780
898
  var _a;
781
899
  if (options === void 0) { options = {}; }
@@ -851,35 +969,6 @@ function getByGroup(severityKey, group, fieldName) {
851
969
  });
852
970
  }
853
971
 
854
- /**
855
- * Determines whether a certain test profile has failures.
856
- */
857
- function hasFailuresLogic(testObject, severityKey, fieldName) {
858
- if (!testObject.hasFailures()) {
859
- return false;
860
- }
861
- if (nonMatchingFieldName(testObject, fieldName)) {
862
- return false;
863
- }
864
- if (nonMatchingSeverityProfile(severityKey, testObject)) {
865
- return false;
866
- }
867
- return true;
868
- }
869
-
870
- function hasErrors(fieldName) {
871
- return has(Severity.ERRORS, fieldName);
872
- }
873
- function hasWarnings(fieldName) {
874
- return has(Severity.WARNINGS, fieldName);
875
- }
876
- function has(severityKey, fieldName) {
877
- var testObjects = useTestsFlat();
878
- return testObjects.some(function (testObject) {
879
- return hasFailuresLogic(testObject, severityKey, fieldName);
880
- });
881
- }
882
-
883
972
  function hasErrorsByGroup(groupName, fieldName) {
884
973
  return hasByGroup(Severity.ERRORS, groupName, fieldName);
885
974
  }
@@ -898,88 +987,6 @@ function hasByGroup(severityKey, group, fieldName) {
898
987
  });
899
988
  }
900
989
 
901
- /**
902
- * A safe hasOwnProperty access
903
- */
904
- function hasOwnProperty(obj, key) {
905
- return Object.prototype.hasOwnProperty.call(obj, key);
906
- }
907
-
908
- function isNumber(value) {
909
- return Boolean(typeof value === 'number');
910
- }
911
-
912
- function isEmpty(value) {
913
- if (!value) {
914
- return true;
915
- }
916
- else if (isNumber(value)) {
917
- return value === 0;
918
- }
919
- else if (hasOwnProperty(value, 'length')) {
920
- return lengthEquals(value, 0);
921
- }
922
- else if (typeof value === 'object') {
923
- return lengthEquals(Object.keys(value), 0);
924
- }
925
- return true;
926
- }
927
- var isNotEmpty = bindNot(isEmpty);
928
-
929
- // eslint-disable-next-line max-statements, complexity
930
- function isValid(fieldName) {
931
- if (fieldIsOmitted(fieldName)) {
932
- return true;
933
- }
934
- if (hasErrors(fieldName)) {
935
- return false;
936
- }
937
- var testObjects = useTestsFlat();
938
- if (isEmpty(testObjects)) {
939
- return false;
940
- }
941
- if (fieldDoesNotExist(fieldName)) {
942
- return false;
943
- }
944
- if (hasNonOptionalIncomplete(fieldName)) {
945
- return false;
946
- }
947
- return noMissingTests(fieldName);
948
- }
949
- function fieldIsOmitted(fieldName) {
950
- var omittedFields = useOmittedFields();
951
- if (!fieldName) {
952
- return false;
953
- }
954
- return !!omittedFields[fieldName];
955
- }
956
- function hasNonOptionalIncomplete(fieldName) {
957
- var optionalFields = useOptionalFields()[0];
958
- return isNotEmpty(useAllIncomplete().filter(function (testObject) {
959
- if (nonMatchingFieldName(testObject, fieldName)) {
960
- return false;
961
- }
962
- return optionalFields[testObject.fieldName] !== true;
963
- }));
964
- }
965
- function fieldDoesNotExist(fieldName) {
966
- var testObjects = useTestsFlat();
967
- return (!!fieldName &&
968
- !testObjects.find(function (testObject) { return testObject.fieldName === fieldName; }));
969
- }
970
- function noMissingTests(fieldName) {
971
- var testObjects = useTestsFlat();
972
- var optionalFields = useOptionalFields()[0];
973
- return testObjects.every(function (testObject) {
974
- if (nonMatchingFieldName(testObject, fieldName)) {
975
- return true;
976
- }
977
- return (optionalFields[testObject.fieldName] === true ||
978
- testObject.isTested() ||
979
- testObject.isOmitted());
980
- });
981
- }
982
-
983
990
  var cache$1 = createCache(20);
984
991
  function produceSuiteResult() {
985
992
  var testObjects = useTestsFlat();
@@ -1886,7 +1893,7 @@ function warn() {
1886
1893
  ctx.currentTest.warn();
1887
1894
  }
1888
1895
 
1889
- var VERSION = "4.2.3-dev-87ebfa";
1896
+ var VERSION = "4.3.0";
1890
1897
 
1891
1898
  Object.defineProperty(exports, 'enforce', {
1892
1899
  enumerable: true,