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