vest 4.2.2 → 4.2.3-dev-87ebfa

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 (34) hide show
  1. package/dist/cjs/classnames.development.js +21 -8
  2. package/dist/cjs/classnames.production.js +1 -1
  3. package/dist/cjs/enforce/compose.development.js +27 -59
  4. package/dist/cjs/enforce/compose.production.js +1 -1
  5. package/dist/cjs/promisify.development.js +21 -8
  6. package/dist/cjs/promisify.production.js +1 -1
  7. package/dist/cjs/vest.development.js +312 -304
  8. package/dist/cjs/vest.production.js +1 -1
  9. package/dist/es/classnames.development.js +21 -8
  10. package/dist/es/classnames.production.js +1 -1
  11. package/dist/es/enforce/compose.development.js +27 -59
  12. package/dist/es/enforce/compose.production.js +1 -1
  13. package/dist/es/promisify.development.js +21 -8
  14. package/dist/es/promisify.production.js +1 -1
  15. package/dist/es/vest.development.js +312 -304
  16. package/dist/es/vest.production.js +1 -1
  17. package/dist/umd/classnames.development.js +21 -8
  18. package/dist/umd/classnames.production.js +1 -1
  19. package/dist/umd/enforce/compose.development.js +73 -83
  20. package/dist/umd/enforce/compose.production.js +1 -1
  21. package/dist/umd/enforce/compounds.development.js +18 -20
  22. package/dist/umd/enforce/compounds.production.js +1 -1
  23. package/dist/umd/enforce/schema.development.js +18 -20
  24. package/dist/umd/enforce/schema.production.js +1 -1
  25. package/dist/umd/promisify.development.js +21 -8
  26. package/dist/umd/promisify.production.js +1 -1
  27. package/dist/umd/vest.development.js +269 -268
  28. package/dist/umd/vest.production.js +1 -1
  29. package/package.json +3 -3
  30. package/testUtils/mockThrowError.ts +3 -6
  31. package/types/classnames.d.ts +2 -1
  32. package/types/parser.d.ts +2 -1
  33. package/types/promisify.d.ts +2 -1
  34. package/types/vest.d.ts +56 -55
@@ -1,6 +1,8 @@
1
1
  export { enforce } from 'n4s';
2
2
  import { createContext } from 'context';
3
3
 
4
+ var assign = Object.assign;
5
+
4
6
  /**
5
7
  * @returns a unique numeric id.
6
8
  */
@@ -8,76 +10,203 @@ var genId = (function (n) { return function () {
8
10
  return "".concat(n++);
9
11
  }; })(0);
10
12
 
11
- function isStringValue(v) {
12
- return String(v) === v;
13
+ function isFunction(value) {
14
+ return typeof value === 'function';
13
15
  }
14
16
 
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
- };
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
23
  }
24
24
 
25
- function isUndefined(value) {
26
- return value === undefined;
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);
27
37
  }
28
38
 
29
- function shouldUseErrorAsMessage(message, error) {
30
- // kind of cheating with this safe guard, but it does the job
31
- return isUndefined(message) && isStringValue(error);
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();
99
+ }
100
+ }
32
101
  }
33
102
 
34
- function asArray(possibleArg) {
35
- return [].concat(possibleArg);
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 = {}));
112
+
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
+ };
36
130
  }
37
131
 
38
- function lengthEquals(value, arg1) {
39
- return value.length === Number(arg1);
132
+ function asArray(possibleArg) {
133
+ return [].concat(possibleArg);
40
134
  }
41
135
 
42
- function longerThan(value, arg1) {
43
- return value.length > Number(arg1);
136
+ function last(values) {
137
+ var valuesArray = asArray(values);
138
+ return valuesArray[valuesArray.length - 1];
44
139
  }
45
140
 
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;
141
+ function createCursor() {
142
+ var storage = {
143
+ cursor: []
62
144
  };
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);
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
68
172
  };
69
- // Retrieves an item from the cache.
70
- cache.get = function (deps) {
71
- return cacheStorage[findIndex(deps)] || null;
173
+ }
174
+
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);
72
209
  };
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
- }
81
210
  }
82
211
 
83
212
  // The module is named "isArrayValue" since it
@@ -92,28 +221,11 @@ function isNull(value) {
92
221
  }
93
222
  var isNotNull = bindNot(isNull);
94
223
 
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
-
107
224
  function defaultTo(callback, defaultValue) {
108
225
  var _a;
109
226
  return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
110
227
  }
111
228
 
112
- function last(values) {
113
- var valuesArray = asArray(values);
114
- return valuesArray[valuesArray.length - 1];
115
- }
116
-
117
229
  // This is kind of a map/filter in one function.
118
230
  // Normally, behaves like a nested-array map,
119
231
  // but returning `null` will drop the element from the array
@@ -159,78 +271,73 @@ function getCurrent(array, path) {
159
271
  return current;
160
272
  }
161
273
 
162
- var assign = Object.assign;
274
+ function isUndefined(value) {
275
+ return value === undefined;
276
+ }
163
277
 
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
- };
278
+ function isNullish(value) {
279
+ return isNull(value) || isUndefined(value);
196
280
  }
197
281
 
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 = {}));
282
+ function deferThrow(message) {
283
+ setTimeout(function () {
284
+ throw new Error(message);
285
+ }, 0);
286
+ }
207
287
 
208
- var Modes;
209
- (function (Modes) {
210
- Modes[Modes["ALL"] = 0] = "ALL";
211
- Modes[Modes["EAGER"] = 1] = "EAGER";
212
- })(Modes || (Modes = {}));
288
+ function isStringValue(v) {
289
+ return String(v) === v;
290
+ }
213
291
 
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
- });
292
+ function shouldUseErrorAsMessage(message, error) {
293
+ // kind of cheating with this safe guard, but it does the job
294
+ return isUndefined(message) && isStringValue(error);
295
+ }
296
+
297
+ function lengthEquals(value, arg1) {
298
+ return value.length === Number(arg1);
299
+ }
300
+
301
+ function longerThan(value, arg1) {
302
+ return value.length > Number(arg1);
303
+ }
304
+
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
+ }
234
341
 
235
342
  // STATE REF
236
343
  function useStateRef() {
@@ -447,105 +554,6 @@ var STATUS_PENDING = 'PENDING';
447
554
  var STATUS_CANCELED = 'CANCELED';
448
555
  var STATUS_OMITTED = 'OMITTED';
449
556
 
450
- /**
451
- * Throws a timed out error.
452
- */
453
- function throwError(devMessage, productionMessage) {
454
- throw new Error(devMessage );
455
- }
456
- function throwErrorDeferred(devMessage, productionMessage) {
457
- setTimeout(function () {
458
- throwError(devMessage);
459
- }, 0);
460
- }
461
-
462
- // eslint-disable-next-line max-lines-per-function
463
- function createState(onStateChange) {
464
- var state = {
465
- references: []
466
- };
467
- var registrations = [];
468
- return {
469
- registerStateKey: registerStateKey,
470
- reset: reset
471
- };
472
- /**
473
- * Registers a new key in the state, takes the initial value (may be a function that returns the initial value), returns a function.
474
- *
475
- * @example
476
- *
477
- * const useColor = state.registerStateKey("blue");
478
- *
479
- * let [color, setColor] = useColor(); // -> ["blue", Function]
480
- *
481
- * setColor("green");
482
- *
483
- * useColor()[0]; -> "green"
484
- */
485
- function registerStateKey(initialState, onUpdate) {
486
- var key = registrations.length;
487
- registrations.push([initialState, onUpdate]);
488
- return initKey(key, initialState);
489
- }
490
- function reset() {
491
- var prev = current();
492
- state.references = [];
493
- registrations.forEach(function (_a, index) {
494
- var initialValue = _a[0];
495
- return initKey(index, initialValue, prev[index]);
496
- });
497
- }
498
- function initKey(key, initialState, prevState) {
499
- current().push();
500
- set(key, optionalFunctionValue(initialState, prevState));
501
- return function useStateKey() {
502
- return [
503
- current()[key],
504
- function (nextState) {
505
- return set(key, optionalFunctionValue(nextState, current()[key]));
506
- },
507
- ];
508
- };
509
- }
510
- function current() {
511
- return state.references;
512
- }
513
- function set(index, value) {
514
- var prevValue = state.references[index];
515
- state.references[index] = value;
516
- var _a = registrations[index], onUpdate = _a[1];
517
- if (isFunction(onUpdate)) {
518
- onUpdate(value, prevValue);
519
- }
520
- if (isFunction(onStateChange)) {
521
- onStateChange();
522
- }
523
- }
524
- }
525
-
526
- function createStateRef(state, _a) {
527
- var suiteId = _a.suiteId, suiteName = _a.suiteName;
528
- return {
529
- optionalFields: state.registerStateKey(function () { return ({}); }),
530
- suiteId: state.registerStateKey(suiteId),
531
- suiteName: state.registerStateKey(suiteName),
532
- testCallbacks: state.registerStateKey(function () { return ({
533
- fieldCallbacks: {},
534
- doneCallbacks: []
535
- }); }),
536
- testObjects: state.registerStateKey(function (prev) {
537
- return {
538
- prev: prev ? prev.current : [],
539
- current: []
540
- };
541
- })
542
- };
543
- }
544
-
545
- function isNullish(value) {
546
- return isNull(value) || isUndefined(value);
547
- }
548
-
549
557
  function usePath() {
550
558
  var context$1 = context.useX();
551
559
  return context$1.testCursor.getCursor();
@@ -591,7 +599,7 @@ function useRetainTestKey(key, testObject) {
591
599
  current[key] = testObject;
592
600
  }
593
601
  else {
594
- throwErrorDeferred("Encountered the same test key \"".concat(key, "\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."));
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."));
595
603
  }
596
604
  }
597
605
 
@@ -624,6 +632,11 @@ var Severity;
624
632
  Severity["WARNINGS"] = "warnings";
625
633
  Severity["ERRORS"] = "errors";
626
634
  })(Severity || (Severity = {}));
635
+ var SeverityCount;
636
+ (function (SeverityCount) {
637
+ SeverityCount["ERROR_COUNT"] = "errorCount";
638
+ SeverityCount["WARN_COUNT"] = "warnCount";
639
+ })(SeverityCount || (SeverityCount = {}));
627
640
 
628
641
  /**
629
642
  * Reads the testObjects list and gets full validation result from it.
@@ -634,18 +647,26 @@ function genTestsSummary() {
634
647
  groups: {},
635
648
  tests: {}
636
649
  });
637
- appendSummary(testObjects);
650
+ testObjects.reduce(function (summary, testObject) {
651
+ appendToTest(summary.tests, testObject);
652
+ appendToGroup(summary.groups, testObject);
653
+ return summary;
654
+ }, summary);
638
655
  return countFailures(summary);
639
- function appendSummary(testObjects) {
640
- testObjects.forEach(function (testObject) {
641
- var fieldName = testObject.fieldName, groupName = testObject.groupName;
642
- summary.tests[fieldName] = genTestObject(summary.tests, testObject);
643
- if (groupName) {
644
- summary.groups[groupName] = summary.groups[groupName] || {};
645
- summary.groups[groupName][fieldName] = genTestObject(summary.groups[groupName], testObject);
646
- }
647
- });
656
+ }
657
+ function appendToTest(tests, testObject) {
658
+ tests[testObject.fieldName] = appendTestObject(tests, testObject);
659
+ }
660
+ /**
661
+ * Appends to a group object if within a group
662
+ */
663
+ function appendToGroup(groups, testObject) {
664
+ var groupName = testObject.groupName;
665
+ if (!groupName) {
666
+ return;
648
667
  }
668
+ groups[groupName] = groups[groupName] || {};
669
+ groups[groupName][testObject.fieldName] = appendTestObject(groups[groupName], testObject);
649
670
  }
650
671
  /**
651
672
  * Counts the failed tests and adds global counters
@@ -658,29 +679,36 @@ function countFailures(summary) {
658
679
  }
659
680
  return summary;
660
681
  }
682
+ /**
683
+ * Appends the test to a results object
684
+ */
661
685
  // eslint-disable-next-line max-statements
662
- function genTestObject(summaryKey, testObject) {
686
+ function appendTestObject(summaryKey, testObject) {
663
687
  var fieldName = testObject.fieldName, message = testObject.message;
664
688
  summaryKey[fieldName] = summaryKey[fieldName] || baseStats();
665
689
  var testKey = summaryKey[fieldName];
666
690
  if (testObject.isNonActionable())
667
691
  return testKey;
668
692
  summaryKey[fieldName].testCount++;
669
- // Adds to severity group
670
- function addTo(severity) {
671
- var countKey = severity === Severity.ERRORS ? 'errorCount' : 'warnCount';
672
- testKey[countKey]++;
673
- if (message) {
674
- testKey[severity] = (testKey[severity] || []).concat(message);
675
- }
676
- }
677
693
  if (testObject.isFailing()) {
678
- addTo(Severity.ERRORS);
694
+ incrementFailures(Severity.ERRORS);
679
695
  }
680
696
  else if (testObject.isWarning()) {
681
- addTo(Severity.WARNINGS);
697
+ incrementFailures(Severity.WARNINGS);
682
698
  }
683
699
  return testKey;
700
+ function incrementFailures(severity) {
701
+ var countKey = getCountKey(severity);
702
+ testKey[countKey]++;
703
+ if (message) {
704
+ testKey[severity] = (testKey[severity] || []).concat(message);
705
+ }
706
+ }
707
+ }
708
+ function getCountKey(severity) {
709
+ return severity === Severity.ERRORS
710
+ ? SeverityCount.ERROR_COUNT
711
+ : SeverityCount.WARN_COUNT;
684
712
  }
685
713
  function baseStats() {
686
714
  return {
@@ -811,9 +839,7 @@ function getWarningsByGroup(groupName, fieldName) {
811
839
  * Gets failure messages by group.
812
840
  */
813
841
  function getByGroup(severityKey, group, fieldName) {
814
- if (!group) {
815
- throwError("get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
816
- }
842
+ invariant(group, "get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
817
843
  var testObjects = useTestsFlat();
818
844
  return collectFailureMessages(severityKey, testObjects, {
819
845
  group: group,
@@ -897,18 +923,18 @@ function isEmpty(value) {
897
923
  var isNotEmpty = bindNot(isEmpty);
898
924
 
899
925
  // eslint-disable-next-line max-statements, complexity
900
- function isValid(result, fieldName) {
926
+ function isValid(fieldName) {
901
927
  if (fieldIsOmitted(fieldName)) {
902
928
  return true;
903
929
  }
904
- if (result.hasErrors(fieldName)) {
930
+ if (hasErrors(fieldName)) {
905
931
  return false;
906
932
  }
907
933
  var testObjects = useTestsFlat();
908
934
  if (isEmpty(testObjects)) {
909
935
  return false;
910
936
  }
911
- if (fieldDoesNotExist(result, fieldName)) {
937
+ if (fieldDoesNotExist(fieldName)) {
912
938
  return false;
913
939
  }
914
940
  if (hasNonOptionalIncomplete(fieldName)) {
@@ -932,8 +958,10 @@ function hasNonOptionalIncomplete(fieldName) {
932
958
  return optionalFields[testObject.fieldName] !== true;
933
959
  }));
934
960
  }
935
- function fieldDoesNotExist(result, fieldName) {
936
- return !!fieldName && isEmpty(result.tests[fieldName]);
961
+ function fieldDoesNotExist(fieldName) {
962
+ var testObjects = useTestsFlat();
963
+ return (!!fieldName &&
964
+ !testObjects.find(function (testObject) { return testObject.fieldName === fieldName; }));
937
965
  }
938
966
  function noMissingTests(fieldName) {
939
967
  var testObjects = useTestsFlat();
@@ -963,9 +991,7 @@ function produceSuiteResult() {
963
991
  hasErrorsByGroup: context.bind(ctxRef, hasErrorsByGroup),
964
992
  hasWarnings: context.bind(ctxRef, hasWarnings),
965
993
  hasWarningsByGroup: context.bind(ctxRef, hasWarningsByGroup),
966
- isValid: context.bind(ctxRef, function (fieldName) {
967
- return isValid(produceSuiteResult(), fieldName);
968
- }),
994
+ isValid: context.bind(ctxRef, isValid),
969
995
  suiteName: suiteName
970
996
  });
971
997
  }));
@@ -1174,9 +1200,7 @@ function initBus() {
1174
1200
  }
1175
1201
  function useBus() {
1176
1202
  var context$1 = context.useX();
1177
- if (!context$1.bus) {
1178
- throwError();
1179
- }
1203
+ invariant(context$1.bus);
1180
1204
  return context$1.bus;
1181
1205
  }
1182
1206
  var Events;
@@ -1195,9 +1219,7 @@ function create() {
1195
1219
  args[_i] = arguments[_i];
1196
1220
  }
1197
1221
  var _a = args.reverse(), suiteCallback = _a[0], suiteName = _a[1];
1198
- if (!isFunction(suiteCallback)) {
1199
- throwError('vest.create: Expected callback to be a function.');
1200
- }
1222
+ invariant(isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
1201
1223
  // Event bus initialization
1202
1224
  var bus = initBus();
1203
1225
  // State initialization
@@ -1252,9 +1274,7 @@ function create() {
1252
1274
  * })
1253
1275
  */
1254
1276
  function each(list, callback) {
1255
- if (!isFunction(callback)) {
1256
- throwError('each callback must be a function');
1257
- }
1277
+ invariant(isFunction(callback), 'each callback must be a function');
1258
1278
  isolate({ type: IsolateTypes.EACH }, function () {
1259
1279
  list.forEach(function (arg, index) {
1260
1280
  callback(arg, index);
@@ -1451,19 +1471,15 @@ function hasIncludedTests(keyTests) {
1451
1471
  * });
1452
1472
  */
1453
1473
  function group(groupName, tests) {
1454
- if (!isStringValue(groupName)) {
1455
- throwGroupError('name must be a string');
1456
- }
1457
- if (!isFunction(tests)) {
1458
- throwGroupError('callback must be a function');
1459
- }
1474
+ invariant(isStringValue(groupName), groupErrorMsg('name must be a string'));
1475
+ invariant(isFunction(tests), groupErrorMsg('callback must be a function'));
1460
1476
  // Running with the context applied
1461
1477
  isolate({ type: IsolateTypes.GROUP }, function () {
1462
1478
  context.run({ groupName: groupName }, tests);
1463
1479
  });
1464
1480
  }
1465
- function throwGroupError(error) {
1466
- throwError("Wrong arguments passed to group. Group ".concat(error, "."));
1481
+ function groupErrorMsg(error) {
1482
+ return "Wrong arguments passed to group. Group ".concat(error, ".");
1467
1483
  }
1468
1484
 
1469
1485
  function include(fieldName) {
@@ -1579,8 +1595,6 @@ function optional(optionals) {
1579
1595
  });
1580
1596
  }
1581
1597
 
1582
- var isNotString = bindNot(isStringValue);
1583
-
1584
1598
  function isPromise(value) {
1585
1599
  return value && isFunction(value.then);
1586
1600
  }
@@ -1674,7 +1688,7 @@ function registerTest(testObject) {
1674
1688
  }
1675
1689
  }
1676
1690
  catch (e) {
1677
- throwError("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(testObject), ".\n Error: ").concat(e, "."));
1691
+ throw new Error("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(testObject), ".\n Error: ").concat(e, "."));
1678
1692
  }
1679
1693
  }
1680
1694
 
@@ -1701,7 +1715,7 @@ function useTestAtCursor(newTestObject) {
1701
1715
  useSetTestAtCursor(nextTest_1);
1702
1716
  return nextTest_1;
1703
1717
  }
1704
- if (shouldPurgePrevTest(prevTest, newTestObject)) {
1718
+ if (testReorderDetected(prevTest, newTestObject)) {
1705
1719
  throwTestOrderError(prevTest, newTestObject);
1706
1720
  removeAllNextTestsInIsolate();
1707
1721
  // Need to see if this has any effect at all.
@@ -1738,14 +1752,14 @@ function useGetTestAtCursor(tests) {
1738
1752
  var cursorPath = usePath();
1739
1753
  return valueAtPath(tests, cursorPath);
1740
1754
  }
1741
- function shouldPurgePrevTest(prevTest, newTest) {
1755
+ function testReorderDetected(prevTest, newTest) {
1742
1756
  return isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
1743
1757
  }
1744
1758
  function throwTestOrderError(prevTest, newTestObject) {
1745
1759
  if (shouldAllowReorder()) {
1746
1760
  return;
1747
1761
  }
1748
- throwErrorDeferred("Vest Critical Error: Tests called in different order than previous run.\n expected: ".concat(prevTest.fieldName, "\n received: ").concat(newTestObject.fieldName, "\n This can happen on one of two reasons:\n 1. You're using if/else statements to conditionally select tests. Instead, use \"skipWhen\".\n 2. You are iterating over a list of tests, and their order changed. Use \"each\" and a custom key prop so that Vest retains their state."));
1762
+ deferThrow("Vest Critical Error: Tests called in different order than previous run.\n expected: ".concat(prevTest.fieldName, "\n received: ").concat(newTestObject.fieldName, "\n This can happen on one of two reasons:\n 1. You're using if/else statements to conditionally select tests. Instead, use \"skipWhen\".\n 2. You are iterating over a list of tests, and their order changed. Use \"each\" and a custom key prop so that Vest retains their state."));
1749
1763
  }
1750
1764
  function handleKeyTest(key, newTestObject) {
1751
1765
  var prevTestByKey = usePrevTestByKey(key);
@@ -1831,12 +1845,8 @@ function testBase(fieldName) {
1831
1845
  args[_i - 1] = arguments[_i];
1832
1846
  }
1833
1847
  var _a = (isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
1834
- if (isNotString(fieldName)) {
1835
- throwIncompatibleParamsError('fieldName', 'string');
1836
- }
1837
- if (!isFunction(testFn)) {
1838
- throwIncompatibleParamsError('Test callback', 'function');
1839
- }
1848
+ invariant(isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
1849
+ invariant(isFunction(testFn), incompatibleParamsError('Test callback', 'function'));
1840
1850
  var context$1 = context.useX();
1841
1851
  var testObject = new VestTest(fieldName, testFn, {
1842
1852
  message: message,
@@ -1857,8 +1867,8 @@ function testBase(fieldName) {
1857
1867
  var test = assign(testBase, {
1858
1868
  memo: bindTestMemo(testBase)
1859
1869
  });
1860
- function throwIncompatibleParamsError(name, expected) {
1861
- throwError("Incompatible params passed to test function. ".concat(name, " must be a ").concat(expected));
1870
+ function incompatibleParamsError(name, expected) {
1871
+ return "Incompatible params passed to test function. ".concat(name, " must be a ").concat(expected);
1862
1872
  }
1863
1873
 
1864
1874
  var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won't have an effect."
@@ -1868,12 +1878,10 @@ var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won
1868
1878
  */
1869
1879
  function warn() {
1870
1880
  var ctx = context.useX('warn ' + ERROR_HOOK_CALLED_OUTSIDE);
1871
- if (!ctx.currentTest) {
1872
- throwError(ERROR_OUTSIDE_OF_TEST);
1873
- }
1881
+ invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
1874
1882
  ctx.currentTest.warn();
1875
1883
  }
1876
1884
 
1877
- var VERSION = "4.2.2";
1885
+ var VERSION = "4.2.3-dev-87ebfa";
1878
1886
 
1879
1887
  export { VERSION, context, create, each, eager, group, include, omitWhen, only, optional, skip, skipWhen, test, warn };