vest 4.2.3-dev-87ebfa → 4.3.2-dev-2805e3

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 (41) hide show
  1. package/dist/cjs/classnames.development.js +61 -23
  2. package/dist/cjs/classnames.production.js +1 -1
  3. package/dist/cjs/enforce/compose.development.js +1 -1
  4. package/dist/cjs/enforce/compounds.development.js +20 -5
  5. package/dist/cjs/enforce/compounds.production.js +1 -1
  6. package/dist/cjs/enforce/schema.development.js +1 -1
  7. package/dist/cjs/parser.development.js +87 -22
  8. package/dist/cjs/parser.production.js +1 -1
  9. package/dist/cjs/vest.development.js +548 -566
  10. package/dist/cjs/vest.production.js +1 -1
  11. package/dist/es/classnames.development.js +61 -23
  12. package/dist/es/classnames.production.js +1 -1
  13. package/dist/es/enforce/compose.development.js +1 -1
  14. package/dist/es/enforce/compounds.development.js +20 -5
  15. package/dist/es/enforce/compounds.production.js +1 -1
  16. package/dist/es/enforce/schema.development.js +1 -1
  17. package/dist/es/parser.development.js +87 -22
  18. package/dist/es/parser.production.js +1 -1
  19. package/dist/es/vest.development.js +548 -566
  20. package/dist/es/vest.production.js +1 -1
  21. package/dist/umd/classnames.development.js +61 -23
  22. package/dist/umd/classnames.production.js +1 -1
  23. package/dist/umd/enforce/compose.development.js +34 -30
  24. package/dist/umd/enforce/compose.production.js +1 -1
  25. package/dist/umd/enforce/compounds.development.js +36 -32
  26. package/dist/umd/enforce/compounds.production.js +1 -1
  27. package/dist/umd/enforce/schema.development.js +34 -30
  28. package/dist/umd/enforce/schema.production.js +1 -1
  29. package/dist/umd/parser.development.js +87 -22
  30. package/dist/umd/parser.production.js +1 -1
  31. package/dist/umd/vest.development.js +482 -515
  32. package/dist/umd/vest.production.js +1 -1
  33. package/package.json +1 -1
  34. package/testUtils/suiteDummy.ts +5 -1
  35. package/types/classnames.d.ts +17 -55
  36. package/types/enforce/compose.d.ts +22 -21
  37. package/types/enforce/compounds.d.ts +24 -23
  38. package/types/enforce/schema.d.ts +26 -25
  39. package/types/parser.d.ts +16 -54
  40. package/types/promisify.d.ts +23 -16
  41. package/types/vest.d.ts +109 -101
@@ -61,8 +61,13 @@
61
61
  return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
62
62
  }
63
63
 
64
+ function numberEquals(value, eq) {
65
+ return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
66
+ }
67
+ var numberNotEquals = bindNot(numberEquals);
68
+
64
69
  function greaterThanOrEquals(value, gte) {
65
- return isNumeric(value) && isNumeric(gte) && Number(value) >= Number(gte);
70
+ return numberEquals(value, gte) || greaterThan(value, gte);
66
71
  }
67
72
 
68
73
  // The module is named "isArrayValue" since it
@@ -85,8 +90,12 @@
85
90
  }
86
91
  var notInside = bindNot(inside);
87
92
 
93
+ function lessThan(value, lt) {
94
+ return isNumeric(value) && isNumeric(lt) && Number(value) < Number(lt);
95
+ }
96
+
88
97
  function lessThanOrEquals(value, lte) {
89
- return isNumeric(value) && isNumeric(lte) && Number(value) <= Number(lte);
98
+ return numberEquals(value, lte) || lessThan(value, lte);
90
99
  }
91
100
 
92
101
  function isBetween(value, min, max) {
@@ -118,7 +127,7 @@
118
127
  var isNotNumber = bindNot(isNumber);
119
128
 
120
129
  function lengthEquals(value, arg1) {
121
- return value.length === Number(arg1);
130
+ return numberEquals(value.length, arg1);
122
131
  }
123
132
  var lengthNotEquals = bindNot(lengthEquals);
124
133
 
@@ -135,7 +144,7 @@
135
144
  else if (typeof value === 'object') {
136
145
  return lengthEquals(Object.keys(value), 0);
137
146
  }
138
- return true;
147
+ return false;
139
148
  }
140
149
  var isNotEmpty = bindNot(isEmpty);
141
150
 
@@ -160,12 +169,8 @@
160
169
  var isNotNaN = bindNot(isNaN$1);
161
170
 
162
171
  function isNegative(value) {
163
- if (isNumeric(value)) {
164
- return Number(value) < 0;
165
- }
166
- return false;
172
+ return lessThan(value, 0);
167
173
  }
168
- var isPositive = bindNot(isNegative);
169
174
 
170
175
  /**
171
176
  * Validates that a given value is an odd number
@@ -177,6 +182,10 @@
177
182
  return false;
178
183
  };
179
184
 
185
+ function isPositive(value) {
186
+ return greaterThan(value, 0);
187
+ }
188
+
180
189
  var isNotString = bindNot(isStringValue);
181
190
 
182
191
  function isTruthy(value) {
@@ -197,16 +206,12 @@
197
206
  }
198
207
  var isNotValueOf = bindNot(isValueOf);
199
208
 
200
- function lessThan(value, lt) {
201
- return isNumeric(value) && isNumeric(lt) && Number(value) < Number(lt);
202
- }
203
-
204
209
  function longerThan(value, arg1) {
205
- return value.length > Number(arg1);
210
+ return greaterThan(value.length, arg1);
206
211
  }
207
212
 
208
213
  function longerThanOrEquals(value, arg1) {
209
- return value.length >= Number(arg1);
214
+ return greaterThanOrEquals(value.length, arg1);
210
215
  }
211
216
 
212
217
  function matches(value, regex) {
@@ -222,11 +227,6 @@
222
227
  }
223
228
  var notMatches = bindNot(matches);
224
229
 
225
- function numberEquals(value, eq) {
226
- return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
227
- }
228
- var numberNotEquals = bindNot(numberEquals);
229
-
230
230
  function condition(value, callback) {
231
231
  try {
232
232
  return callback(value);
@@ -237,11 +237,11 @@
237
237
  }
238
238
 
239
239
  function shorterThan(value, arg1) {
240
- return value.length < Number(arg1);
240
+ return lessThan(value.length, arg1);
241
241
  }
242
242
 
243
243
  function shorterThanOrEquals(value, arg1) {
244
- return value.length <= Number(arg1);
244
+ return lessThanOrEquals(value.length, arg1);
245
245
  }
246
246
 
247
247
  function startsWith(value, arg1) {
@@ -453,17 +453,6 @@
453
453
  PERFORMANCE OF THIS SOFTWARE.
454
454
  ***************************************************************************** */
455
455
 
456
- var __assign = function() {
457
- __assign = Object.assign || function __assign(t) {
458
- for (var s, i = 1, n = arguments.length; i < n; i++) {
459
- s = arguments[i];
460
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
461
- }
462
- return t;
463
- };
464
- return __assign.apply(this, arguments);
465
- };
466
-
467
456
  function __spreadArray(to, from, pack) {
468
457
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
469
458
  if (ar || !(i in from)) {
@@ -655,15 +644,10 @@
655
644
  context: function () { return ctx.useX(); },
656
645
  extend: function (customRules) {
657
646
  assign(baseRules, customRules);
647
+ handleNoProxy(); // TODO: REMOVE when we stop supporting ES5
658
648
  }
659
649
  };
660
- if (!isProxySupported()) {
661
- eachEnforceRule(function (ruleName) {
662
- // Only on the first rule access - start the chain of calls
663
- target[ruleName] = genEnforceLazy(ruleName);
664
- });
665
- return assign(enforceEager, target);
666
- }
650
+ handleNoProxy();
667
651
  return new Proxy(assign(enforceEager, target), {
668
652
  get: function (target, key) {
669
653
  if (key in target) {
@@ -676,6 +660,15 @@
676
660
  return genEnforceLazy(key);
677
661
  }
678
662
  });
663
+ function handleNoProxy() {
664
+ if (!isProxySupported()) {
665
+ eachEnforceRule(function (ruleName) {
666
+ // Only on the first rule access - start the chain of calls
667
+ target[ruleName] = genEnforceLazy(ruleName);
668
+ });
669
+ return assign(enforceEager, target);
670
+ }
671
+ }
679
672
  }
680
673
  var enforce = genEnforce();
681
674
 
@@ -686,106 +679,100 @@
686
679
  return "".concat(n++);
687
680
  }; })(0);
688
681
 
689
- // eslint-disable-next-line max-lines-per-function
690
- function createState(onStateChange) {
691
- var state = {
692
- references: []
682
+ function shouldUseErrorAsMessage(message, error) {
683
+ // kind of cheating with this safe guard, but it does the job
684
+ return isUndefined(message) && isStringValue(error);
685
+ }
686
+
687
+ function asArray(possibleArg) {
688
+ return [].concat(possibleArg);
689
+ }
690
+
691
+ /**
692
+ * Creates a cache function
693
+ */
694
+ function createCache(maxSize) {
695
+ if (maxSize === void 0) { maxSize = 1; }
696
+ var cacheStorage = [];
697
+ var cache = function (deps, cacheAction) {
698
+ var cacheHit = cache.get(deps);
699
+ // cache hit is not null
700
+ if (cacheHit)
701
+ return cacheHit[1];
702
+ var result = cacheAction();
703
+ cacheStorage.unshift([deps.concat(), result]);
704
+ if (longerThan(cacheStorage, maxSize))
705
+ cacheStorage.length = maxSize;
706
+ return result;
693
707
  };
694
- var registrations = [];
695
- return {
696
- registerStateKey: registerStateKey,
697
- reset: reset
708
+ // invalidate an item in the cache by its dependencies
709
+ cache.invalidate = function (deps) {
710
+ var index = findIndex(deps);
711
+ if (index > -1)
712
+ cacheStorage.splice(index, 1);
698
713
  };
699
- /**
700
- * Registers a new key in the state, takes the initial value (may be a function that returns the initial value), returns a function.
701
- *
702
- * @example
703
- *
704
- * const useColor = state.registerStateKey("blue");
705
- *
706
- * let [color, setColor] = useColor(); // -> ["blue", Function]
707
- *
708
- * setColor("green");
709
- *
710
- * useColor()[0]; -> "green"
711
- */
712
- function registerStateKey(initialState, onUpdate) {
713
- var key = registrations.length;
714
- registrations.push([initialState, onUpdate]);
715
- return initKey(key, initialState);
716
- }
717
- function reset() {
718
- var prev = current();
719
- state.references = [];
720
- registrations.forEach(function (_a, index) {
721
- var initialValue = _a[0];
722
- return initKey(index, initialValue, prev[index]);
714
+ // Retrieves an item from the cache.
715
+ cache.get = function (deps) {
716
+ return cacheStorage[findIndex(deps)] || null;
717
+ };
718
+ return cache;
719
+ function findIndex(deps) {
720
+ return cacheStorage.findIndex(function (_a) {
721
+ var cachedDeps = _a[0];
722
+ return lengthEquals(deps, cachedDeps.length) &&
723
+ deps.every(function (dep, i) { return dep === cachedDeps[i]; });
723
724
  });
724
725
  }
725
- function initKey(key, initialState, prevState) {
726
- current().push();
727
- set(key, optionalFunctionValue(initialState, prevState));
728
- return function useStateKey() {
729
- return [
730
- current()[key],
731
- function (nextState) {
732
- return set(key, optionalFunctionValue(nextState, current()[key]));
733
- },
734
- ];
735
- };
736
- }
737
- function current() {
738
- return state.references;
739
- }
740
- function set(index, value) {
741
- var prevValue = state.references[index];
742
- state.references[index] = value;
743
- var _a = registrations[index], onUpdate = _a[1];
744
- if (isFunction(onUpdate)) {
745
- onUpdate(value, prevValue);
726
+ }
727
+
728
+ function last(values) {
729
+ var valuesArray = asArray(values);
730
+ return valuesArray[valuesArray.length - 1];
731
+ }
732
+
733
+ // This is kind of a map/filter in one function.
734
+ // Normally, behaves like a nested-array map,
735
+ // but returning `null` will drop the element from the array
736
+ function transform(array, cb) {
737
+ var res = [];
738
+ for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
739
+ var v = array_1[_i];
740
+ if (isArray(v)) {
741
+ res.push(transform(v, cb));
746
742
  }
747
- if (isFunction(onStateChange)) {
748
- onStateChange();
743
+ else {
744
+ var output = cb(v);
745
+ if (isNotNull(output)) {
746
+ res.push(output);
747
+ }
749
748
  }
750
749
  }
750
+ return res;
751
751
  }
752
-
753
- var IsolateTypes;
754
- (function (IsolateTypes) {
755
- IsolateTypes[IsolateTypes["DEFAULT"] = 0] = "DEFAULT";
756
- IsolateTypes[IsolateTypes["SUITE"] = 1] = "SUITE";
757
- IsolateTypes[IsolateTypes["EACH"] = 2] = "EACH";
758
- IsolateTypes[IsolateTypes["SKIP_WHEN"] = 3] = "SKIP_WHEN";
759
- IsolateTypes[IsolateTypes["OMIT_WHEN"] = 4] = "OMIT_WHEN";
760
- IsolateTypes[IsolateTypes["GROUP"] = 5] = "GROUP";
761
- })(IsolateTypes || (IsolateTypes = {}));
762
-
763
- function createStateRef(state, _a) {
764
- var suiteId = _a.suiteId, suiteName = _a.suiteName;
765
- return {
766
- optionalFields: state.registerStateKey(function () { return ({}); }),
767
- suiteId: state.registerStateKey(suiteId),
768
- suiteName: state.registerStateKey(suiteName),
769
- testCallbacks: state.registerStateKey(function () { return ({
770
- fieldCallbacks: {},
771
- doneCallbacks: []
772
- }); }),
773
- testObjects: state.registerStateKey(function (prev) {
774
- return {
775
- prev: prev ? prev.current : [],
776
- current: []
777
- };
778
- })
779
- };
752
+ function valueAtPath(array, path) {
753
+ return getCurrent(array, path)[last(path)];
780
754
  }
781
-
782
- function asArray(possibleArg) {
783
- return [].concat(possibleArg);
755
+ function setValueAtPath(array, path, value) {
756
+ var current = getCurrent(array, path);
757
+ current[last(path)] = value;
758
+ return array;
784
759
  }
785
-
786
- function last(values) {
787
- var valuesArray = asArray(values);
788
- return valuesArray[valuesArray.length - 1];
760
+ function flatten(values) {
761
+ return asArray(values).reduce(function (acc, value) {
762
+ if (isArray(value)) {
763
+ return acc.concat(flatten(value));
764
+ }
765
+ return asArray(acc).concat(value);
766
+ }, []);
767
+ }
768
+ function getCurrent(array, path) {
769
+ var current = array;
770
+ for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) {
771
+ var p = _a[_i];
772
+ current[p] = defaultTo(current[p], []);
773
+ current = current[p];
774
+ }
775
+ return current;
789
776
  }
790
777
 
791
778
  function createCursor() {
@@ -822,6 +809,16 @@
822
809
  };
823
810
  }
824
811
 
812
+ var IsolateTypes;
813
+ (function (IsolateTypes) {
814
+ IsolateTypes[IsolateTypes["DEFAULT"] = 0] = "DEFAULT";
815
+ IsolateTypes[IsolateTypes["SUITE"] = 1] = "SUITE";
816
+ IsolateTypes[IsolateTypes["EACH"] = 2] = "EACH";
817
+ IsolateTypes[IsolateTypes["SKIP_WHEN"] = 3] = "SKIP_WHEN";
818
+ IsolateTypes[IsolateTypes["OMIT_WHEN"] = 4] = "OMIT_WHEN";
819
+ IsolateTypes[IsolateTypes["GROUP"] = 5] = "GROUP";
820
+ })(IsolateTypes || (IsolateTypes = {}));
821
+
825
822
  var Modes;
826
823
  (function (Modes) {
827
824
  Modes[Modes["ALL"] = 0] = "ALL";
@@ -849,99 +846,6 @@
849
846
  }, ctxRef);
850
847
  });
851
848
 
852
- // This is kind of a map/filter in one function.
853
- // Normally, behaves like a nested-array map,
854
- // but returning `null` will drop the element from the array
855
- function transform(array, cb) {
856
- var res = [];
857
- for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
858
- var v = array_1[_i];
859
- if (isArray(v)) {
860
- res.push(transform(v, cb));
861
- }
862
- else {
863
- var output = cb(v);
864
- if (isNotNull(output)) {
865
- res.push(output);
866
- }
867
- }
868
- }
869
- return res;
870
- }
871
- function valueAtPath(array, path) {
872
- return getCurrent(array, path)[last(path)];
873
- }
874
- function setValueAtPath(array, path, value) {
875
- var current = getCurrent(array, path);
876
- current[last(path)] = value;
877
- return array;
878
- }
879
- function flatten(values) {
880
- return asArray(values).reduce(function (acc, value) {
881
- if (isArray(value)) {
882
- return acc.concat(flatten(value));
883
- }
884
- return asArray(acc).concat(value);
885
- }, []);
886
- }
887
- function getCurrent(array, path) {
888
- var current = array;
889
- for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) {
890
- var p = _a[_i];
891
- current[p] = defaultTo(current[p], []);
892
- current = current[p];
893
- }
894
- return current;
895
- }
896
-
897
- function deferThrow(message) {
898
- setTimeout(function () {
899
- throw new Error(message);
900
- }, 0);
901
- }
902
-
903
- function shouldUseErrorAsMessage(message, error) {
904
- // kind of cheating with this safe guard, but it does the job
905
- return isUndefined(message) && isStringValue(error);
906
- }
907
-
908
- /**
909
- * Creates a cache function
910
- */
911
- function createCache(maxSize) {
912
- if (maxSize === void 0) { maxSize = 1; }
913
- var cacheStorage = [];
914
- var cache = function (deps, cacheAction) {
915
- var cacheHit = cache.get(deps);
916
- // cache hit is not null
917
- if (cacheHit)
918
- return cacheHit[1];
919
- var result = cacheAction();
920
- cacheStorage.unshift([deps.concat(), result]);
921
- if (longerThan(cacheStorage, maxSize))
922
- cacheStorage.length = maxSize;
923
- return result;
924
- };
925
- // invalidate an item in the cache by its dependencies
926
- cache.invalidate = function (deps) {
927
- var index = findIndex(deps);
928
- if (index > -1)
929
- cacheStorage.splice(index, 1);
930
- };
931
- // Retrieves an item from the cache.
932
- cache.get = function (deps) {
933
- return cacheStorage[findIndex(deps)] || null;
934
- };
935
- return cache;
936
- function findIndex(deps) {
937
- return cacheStorage.findIndex(function (_a) {
938
- var cachedDeps = _a[0];
939
- return lengthEquals(deps, cachedDeps.length) &&
940
- deps.every(function (dep, i) { return dep === cachedDeps[i]; });
941
- });
942
- }
943
- }
944
-
945
849
  // STATE REF
946
850
  function useStateRef() {
947
851
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -991,18 +895,6 @@
991
895
  return testObject.isPending() ? testObject : null;
992
896
  }));
993
897
  }
994
- function useOmittedFields() {
995
- var testObjects = useTestsFlat();
996
- return testObjects.reduce(function (omittedFields, testObject) {
997
- if (omittedFields[testObject.fieldName]) {
998
- return omittedFields;
999
- }
1000
- if (testObject.isOmitted()) {
1001
- omittedFields[testObject.fieldName] = true;
1002
- }
1003
- return omittedFields;
1004
- }, {});
1005
- }
1006
898
  var flatCache = createCache();
1007
899
  function useTestsFlat() {
1008
900
  var current = useTestObjects()[0].current;
@@ -1157,6 +1049,95 @@
1157
1049
  var STATUS_CANCELED = 'CANCELED';
1158
1050
  var STATUS_OMITTED = 'OMITTED';
1159
1051
 
1052
+ // eslint-disable-next-line max-lines-per-function
1053
+ function createState(onStateChange) {
1054
+ var state = {
1055
+ references: []
1056
+ };
1057
+ var registrations = [];
1058
+ return {
1059
+ registerStateKey: registerStateKey,
1060
+ reset: reset
1061
+ };
1062
+ /**
1063
+ * Registers a new key in the state, takes the initial value (may be a function that returns the initial value), returns a function.
1064
+ *
1065
+ * @example
1066
+ *
1067
+ * const useColor = state.registerStateKey("blue");
1068
+ *
1069
+ * let [color, setColor] = useColor(); // -> ["blue", Function]
1070
+ *
1071
+ * setColor("green");
1072
+ *
1073
+ * useColor()[0]; -> "green"
1074
+ */
1075
+ function registerStateKey(initialState, onUpdate) {
1076
+ var key = registrations.length;
1077
+ registrations.push([initialState, onUpdate]);
1078
+ return initKey(key, initialState);
1079
+ }
1080
+ function reset() {
1081
+ var prev = current();
1082
+ state.references = [];
1083
+ registrations.forEach(function (_a, index) {
1084
+ var initialValue = _a[0];
1085
+ return initKey(index, initialValue, prev[index]);
1086
+ });
1087
+ }
1088
+ function initKey(key, initialState, prevState) {
1089
+ current().push();
1090
+ set(key, optionalFunctionValue(initialState, prevState));
1091
+ return function useStateKey() {
1092
+ return [
1093
+ current()[key],
1094
+ function (nextState) {
1095
+ return set(key, optionalFunctionValue(nextState, current()[key]));
1096
+ },
1097
+ ];
1098
+ };
1099
+ }
1100
+ function current() {
1101
+ return state.references;
1102
+ }
1103
+ function set(index, value) {
1104
+ var prevValue = state.references[index];
1105
+ state.references[index] = value;
1106
+ var _a = registrations[index], onUpdate = _a[1];
1107
+ if (isFunction(onUpdate)) {
1108
+ onUpdate(value, prevValue);
1109
+ }
1110
+ if (isFunction(onStateChange)) {
1111
+ onStateChange();
1112
+ }
1113
+ }
1114
+ }
1115
+
1116
+ function createStateRef(state, _a) {
1117
+ var suiteId = _a.suiteId, suiteName = _a.suiteName;
1118
+ return {
1119
+ optionalFields: state.registerStateKey(function () { return ({}); }),
1120
+ suiteId: state.registerStateKey(suiteId),
1121
+ suiteName: state.registerStateKey(suiteName),
1122
+ testCallbacks: state.registerStateKey(function () { return ({
1123
+ fieldCallbacks: {},
1124
+ doneCallbacks: []
1125
+ }); }),
1126
+ testObjects: state.registerStateKey(function (prev) {
1127
+ return {
1128
+ prev: prev ? prev.current : [],
1129
+ current: []
1130
+ };
1131
+ })
1132
+ };
1133
+ }
1134
+
1135
+ function deferThrow(message) {
1136
+ setTimeout(function () {
1137
+ throw new Error(message);
1138
+ }, 0);
1139
+ }
1140
+
1160
1141
  function usePath() {
1161
1142
  var context$1 = context.useX();
1162
1143
  return context$1.testCursor.getCursor();
@@ -1201,46 +1182,147 @@
1201
1182
  if (isNullish(current[key])) {
1202
1183
  current[key] = testObject;
1203
1184
  }
1204
- else {
1205
- 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."));
1185
+ else {
1186
+ 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."));
1187
+ }
1188
+ }
1189
+
1190
+ function isolate(_a, callback) {
1191
+ var _b = _a.type, type = _b === void 0 ? IsolateTypes.DEFAULT : _b;
1192
+ invariant(isFunction(callback));
1193
+ var keys = {
1194
+ current: {},
1195
+ prev: {}
1196
+ };
1197
+ var path = usePath();
1198
+ return context.run({ isolate: { type: type, keys: keys } }, function () {
1199
+ addLevel();
1200
+ keys.prev = usePrevKeys();
1201
+ useSetTests(function (tests) { return setValueAtPath(tests, path, []); });
1202
+ var res = callback();
1203
+ removeLevel();
1204
+ moveForward();
1205
+ return res;
1206
+ });
1207
+ }
1208
+ function shouldAllowReorder() {
1209
+ return context.useX().isolate.type === IsolateTypes.EACH;
1210
+ }
1211
+
1212
+ var Severity;
1213
+ (function (Severity) {
1214
+ Severity["WARNINGS"] = "warnings";
1215
+ Severity["ERRORS"] = "errors";
1216
+ })(Severity || (Severity = {}));
1217
+ var SeverityCount;
1218
+ (function (SeverityCount) {
1219
+ SeverityCount["ERROR_COUNT"] = "errorCount";
1220
+ SeverityCount["WARN_COUNT"] = "warnCount";
1221
+ })(SeverityCount || (SeverityCount = {}));
1222
+ function countKeyBySeverity(severity) {
1223
+ return severity === Severity.ERRORS
1224
+ ? SeverityCount.ERROR_COUNT
1225
+ : SeverityCount.WARN_COUNT;
1226
+ }
1227
+
1228
+ function nonMatchingFieldName(testObject, fieldName) {
1229
+ return !!fieldName && !matchingFieldName(testObject, fieldName);
1230
+ }
1231
+ function matchingFieldName(testObject, fieldName) {
1232
+ return !!(fieldName && testObject.fieldName === fieldName);
1233
+ }
1234
+
1235
+ function either(a, b) {
1236
+ return !!a !== !!b;
1237
+ }
1238
+
1239
+ /**
1240
+ * Checks that a given test object matches the currently specified severity level
1241
+ */
1242
+ function nonMatchingSeverityProfile(severity, testObject) {
1243
+ return either(severity === Severity.WARNINGS, testObject.warns());
1244
+ }
1245
+
1246
+ /**
1247
+ * The difference between this file and hasFailures is that hasFailures uses the static
1248
+ * summary object, while this one uses the actual validation state
1249
+ */
1250
+ function hasErrorsByTestObjects(fieldName) {
1251
+ return hasFailuresByTestObjects(Severity.ERRORS, fieldName);
1252
+ }
1253
+ function hasFailuresByTestObjects(severityKey, fieldName) {
1254
+ var testObjects = useTestsFlat();
1255
+ return testObjects.some(function (testObject) {
1256
+ return hasFailuresByTestObject(testObject, severityKey, fieldName);
1257
+ });
1258
+ }
1259
+ /**
1260
+ * Determines whether a certain test profile has failures.
1261
+ */
1262
+ function hasFailuresByTestObject(testObject, severityKey, fieldName) {
1263
+ if (!testObject.hasFailures()) {
1264
+ return false;
1265
+ }
1266
+ if (nonMatchingFieldName(testObject, fieldName)) {
1267
+ return false;
1268
+ }
1269
+ if (nonMatchingSeverityProfile(severityKey, testObject)) {
1270
+ return false;
1206
1271
  }
1272
+ return true;
1207
1273
  }
1208
1274
 
1209
- function isolate(_a, callback) {
1210
- var _b = _a.type, type = _b === void 0 ? IsolateTypes.DEFAULT : _b;
1211
- if (!isFunction(callback)) {
1212
- return;
1275
+ // eslint-disable-next-line max-statements, complexity
1276
+ function shouldAddValidProp(fieldName) {
1277
+ if (fieldIsOmitted(fieldName)) {
1278
+ return true;
1213
1279
  }
1214
- var keys = {
1215
- current: {},
1216
- prev: {}
1217
- };
1218
- var path = usePath();
1219
- return context.run({ isolate: { type: type, keys: keys } }, function () {
1220
- addLevel();
1221
- keys.prev = usePrevKeys();
1222
- useSetTests(function (tests) { return setValueAtPath(tests, path, []); });
1223
- var res = callback();
1224
- removeLevel();
1225
- moveForward();
1226
- return res;
1227
- });
1280
+ if (hasErrorsByTestObjects(fieldName)) {
1281
+ return false;
1282
+ }
1283
+ var testObjects = useTestsFlat();
1284
+ if (isEmpty(testObjects)) {
1285
+ return false;
1286
+ }
1287
+ if (hasNonOptionalIncomplete(fieldName)) {
1288
+ return false;
1289
+ }
1290
+ return noMissingTests(fieldName);
1228
1291
  }
1229
- function shouldAllowReorder() {
1230
- return context.useX().isolate.type === IsolateTypes.EACH;
1292
+ function fieldIsOmitted(fieldName) {
1293
+ if (!fieldName) {
1294
+ return false;
1295
+ }
1296
+ var flatTests = useTestsFlat();
1297
+ return flatTests.some(function (testObject) { return testObject.fieldName === fieldName && testObject.isOmitted(); });
1298
+ }
1299
+ function hasNonOptionalIncomplete(fieldName) {
1300
+ var optionalFields = useOptionalFields()[0];
1301
+ return isNotEmpty(useAllIncomplete().filter(function (testObject) {
1302
+ if (nonMatchingFieldName(testObject, fieldName)) {
1303
+ return false;
1304
+ }
1305
+ return optionalFields[testObject.fieldName] !== true;
1306
+ }));
1307
+ }
1308
+ function noMissingTests(fieldName) {
1309
+ var testObjects = useTestsFlat();
1310
+ var optionalFields = useOptionalFields()[0];
1311
+ return testObjects.every(function (testObject) {
1312
+ if (nonMatchingFieldName(testObject, fieldName)) {
1313
+ return true;
1314
+ }
1315
+ return (optionalFields[testObject.fieldName] === true ||
1316
+ testObject.isTested() ||
1317
+ testObject.isOmitted());
1318
+ });
1231
1319
  }
1232
1320
 
1233
- var Severity;
1234
- (function (Severity) {
1235
- Severity["WARNINGS"] = "warnings";
1236
- Severity["ERRORS"] = "errors";
1237
- })(Severity || (Severity = {}));
1238
- var SeverityCount;
1239
- (function (SeverityCount) {
1240
- SeverityCount["ERROR_COUNT"] = "errorCount";
1241
- SeverityCount["WARN_COUNT"] = "warnCount";
1242
- })(SeverityCount || (SeverityCount = {}));
1243
-
1321
+ function useSummary() {
1322
+ var summary = context.useX().summary;
1323
+ invariant(summary);
1324
+ return summary;
1325
+ }
1244
1326
  /**
1245
1327
  * Reads the testObjects list and gets full validation result from it.
1246
1328
  */
@@ -1248,17 +1330,24 @@
1248
1330
  var testObjects = useTestsFlat();
1249
1331
  var summary = assign(baseStats(), {
1250
1332
  groups: {},
1251
- tests: {}
1333
+ tests: {},
1334
+ valid: false
1252
1335
  });
1253
1336
  testObjects.reduce(function (summary, testObject) {
1254
1337
  appendToTest(summary.tests, testObject);
1255
1338
  appendToGroup(summary.groups, testObject);
1256
1339
  return summary;
1257
1340
  }, summary);
1341
+ summary.valid = shouldAddValidProp();
1258
1342
  return countFailures(summary);
1259
1343
  }
1260
1344
  function appendToTest(tests, testObject) {
1261
1345
  tests[testObject.fieldName] = appendTestObject(tests, testObject);
1346
+ // If `valid` is false to begin with, keep it that way. Otherwise, assess.
1347
+ tests[testObject.fieldName].valid =
1348
+ tests[testObject.fieldName].valid === false
1349
+ ? false
1350
+ : shouldAddValidProp(testObject.fieldName);
1262
1351
  }
1263
1352
  /**
1264
1353
  * Appends to a group object if within a group
@@ -1282,13 +1371,9 @@
1282
1371
  }
1283
1372
  return summary;
1284
1373
  }
1285
- /**
1286
- * Appends the test to a results object
1287
- */
1288
- // eslint-disable-next-line max-statements
1289
1374
  function appendTestObject(summaryKey, testObject) {
1290
1375
  var fieldName = testObject.fieldName, message = testObject.message;
1291
- summaryKey[fieldName] = summaryKey[fieldName] || baseStats();
1376
+ summaryKey[fieldName] = summaryKey[fieldName] || baseTestStats();
1292
1377
  var testKey = summaryKey[fieldName];
1293
1378
  if (testObject.isNonActionable())
1294
1379
  return testKey;
@@ -1301,18 +1386,13 @@
1301
1386
  }
1302
1387
  return testKey;
1303
1388
  function incrementFailures(severity) {
1304
- var countKey = getCountKey(severity);
1389
+ var countKey = countKeyBySeverity(severity);
1305
1390
  testKey[countKey]++;
1306
1391
  if (message) {
1307
1392
  testKey[severity] = (testKey[severity] || []).concat(message);
1308
1393
  }
1309
1394
  }
1310
1395
  }
1311
- function getCountKey(severity) {
1312
- return severity === Severity.ERRORS
1313
- ? SeverityCount.ERROR_COUNT
1314
- : SeverityCount.WARN_COUNT;
1315
- }
1316
1396
  function baseStats() {
1317
1397
  return {
1318
1398
  errorCount: 0,
@@ -1320,61 +1400,31 @@
1320
1400
  testCount: 0
1321
1401
  };
1322
1402
  }
1323
-
1324
- function nonMatchingFieldName(testObject, fieldName) {
1325
- return !!fieldName && !matchingFieldName(testObject, fieldName);
1326
- }
1327
- function matchingFieldName(testObject, fieldName) {
1328
- return !!(fieldName && testObject.fieldName === fieldName);
1329
- }
1330
-
1331
- function either(a, b) {
1332
- return !!a !== !!b;
1403
+ function baseTestStats() {
1404
+ return assign(baseStats(), {
1405
+ errors: [],
1406
+ warnings: []
1407
+ });
1333
1408
  }
1334
1409
 
1335
- /**
1336
- * Checks that a given test object matches the currently specified severity level
1337
- */
1338
- function nonMatchingSeverityProfile(severity, testObject) {
1339
- return either(severity === Severity.WARNINGS, testObject.warns());
1410
+ // calls collectAll or getByFieldName depending on whether fieldName is provided
1411
+ function gatherFailures(testGroup, severityKey, fieldName) {
1412
+ return fieldName
1413
+ ? getByFieldName(testGroup, severityKey, fieldName)
1414
+ : collectAll(testGroup, severityKey);
1340
1415
  }
1341
-
1342
- function collectFailureMessages(severity, testObjects, options) {
1416
+ function getByFieldName(testGroup, severityKey, fieldName) {
1343
1417
  var _a;
1344
- if (options === void 0) { options = {}; }
1345
- var _b = options || {}, group = _b.group, fieldName = _b.fieldName;
1346
- return testObjects.reduce(function (collector, testObject) {
1347
- if (noMatch(testObject, severity, group, fieldName)) {
1348
- return collector;
1349
- }
1350
- if (!testObject.hasFailures()) {
1351
- return collector;
1352
- }
1353
- collector[testObject.fieldName] = (collector[testObject.fieldName] || []).concat(testObject.message || []);
1354
- return collector;
1355
- }, __assign({}, (fieldName && (_a = {}, _a[fieldName] = [], _a))));
1356
- }
1357
- function noGroupMatch(testObject, groupName) {
1358
- return !!(groupName && testObject.groupName !== groupName);
1359
- }
1360
- function noMatch(testObject, severity, group, fieldName) {
1361
- if (noGroupMatch(testObject, group)) {
1362
- return true;
1363
- }
1364
- if (nonMatchingFieldName(testObject, fieldName)) {
1365
- return true;
1366
- }
1367
- if (nonMatchingSeverityProfile(severity, testObject)) {
1368
- return true;
1369
- }
1370
- return false;
1418
+ return ((_a = testGroup === null || testGroup === void 0 ? void 0 : testGroup[fieldName]) === null || _a === void 0 ? void 0 : _a[severityKey]) || [];
1371
1419
  }
1372
-
1373
- function getFailuresArrayOrObject(group, fieldName) {
1374
- if (fieldName) {
1375
- return group[fieldName];
1420
+ function collectAll(testGroup, severityKey) {
1421
+ var output = {};
1422
+ for (var field in testGroup) {
1423
+ // We will probably never get to the fallback array
1424
+ // leaving it just in case the implementation changes
1425
+ output[field] = testGroup[field][severityKey] || [];
1376
1426
  }
1377
- return group;
1427
+ return output;
1378
1428
  }
1379
1429
 
1380
1430
  function getErrors(fieldName) {
@@ -1387,150 +1437,86 @@
1387
1437
  * @returns suite or field's errors or warnings.
1388
1438
  */
1389
1439
  function getFailures(severityKey, fieldName) {
1390
- var testObjects = useTestsFlat();
1391
- var failureMessages = collectFailureMessages(severityKey, testObjects, {
1392
- fieldName: fieldName
1393
- });
1394
- return getFailuresArrayOrObject(failureMessages, fieldName);
1440
+ var summary = useSummary();
1441
+ return gatherFailures(summary.tests, severityKey, fieldName);
1395
1442
  }
1396
1443
 
1397
1444
  function getErrorsByGroup(groupName, fieldName) {
1398
- var errors = getByGroup(Severity.ERRORS, groupName, fieldName);
1399
- return getFailuresArrayOrObject(errors, fieldName);
1445
+ return getFailuresByGroup(groupName, Severity.ERRORS, fieldName);
1400
1446
  }
1401
1447
  function getWarningsByGroup(groupName, fieldName) {
1402
- var warnings = getByGroup(Severity.WARNINGS, groupName, fieldName);
1403
- return getFailuresArrayOrObject(warnings, fieldName);
1404
- }
1405
- /**
1406
- * Gets failure messages by group.
1407
- */
1408
- function getByGroup(severityKey, group, fieldName) {
1409
- invariant(group, "get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
1410
- var testObjects = useTestsFlat();
1411
- return collectFailureMessages(severityKey, testObjects, {
1412
- group: group,
1413
- fieldName: fieldName
1414
- });
1448
+ return getFailuresByGroup(groupName, Severity.WARNINGS, fieldName);
1415
1449
  }
1416
-
1417
- /**
1418
- * Determines whether a certain test profile has failures.
1419
- */
1420
- function hasFailuresLogic(testObject, severityKey, fieldName) {
1421
- if (!testObject.hasFailures()) {
1422
- return false;
1423
- }
1424
- if (nonMatchingFieldName(testObject, fieldName)) {
1425
- return false;
1426
- }
1427
- if (nonMatchingSeverityProfile(severityKey, testObject)) {
1428
- return false;
1429
- }
1430
- return true;
1450
+ function getFailuresByGroup(groupName, severityKey, fieldName) {
1451
+ var summary = useSummary();
1452
+ return gatherFailures(summary.groups[groupName], severityKey, fieldName);
1431
1453
  }
1432
1454
 
1433
1455
  function hasErrors(fieldName) {
1434
- return has(Severity.ERRORS, fieldName);
1456
+ return hasFailures(SeverityCount.ERROR_COUNT, fieldName);
1435
1457
  }
1436
1458
  function hasWarnings(fieldName) {
1437
- return has(Severity.WARNINGS, fieldName);
1459
+ return hasFailures(SeverityCount.WARN_COUNT, fieldName);
1438
1460
  }
1439
- function has(severityKey, fieldName) {
1440
- var testObjects = useTestsFlat();
1441
- return testObjects.some(function (testObject) {
1442
- return hasFailuresLogic(testObject, severityKey, fieldName);
1443
- });
1461
+ function hasFailures(severityCount, fieldName) {
1462
+ var _a;
1463
+ var summary = useSummary();
1464
+ if (fieldName) {
1465
+ return isPositive((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
1466
+ }
1467
+ return isPositive(summary[severityCount]);
1444
1468
  }
1445
1469
 
1446
1470
  function hasErrorsByGroup(groupName, fieldName) {
1447
- return hasByGroup(Severity.ERRORS, groupName, fieldName);
1471
+ return hasFailuresByGroup(Severity.ERRORS, groupName, fieldName);
1448
1472
  }
1449
1473
  function hasWarningsByGroup(groupName, fieldName) {
1450
- return hasByGroup(Severity.WARNINGS, groupName, fieldName);
1451
- }
1452
- /**
1453
- * Checks whether there are failures in a given group.
1454
- */
1455
- function hasByGroup(severityKey, group, fieldName) {
1456
- var testObjects = useTestsFlat();
1457
- return testObjects.some(function (testObject) {
1458
- return group === testObject.groupName
1459
- ? hasFailuresLogic(testObject, severityKey, fieldName)
1460
- : false;
1461
- });
1474
+ return hasFailuresByGroup(Severity.WARNINGS, groupName, fieldName);
1462
1475
  }
1463
-
1464
- // eslint-disable-next-line max-statements, complexity
1465
- function isValid(fieldName) {
1466
- if (fieldIsOmitted(fieldName)) {
1467
- return true;
1468
- }
1469
- if (hasErrors(fieldName)) {
1470
- return false;
1471
- }
1472
- var testObjects = useTestsFlat();
1473
- if (isEmpty(testObjects)) {
1474
- return false;
1475
- }
1476
- if (fieldDoesNotExist(fieldName)) {
1477
- return false;
1478
- }
1479
- if (hasNonOptionalIncomplete(fieldName)) {
1476
+ // eslint-disable-next-line max-statements
1477
+ function hasFailuresByGroup(severityKey, groupName, fieldName) {
1478
+ var _a, _b;
1479
+ var summary = useSummary();
1480
+ var severityCount = countKeyBySeverity(severityKey);
1481
+ var group = summary.groups[groupName];
1482
+ if (!group) {
1480
1483
  return false;
1481
1484
  }
1482
- return noMissingTests(fieldName);
1483
- }
1484
- function fieldIsOmitted(fieldName) {
1485
- var omittedFields = useOmittedFields();
1486
- if (!fieldName) {
1487
- return false;
1485
+ if (fieldName) {
1486
+ return isPositive((_a = group[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
1488
1487
  }
1489
- return !!omittedFields[fieldName];
1490
- }
1491
- function hasNonOptionalIncomplete(fieldName) {
1492
- var optionalFields = useOptionalFields()[0];
1493
- return isNotEmpty(useAllIncomplete().filter(function (testObject) {
1494
- if (nonMatchingFieldName(testObject, fieldName)) {
1495
- return false;
1496
- }
1497
- return optionalFields[testObject.fieldName] !== true;
1498
- }));
1499
- }
1500
- function fieldDoesNotExist(fieldName) {
1501
- var testObjects = useTestsFlat();
1502
- return (!!fieldName &&
1503
- !testObjects.find(function (testObject) { return testObject.fieldName === fieldName; }));
1504
- }
1505
- function noMissingTests(fieldName) {
1506
- var testObjects = useTestsFlat();
1507
- var optionalFields = useOptionalFields()[0];
1508
- return testObjects.every(function (testObject) {
1509
- if (nonMatchingFieldName(testObject, fieldName)) {
1488
+ for (var field in group) {
1489
+ if (isPositive((_b = group[field]) === null || _b === void 0 ? void 0 : _b[severityCount])) {
1510
1490
  return true;
1511
1491
  }
1512
- return (optionalFields[testObject.fieldName] === true ||
1513
- testObject.isTested() ||
1514
- testObject.isOmitted());
1515
- });
1492
+ }
1493
+ return false;
1494
+ }
1495
+
1496
+ function isValid(fieldName) {
1497
+ var _a;
1498
+ var summary = useSummary();
1499
+ return fieldName ? Boolean((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.valid) : summary.valid;
1516
1500
  }
1517
1501
 
1518
- var cache$1 = createCache(20);
1502
+ var cache$1 = createCache(1);
1519
1503
  function produceSuiteResult() {
1520
1504
  var testObjects = useTestsFlat();
1521
1505
  var ctxRef = { stateRef: useStateRef() };
1522
1506
  return cache$1([testObjects], context.bind(ctxRef, function () {
1507
+ var summary = genTestsSummary();
1523
1508
  var suiteName = useSuiteName();
1524
- return assign(genTestsSummary(), {
1525
- getErrors: context.bind(ctxRef, getErrors),
1526
- getErrorsByGroup: context.bind(ctxRef, getErrorsByGroup),
1527
- getWarnings: context.bind(ctxRef, getWarnings),
1528
- getWarningsByGroup: context.bind(ctxRef, getWarningsByGroup),
1529
- hasErrors: context.bind(ctxRef, hasErrors),
1530
- hasErrorsByGroup: context.bind(ctxRef, hasErrorsByGroup),
1531
- hasWarnings: context.bind(ctxRef, hasWarnings),
1532
- hasWarningsByGroup: context.bind(ctxRef, hasWarningsByGroup),
1533
- isValid: context.bind(ctxRef, isValid),
1509
+ var ref = { summary: summary };
1510
+ return assign(summary, {
1511
+ getErrors: context.bind(ref, getErrors),
1512
+ getErrorsByGroup: context.bind(ref, getErrorsByGroup),
1513
+ getWarnings: context.bind(ref, getWarnings),
1514
+ getWarningsByGroup: context.bind(ref, getWarningsByGroup),
1515
+ hasErrors: context.bind(ref, hasErrors),
1516
+ hasErrorsByGroup: context.bind(ref, hasErrorsByGroup),
1517
+ hasWarnings: context.bind(ref, hasWarnings),
1518
+ hasWarningsByGroup: context.bind(ref, hasWarningsByGroup),
1519
+ isValid: context.bind(ref, isValid),
1534
1520
  suiteName: suiteName
1535
1521
  });
1536
1522
  }));
@@ -1599,14 +1585,13 @@
1599
1585
  return output;
1600
1586
  };
1601
1587
  function deferDoneCallback(doneCallback, fieldName) {
1602
- var deferredCallback = context.bind({}, doneCallback);
1603
1588
  var _a = useTestCallbacks(), setTestCallbacks = _a[1];
1604
1589
  setTestCallbacks(function (current) {
1605
1590
  if (fieldName) {
1606
- current.fieldCallbacks[fieldName] = (current.fieldCallbacks[fieldName] || []).concat(deferredCallback);
1591
+ current.fieldCallbacks[fieldName] = (current.fieldCallbacks[fieldName] || []).concat(doneCallback);
1607
1592
  }
1608
1593
  else {
1609
- current.doneCallbacks.push(deferredCallback);
1594
+ current.doneCallbacks.push(doneCallback);
1610
1595
  }
1611
1596
  return current;
1612
1597
  });
@@ -1616,19 +1601,22 @@
1616
1601
  var listeners = {};
1617
1602
  return {
1618
1603
  emit: function (event, data) {
1619
- (listeners[event] || []).forEach(function (handler) {
1604
+ listener(event).forEach(function (handler) {
1620
1605
  handler(data);
1621
1606
  });
1622
1607
  },
1623
1608
  on: function (event, handler) {
1624
- listeners[event] = (listeners[event] || []).concat(handler);
1609
+ listeners[event] = listener(event).concat(handler);
1625
1610
  return {
1626
1611
  off: function () {
1627
- listeners[event] = listeners[event].filter(function (h) { return h !== handler; });
1612
+ listeners[event] = listener(event).filter(function (h) { return h !== handler; });
1628
1613
  }
1629
1614
  };
1630
1615
  }
1631
1616
  };
1617
+ function listener(event) {
1618
+ return listeners[event] || [];
1619
+ }
1632
1620
  }
1633
1621
 
1634
1622
  function omitOptionalTests() {
@@ -1640,24 +1628,27 @@
1640
1628
  useSetTests(function (tests) {
1641
1629
  return transform(tests, function (testObject) {
1642
1630
  var fieldName = testObject.fieldName;
1643
- if (shouldOmit.hasOwnProperty(fieldName)) {
1644
- omit(testObject);
1631
+ if (hasOwnProperty(shouldOmit, fieldName)) {
1632
+ verifyAndOmit(testObject);
1645
1633
  }
1646
1634
  else {
1647
- var optionalConfig = optionalFields[fieldName];
1648
- if (isFunction(optionalConfig)) {
1649
- shouldOmit[fieldName] = optionalConfig();
1650
- omit(testObject);
1651
- }
1635
+ runOptionalConfig(testObject);
1652
1636
  }
1653
1637
  return testObject;
1654
1638
  });
1655
1639
  });
1656
- function omit(testObject) {
1640
+ function verifyAndOmit(testObject) {
1657
1641
  if (shouldOmit[testObject.fieldName]) {
1658
1642
  testObject.omit();
1659
1643
  }
1660
1644
  }
1645
+ function runOptionalConfig(testObject) {
1646
+ var optionalConfig = optionalFields[testObject.fieldName];
1647
+ if (isFunction(optionalConfig)) {
1648
+ shouldOmit[testObject.fieldName] = optionalConfig();
1649
+ verifyAndOmit(testObject);
1650
+ }
1651
+ }
1661
1652
  }
1662
1653
 
1663
1654
  /**
@@ -1908,7 +1899,7 @@
1908
1899
  return keyTests[fieldName] === false;
1909
1900
  }
1910
1901
  }
1911
- if (isMissingFromIncludedGroup(groupName)) {
1902
+ if (isTopLevelWhenThereIsAnIncludedGroup(groupName)) {
1912
1903
  return true;
1913
1904
  }
1914
1905
  // if field is only'ed
@@ -1917,39 +1908,13 @@
1917
1908
  // If there is _ANY_ `only`ed test (and we already know this one isn't) return true
1918
1909
  if (hasIncludedTests(keyTests)) {
1919
1910
  // Check if inclusion rules for this field (`include` hook)
1911
+ // TODO: Check if this may need to be moved outside of the condition.
1912
+ // What if there are no included tests? This shouldn't run then?
1920
1913
  return !optionalFunctionValue(inclusion[fieldName]);
1921
1914
  }
1922
1915
  // We're done here. This field is not excluded
1923
1916
  return false;
1924
1917
  }
1925
- // eslint-disable-next-line max-statements
1926
- function isMissingFromIncludedGroup(groupName) {
1927
- var context$1 = context.useX();
1928
- var exclusion = context$1.exclusion;
1929
- if (!hasIncludedGroups()) {
1930
- return false;
1931
- }
1932
- if (!groupName) {
1933
- return true;
1934
- }
1935
- if (groupName in exclusion.groups) {
1936
- if (exclusion.groups[groupName]) {
1937
- return false;
1938
- }
1939
- return true;
1940
- }
1941
- return true;
1942
- }
1943
- function hasIncludedGroups() {
1944
- var context$1 = context.useX();
1945
- var exclusion = context$1.exclusion;
1946
- for (var group in exclusion.groups) {
1947
- if (exclusion.groups[group]) {
1948
- return true;
1949
- }
1950
- }
1951
- return false;
1952
- }
1953
1918
  /**
1954
1919
  * Checks whether a given group is excluded from running.
1955
1920
  */
@@ -1964,13 +1929,8 @@
1964
1929
  return keyGroups[groupName] === false;
1965
1930
  }
1966
1931
  // Group is not present
1967
- for (var group in keyGroups) {
1968
- // If any other group is only'ed
1969
- if (keyGroups[group] === true) {
1970
- return true;
1971
- }
1972
- }
1973
- return false;
1932
+ // Return whether other groups are included
1933
+ return hasIncludedGroups();
1974
1934
  }
1975
1935
  /**
1976
1936
  * Adds fields to a specified exclusion group.
@@ -1999,6 +1959,24 @@
1999
1959
  }
2000
1960
  return false;
2001
1961
  }
1962
+ // are we not in a group and there is an included group?
1963
+ function isTopLevelWhenThereIsAnIncludedGroup(groupName) {
1964
+ if (!hasIncludedGroups()) {
1965
+ return false;
1966
+ }
1967
+ // Return whether there's an included group, and we're not inside a group
1968
+ return !groupName;
1969
+ }
1970
+ function hasIncludedGroups() {
1971
+ var context$1 = context.useX();
1972
+ var exclusion = context$1.exclusion;
1973
+ for (var group in exclusion.groups) {
1974
+ if (exclusion.groups[group]) {
1975
+ return true;
1976
+ }
1977
+ }
1978
+ return false;
1979
+ }
2002
1980
 
2003
1981
  /**
2004
1982
  * Runs tests within a group so that they can be controlled or queried separately.
@@ -2024,16 +2002,18 @@
2024
2002
  function include(fieldName) {
2025
2003
  var context$1 = context.useX();
2026
2004
  var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
2027
- if (!fieldName) {
2028
- return { when: when };
2029
- }
2005
+ invariant(isStringValue(fieldName));
2030
2006
  inclusion[fieldName] = defaultTo(exclusion.tests[fieldName], true);
2031
2007
  return { when: when };
2032
2008
  function when(condition) {
2033
2009
  var context$1 = context.useX();
2034
2010
  var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
2011
+ // This callback will run as part of the "isExcluded" series of checks
2035
2012
  inclusion[fieldName] = function () {
2036
2013
  if (hasOwnProperty(exclusion.tests, fieldName)) {
2014
+ // I suspect this code is technically unreachable because
2015
+ // if there are any skip/only rules applied to the current
2016
+ // field, the "isExcluded" function will have already bailed
2037
2017
  return defaultTo(exclusion.tests[fieldName], true);
2038
2018
  }
2039
2019
  if (isStringValue(condition)) {
@@ -2067,7 +2047,7 @@
2067
2047
  setMode(Modes.EAGER);
2068
2048
  }
2069
2049
  function shouldSkipBasedOnMode(testObject) {
2070
- if (isEager() && hasErrors(testObject.fieldName))
2050
+ if (isEager() && hasErrorsByTestObjects(testObject.fieldName))
2071
2051
  return true;
2072
2052
  return false;
2073
2053
  }
@@ -2179,6 +2159,8 @@
2179
2159
  asyncTest.then(done, fail);
2180
2160
  }
2181
2161
  catch (e) {
2162
+ // We will probably never get here, unless the consumer uses a buggy custom Promise
2163
+ // implementation that behaves differently than the native one, or if they for some
2182
2164
  fail();
2183
2165
  }
2184
2166
  }
@@ -2187,22 +2169,7 @@
2187
2169
  * Runs sync tests - or extracts promise.
2188
2170
  */
2189
2171
  function runSyncTest(testObject) {
2190
- return context.run({ currentTest: testObject }, function () {
2191
- var result;
2192
- try {
2193
- result = testObject.testFn();
2194
- }
2195
- catch (e) {
2196
- if (shouldUseErrorAsMessage(testObject.message, e)) {
2197
- testObject.message = e;
2198
- }
2199
- result = false;
2200
- }
2201
- if (result === false) {
2202
- testObject.fail();
2203
- }
2204
- return result;
2205
- });
2172
+ return context.run({ currentTest: testObject }, function () { return testObject.run(); });
2206
2173
  }
2207
2174
 
2208
2175
  /**
@@ -2352,7 +2319,7 @@
2352
2319
  /* eslint-disable jest/valid-title */
2353
2320
  // eslint-disable-next-line max-lines-per-function
2354
2321
  function bindTestMemo(test) {
2355
- var cache = createCache(100); // arbitrary cache size
2322
+ var cache = createCache(10); // arbitrary cache size
2356
2323
  // eslint-disable-next-line max-statements
2357
2324
  function memo(fieldName) {
2358
2325
  var args = [];
@@ -2421,7 +2388,7 @@
2421
2388
  ctx.currentTest.warn();
2422
2389
  }
2423
2390
 
2424
- var VERSION = "4.2.3-dev-87ebfa";
2391
+ var VERSION = "4.3.2-dev-2805e3";
2425
2392
 
2426
2393
  exports.VERSION = VERSION;
2427
2394
  exports.context = context;