vest 4.2.1-dev-ee64be → 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 (35) 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 +322 -313
  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 +322 -313
  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 +279 -277
  28. package/dist/umd/vest.production.js +1 -1
  29. package/package.json +1 -1
  30. package/testUtils/mockThrowError.ts +3 -6
  31. package/testUtils/suiteDummy.ts +5 -5
  32. package/types/classnames.d.ts +9 -8
  33. package/types/parser.d.ts +9 -8
  34. package/types/promisify.d.ts +9 -8
  35. package/types/vest.d.ts +69 -68
@@ -343,16 +343,18 @@
343
343
  return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
344
344
  }
345
345
 
346
- /**
347
- * Throws a timed out error.
348
- */
349
- function throwError(devMessage, productionMessage) {
350
- throw new Error(devMessage );
351
- }
352
- function throwErrorDeferred(devMessage, productionMessage) {
353
- setTimeout(function () {
354
- throwError(devMessage);
355
- }, 0);
346
+ function invariant(condition,
347
+ // eslint-disable-next-line @typescript-eslint/ban-types
348
+ message) {
349
+ if (condition) {
350
+ return;
351
+ }
352
+ // If message is a string object (rather than string literal)
353
+ // Throw the value directly as a string
354
+ // Alternatively, throw an error with the message
355
+ throw message instanceof String
356
+ ? message.valueOf()
357
+ : new Error(message ? optionalFunctionValue(message) : message);
356
358
  }
357
359
 
358
360
  // eslint-disable-next-line max-lines-per-function
@@ -365,8 +367,8 @@
365
367
  useX: useX
366
368
  };
367
369
  function useX(errorMessage) {
368
- var _a;
369
- return ((_a = storage.ctx) !== null && _a !== void 0 ? _a : throwError(defaultTo(errorMessage, 'Context was used after it was closed')));
370
+ invariant(storage.ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
371
+ return storage.ctx;
370
372
  }
371
373
  function run(ctxRef, fn) {
372
374
  var _a;
@@ -514,10 +516,7 @@
514
516
  }
515
517
  function validateResult(result) {
516
518
  // if result is boolean, or if result.pass is boolean
517
- if (isBoolean(result) || (result && isBoolean(result.pass))) {
518
- return;
519
- }
520
- throwError('Incorrect return value for rule: ' + JSON.stringify(result));
519
+ invariant(isBoolean(result) || (result && isBoolean(result.pass)), 'Incorrect return value for rule: ' + JSON.stringify(result));
521
520
  }
522
521
 
523
522
  function enforceEager(value) {
@@ -546,15 +545,9 @@
546
545
  var transformedResult = transformResult.apply(void 0, __spreadArray([ctx.run({ value: value }, function () { return rule.apply(void 0, __spreadArray([value], args, false)); }),
547
546
  ruleName,
548
547
  value], args, false));
549
- if (!transformedResult.pass) {
550
- if (isEmpty(transformedResult.message)) {
551
- throwError("enforce/".concat(ruleName, " failed with ").concat(JSON.stringify(value)));
552
- }
553
- else {
554
- // Explicitly throw a string so that vest.test can pick it up as the validation error message
555
- throw transformedResult.message;
556
- }
557
- }
548
+ invariant(transformedResult.pass, isEmpty(transformedResult.message)
549
+ ? "enforce/".concat(ruleName, " failed with ").concat(JSON.stringify(value))
550
+ : new String(transformedResult.message));
558
551
  return target;
559
552
  };
560
553
  }
@@ -693,100 +686,106 @@
693
686
  return "".concat(n++);
694
687
  }; })(0);
695
688
 
696
- function shouldUseErrorAsMessage(message, error) {
697
- // kind of cheating with this safe guard, but it does the job
698
- return isUndefined(message) && isStringValue(error);
699
- }
700
-
701
- function asArray(possibleArg) {
702
- return [].concat(possibleArg);
703
- }
704
-
705
- /**
706
- * Creates a cache function
707
- */
708
- function createCache(maxSize) {
709
- if (maxSize === void 0) { maxSize = 1; }
710
- var cacheStorage = [];
711
- var cache = function (deps, cacheAction) {
712
- var cacheHit = cache.get(deps);
713
- // cache hit is not null
714
- if (cacheHit)
715
- return cacheHit[1];
716
- var result = cacheAction();
717
- cacheStorage.unshift([deps.concat(), result]);
718
- if (longerThan(cacheStorage, maxSize))
719
- cacheStorage.length = maxSize;
720
- return result;
721
- };
722
- // invalidate an item in the cache by its dependencies
723
- cache.invalidate = function (deps) {
724
- var index = findIndex(deps);
725
- if (index > -1)
726
- cacheStorage.splice(index, 1);
689
+ // eslint-disable-next-line max-lines-per-function
690
+ function createState(onStateChange) {
691
+ var state = {
692
+ references: []
727
693
  };
728
- // Retrieves an item from the cache.
729
- cache.get = function (deps) {
730
- return cacheStorage[findIndex(deps)] || null;
694
+ var registrations = [];
695
+ return {
696
+ registerStateKey: registerStateKey,
697
+ reset: reset
731
698
  };
732
- return cache;
733
- function findIndex(deps) {
734
- return cacheStorage.findIndex(function (_a) {
735
- var cachedDeps = _a[0];
736
- return lengthEquals(deps, cachedDeps.length) &&
737
- deps.every(function (dep, i) { return dep === cachedDeps[i]; });
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]);
738
723
  });
739
724
  }
740
- }
741
-
742
- function last(values) {
743
- var valuesArray = asArray(values);
744
- return valuesArray[valuesArray.length - 1];
745
- }
746
-
747
- // This is kind of a map/filter in one function.
748
- // Normally, behaves like a nested-array map,
749
- // but returning `null` will drop the element from the array
750
- function transform(array, cb) {
751
- var res = [];
752
- for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
753
- var v = array_1[_i];
754
- if (isArray(v)) {
755
- res.push(transform(v, cb));
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);
756
746
  }
757
- else {
758
- var output = cb(v);
759
- if (isNotNull(output)) {
760
- res.push(output);
761
- }
747
+ if (isFunction(onStateChange)) {
748
+ onStateChange();
762
749
  }
763
750
  }
764
- return res;
765
751
  }
766
- function valueAtPath(array, path) {
767
- return getCurrent(array, path)[last(path)];
768
- }
769
- function setValueAtPath(array, path, value) {
770
- var current = getCurrent(array, path);
771
- current[last(path)] = value;
772
- return array;
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
+ };
773
780
  }
774
- function flatten(values) {
775
- return asArray(values).reduce(function (acc, value) {
776
- if (isArray(value)) {
777
- return acc.concat(flatten(value));
778
- }
779
- return asArray(acc).concat(value);
780
- }, []);
781
+
782
+ function asArray(possibleArg) {
783
+ return [].concat(possibleArg);
781
784
  }
782
- function getCurrent(array, path) {
783
- var current = array;
784
- for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) {
785
- var p = _a[_i];
786
- current[p] = defaultTo(current[p], []);
787
- current = current[p];
788
- }
789
- return current;
785
+
786
+ function last(values) {
787
+ var valuesArray = asArray(values);
788
+ return valuesArray[valuesArray.length - 1];
790
789
  }
791
790
 
792
791
  function createCursor() {
@@ -823,16 +822,6 @@
823
822
  };
824
823
  }
825
824
 
826
- var IsolateTypes;
827
- (function (IsolateTypes) {
828
- IsolateTypes[IsolateTypes["DEFAULT"] = 0] = "DEFAULT";
829
- IsolateTypes[IsolateTypes["SUITE"] = 1] = "SUITE";
830
- IsolateTypes[IsolateTypes["EACH"] = 2] = "EACH";
831
- IsolateTypes[IsolateTypes["SKIP_WHEN"] = 3] = "SKIP_WHEN";
832
- IsolateTypes[IsolateTypes["OMIT_WHEN"] = 4] = "OMIT_WHEN";
833
- IsolateTypes[IsolateTypes["GROUP"] = 5] = "GROUP";
834
- })(IsolateTypes || (IsolateTypes = {}));
835
-
836
825
  var Modes;
837
826
  (function (Modes) {
838
827
  Modes[Modes["ALL"] = 0] = "ALL";
@@ -860,6 +849,99 @@
860
849
  }, ctxRef);
861
850
  });
862
851
 
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
+
863
945
  // STATE REF
864
946
  function useStateRef() {
865
947
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -1075,89 +1157,6 @@
1075
1157
  var STATUS_CANCELED = 'CANCELED';
1076
1158
  var STATUS_OMITTED = 'OMITTED';
1077
1159
 
1078
- // eslint-disable-next-line max-lines-per-function
1079
- function createState(onStateChange) {
1080
- var state = {
1081
- references: []
1082
- };
1083
- var registrations = [];
1084
- return {
1085
- registerStateKey: registerStateKey,
1086
- reset: reset
1087
- };
1088
- /**
1089
- * Registers a new key in the state, takes the initial value (may be a function that returns the initial value), returns a function.
1090
- *
1091
- * @example
1092
- *
1093
- * const useColor = state.registerStateKey("blue");
1094
- *
1095
- * let [color, setColor] = useColor(); // -> ["blue", Function]
1096
- *
1097
- * setColor("green");
1098
- *
1099
- * useColor()[0]; -> "green"
1100
- */
1101
- function registerStateKey(initialState, onUpdate) {
1102
- var key = registrations.length;
1103
- registrations.push([initialState, onUpdate]);
1104
- return initKey(key, initialState);
1105
- }
1106
- function reset() {
1107
- var prev = current();
1108
- state.references = [];
1109
- registrations.forEach(function (_a, index) {
1110
- var initialValue = _a[0];
1111
- return initKey(index, initialValue, prev[index]);
1112
- });
1113
- }
1114
- function initKey(key, initialState, prevState) {
1115
- current().push();
1116
- set(key, optionalFunctionValue(initialState, prevState));
1117
- return function useStateKey() {
1118
- return [
1119
- current()[key],
1120
- function (nextState) {
1121
- return set(key, optionalFunctionValue(nextState, current()[key]));
1122
- },
1123
- ];
1124
- };
1125
- }
1126
- function current() {
1127
- return state.references;
1128
- }
1129
- function set(index, value) {
1130
- var prevValue = state.references[index];
1131
- state.references[index] = value;
1132
- var _a = registrations[index], onUpdate = _a[1];
1133
- if (isFunction(onUpdate)) {
1134
- onUpdate(value, prevValue);
1135
- }
1136
- if (isFunction(onStateChange)) {
1137
- onStateChange();
1138
- }
1139
- }
1140
- }
1141
-
1142
- function createStateRef(state, _a) {
1143
- var suiteId = _a.suiteId, suiteName = _a.suiteName;
1144
- return {
1145
- optionalFields: state.registerStateKey(function () { return ({}); }),
1146
- suiteId: state.registerStateKey(suiteId),
1147
- suiteName: state.registerStateKey(suiteName),
1148
- testCallbacks: state.registerStateKey(function () { return ({
1149
- fieldCallbacks: {},
1150
- doneCallbacks: []
1151
- }); }),
1152
- testObjects: state.registerStateKey(function (prev) {
1153
- return {
1154
- prev: prev ? prev.current : [],
1155
- current: []
1156
- };
1157
- })
1158
- };
1159
- }
1160
-
1161
1160
  function usePath() {
1162
1161
  var context$1 = context.useX();
1163
1162
  return context$1.testCursor.getCursor();
@@ -1203,7 +1202,7 @@
1203
1202
  current[key] = testObject;
1204
1203
  }
1205
1204
  else {
1206
- 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."));
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."));
1207
1206
  }
1208
1207
  }
1209
1208
 
@@ -1236,6 +1235,11 @@
1236
1235
  Severity["WARNINGS"] = "warnings";
1237
1236
  Severity["ERRORS"] = "errors";
1238
1237
  })(Severity || (Severity = {}));
1238
+ var SeverityCount;
1239
+ (function (SeverityCount) {
1240
+ SeverityCount["ERROR_COUNT"] = "errorCount";
1241
+ SeverityCount["WARN_COUNT"] = "warnCount";
1242
+ })(SeverityCount || (SeverityCount = {}));
1239
1243
 
1240
1244
  /**
1241
1245
  * Reads the testObjects list and gets full validation result from it.
@@ -1246,18 +1250,26 @@
1246
1250
  groups: {},
1247
1251
  tests: {}
1248
1252
  });
1249
- appendSummary(testObjects);
1253
+ testObjects.reduce(function (summary, testObject) {
1254
+ appendToTest(summary.tests, testObject);
1255
+ appendToGroup(summary.groups, testObject);
1256
+ return summary;
1257
+ }, summary);
1250
1258
  return countFailures(summary);
1251
- function appendSummary(testObjects) {
1252
- testObjects.forEach(function (testObject) {
1253
- var fieldName = testObject.fieldName, groupName = testObject.groupName;
1254
- summary.tests[fieldName] = genTestObject(summary.tests, testObject);
1255
- if (groupName) {
1256
- summary.groups[groupName] = summary.groups[groupName] || {};
1257
- summary.groups[groupName][fieldName] = genTestObject(summary.groups[groupName], testObject);
1258
- }
1259
- });
1259
+ }
1260
+ function appendToTest(tests, testObject) {
1261
+ tests[testObject.fieldName] = appendTestObject(tests, testObject);
1262
+ }
1263
+ /**
1264
+ * Appends to a group object if within a group
1265
+ */
1266
+ function appendToGroup(groups, testObject) {
1267
+ var groupName = testObject.groupName;
1268
+ if (!groupName) {
1269
+ return;
1260
1270
  }
1271
+ groups[groupName] = groups[groupName] || {};
1272
+ groups[groupName][testObject.fieldName] = appendTestObject(groups[groupName], testObject);
1261
1273
  }
1262
1274
  /**
1263
1275
  * Counts the failed tests and adds global counters
@@ -1270,29 +1282,36 @@
1270
1282
  }
1271
1283
  return summary;
1272
1284
  }
1285
+ /**
1286
+ * Appends the test to a results object
1287
+ */
1273
1288
  // eslint-disable-next-line max-statements
1274
- function genTestObject(summaryKey, testObject) {
1289
+ function appendTestObject(summaryKey, testObject) {
1275
1290
  var fieldName = testObject.fieldName, message = testObject.message;
1276
1291
  summaryKey[fieldName] = summaryKey[fieldName] || baseStats();
1277
1292
  var testKey = summaryKey[fieldName];
1278
1293
  if (testObject.isNonActionable())
1279
1294
  return testKey;
1280
1295
  summaryKey[fieldName].testCount++;
1281
- // Adds to severity group
1282
- function addTo(severity) {
1283
- var countKey = severity === Severity.ERRORS ? 'errorCount' : 'warnCount';
1284
- testKey[countKey]++;
1285
- if (message) {
1286
- testKey[severity] = (testKey[severity] || []).concat(message);
1287
- }
1288
- }
1289
1296
  if (testObject.isFailing()) {
1290
- addTo(Severity.ERRORS);
1297
+ incrementFailures(Severity.ERRORS);
1291
1298
  }
1292
1299
  else if (testObject.isWarning()) {
1293
- addTo(Severity.WARNINGS);
1300
+ incrementFailures(Severity.WARNINGS);
1294
1301
  }
1295
1302
  return testKey;
1303
+ function incrementFailures(severity) {
1304
+ var countKey = getCountKey(severity);
1305
+ testKey[countKey]++;
1306
+ if (message) {
1307
+ testKey[severity] = (testKey[severity] || []).concat(message);
1308
+ }
1309
+ }
1310
+ }
1311
+ function getCountKey(severity) {
1312
+ return severity === Severity.ERRORS
1313
+ ? SeverityCount.ERROR_COUNT
1314
+ : SeverityCount.WARN_COUNT;
1296
1315
  }
1297
1316
  function baseStats() {
1298
1317
  return {
@@ -1387,9 +1406,7 @@
1387
1406
  * Gets failure messages by group.
1388
1407
  */
1389
1408
  function getByGroup(severityKey, group, fieldName) {
1390
- if (!group) {
1391
- throwError("get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
1392
- }
1409
+ invariant(group, "get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
1393
1410
  var testObjects = useTestsFlat();
1394
1411
  return collectFailureMessages(severityKey, testObjects, {
1395
1412
  group: group,
@@ -1445,18 +1462,18 @@
1445
1462
  }
1446
1463
 
1447
1464
  // eslint-disable-next-line max-statements, complexity
1448
- function isValid(result, fieldName) {
1465
+ function isValid(fieldName) {
1449
1466
  if (fieldIsOmitted(fieldName)) {
1450
1467
  return true;
1451
1468
  }
1452
- if (result.hasErrors(fieldName)) {
1469
+ if (hasErrors(fieldName)) {
1453
1470
  return false;
1454
1471
  }
1455
1472
  var testObjects = useTestsFlat();
1456
1473
  if (isEmpty(testObjects)) {
1457
1474
  return false;
1458
1475
  }
1459
- if (fieldDoesNotExist(result, fieldName)) {
1476
+ if (fieldDoesNotExist(fieldName)) {
1460
1477
  return false;
1461
1478
  }
1462
1479
  if (hasNonOptionalIncomplete(fieldName)) {
@@ -1480,8 +1497,10 @@
1480
1497
  return optionalFields[testObject.fieldName] !== true;
1481
1498
  }));
1482
1499
  }
1483
- function fieldDoesNotExist(result, fieldName) {
1484
- return !!fieldName && isEmpty(result.tests[fieldName]);
1500
+ function fieldDoesNotExist(fieldName) {
1501
+ var testObjects = useTestsFlat();
1502
+ return (!!fieldName &&
1503
+ !testObjects.find(function (testObject) { return testObject.fieldName === fieldName; }));
1485
1504
  }
1486
1505
  function noMissingTests(fieldName) {
1487
1506
  var testObjects = useTestsFlat();
@@ -1497,7 +1516,7 @@
1497
1516
  }
1498
1517
 
1499
1518
  var cache$1 = createCache(20);
1500
- function produceBase() {
1519
+ function produceSuiteResult() {
1501
1520
  var testObjects = useTestsFlat();
1502
1521
  var ctxRef = { stateRef: useStateRef() };
1503
1522
  return cache$1([testObjects], context.bind(ctxRef, function () {
@@ -1511,9 +1530,7 @@
1511
1530
  hasErrorsByGroup: context.bind(ctxRef, hasErrorsByGroup),
1512
1531
  hasWarnings: context.bind(ctxRef, hasWarnings),
1513
1532
  hasWarningsByGroup: context.bind(ctxRef, hasWarningsByGroup),
1514
- isValid: context.bind(ctxRef, function (fieldName) {
1515
- return isValid(produceBase(), fieldName);
1516
- }),
1533
+ isValid: context.bind(ctxRef, isValid),
1517
1534
  suiteName: suiteName
1518
1535
  });
1519
1536
  }));
@@ -1540,7 +1557,7 @@
1540
1557
  var testObjects = useTestsFlat();
1541
1558
  var ctxRef = { stateRef: useStateRef() };
1542
1559
  return cache([testObjects], context.bind(ctxRef, function () {
1543
- return assign({}, produceBase(), {
1560
+ return assign({}, produceSuiteResult(), {
1544
1561
  done: context.bind(ctxRef, done)
1545
1562
  });
1546
1563
  }));
@@ -1573,7 +1590,7 @@
1573
1590
  if (shouldSkipDoneRegistration(callback, fieldName, output)) {
1574
1591
  return output;
1575
1592
  }
1576
- var doneCallback = function () { return callback(produceBase()); };
1593
+ var doneCallback = function () { return callback(produceSuiteResult()); };
1577
1594
  if (shouldRunDoneCallback(fieldName)) {
1578
1595
  doneCallback();
1579
1596
  return output;
@@ -1722,9 +1739,7 @@
1722
1739
  }
1723
1740
  function useBus() {
1724
1741
  var context$1 = context.useX();
1725
- if (!context$1.bus) {
1726
- throwError();
1727
- }
1742
+ invariant(context$1.bus);
1728
1743
  return context$1.bus;
1729
1744
  }
1730
1745
  var Events;
@@ -1743,9 +1758,7 @@
1743
1758
  args[_i] = arguments[_i];
1744
1759
  }
1745
1760
  var _a = args.reverse(), suiteCallback = _a[0], suiteName = _a[1];
1746
- if (!isFunction(suiteCallback)) {
1747
- throwError('vest.create: Expected callback to be a function.');
1748
- }
1761
+ invariant(isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
1749
1762
  // Event bus initialization
1750
1763
  var bus = initBus();
1751
1764
  // State initialization
@@ -1774,7 +1787,7 @@
1774
1787
  // Return the result
1775
1788
  return produceFullResult();
1776
1789
  }), {
1777
- get: context.bind(ctxRef, produceBase),
1790
+ get: context.bind(ctxRef, produceSuiteResult),
1778
1791
  remove: context.bind(ctxRef, function (fieldName) {
1779
1792
  bus.emit(Events.REMOVE_FIELD, fieldName);
1780
1793
  }),
@@ -1800,9 +1813,7 @@
1800
1813
  * })
1801
1814
  */
1802
1815
  function each(list, callback) {
1803
- if (!isFunction(callback)) {
1804
- throwError('each callback must be a function');
1805
- }
1816
+ invariant(isFunction(callback), 'each callback must be a function');
1806
1817
  isolate({ type: IsolateTypes.EACH }, function () {
1807
1818
  list.forEach(function (arg, index) {
1808
1819
  callback(arg, index);
@@ -1832,7 +1843,7 @@
1832
1843
  // we should skip the test if the parent conditional is true.
1833
1844
  isExcludedIndividually() ||
1834
1845
  // Otherwise, we should skip the test if the conditional is true.
1835
- optionalFunctionValue(conditional, optionalFunctionValue(produceBase))
1846
+ optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
1836
1847
  }, function () { return callback(); });
1837
1848
  });
1838
1849
  }
@@ -1999,19 +2010,15 @@
1999
2010
  * });
2000
2011
  */
2001
2012
  function group(groupName, tests) {
2002
- if (!isStringValue(groupName)) {
2003
- throwGroupError('name must be a string');
2004
- }
2005
- if (!isFunction(tests)) {
2006
- throwGroupError('callback must be a function');
2007
- }
2013
+ invariant(isStringValue(groupName), groupErrorMsg('name must be a string'));
2014
+ invariant(isFunction(tests), groupErrorMsg('callback must be a function'));
2008
2015
  // Running with the context applied
2009
2016
  isolate({ type: IsolateTypes.GROUP }, function () {
2010
2017
  context.run({ groupName: groupName }, tests);
2011
2018
  });
2012
2019
  }
2013
- function throwGroupError(error) {
2014
- throwError("Wrong arguments passed to group. Group ".concat(error, "."));
2020
+ function groupErrorMsg(error) {
2021
+ return "Wrong arguments passed to group. Group ".concat(error, ".");
2015
2022
  }
2016
2023
 
2017
2024
  function include(fieldName) {
@@ -2032,7 +2039,7 @@
2032
2039
  if (isStringValue(condition)) {
2033
2040
  return Boolean(exclusion.tests[condition]);
2034
2041
  }
2035
- return optionalFunctionValue(condition, optionalFunctionValue(produceBase));
2042
+ return optionalFunctionValue(condition, optionalFunctionValue(produceSuiteResult));
2036
2043
  };
2037
2044
  }
2038
2045
  }
@@ -2089,7 +2096,7 @@
2089
2096
  isolate({ type: IsolateTypes.OMIT_WHEN }, function () {
2090
2097
  context.run({
2091
2098
  omitted: isOmitted() ||
2092
- optionalFunctionValue(conditional, optionalFunctionValue(produceBase))
2099
+ optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
2093
2100
  }, function () { return callback(); });
2094
2101
  });
2095
2102
  }
@@ -2220,7 +2227,7 @@
2220
2227
  }
2221
2228
  }
2222
2229
  catch (e) {
2223
- throwError("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(testObject), ".\n Error: ").concat(e, "."));
2230
+ throw new Error("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(testObject), ".\n Error: ").concat(e, "."));
2224
2231
  }
2225
2232
  }
2226
2233
 
@@ -2247,7 +2254,7 @@
2247
2254
  useSetTestAtCursor(nextTest_1);
2248
2255
  return nextTest_1;
2249
2256
  }
2250
- if (shouldPurgePrevTest(prevTest, newTestObject)) {
2257
+ if (testReorderDetected(prevTest, newTestObject)) {
2251
2258
  throwTestOrderError(prevTest, newTestObject);
2252
2259
  removeAllNextTestsInIsolate();
2253
2260
  // Need to see if this has any effect at all.
@@ -2284,14 +2291,14 @@
2284
2291
  var cursorPath = usePath();
2285
2292
  return valueAtPath(tests, cursorPath);
2286
2293
  }
2287
- function shouldPurgePrevTest(prevTest, newTest) {
2294
+ function testReorderDetected(prevTest, newTest) {
2288
2295
  return isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
2289
2296
  }
2290
2297
  function throwTestOrderError(prevTest, newTestObject) {
2291
2298
  if (shouldAllowReorder()) {
2292
2299
  return;
2293
2300
  }
2294
- 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."));
2301
+ 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."));
2295
2302
  }
2296
2303
  function handleKeyTest(key, newTestObject) {
2297
2304
  var prevTestByKey = usePrevTestByKey(key);
@@ -2305,12 +2312,13 @@
2305
2312
 
2306
2313
  // eslint-disable-next-line max-statements
2307
2314
  function registerPrevRunTest(testObject) {
2308
- var prevRunTest = useTestAtCursor(testObject);
2309
2315
  if (shouldSkipBasedOnMode(testObject)) {
2310
- moveForward();
2311
2316
  testObject.skip();
2317
+ useTestAtCursor(testObject);
2318
+ moveForward();
2312
2319
  return testObject;
2313
2320
  }
2321
+ var prevRunTest = useTestAtCursor(testObject);
2314
2322
  if (isOmitted()) {
2315
2323
  prevRunTest.omit();
2316
2324
  moveForward();
@@ -2376,12 +2384,8 @@
2376
2384
  args[_i - 1] = arguments[_i];
2377
2385
  }
2378
2386
  var _a = (isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
2379
- if (isNotString(fieldName)) {
2380
- throwIncompatibleParamsError('fieldName', 'string');
2381
- }
2382
- if (!isFunction(testFn)) {
2383
- throwIncompatibleParamsError('Test callback', 'function');
2384
- }
2387
+ invariant(isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
2388
+ invariant(isFunction(testFn), incompatibleParamsError('Test callback', 'function'));
2385
2389
  var context$1 = context.useX();
2386
2390
  var testObject = new VestTest(fieldName, testFn, {
2387
2391
  message: message,
@@ -2402,8 +2406,8 @@
2402
2406
  var test = assign(testBase, {
2403
2407
  memo: bindTestMemo(testBase)
2404
2408
  });
2405
- function throwIncompatibleParamsError(name, expected) {
2406
- throwError("Incompatible params passed to test function. ".concat(name, " must be a ").concat(expected));
2409
+ function incompatibleParamsError(name, expected) {
2410
+ return "Incompatible params passed to test function. ".concat(name, " must be a ").concat(expected);
2407
2411
  }
2408
2412
 
2409
2413
  var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won't have an effect."
@@ -2413,13 +2417,11 @@
2413
2417
  */
2414
2418
  function warn() {
2415
2419
  var ctx = context.useX('warn ' + ERROR_HOOK_CALLED_OUTSIDE);
2416
- if (!ctx.currentTest) {
2417
- throwError(ERROR_OUTSIDE_OF_TEST);
2418
- }
2420
+ invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
2419
2421
  ctx.currentTest.warn();
2420
2422
  }
2421
2423
 
2422
- var VERSION = "4.2.1-dev-ee64be";
2424
+ var VERSION = "4.2.3-dev-87ebfa";
2423
2425
 
2424
2426
  exports.VERSION = VERSION;
2425
2427
  exports.context = context;