vest 4.2.1 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/cjs/classnames.development.js +76 -28
  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/parser.development.js +84 -22
  6. package/dist/cjs/parser.production.js +1 -1
  7. package/dist/cjs/promisify.development.js +21 -8
  8. package/dist/cjs/promisify.production.js +1 -1
  9. package/dist/cjs/vest.development.js +219 -203
  10. package/dist/cjs/vest.production.js +1 -1
  11. package/dist/es/classnames.development.js +76 -28
  12. package/dist/es/classnames.production.js +1 -1
  13. package/dist/es/enforce/compose.development.js +27 -59
  14. package/dist/es/enforce/compose.production.js +1 -1
  15. package/dist/es/parser.development.js +84 -22
  16. package/dist/es/parser.production.js +1 -1
  17. package/dist/es/promisify.development.js +21 -8
  18. package/dist/es/promisify.production.js +1 -1
  19. package/dist/es/vest.development.js +219 -203
  20. package/dist/es/vest.production.js +1 -1
  21. package/dist/umd/classnames.development.js +76 -28
  22. package/dist/umd/classnames.production.js +1 -1
  23. package/dist/umd/enforce/compose.development.js +89 -99
  24. package/dist/umd/enforce/compose.production.js +1 -1
  25. package/dist/umd/enforce/compounds.development.js +34 -36
  26. package/dist/umd/enforce/compounds.production.js +1 -1
  27. package/dist/umd/enforce/schema.development.js +34 -36
  28. package/dist/umd/enforce/schema.production.js +1 -1
  29. package/dist/umd/parser.development.js +84 -22
  30. package/dist/umd/parser.production.js +1 -1
  31. package/dist/umd/promisify.development.js +21 -8
  32. package/dist/umd/promisify.production.js +1 -1
  33. package/dist/umd/vest.development.js +213 -204
  34. package/dist/umd/vest.production.js +1 -1
  35. package/package.json +3 -3
  36. package/testUtils/mockThrowError.ts +3 -6
  37. package/testUtils/suiteDummy.ts +5 -1
  38. package/types/classnames.d.ts +13 -54
  39. package/types/enforce/compose.d.ts +2 -1
  40. package/types/enforce/compounds.d.ts +2 -1
  41. package/types/enforce/schema.d.ts +2 -1
  42. package/types/parser.d.ts +12 -53
  43. package/types/promisify.d.ts +12 -9
  44. package/types/vest.d.ts +17 -14
@@ -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) {
@@ -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,10 +206,6 @@
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
210
  return value.length > Number(arg1);
206
211
  }
@@ -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);
@@ -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
  }
@@ -1158,6 +1151,12 @@
1158
1151
  };
1159
1152
  }
1160
1153
 
1154
+ function deferThrow(message) {
1155
+ setTimeout(function () {
1156
+ throw new Error(message);
1157
+ }, 0);
1158
+ }
1159
+
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,112 @@
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 = {}));
1243
+
1244
+ function nonMatchingFieldName(testObject, fieldName) {
1245
+ return !!fieldName && !matchingFieldName(testObject, fieldName);
1246
+ }
1247
+ function matchingFieldName(testObject, fieldName) {
1248
+ return !!(fieldName && testObject.fieldName === fieldName);
1249
+ }
1250
+
1251
+ function either(a, b) {
1252
+ return !!a !== !!b;
1253
+ }
1254
+
1255
+ /**
1256
+ * Checks that a given test object matches the currently specified severity level
1257
+ */
1258
+ function nonMatchingSeverityProfile(severity, testObject) {
1259
+ return either(severity === Severity.WARNINGS, testObject.warns());
1260
+ }
1261
+
1262
+ /**
1263
+ * Determines whether a certain test profile has failures.
1264
+ */
1265
+ function hasFailuresLogic(testObject, severityKey, fieldName) {
1266
+ if (!testObject.hasFailures()) {
1267
+ return false;
1268
+ }
1269
+ if (nonMatchingFieldName(testObject, fieldName)) {
1270
+ return false;
1271
+ }
1272
+ if (nonMatchingSeverityProfile(severityKey, testObject)) {
1273
+ return false;
1274
+ }
1275
+ return true;
1276
+ }
1277
+
1278
+ function hasErrors(fieldName) {
1279
+ return has(Severity.ERRORS, fieldName);
1280
+ }
1281
+ function hasWarnings(fieldName) {
1282
+ return has(Severity.WARNINGS, fieldName);
1283
+ }
1284
+ function has(severityKey, fieldName) {
1285
+ var testObjects = useTestsFlat();
1286
+ return testObjects.some(function (testObject) {
1287
+ return hasFailuresLogic(testObject, severityKey, fieldName);
1288
+ });
1289
+ }
1290
+
1291
+ // eslint-disable-next-line max-statements, complexity
1292
+ function isValid(fieldName) {
1293
+ if (fieldIsOmitted(fieldName)) {
1294
+ return true;
1295
+ }
1296
+ if (hasErrors(fieldName)) {
1297
+ return false;
1298
+ }
1299
+ var testObjects = useTestsFlat();
1300
+ if (isEmpty(testObjects)) {
1301
+ return false;
1302
+ }
1303
+ if (fieldDoesNotExist(fieldName)) {
1304
+ return false;
1305
+ }
1306
+ if (hasNonOptionalIncomplete(fieldName)) {
1307
+ return false;
1308
+ }
1309
+ return noMissingTests(fieldName);
1310
+ }
1311
+ function fieldIsOmitted(fieldName) {
1312
+ var omittedFields = useOmittedFields();
1313
+ if (!fieldName) {
1314
+ return false;
1315
+ }
1316
+ return !!omittedFields[fieldName];
1317
+ }
1318
+ function hasNonOptionalIncomplete(fieldName) {
1319
+ var optionalFields = useOptionalFields()[0];
1320
+ return isNotEmpty(useAllIncomplete().filter(function (testObject) {
1321
+ if (nonMatchingFieldName(testObject, fieldName)) {
1322
+ return false;
1323
+ }
1324
+ return optionalFields[testObject.fieldName] !== true;
1325
+ }));
1326
+ }
1327
+ function fieldDoesNotExist(fieldName) {
1328
+ var testObjects = useTestsFlat();
1329
+ return (!!fieldName &&
1330
+ !testObjects.find(function (testObject) { return testObject.fieldName === fieldName; }));
1331
+ }
1332
+ function noMissingTests(fieldName) {
1333
+ var testObjects = useTestsFlat();
1334
+ var optionalFields = useOptionalFields()[0];
1335
+ return testObjects.every(function (testObject) {
1336
+ if (nonMatchingFieldName(testObject, fieldName)) {
1337
+ return true;
1338
+ }
1339
+ return (optionalFields[testObject.fieldName] === true ||
1340
+ testObject.isTested() ||
1341
+ testObject.isOmitted());
1342
+ });
1343
+ }
1239
1344
 
1240
1345
  /**
1241
1346
  * Reads the testObjects list and gets full validation result from it.
@@ -1244,20 +1349,35 @@
1244
1349
  var testObjects = useTestsFlat();
1245
1350
  var summary = assign(baseStats(), {
1246
1351
  groups: {},
1247
- tests: {}
1352
+ tests: {},
1353
+ valid: false
1248
1354
  });
1249
- appendSummary(testObjects);
1355
+ testObjects.reduce(function (summary, testObject) {
1356
+ appendToTest(summary.tests, testObject);
1357
+ appendToGroup(summary.groups, testObject);
1358
+ return summary;
1359
+ }, summary);
1360
+ summary.valid = isValid();
1250
1361
  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
- });
1362
+ }
1363
+ function appendToTest(tests, testObject) {
1364
+ tests[testObject.fieldName] = appendTestObject(tests, testObject);
1365
+ // If `valid` is false to begin with, keep it that way. Otherwise, assess.
1366
+ tests[testObject.fieldName].valid =
1367
+ tests[testObject.fieldName].valid === false
1368
+ ? false
1369
+ : isValid(testObject.fieldName);
1370
+ }
1371
+ /**
1372
+ * Appends to a group object if within a group
1373
+ */
1374
+ function appendToGroup(groups, testObject) {
1375
+ var groupName = testObject.groupName;
1376
+ if (!groupName) {
1377
+ return;
1260
1378
  }
1379
+ groups[groupName] = groups[groupName] || {};
1380
+ groups[groupName][testObject.fieldName] = appendTestObject(groups[groupName], testObject);
1261
1381
  }
1262
1382
  /**
1263
1383
  * Counts the failed tests and adds global counters
@@ -1270,29 +1390,36 @@
1270
1390
  }
1271
1391
  return summary;
1272
1392
  }
1393
+ /**
1394
+ * Appends the test to a results object
1395
+ */
1273
1396
  // eslint-disable-next-line max-statements
1274
- function genTestObject(summaryKey, testObject) {
1397
+ function appendTestObject(summaryKey, testObject) {
1275
1398
  var fieldName = testObject.fieldName, message = testObject.message;
1276
1399
  summaryKey[fieldName] = summaryKey[fieldName] || baseStats();
1277
1400
  var testKey = summaryKey[fieldName];
1278
1401
  if (testObject.isNonActionable())
1279
1402
  return testKey;
1280
1403
  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
1404
  if (testObject.isFailing()) {
1290
- addTo(Severity.ERRORS);
1405
+ incrementFailures(Severity.ERRORS);
1291
1406
  }
1292
1407
  else if (testObject.isWarning()) {
1293
- addTo(Severity.WARNINGS);
1408
+ incrementFailures(Severity.WARNINGS);
1294
1409
  }
1295
1410
  return testKey;
1411
+ function incrementFailures(severity) {
1412
+ var countKey = getCountKey(severity);
1413
+ testKey[countKey]++;
1414
+ if (message) {
1415
+ testKey[severity] = (testKey[severity] || []).concat(message);
1416
+ }
1417
+ }
1418
+ }
1419
+ function getCountKey(severity) {
1420
+ return severity === Severity.ERRORS
1421
+ ? SeverityCount.ERROR_COUNT
1422
+ : SeverityCount.WARN_COUNT;
1296
1423
  }
1297
1424
  function baseStats() {
1298
1425
  return {
@@ -1302,24 +1429,6 @@
1302
1429
  };
1303
1430
  }
1304
1431
 
1305
- function nonMatchingFieldName(testObject, fieldName) {
1306
- return !!fieldName && !matchingFieldName(testObject, fieldName);
1307
- }
1308
- function matchingFieldName(testObject, fieldName) {
1309
- return !!(fieldName && testObject.fieldName === fieldName);
1310
- }
1311
-
1312
- function either(a, b) {
1313
- return !!a !== !!b;
1314
- }
1315
-
1316
- /**
1317
- * Checks that a given test object matches the currently specified severity level
1318
- */
1319
- function nonMatchingSeverityProfile(severity, testObject) {
1320
- return either(severity === Severity.WARNINGS, testObject.warns());
1321
- }
1322
-
1323
1432
  function collectFailureMessages(severity, testObjects, options) {
1324
1433
  var _a;
1325
1434
  if (options === void 0) { options = {}; }
@@ -1387,9 +1496,7 @@
1387
1496
  * Gets failure messages by group.
1388
1497
  */
1389
1498
  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
- }
1499
+ invariant(group, "get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
1393
1500
  var testObjects = useTestsFlat();
1394
1501
  return collectFailureMessages(severityKey, testObjects, {
1395
1502
  group: group,
@@ -1397,35 +1504,6 @@
1397
1504
  });
1398
1505
  }
1399
1506
 
1400
- /**
1401
- * Determines whether a certain test profile has failures.
1402
- */
1403
- function hasFailuresLogic(testObject, severityKey, fieldName) {
1404
- if (!testObject.hasFailures()) {
1405
- return false;
1406
- }
1407
- if (nonMatchingFieldName(testObject, fieldName)) {
1408
- return false;
1409
- }
1410
- if (nonMatchingSeverityProfile(severityKey, testObject)) {
1411
- return false;
1412
- }
1413
- return true;
1414
- }
1415
-
1416
- function hasErrors(fieldName) {
1417
- return has(Severity.ERRORS, fieldName);
1418
- }
1419
- function hasWarnings(fieldName) {
1420
- return has(Severity.WARNINGS, fieldName);
1421
- }
1422
- function has(severityKey, fieldName) {
1423
- var testObjects = useTestsFlat();
1424
- return testObjects.some(function (testObject) {
1425
- return hasFailuresLogic(testObject, severityKey, fieldName);
1426
- });
1427
- }
1428
-
1429
1507
  function hasErrorsByGroup(groupName, fieldName) {
1430
1508
  return hasByGroup(Severity.ERRORS, groupName, fieldName);
1431
1509
  }
@@ -1444,58 +1522,6 @@
1444
1522
  });
1445
1523
  }
1446
1524
 
1447
- // eslint-disable-next-line max-statements, complexity
1448
- function isValid(result, fieldName) {
1449
- if (fieldIsOmitted(fieldName)) {
1450
- return true;
1451
- }
1452
- if (result.hasErrors(fieldName)) {
1453
- return false;
1454
- }
1455
- var testObjects = useTestsFlat();
1456
- if (isEmpty(testObjects)) {
1457
- return false;
1458
- }
1459
- if (fieldDoesNotExist(result, fieldName)) {
1460
- return false;
1461
- }
1462
- if (hasNonOptionalIncomplete(fieldName)) {
1463
- return false;
1464
- }
1465
- return noMissingTests(fieldName);
1466
- }
1467
- function fieldIsOmitted(fieldName) {
1468
- var omittedFields = useOmittedFields();
1469
- if (!fieldName) {
1470
- return false;
1471
- }
1472
- return !!omittedFields[fieldName];
1473
- }
1474
- function hasNonOptionalIncomplete(fieldName) {
1475
- var optionalFields = useOptionalFields()[0];
1476
- return isNotEmpty(useAllIncomplete().filter(function (testObject) {
1477
- if (nonMatchingFieldName(testObject, fieldName)) {
1478
- return false;
1479
- }
1480
- return optionalFields[testObject.fieldName] !== true;
1481
- }));
1482
- }
1483
- function fieldDoesNotExist(result, fieldName) {
1484
- return !!fieldName && isEmpty(result.tests[fieldName]);
1485
- }
1486
- function noMissingTests(fieldName) {
1487
- var testObjects = useTestsFlat();
1488
- var optionalFields = useOptionalFields()[0];
1489
- return testObjects.every(function (testObject) {
1490
- if (nonMatchingFieldName(testObject, fieldName)) {
1491
- return true;
1492
- }
1493
- return (optionalFields[testObject.fieldName] === true ||
1494
- testObject.isTested() ||
1495
- testObject.isOmitted());
1496
- });
1497
- }
1498
-
1499
1525
  var cache$1 = createCache(20);
1500
1526
  function produceSuiteResult() {
1501
1527
  var testObjects = useTestsFlat();
@@ -1511,9 +1537,7 @@
1511
1537
  hasErrorsByGroup: context.bind(ctxRef, hasErrorsByGroup),
1512
1538
  hasWarnings: context.bind(ctxRef, hasWarnings),
1513
1539
  hasWarningsByGroup: context.bind(ctxRef, hasWarningsByGroup),
1514
- isValid: context.bind(ctxRef, function (fieldName) {
1515
- return isValid(produceSuiteResult(), fieldName);
1516
- }),
1540
+ isValid: context.bind(ctxRef, isValid),
1517
1541
  suiteName: suiteName
1518
1542
  });
1519
1543
  }));
@@ -1722,9 +1746,7 @@
1722
1746
  }
1723
1747
  function useBus() {
1724
1748
  var context$1 = context.useX();
1725
- if (!context$1.bus) {
1726
- throwError();
1727
- }
1749
+ invariant(context$1.bus);
1728
1750
  return context$1.bus;
1729
1751
  }
1730
1752
  var Events;
@@ -1743,9 +1765,7 @@
1743
1765
  args[_i] = arguments[_i];
1744
1766
  }
1745
1767
  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
- }
1768
+ invariant(isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
1749
1769
  // Event bus initialization
1750
1770
  var bus = initBus();
1751
1771
  // State initialization
@@ -1800,9 +1820,7 @@
1800
1820
  * })
1801
1821
  */
1802
1822
  function each(list, callback) {
1803
- if (!isFunction(callback)) {
1804
- throwError('each callback must be a function');
1805
- }
1823
+ invariant(isFunction(callback), 'each callback must be a function');
1806
1824
  isolate({ type: IsolateTypes.EACH }, function () {
1807
1825
  list.forEach(function (arg, index) {
1808
1826
  callback(arg, index);
@@ -1999,19 +2017,15 @@
1999
2017
  * });
2000
2018
  */
2001
2019
  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
- }
2020
+ invariant(isStringValue(groupName), groupErrorMsg('name must be a string'));
2021
+ invariant(isFunction(tests), groupErrorMsg('callback must be a function'));
2008
2022
  // Running with the context applied
2009
2023
  isolate({ type: IsolateTypes.GROUP }, function () {
2010
2024
  context.run({ groupName: groupName }, tests);
2011
2025
  });
2012
2026
  }
2013
- function throwGroupError(error) {
2014
- throwError("Wrong arguments passed to group. Group ".concat(error, "."));
2027
+ function groupErrorMsg(error) {
2028
+ return "Wrong arguments passed to group. Group ".concat(error, ".");
2015
2029
  }
2016
2030
 
2017
2031
  function include(fieldName) {
@@ -2220,7 +2234,7 @@
2220
2234
  }
2221
2235
  }
2222
2236
  catch (e) {
2223
- throwError("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(testObject), ".\n Error: ").concat(e, "."));
2237
+ throw new Error("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(testObject), ".\n Error: ").concat(e, "."));
2224
2238
  }
2225
2239
  }
2226
2240
 
@@ -2247,7 +2261,7 @@
2247
2261
  useSetTestAtCursor(nextTest_1);
2248
2262
  return nextTest_1;
2249
2263
  }
2250
- if (shouldPurgePrevTest(prevTest, newTestObject)) {
2264
+ if (testReorderDetected(prevTest, newTestObject)) {
2251
2265
  throwTestOrderError(prevTest, newTestObject);
2252
2266
  removeAllNextTestsInIsolate();
2253
2267
  // Need to see if this has any effect at all.
@@ -2284,14 +2298,14 @@
2284
2298
  var cursorPath = usePath();
2285
2299
  return valueAtPath(tests, cursorPath);
2286
2300
  }
2287
- function shouldPurgePrevTest(prevTest, newTest) {
2301
+ function testReorderDetected(prevTest, newTest) {
2288
2302
  return isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
2289
2303
  }
2290
2304
  function throwTestOrderError(prevTest, newTestObject) {
2291
2305
  if (shouldAllowReorder()) {
2292
2306
  return;
2293
2307
  }
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."));
2308
+ 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
2309
  }
2296
2310
  function handleKeyTest(key, newTestObject) {
2297
2311
  var prevTestByKey = usePrevTestByKey(key);
@@ -2305,12 +2319,13 @@
2305
2319
 
2306
2320
  // eslint-disable-next-line max-statements
2307
2321
  function registerPrevRunTest(testObject) {
2308
- var prevRunTest = useTestAtCursor(testObject);
2309
2322
  if (shouldSkipBasedOnMode(testObject)) {
2310
- moveForward();
2311
2323
  testObject.skip();
2324
+ useTestAtCursor(testObject);
2325
+ moveForward();
2312
2326
  return testObject;
2313
2327
  }
2328
+ var prevRunTest = useTestAtCursor(testObject);
2314
2329
  if (isOmitted()) {
2315
2330
  prevRunTest.omit();
2316
2331
  moveForward();
@@ -2376,12 +2391,8 @@
2376
2391
  args[_i - 1] = arguments[_i];
2377
2392
  }
2378
2393
  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
- }
2394
+ invariant(isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
2395
+ invariant(isFunction(testFn), incompatibleParamsError('Test callback', 'function'));
2385
2396
  var context$1 = context.useX();
2386
2397
  var testObject = new VestTest(fieldName, testFn, {
2387
2398
  message: message,
@@ -2402,8 +2413,8 @@
2402
2413
  var test = assign(testBase, {
2403
2414
  memo: bindTestMemo(testBase)
2404
2415
  });
2405
- function throwIncompatibleParamsError(name, expected) {
2406
- throwError("Incompatible params passed to test function. ".concat(name, " must be a ").concat(expected));
2416
+ function incompatibleParamsError(name, expected) {
2417
+ return "Incompatible params passed to test function. ".concat(name, " must be a ").concat(expected);
2407
2418
  }
2408
2419
 
2409
2420
  var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won't have an effect."
@@ -2413,13 +2424,11 @@
2413
2424
  */
2414
2425
  function warn() {
2415
2426
  var ctx = context.useX('warn ' + ERROR_HOOK_CALLED_OUTSIDE);
2416
- if (!ctx.currentTest) {
2417
- throwError(ERROR_OUTSIDE_OF_TEST);
2418
- }
2427
+ invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
2419
2428
  ctx.currentTest.warn();
2420
2429
  }
2421
2430
 
2422
- var VERSION = "4.2.1";
2431
+ var VERSION = "4.3.0";
2423
2432
 
2424
2433
  exports.VERSION = VERSION;
2425
2434
  exports.context = context;