vest 4.2.2 → 4.3.1

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 (50) 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 +28 -60
  4. package/dist/cjs/enforce/compose.production.js +1 -1
  5. package/dist/cjs/enforce/compounds.development.js +17 -2
  6. package/dist/cjs/enforce/compounds.production.js +1 -1
  7. package/dist/cjs/enforce/schema.development.js +1 -1
  8. package/dist/cjs/parser.development.js +84 -22
  9. package/dist/cjs/parser.production.js +1 -1
  10. package/dist/cjs/promisify.development.js +21 -8
  11. package/dist/cjs/promisify.production.js +1 -1
  12. package/dist/cjs/vest.development.js +297 -294
  13. package/dist/cjs/vest.production.js +1 -1
  14. package/dist/es/classnames.development.js +76 -28
  15. package/dist/es/classnames.production.js +1 -1
  16. package/dist/es/enforce/compose.development.js +28 -60
  17. package/dist/es/enforce/compose.production.js +1 -1
  18. package/dist/es/enforce/compounds.development.js +17 -2
  19. package/dist/es/enforce/compounds.production.js +1 -1
  20. package/dist/es/enforce/schema.development.js +1 -1
  21. package/dist/es/parser.development.js +84 -22
  22. package/dist/es/parser.production.js +1 -1
  23. package/dist/es/promisify.development.js +21 -8
  24. package/dist/es/promisify.production.js +1 -1
  25. package/dist/es/vest.development.js +297 -294
  26. package/dist/es/vest.production.js +1 -1
  27. package/dist/umd/classnames.development.js +76 -28
  28. package/dist/umd/classnames.production.js +1 -1
  29. package/dist/umd/enforce/compose.development.js +94 -104
  30. package/dist/umd/enforce/compose.production.js +1 -1
  31. package/dist/umd/enforce/compounds.development.js +39 -41
  32. package/dist/umd/enforce/compounds.production.js +1 -1
  33. package/dist/umd/enforce/schema.development.js +40 -42
  34. package/dist/umd/enforce/schema.production.js +1 -1
  35. package/dist/umd/parser.development.js +84 -22
  36. package/dist/umd/parser.production.js +1 -1
  37. package/dist/umd/promisify.development.js +21 -8
  38. package/dist/umd/promisify.production.js +1 -1
  39. package/dist/umd/vest.development.js +264 -283
  40. package/dist/umd/vest.production.js +1 -1
  41. package/package.json +3 -3
  42. package/testUtils/mockThrowError.ts +3 -6
  43. package/testUtils/suiteDummy.ts +5 -1
  44. package/types/classnames.d.ts +13 -54
  45. package/types/enforce/compose.d.ts +22 -21
  46. package/types/enforce/compounds.d.ts +24 -23
  47. package/types/enforce/schema.d.ts +26 -25
  48. package/types/parser.d.ts +12 -53
  49. package/types/promisify.d.ts +19 -15
  50. package/types/vest.d.ts +66 -61
@@ -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
 
@@ -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) {
@@ -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;
@@ -451,17 +453,6 @@
451
453
  PERFORMANCE OF THIS SOFTWARE.
452
454
  ***************************************************************************** */
453
455
 
454
- var __assign = function() {
455
- __assign = Object.assign || function __assign(t) {
456
- for (var s, i = 1, n = arguments.length; i < n; i++) {
457
- s = arguments[i];
458
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
459
- }
460
- return t;
461
- };
462
- return __assign.apply(this, arguments);
463
- };
464
-
465
456
  function __spreadArray(to, from, pack) {
466
457
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
467
458
  if (ar || !(i in from)) {
@@ -514,10 +505,7 @@
514
505
  }
515
506
  function validateResult(result) {
516
507
  // 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));
508
+ invariant(isBoolean(result) || (result && isBoolean(result.pass)), 'Incorrect return value for rule: ' + JSON.stringify(result));
521
509
  }
522
510
 
523
511
  function enforceEager(value) {
@@ -546,15 +534,9 @@
546
534
  var transformedResult = transformResult.apply(void 0, __spreadArray([ctx.run({ value: value }, function () { return rule.apply(void 0, __spreadArray([value], args, false)); }),
547
535
  ruleName,
548
536
  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
- }
537
+ invariant(transformedResult.pass, isEmpty(transformedResult.message)
538
+ ? "enforce/".concat(ruleName, " failed with ").concat(JSON.stringify(value))
539
+ : new String(transformedResult.message));
558
540
  return target;
559
541
  };
560
542
  }
@@ -1158,6 +1140,12 @@
1158
1140
  };
1159
1141
  }
1160
1142
 
1143
+ function deferThrow(message) {
1144
+ setTimeout(function () {
1145
+ throw new Error(message);
1146
+ }, 0);
1147
+ }
1148
+
1161
1149
  function usePath() {
1162
1150
  var context$1 = context.useX();
1163
1151
  return context$1.testCursor.getCursor();
@@ -1203,7 +1191,7 @@
1203
1191
  current[key] = testObject;
1204
1192
  }
1205
1193
  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."));
1194
+ 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
1195
  }
1208
1196
  }
1209
1197
 
@@ -1236,71 +1224,11 @@
1236
1224
  Severity["WARNINGS"] = "warnings";
1237
1225
  Severity["ERRORS"] = "errors";
1238
1226
  })(Severity || (Severity = {}));
1239
-
1240
- /**
1241
- * Reads the testObjects list and gets full validation result from it.
1242
- */
1243
- function genTestsSummary() {
1244
- var testObjects = useTestsFlat();
1245
- var summary = assign(baseStats(), {
1246
- groups: {},
1247
- tests: {}
1248
- });
1249
- appendSummary(testObjects);
1250
- 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
- });
1260
- }
1261
- }
1262
- /**
1263
- * Counts the failed tests and adds global counters
1264
- */
1265
- function countFailures(summary) {
1266
- for (var test in summary.tests) {
1267
- summary.errorCount += summary.tests[test].errorCount;
1268
- summary.warnCount += summary.tests[test].warnCount;
1269
- summary.testCount += summary.tests[test].testCount;
1270
- }
1271
- return summary;
1272
- }
1273
- // eslint-disable-next-line max-statements
1274
- function genTestObject(summaryKey, testObject) {
1275
- var fieldName = testObject.fieldName, message = testObject.message;
1276
- summaryKey[fieldName] = summaryKey[fieldName] || baseStats();
1277
- var testKey = summaryKey[fieldName];
1278
- if (testObject.isNonActionable())
1279
- return testKey;
1280
- 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
- if (testObject.isFailing()) {
1290
- addTo(Severity.ERRORS);
1291
- }
1292
- else if (testObject.isWarning()) {
1293
- addTo(Severity.WARNINGS);
1294
- }
1295
- return testKey;
1296
- }
1297
- function baseStats() {
1298
- return {
1299
- errorCount: 0,
1300
- warnCount: 0,
1301
- testCount: 0
1302
- };
1303
- }
1227
+ var SeverityCount;
1228
+ (function (SeverityCount) {
1229
+ SeverityCount["ERROR_COUNT"] = "errorCount";
1230
+ SeverityCount["WARN_COUNT"] = "warnCount";
1231
+ })(SeverityCount || (SeverityCount = {}));
1304
1232
 
1305
1233
  function nonMatchingFieldName(testObject, fieldName) {
1306
1234
  return !!fieldName && !matchingFieldName(testObject, fieldName);
@@ -1320,83 +1248,6 @@
1320
1248
  return either(severity === Severity.WARNINGS, testObject.warns());
1321
1249
  }
1322
1250
 
1323
- function collectFailureMessages(severity, testObjects, options) {
1324
- var _a;
1325
- if (options === void 0) { options = {}; }
1326
- var _b = options || {}, group = _b.group, fieldName = _b.fieldName;
1327
- return testObjects.reduce(function (collector, testObject) {
1328
- if (noMatch(testObject, severity, group, fieldName)) {
1329
- return collector;
1330
- }
1331
- if (!testObject.hasFailures()) {
1332
- return collector;
1333
- }
1334
- collector[testObject.fieldName] = (collector[testObject.fieldName] || []).concat(testObject.message || []);
1335
- return collector;
1336
- }, __assign({}, (fieldName && (_a = {}, _a[fieldName] = [], _a))));
1337
- }
1338
- function noGroupMatch(testObject, groupName) {
1339
- return !!(groupName && testObject.groupName !== groupName);
1340
- }
1341
- function noMatch(testObject, severity, group, fieldName) {
1342
- if (noGroupMatch(testObject, group)) {
1343
- return true;
1344
- }
1345
- if (nonMatchingFieldName(testObject, fieldName)) {
1346
- return true;
1347
- }
1348
- if (nonMatchingSeverityProfile(severity, testObject)) {
1349
- return true;
1350
- }
1351
- return false;
1352
- }
1353
-
1354
- function getFailuresArrayOrObject(group, fieldName) {
1355
- if (fieldName) {
1356
- return group[fieldName];
1357
- }
1358
- return group;
1359
- }
1360
-
1361
- function getErrors(fieldName) {
1362
- return getFailures(Severity.ERRORS, fieldName);
1363
- }
1364
- function getWarnings(fieldName) {
1365
- return getFailures(Severity.WARNINGS, fieldName);
1366
- }
1367
- /**
1368
- * @returns suite or field's errors or warnings.
1369
- */
1370
- function getFailures(severityKey, fieldName) {
1371
- var testObjects = useTestsFlat();
1372
- var failureMessages = collectFailureMessages(severityKey, testObjects, {
1373
- fieldName: fieldName
1374
- });
1375
- return getFailuresArrayOrObject(failureMessages, fieldName);
1376
- }
1377
-
1378
- function getErrorsByGroup(groupName, fieldName) {
1379
- var errors = getByGroup(Severity.ERRORS, groupName, fieldName);
1380
- return getFailuresArrayOrObject(errors, fieldName);
1381
- }
1382
- function getWarningsByGroup(groupName, fieldName) {
1383
- var warnings = getByGroup(Severity.WARNINGS, groupName, fieldName);
1384
- return getFailuresArrayOrObject(warnings, fieldName);
1385
- }
1386
- /**
1387
- * Gets failure messages by group.
1388
- */
1389
- 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
- }
1393
- var testObjects = useTestsFlat();
1394
- return collectFailureMessages(severityKey, testObjects, {
1395
- group: group,
1396
- fieldName: fieldName
1397
- });
1398
- }
1399
-
1400
1251
  /**
1401
1252
  * Determines whether a certain test profile has failures.
1402
1253
  */
@@ -1426,37 +1277,25 @@
1426
1277
  });
1427
1278
  }
1428
1279
 
1429
- function hasErrorsByGroup(groupName, fieldName) {
1430
- return hasByGroup(Severity.ERRORS, groupName, fieldName);
1431
- }
1432
- function hasWarningsByGroup(groupName, fieldName) {
1433
- return hasByGroup(Severity.WARNINGS, groupName, fieldName);
1434
- }
1435
- /**
1436
- * Checks whether there are failures in a given group.
1437
- */
1438
- function hasByGroup(severityKey, group, fieldName) {
1439
- var testObjects = useTestsFlat();
1440
- return testObjects.some(function (testObject) {
1441
- return group === testObject.groupName
1442
- ? hasFailuresLogic(testObject, severityKey, fieldName)
1443
- : false;
1444
- });
1280
+ function isValid(fieldName) {
1281
+ var _a, _b;
1282
+ var summary = context.useX().summary;
1283
+ invariant(summary);
1284
+ return Boolean(fieldName ? (_b = (_a = summary.tests) === null || _a === void 0 ? void 0 : _a[fieldName]) === null || _b === void 0 ? void 0 : _b.valid : summary.valid);
1445
1285
  }
1446
-
1447
1286
  // eslint-disable-next-line max-statements, complexity
1448
- function isValid(result, fieldName) {
1287
+ function shouldAddValidProp(fieldName) {
1449
1288
  if (fieldIsOmitted(fieldName)) {
1450
1289
  return true;
1451
1290
  }
1452
- if (result.hasErrors(fieldName)) {
1291
+ if (hasErrors(fieldName)) {
1453
1292
  return false;
1454
1293
  }
1455
1294
  var testObjects = useTestsFlat();
1456
1295
  if (isEmpty(testObjects)) {
1457
1296
  return false;
1458
1297
  }
1459
- if (fieldDoesNotExist(result, fieldName)) {
1298
+ if (fieldDoesNotExist(fieldName)) {
1460
1299
  return false;
1461
1300
  }
1462
1301
  if (hasNonOptionalIncomplete(fieldName)) {
@@ -1480,8 +1319,10 @@
1480
1319
  return optionalFields[testObject.fieldName] !== true;
1481
1320
  }));
1482
1321
  }
1483
- function fieldDoesNotExist(result, fieldName) {
1484
- return !!fieldName && isEmpty(result.tests[fieldName]);
1322
+ function fieldDoesNotExist(fieldName) {
1323
+ var testObjects = useTestsFlat();
1324
+ return (!!fieldName &&
1325
+ !testObjects.find(function (testObject) { return testObject.fieldName === fieldName; }));
1485
1326
  }
1486
1327
  function noMissingTests(fieldName) {
1487
1328
  var testObjects = useTestsFlat();
@@ -1496,24 +1337,175 @@
1496
1337
  });
1497
1338
  }
1498
1339
 
1499
- var cache$1 = createCache(20);
1340
+ /**
1341
+ * Reads the testObjects list and gets full validation result from it.
1342
+ */
1343
+ function genTestsSummary() {
1344
+ var testObjects = useTestsFlat();
1345
+ var summary = assign(baseStats(), {
1346
+ groups: {},
1347
+ tests: {},
1348
+ valid: false
1349
+ });
1350
+ testObjects.reduce(function (summary, testObject) {
1351
+ appendToTest(summary.tests, testObject);
1352
+ appendToGroup(summary.groups, testObject);
1353
+ return summary;
1354
+ }, summary);
1355
+ summary.valid = shouldAddValidProp();
1356
+ return countFailures(summary);
1357
+ }
1358
+ function appendToTest(tests, testObject) {
1359
+ tests[testObject.fieldName] = appendTestObject(tests, testObject);
1360
+ // If `valid` is false to begin with, keep it that way. Otherwise, assess.
1361
+ tests[testObject.fieldName].valid =
1362
+ tests[testObject.fieldName].valid === false
1363
+ ? false
1364
+ : shouldAddValidProp(testObject.fieldName);
1365
+ }
1366
+ /**
1367
+ * Appends to a group object if within a group
1368
+ */
1369
+ function appendToGroup(groups, testObject) {
1370
+ var groupName = testObject.groupName;
1371
+ if (!groupName) {
1372
+ return;
1373
+ }
1374
+ groups[groupName] = groups[groupName] || {};
1375
+ groups[groupName][testObject.fieldName] = appendTestObject(groups[groupName], testObject);
1376
+ }
1377
+ /**
1378
+ * Counts the failed tests and adds global counters
1379
+ */
1380
+ function countFailures(summary) {
1381
+ for (var test in summary.tests) {
1382
+ summary.errorCount += summary.tests[test].errorCount;
1383
+ summary.warnCount += summary.tests[test].warnCount;
1384
+ summary.testCount += summary.tests[test].testCount;
1385
+ }
1386
+ return summary;
1387
+ }
1388
+ /**
1389
+ * Appends the test to a results object
1390
+ */
1391
+ // eslint-disable-next-line max-statements
1392
+ function appendTestObject(summaryKey, testObject) {
1393
+ var fieldName = testObject.fieldName, message = testObject.message;
1394
+ summaryKey[fieldName] = summaryKey[fieldName] || baseStats();
1395
+ var testKey = summaryKey[fieldName];
1396
+ if (testObject.isNonActionable())
1397
+ return testKey;
1398
+ summaryKey[fieldName].testCount++;
1399
+ if (testObject.isFailing()) {
1400
+ incrementFailures(Severity.ERRORS);
1401
+ }
1402
+ else if (testObject.isWarning()) {
1403
+ incrementFailures(Severity.WARNINGS);
1404
+ }
1405
+ return testKey;
1406
+ function incrementFailures(severity) {
1407
+ var countKey = getCountKey(severity);
1408
+ testKey[countKey]++;
1409
+ if (message) {
1410
+ testKey[severity] = (testKey[severity] || []).concat(message);
1411
+ }
1412
+ }
1413
+ }
1414
+ function getCountKey(severity) {
1415
+ return severity === Severity.ERRORS
1416
+ ? SeverityCount.ERROR_COUNT
1417
+ : SeverityCount.WARN_COUNT;
1418
+ }
1419
+ function baseStats() {
1420
+ return {
1421
+ errorCount: 0,
1422
+ warnCount: 0,
1423
+ testCount: 0
1424
+ };
1425
+ }
1426
+
1427
+ // calls collectAll or getByFieldName depending on whether fieldName is provided
1428
+ function gatherFailures(testGroup, severityKey, fieldName) {
1429
+ return fieldName
1430
+ ? getByFieldName(testGroup, severityKey, fieldName)
1431
+ : collectAll(testGroup, severityKey);
1432
+ }
1433
+ function getByFieldName(testGroup, severityKey, fieldName) {
1434
+ var _a;
1435
+ return ((_a = testGroup === null || testGroup === void 0 ? void 0 : testGroup[fieldName]) === null || _a === void 0 ? void 0 : _a[severityKey]) || [];
1436
+ }
1437
+ function collectAll(testGroup, severityKey) {
1438
+ var _a;
1439
+ var output = {};
1440
+ for (var field in testGroup) {
1441
+ output[field] = ((_a = testGroup[field]) === null || _a === void 0 ? void 0 : _a[severityKey]) || [];
1442
+ }
1443
+ return output;
1444
+ }
1445
+
1446
+ function getErrors(fieldName) {
1447
+ return getFailures(Severity.ERRORS, fieldName);
1448
+ }
1449
+ function getWarnings(fieldName) {
1450
+ return getFailures(Severity.WARNINGS, fieldName);
1451
+ }
1452
+ /**
1453
+ * @returns suite or field's errors or warnings.
1454
+ */
1455
+ function getFailures(severityKey, fieldName) {
1456
+ var summary = context.useX().summary;
1457
+ invariant(summary);
1458
+ return gatherFailures(summary.tests, severityKey, fieldName);
1459
+ }
1460
+
1461
+ function getErrorsByGroup(groupName, fieldName) {
1462
+ return getFailuresByGroup(groupName, Severity.ERRORS, fieldName);
1463
+ }
1464
+ function getWarningsByGroup(groupName, fieldName) {
1465
+ return getFailuresByGroup(groupName, Severity.WARNINGS, fieldName);
1466
+ }
1467
+ function getFailuresByGroup(groupName, severityKey, fieldName) {
1468
+ var summary = context.useX().summary;
1469
+ invariant(summary);
1470
+ return gatherFailures(summary.groups[groupName], severityKey, fieldName);
1471
+ }
1472
+
1473
+ function hasErrorsByGroup(groupName, fieldName) {
1474
+ return hasByGroup(Severity.ERRORS, groupName, fieldName);
1475
+ }
1476
+ function hasWarningsByGroup(groupName, fieldName) {
1477
+ return hasByGroup(Severity.WARNINGS, groupName, fieldName);
1478
+ }
1479
+ /**
1480
+ * Checks whether there are failures in a given group.
1481
+ */
1482
+ function hasByGroup(severityKey, group, fieldName) {
1483
+ var testObjects = useTestsFlat();
1484
+ return testObjects.some(function (testObject) {
1485
+ return group === testObject.groupName
1486
+ ? hasFailuresLogic(testObject, severityKey, fieldName)
1487
+ : false;
1488
+ });
1489
+ }
1490
+
1491
+ var cache$1 = createCache(1);
1500
1492
  function produceSuiteResult() {
1501
1493
  var testObjects = useTestsFlat();
1502
1494
  var ctxRef = { stateRef: useStateRef() };
1503
1495
  return cache$1([testObjects], context.bind(ctxRef, function () {
1496
+ var summary = genTestsSummary();
1504
1497
  var suiteName = useSuiteName();
1505
- return assign(genTestsSummary(), {
1506
- getErrors: context.bind(ctxRef, getErrors),
1507
- getErrorsByGroup: context.bind(ctxRef, getErrorsByGroup),
1508
- getWarnings: context.bind(ctxRef, getWarnings),
1509
- getWarningsByGroup: context.bind(ctxRef, getWarningsByGroup),
1510
- hasErrors: context.bind(ctxRef, hasErrors),
1511
- hasErrorsByGroup: context.bind(ctxRef, hasErrorsByGroup),
1512
- hasWarnings: context.bind(ctxRef, hasWarnings),
1513
- hasWarningsByGroup: context.bind(ctxRef, hasWarningsByGroup),
1514
- isValid: context.bind(ctxRef, function (fieldName) {
1515
- return isValid(produceSuiteResult(), fieldName);
1516
- }),
1498
+ var ref = assign({ summary: summary }, ctxRef);
1499
+ return assign(summary, {
1500
+ getErrors: context.bind(ref, getErrors),
1501
+ getErrorsByGroup: context.bind(ref, getErrorsByGroup),
1502
+ getWarnings: context.bind(ref, getWarnings),
1503
+ getWarningsByGroup: context.bind(ref, getWarningsByGroup),
1504
+ hasErrors: context.bind(ref, hasErrors),
1505
+ hasErrorsByGroup: context.bind(ref, hasErrorsByGroup),
1506
+ hasWarnings: context.bind(ref, hasWarnings),
1507
+ hasWarningsByGroup: context.bind(ref, hasWarningsByGroup),
1508
+ isValid: context.bind(ref, isValid),
1517
1509
  suiteName: suiteName
1518
1510
  });
1519
1511
  }));
@@ -1582,14 +1574,13 @@
1582
1574
  return output;
1583
1575
  };
1584
1576
  function deferDoneCallback(doneCallback, fieldName) {
1585
- var deferredCallback = context.bind({}, doneCallback);
1586
1577
  var _a = useTestCallbacks(), setTestCallbacks = _a[1];
1587
1578
  setTestCallbacks(function (current) {
1588
1579
  if (fieldName) {
1589
- current.fieldCallbacks[fieldName] = (current.fieldCallbacks[fieldName] || []).concat(deferredCallback);
1580
+ current.fieldCallbacks[fieldName] = (current.fieldCallbacks[fieldName] || []).concat(doneCallback);
1590
1581
  }
1591
1582
  else {
1592
- current.doneCallbacks.push(deferredCallback);
1583
+ current.doneCallbacks.push(doneCallback);
1593
1584
  }
1594
1585
  return current;
1595
1586
  });
@@ -1599,19 +1590,22 @@
1599
1590
  var listeners = {};
1600
1591
  return {
1601
1592
  emit: function (event, data) {
1602
- (listeners[event] || []).forEach(function (handler) {
1593
+ listener(event).forEach(function (handler) {
1603
1594
  handler(data);
1604
1595
  });
1605
1596
  },
1606
1597
  on: function (event, handler) {
1607
- listeners[event] = (listeners[event] || []).concat(handler);
1598
+ listeners[event] = listener(event).concat(handler);
1608
1599
  return {
1609
1600
  off: function () {
1610
- listeners[event] = listeners[event].filter(function (h) { return h !== handler; });
1601
+ listeners[event] = listener(event).filter(function (h) { return h !== handler; });
1611
1602
  }
1612
1603
  };
1613
1604
  }
1614
1605
  };
1606
+ function listener(event) {
1607
+ return listeners[event] || [];
1608
+ }
1615
1609
  }
1616
1610
 
1617
1611
  function omitOptionalTests() {
@@ -1623,24 +1617,27 @@
1623
1617
  useSetTests(function (tests) {
1624
1618
  return transform(tests, function (testObject) {
1625
1619
  var fieldName = testObject.fieldName;
1626
- if (shouldOmit.hasOwnProperty(fieldName)) {
1627
- omit(testObject);
1620
+ if (hasOwnProperty(shouldOmit, fieldName)) {
1621
+ verifyAndOmit(testObject);
1628
1622
  }
1629
1623
  else {
1630
- var optionalConfig = optionalFields[fieldName];
1631
- if (isFunction(optionalConfig)) {
1632
- shouldOmit[fieldName] = optionalConfig();
1633
- omit(testObject);
1634
- }
1624
+ runOptionalConfig(testObject);
1635
1625
  }
1636
1626
  return testObject;
1637
1627
  });
1638
1628
  });
1639
- function omit(testObject) {
1629
+ function verifyAndOmit(testObject) {
1640
1630
  if (shouldOmit[testObject.fieldName]) {
1641
1631
  testObject.omit();
1642
1632
  }
1643
1633
  }
1634
+ function runOptionalConfig(testObject) {
1635
+ var optionalConfig = optionalFields[testObject.fieldName];
1636
+ if (isFunction(optionalConfig)) {
1637
+ shouldOmit[testObject.fieldName] = optionalConfig();
1638
+ verifyAndOmit(testObject);
1639
+ }
1640
+ }
1644
1641
  }
1645
1642
 
1646
1643
  /**
@@ -1722,9 +1719,7 @@
1722
1719
  }
1723
1720
  function useBus() {
1724
1721
  var context$1 = context.useX();
1725
- if (!context$1.bus) {
1726
- throwError();
1727
- }
1722
+ invariant(context$1.bus);
1728
1723
  return context$1.bus;
1729
1724
  }
1730
1725
  var Events;
@@ -1743,9 +1738,7 @@
1743
1738
  args[_i] = arguments[_i];
1744
1739
  }
1745
1740
  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
- }
1741
+ invariant(isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
1749
1742
  // Event bus initialization
1750
1743
  var bus = initBus();
1751
1744
  // State initialization
@@ -1800,9 +1793,7 @@
1800
1793
  * })
1801
1794
  */
1802
1795
  function each(list, callback) {
1803
- if (!isFunction(callback)) {
1804
- throwError('each callback must be a function');
1805
- }
1796
+ invariant(isFunction(callback), 'each callback must be a function');
1806
1797
  isolate({ type: IsolateTypes.EACH }, function () {
1807
1798
  list.forEach(function (arg, index) {
1808
1799
  callback(arg, index);
@@ -1999,19 +1990,15 @@
1999
1990
  * });
2000
1991
  */
2001
1992
  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
- }
1993
+ invariant(isStringValue(groupName), groupErrorMsg('name must be a string'));
1994
+ invariant(isFunction(tests), groupErrorMsg('callback must be a function'));
2008
1995
  // Running with the context applied
2009
1996
  isolate({ type: IsolateTypes.GROUP }, function () {
2010
1997
  context.run({ groupName: groupName }, tests);
2011
1998
  });
2012
1999
  }
2013
- function throwGroupError(error) {
2014
- throwError("Wrong arguments passed to group. Group ".concat(error, "."));
2000
+ function groupErrorMsg(error) {
2001
+ return "Wrong arguments passed to group. Group ".concat(error, ".");
2015
2002
  }
2016
2003
 
2017
2004
  function include(fieldName) {
@@ -2220,7 +2207,7 @@
2220
2207
  }
2221
2208
  }
2222
2209
  catch (e) {
2223
- throwError("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(testObject), ".\n Error: ").concat(e, "."));
2210
+ throw new Error("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(testObject), ".\n Error: ").concat(e, "."));
2224
2211
  }
2225
2212
  }
2226
2213
 
@@ -2247,7 +2234,7 @@
2247
2234
  useSetTestAtCursor(nextTest_1);
2248
2235
  return nextTest_1;
2249
2236
  }
2250
- if (shouldPurgePrevTest(prevTest, newTestObject)) {
2237
+ if (testReorderDetected(prevTest, newTestObject)) {
2251
2238
  throwTestOrderError(prevTest, newTestObject);
2252
2239
  removeAllNextTestsInIsolate();
2253
2240
  // Need to see if this has any effect at all.
@@ -2284,14 +2271,14 @@
2284
2271
  var cursorPath = usePath();
2285
2272
  return valueAtPath(tests, cursorPath);
2286
2273
  }
2287
- function shouldPurgePrevTest(prevTest, newTest) {
2274
+ function testReorderDetected(prevTest, newTest) {
2288
2275
  return isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
2289
2276
  }
2290
2277
  function throwTestOrderError(prevTest, newTestObject) {
2291
2278
  if (shouldAllowReorder()) {
2292
2279
  return;
2293
2280
  }
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."));
2281
+ 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
2282
  }
2296
2283
  function handleKeyTest(key, newTestObject) {
2297
2284
  var prevTestByKey = usePrevTestByKey(key);
@@ -2345,7 +2332,7 @@
2345
2332
  /* eslint-disable jest/valid-title */
2346
2333
  // eslint-disable-next-line max-lines-per-function
2347
2334
  function bindTestMemo(test) {
2348
- var cache = createCache(100); // arbitrary cache size
2335
+ var cache = createCache(10); // arbitrary cache size
2349
2336
  // eslint-disable-next-line max-statements
2350
2337
  function memo(fieldName) {
2351
2338
  var args = [];
@@ -2377,12 +2364,8 @@
2377
2364
  args[_i - 1] = arguments[_i];
2378
2365
  }
2379
2366
  var _a = (isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
2380
- if (isNotString(fieldName)) {
2381
- throwIncompatibleParamsError('fieldName', 'string');
2382
- }
2383
- if (!isFunction(testFn)) {
2384
- throwIncompatibleParamsError('Test callback', 'function');
2385
- }
2367
+ invariant(isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
2368
+ invariant(isFunction(testFn), incompatibleParamsError('Test callback', 'function'));
2386
2369
  var context$1 = context.useX();
2387
2370
  var testObject = new VestTest(fieldName, testFn, {
2388
2371
  message: message,
@@ -2403,8 +2386,8 @@
2403
2386
  var test = assign(testBase, {
2404
2387
  memo: bindTestMemo(testBase)
2405
2388
  });
2406
- function throwIncompatibleParamsError(name, expected) {
2407
- throwError("Incompatible params passed to test function. ".concat(name, " must be a ").concat(expected));
2389
+ function incompatibleParamsError(name, expected) {
2390
+ return "Incompatible params passed to test function. ".concat(name, " must be a ").concat(expected);
2408
2391
  }
2409
2392
 
2410
2393
  var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won't have an effect."
@@ -2414,13 +2397,11 @@
2414
2397
  */
2415
2398
  function warn() {
2416
2399
  var ctx = context.useX('warn ' + ERROR_HOOK_CALLED_OUTSIDE);
2417
- if (!ctx.currentTest) {
2418
- throwError(ERROR_OUTSIDE_OF_TEST);
2419
- }
2400
+ invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
2420
2401
  ctx.currentTest.warn();
2421
2402
  }
2422
2403
 
2423
- var VERSION = "4.2.2";
2404
+ var VERSION = "4.3.1";
2424
2405
 
2425
2406
  exports.VERSION = VERSION;
2426
2407
  exports.context = context;