vest 4.3.1 → 4.3.3

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 (33) hide show
  1. package/dist/cjs/classnames.development.js +21 -18
  2. package/dist/cjs/classnames.production.js +1 -1
  3. package/dist/cjs/enforce/compounds.development.js +3 -3
  4. package/dist/cjs/enforce/compounds.production.js +1 -1
  5. package/dist/cjs/parser.development.js +21 -18
  6. package/dist/cjs/parser.production.js +1 -1
  7. package/dist/cjs/vest.development.js +166 -170
  8. package/dist/cjs/vest.production.js +1 -1
  9. package/dist/es/classnames.development.js +21 -18
  10. package/dist/es/classnames.production.js +1 -1
  11. package/dist/es/enforce/compounds.development.js +3 -3
  12. package/dist/es/enforce/compounds.production.js +1 -1
  13. package/dist/es/parser.development.js +21 -18
  14. package/dist/es/parser.production.js +1 -1
  15. package/dist/es/vest.development.js +166 -170
  16. package/dist/es/vest.production.js +1 -1
  17. package/dist/umd/classnames.development.js +21 -18
  18. package/dist/umd/classnames.production.js +1 -1
  19. package/dist/umd/enforce/compose.development.js +12 -8
  20. package/dist/umd/enforce/compose.production.js +1 -1
  21. package/dist/umd/enforce/compounds.development.js +15 -11
  22. package/dist/umd/enforce/compounds.production.js +1 -1
  23. package/dist/umd/enforce/schema.development.js +12 -8
  24. package/dist/umd/enforce/schema.production.js +1 -1
  25. package/dist/umd/parser.development.js +21 -18
  26. package/dist/umd/parser.production.js +1 -1
  27. package/dist/umd/vest.development.js +171 -175
  28. package/dist/umd/vest.production.js +1 -1
  29. package/package.json +3 -3
  30. package/types/classnames.d.ts +9 -5
  31. package/types/parser.d.ts +9 -5
  32. package/types/promisify.d.ts +9 -5
  33. package/types/vest.d.ts +14 -7
@@ -144,7 +144,7 @@
144
144
  else if (typeof value === 'object') {
145
145
  return lengthEquals(Object.keys(value), 0);
146
146
  }
147
- return true;
147
+ return false;
148
148
  }
149
149
  var isNotEmpty = bindNot(isEmpty);
150
150
 
@@ -644,15 +644,10 @@
644
644
  context: function () { return ctx.useX(); },
645
645
  extend: function (customRules) {
646
646
  assign(baseRules, customRules);
647
+ handleNoProxy(); // TODO: REMOVE when we stop supporting ES5
647
648
  }
648
649
  };
649
- if (!isProxySupported()) {
650
- eachEnforceRule(function (ruleName) {
651
- // Only on the first rule access - start the chain of calls
652
- target[ruleName] = genEnforceLazy(ruleName);
653
- });
654
- return assign(enforceEager, target);
655
- }
650
+ handleNoProxy();
656
651
  return new Proxy(assign(enforceEager, target), {
657
652
  get: function (target, key) {
658
653
  if (key in target) {
@@ -665,6 +660,15 @@
665
660
  return genEnforceLazy(key);
666
661
  }
667
662
  });
663
+ function handleNoProxy() {
664
+ if (!isProxySupported()) {
665
+ eachEnforceRule(function (ruleName) {
666
+ // Only on the first rule access - start the chain of calls
667
+ target[ruleName] = genEnforceLazy(ruleName);
668
+ });
669
+ return assign(enforceEager, target);
670
+ }
671
+ }
668
672
  }
669
673
  var enforce = genEnforce();
670
674
 
@@ -857,22 +861,37 @@
857
861
  function useTestCallbacks() {
858
862
  return useStateRef().testCallbacks();
859
863
  }
864
+ // OPTIONAL FIELDS
865
+ function useOptionalField(fieldName) {
866
+ var optionalFields = useOptionalFields()[0];
867
+ return optionalFields[fieldName];
868
+ }
860
869
  function useOptionalFields() {
861
870
  return useStateRef().optionalFields();
862
871
  }
872
+ function useSetOptionalField(fieldName, setter) {
873
+ var _a = useOptionalFields(), setOptionalFields = _a[1];
874
+ setOptionalFields(function (optionalFields) {
875
+ var _a;
876
+ return assign(optionalFields, (_a = {},
877
+ _a[fieldName] = optionalFunctionValue(setter, optionalFields[fieldName]),
878
+ _a));
879
+ });
880
+ }
881
+ function useOptionalFieldApplied(fieldName) {
882
+ var _a;
883
+ return (_a = useOptionalField(fieldName)) === null || _a === void 0 ? void 0 : _a[1];
884
+ }
885
+ function useOptionalFieldConfig(fieldName) {
886
+ var _a;
887
+ return (_a = useOptionalField(fieldName)) === null || _a === void 0 ? void 0 : _a[0];
888
+ }
863
889
  function useTestObjects() {
864
890
  return useStateRef().testObjects();
865
891
  }
866
892
  // STATE ACTIONS
867
893
  function useRefreshTestObjects() {
868
- var _a = useTestObjects(), setTestObjects = _a[1];
869
- setTestObjects(function (_a) {
870
- var current = _a.current, prev = _a.prev;
871
- return ({
872
- prev: prev,
873
- current: asArray(current)
874
- });
875
- });
894
+ useSetTests(function (tests) { return tests; });
876
895
  }
877
896
  function useSetTests(handler) {
878
897
  var _a = useTestObjects(), testObjects = _a[1];
@@ -886,22 +905,7 @@
886
905
  }
887
906
  // Derived state
888
907
  function useAllIncomplete() {
889
- var current = useTestObjects()[0].current;
890
- return flatten(transform(current, function (testObject) {
891
- return testObject.isPending() ? testObject : null;
892
- }));
893
- }
894
- function useOmittedFields() {
895
- var testObjects = useTestsFlat();
896
- return testObjects.reduce(function (omittedFields, testObject) {
897
- if (omittedFields[testObject.fieldName]) {
898
- return omittedFields;
899
- }
900
- if (testObject.isOmitted()) {
901
- omittedFields[testObject.fieldName] = true;
902
- }
903
- return omittedFields;
904
- }, {});
908
+ return useTestsFlat().filter(function (test) { return test.isPending(); });
905
909
  }
906
910
  var flatCache = createCache();
907
911
  function useTestsFlat() {
@@ -1197,9 +1201,7 @@
1197
1201
 
1198
1202
  function isolate(_a, callback) {
1199
1203
  var _b = _a.type, type = _b === void 0 ? IsolateTypes.DEFAULT : _b;
1200
- if (!isFunction(callback)) {
1201
- return;
1202
- }
1204
+ invariant(isFunction(callback));
1203
1205
  var keys = {
1204
1206
  current: {},
1205
1207
  prev: {}
@@ -1229,6 +1231,11 @@
1229
1231
  SeverityCount["ERROR_COUNT"] = "errorCount";
1230
1232
  SeverityCount["WARN_COUNT"] = "warnCount";
1231
1233
  })(SeverityCount || (SeverityCount = {}));
1234
+ function countKeyBySeverity(severity) {
1235
+ return severity === Severity.ERRORS
1236
+ ? SeverityCount.ERROR_COUNT
1237
+ : SeverityCount.WARN_COUNT;
1238
+ }
1232
1239
 
1233
1240
  function nonMatchingFieldName(testObject, fieldName) {
1234
1241
  return !!fieldName && !matchingFieldName(testObject, fieldName);
@@ -1248,10 +1255,23 @@
1248
1255
  return either(severity === Severity.WARNINGS, testObject.warns());
1249
1256
  }
1250
1257
 
1258
+ /**
1259
+ * The difference between this file and hasFailures is that hasFailures uses the static
1260
+ * summary object, while this one uses the actual validation state
1261
+ */
1262
+ function hasErrorsByTestObjects(fieldName) {
1263
+ return hasFailuresByTestObjects(Severity.ERRORS, fieldName);
1264
+ }
1265
+ function hasFailuresByTestObjects(severityKey, fieldName) {
1266
+ var testObjects = useTestsFlat();
1267
+ return testObjects.some(function (testObject) {
1268
+ return hasFailuresByTestObject(testObject, severityKey, fieldName);
1269
+ });
1270
+ }
1251
1271
  /**
1252
1272
  * Determines whether a certain test profile has failures.
1253
1273
  */
1254
- function hasFailuresLogic(testObject, severityKey, fieldName) {
1274
+ function hasFailuresByTestObject(testObject, severityKey, fieldName) {
1255
1275
  if (!testObject.hasFailures()) {
1256
1276
  return false;
1257
1277
  }
@@ -1264,79 +1284,54 @@
1264
1284
  return true;
1265
1285
  }
1266
1286
 
1267
- function hasErrors(fieldName) {
1268
- return has(Severity.ERRORS, fieldName);
1269
- }
1270
- function hasWarnings(fieldName) {
1271
- return has(Severity.WARNINGS, fieldName);
1272
- }
1273
- function has(severityKey, fieldName) {
1274
- var testObjects = useTestsFlat();
1275
- return testObjects.some(function (testObject) {
1276
- return hasFailuresLogic(testObject, severityKey, fieldName);
1277
- });
1278
- }
1279
-
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);
1285
- }
1286
1287
  // eslint-disable-next-line max-statements, complexity
1287
1288
  function shouldAddValidProp(fieldName) {
1288
1289
  if (fieldIsOmitted(fieldName)) {
1289
1290
  return true;
1290
1291
  }
1291
- if (hasErrors(fieldName)) {
1292
+ if (hasErrorsByTestObjects(fieldName)) {
1292
1293
  return false;
1293
1294
  }
1294
1295
  var testObjects = useTestsFlat();
1295
1296
  if (isEmpty(testObjects)) {
1296
1297
  return false;
1297
1298
  }
1298
- if (fieldDoesNotExist(fieldName)) {
1299
- return false;
1300
- }
1301
1299
  if (hasNonOptionalIncomplete(fieldName)) {
1302
1300
  return false;
1303
1301
  }
1304
1302
  return noMissingTests(fieldName);
1305
1303
  }
1306
1304
  function fieldIsOmitted(fieldName) {
1307
- var omittedFields = useOmittedFields();
1308
1305
  if (!fieldName) {
1309
1306
  return false;
1310
1307
  }
1311
- return !!omittedFields[fieldName];
1308
+ return useOptionalFieldApplied(fieldName) === true;
1312
1309
  }
1313
1310
  function hasNonOptionalIncomplete(fieldName) {
1314
- var optionalFields = useOptionalFields()[0];
1315
1311
  return isNotEmpty(useAllIncomplete().filter(function (testObject) {
1316
1312
  if (nonMatchingFieldName(testObject, fieldName)) {
1317
1313
  return false;
1318
1314
  }
1319
- return optionalFields[testObject.fieldName] !== true;
1315
+ return useOptionalFieldConfig(testObject.fieldName) !== true;
1320
1316
  }));
1321
1317
  }
1322
- function fieldDoesNotExist(fieldName) {
1323
- var testObjects = useTestsFlat();
1324
- return (!!fieldName &&
1325
- !testObjects.find(function (testObject) { return testObject.fieldName === fieldName; }));
1326
- }
1327
1318
  function noMissingTests(fieldName) {
1328
1319
  var testObjects = useTestsFlat();
1329
- var optionalFields = useOptionalFields()[0];
1330
1320
  return testObjects.every(function (testObject) {
1331
1321
  if (nonMatchingFieldName(testObject, fieldName)) {
1332
1322
  return true;
1333
1323
  }
1334
- return (optionalFields[testObject.fieldName] === true ||
1324
+ return (useOptionalFieldConfig(testObject.fieldName) === true ||
1335
1325
  testObject.isTested() ||
1336
1326
  testObject.isOmitted());
1337
1327
  });
1338
1328
  }
1339
1329
 
1330
+ function useSummary() {
1331
+ var summary = context.useX().summary;
1332
+ invariant(summary);
1333
+ return summary;
1334
+ }
1340
1335
  /**
1341
1336
  * Reads the testObjects list and gets full validation result from it.
1342
1337
  */
@@ -1385,13 +1380,9 @@
1385
1380
  }
1386
1381
  return summary;
1387
1382
  }
1388
- /**
1389
- * Appends the test to a results object
1390
- */
1391
- // eslint-disable-next-line max-statements
1392
1383
  function appendTestObject(summaryKey, testObject) {
1393
1384
  var fieldName = testObject.fieldName, message = testObject.message;
1394
- summaryKey[fieldName] = summaryKey[fieldName] || baseStats();
1385
+ summaryKey[fieldName] = summaryKey[fieldName] || baseTestStats();
1395
1386
  var testKey = summaryKey[fieldName];
1396
1387
  if (testObject.isNonActionable())
1397
1388
  return testKey;
@@ -1404,18 +1395,13 @@
1404
1395
  }
1405
1396
  return testKey;
1406
1397
  function incrementFailures(severity) {
1407
- var countKey = getCountKey(severity);
1398
+ var countKey = countKeyBySeverity(severity);
1408
1399
  testKey[countKey]++;
1409
1400
  if (message) {
1410
1401
  testKey[severity] = (testKey[severity] || []).concat(message);
1411
1402
  }
1412
1403
  }
1413
1404
  }
1414
- function getCountKey(severity) {
1415
- return severity === Severity.ERRORS
1416
- ? SeverityCount.ERROR_COUNT
1417
- : SeverityCount.WARN_COUNT;
1418
- }
1419
1405
  function baseStats() {
1420
1406
  return {
1421
1407
  errorCount: 0,
@@ -1423,6 +1409,12 @@
1423
1409
  testCount: 0
1424
1410
  };
1425
1411
  }
1412
+ function baseTestStats() {
1413
+ return assign(baseStats(), {
1414
+ errors: [],
1415
+ warnings: []
1416
+ });
1417
+ }
1426
1418
 
1427
1419
  // calls collectAll or getByFieldName depending on whether fieldName is provided
1428
1420
  function gatherFailures(testGroup, severityKey, fieldName) {
@@ -1435,10 +1427,11 @@
1435
1427
  return ((_a = testGroup === null || testGroup === void 0 ? void 0 : testGroup[fieldName]) === null || _a === void 0 ? void 0 : _a[severityKey]) || [];
1436
1428
  }
1437
1429
  function collectAll(testGroup, severityKey) {
1438
- var _a;
1439
1430
  var output = {};
1440
1431
  for (var field in testGroup) {
1441
- output[field] = ((_a = testGroup[field]) === null || _a === void 0 ? void 0 : _a[severityKey]) || [];
1432
+ // We will probably never get to the fallback array
1433
+ // leaving it just in case the implementation changes
1434
+ output[field] = testGroup[field][severityKey] || [];
1442
1435
  }
1443
1436
  return output;
1444
1437
  }
@@ -1453,8 +1446,7 @@
1453
1446
  * @returns suite or field's errors or warnings.
1454
1447
  */
1455
1448
  function getFailures(severityKey, fieldName) {
1456
- var summary = context.useX().summary;
1457
- invariant(summary);
1449
+ var summary = useSummary();
1458
1450
  return gatherFailures(summary.tests, severityKey, fieldName);
1459
1451
  }
1460
1452
 
@@ -1465,27 +1457,55 @@
1465
1457
  return getFailuresByGroup(groupName, Severity.WARNINGS, fieldName);
1466
1458
  }
1467
1459
  function getFailuresByGroup(groupName, severityKey, fieldName) {
1468
- var summary = context.useX().summary;
1469
- invariant(summary);
1460
+ var summary = useSummary();
1470
1461
  return gatherFailures(summary.groups[groupName], severityKey, fieldName);
1471
1462
  }
1472
1463
 
1464
+ function hasErrors(fieldName) {
1465
+ return hasFailures(SeverityCount.ERROR_COUNT, fieldName);
1466
+ }
1467
+ function hasWarnings(fieldName) {
1468
+ return hasFailures(SeverityCount.WARN_COUNT, fieldName);
1469
+ }
1470
+ function hasFailures(severityCount, fieldName) {
1471
+ var _a;
1472
+ var summary = useSummary();
1473
+ if (fieldName) {
1474
+ return isPositive((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
1475
+ }
1476
+ return isPositive(summary[severityCount]);
1477
+ }
1478
+
1473
1479
  function hasErrorsByGroup(groupName, fieldName) {
1474
- return hasByGroup(Severity.ERRORS, groupName, fieldName);
1480
+ return hasFailuresByGroup(Severity.ERRORS, groupName, fieldName);
1475
1481
  }
1476
1482
  function hasWarningsByGroup(groupName, fieldName) {
1477
- return hasByGroup(Severity.WARNINGS, groupName, fieldName);
1483
+ return hasFailuresByGroup(Severity.WARNINGS, groupName, fieldName);
1478
1484
  }
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
- });
1485
+ // eslint-disable-next-line max-statements
1486
+ function hasFailuresByGroup(severityKey, groupName, fieldName) {
1487
+ var _a, _b;
1488
+ var summary = useSummary();
1489
+ var severityCount = countKeyBySeverity(severityKey);
1490
+ var group = summary.groups[groupName];
1491
+ if (!group) {
1492
+ return false;
1493
+ }
1494
+ if (fieldName) {
1495
+ return isPositive((_a = group[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
1496
+ }
1497
+ for (var field in group) {
1498
+ if (isPositive((_b = group[field]) === null || _b === void 0 ? void 0 : _b[severityCount])) {
1499
+ return true;
1500
+ }
1501
+ }
1502
+ return false;
1503
+ }
1504
+
1505
+ function isValid(fieldName) {
1506
+ var _a;
1507
+ var summary = useSummary();
1508
+ return fieldName ? Boolean((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.valid) : summary.valid;
1489
1509
  }
1490
1510
 
1491
1511
  var cache$1 = createCache(1);
@@ -1495,7 +1515,7 @@
1495
1515
  return cache$1([testObjects], context.bind(ctxRef, function () {
1496
1516
  var summary = genTestsSummary();
1497
1517
  var suiteName = useSuiteName();
1498
- var ref = assign({ summary: summary }, ctxRef);
1518
+ var ref = { summary: summary };
1499
1519
  return assign(summary, {
1500
1520
  getErrors: context.bind(ref, getErrors),
1501
1521
  getErrorsByGroup: context.bind(ref, getErrorsByGroup),
@@ -1608,7 +1628,7 @@
1608
1628
  }
1609
1629
  }
1610
1630
 
1611
- function omitOptionalTests() {
1631
+ function omitOptionalFields() {
1612
1632
  var optionalFields = useOptionalFields()[0];
1613
1633
  if (isEmpty(optionalFields)) {
1614
1634
  return;
@@ -1629,10 +1649,11 @@
1629
1649
  function verifyAndOmit(testObject) {
1630
1650
  if (shouldOmit[testObject.fieldName]) {
1631
1651
  testObject.omit();
1652
+ useSetOptionalField(testObject.fieldName, function (current) { return [current[0], true]; });
1632
1653
  }
1633
1654
  }
1634
1655
  function runOptionalConfig(testObject) {
1635
- var optionalConfig = optionalFields[testObject.fieldName];
1656
+ var optionalConfig = useOptionalFieldConfig(testObject.fieldName);
1636
1657
  if (isFunction(optionalConfig)) {
1637
1658
  shouldOmit[testObject.fieldName] = optionalConfig();
1638
1659
  verifyAndOmit(testObject);
@@ -1692,7 +1713,7 @@
1692
1713
  // Async operations may still be running.
1693
1714
  bus.on(Events.SUITE_CALLBACK_DONE_RUNNING, function () {
1694
1715
  // Remove tests that are optional and need to be omitted
1695
- omitOptionalTests();
1716
+ omitOptionalFields();
1696
1717
  });
1697
1718
  // Called when all the tests, including async, are done running
1698
1719
  bus.on(Events.ALL_RUNNING_TESTS_FINISHED, function () {
@@ -1888,7 +1909,7 @@
1888
1909
  return keyTests[fieldName] === false;
1889
1910
  }
1890
1911
  }
1891
- if (isMissingFromIncludedGroup(groupName)) {
1912
+ if (isTopLevelWhenThereIsAnIncludedGroup(groupName)) {
1892
1913
  return true;
1893
1914
  }
1894
1915
  // if field is only'ed
@@ -1897,39 +1918,13 @@
1897
1918
  // If there is _ANY_ `only`ed test (and we already know this one isn't) return true
1898
1919
  if (hasIncludedTests(keyTests)) {
1899
1920
  // Check if inclusion rules for this field (`include` hook)
1921
+ // TODO: Check if this may need to be moved outside of the condition.
1922
+ // What if there are no included tests? This shouldn't run then?
1900
1923
  return !optionalFunctionValue(inclusion[fieldName]);
1901
1924
  }
1902
1925
  // We're done here. This field is not excluded
1903
1926
  return false;
1904
1927
  }
1905
- // eslint-disable-next-line max-statements
1906
- function isMissingFromIncludedGroup(groupName) {
1907
- var context$1 = context.useX();
1908
- var exclusion = context$1.exclusion;
1909
- if (!hasIncludedGroups()) {
1910
- return false;
1911
- }
1912
- if (!groupName) {
1913
- return true;
1914
- }
1915
- if (groupName in exclusion.groups) {
1916
- if (exclusion.groups[groupName]) {
1917
- return false;
1918
- }
1919
- return true;
1920
- }
1921
- return true;
1922
- }
1923
- function hasIncludedGroups() {
1924
- var context$1 = context.useX();
1925
- var exclusion = context$1.exclusion;
1926
- for (var group in exclusion.groups) {
1927
- if (exclusion.groups[group]) {
1928
- return true;
1929
- }
1930
- }
1931
- return false;
1932
- }
1933
1928
  /**
1934
1929
  * Checks whether a given group is excluded from running.
1935
1930
  */
@@ -1944,13 +1939,8 @@
1944
1939
  return keyGroups[groupName] === false;
1945
1940
  }
1946
1941
  // Group is not present
1947
- for (var group in keyGroups) {
1948
- // If any other group is only'ed
1949
- if (keyGroups[group] === true) {
1950
- return true;
1951
- }
1952
- }
1953
- return false;
1942
+ // Return whether other groups are included
1943
+ return hasIncludedGroups();
1954
1944
  }
1955
1945
  /**
1956
1946
  * Adds fields to a specified exclusion group.
@@ -1979,6 +1969,24 @@
1979
1969
  }
1980
1970
  return false;
1981
1971
  }
1972
+ // are we not in a group and there is an included group?
1973
+ function isTopLevelWhenThereIsAnIncludedGroup(groupName) {
1974
+ if (!hasIncludedGroups()) {
1975
+ return false;
1976
+ }
1977
+ // Return whether there's an included group, and we're not inside a group
1978
+ return !groupName;
1979
+ }
1980
+ function hasIncludedGroups() {
1981
+ var context$1 = context.useX();
1982
+ var exclusion = context$1.exclusion;
1983
+ for (var group in exclusion.groups) {
1984
+ if (exclusion.groups[group]) {
1985
+ return true;
1986
+ }
1987
+ }
1988
+ return false;
1989
+ }
1982
1990
 
1983
1991
  /**
1984
1992
  * Runs tests within a group so that they can be controlled or queried separately.
@@ -2004,16 +2012,18 @@
2004
2012
  function include(fieldName) {
2005
2013
  var context$1 = context.useX();
2006
2014
  var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
2007
- if (!fieldName) {
2008
- return { when: when };
2009
- }
2015
+ invariant(isStringValue(fieldName));
2010
2016
  inclusion[fieldName] = defaultTo(exclusion.tests[fieldName], true);
2011
2017
  return { when: when };
2012
2018
  function when(condition) {
2013
2019
  var context$1 = context.useX();
2014
2020
  var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
2021
+ // This callback will run as part of the "isExcluded" series of checks
2015
2022
  inclusion[fieldName] = function () {
2016
2023
  if (hasOwnProperty(exclusion.tests, fieldName)) {
2024
+ // I suspect this code is technically unreachable because
2025
+ // if there are any skip/only rules applied to the current
2026
+ // field, the "isExcluded" function will have already bailed
2017
2027
  return defaultTo(exclusion.tests[fieldName], true);
2018
2028
  }
2019
2029
  if (isStringValue(condition)) {
@@ -2047,7 +2057,7 @@
2047
2057
  setMode(Modes.EAGER);
2048
2058
  }
2049
2059
  function shouldSkipBasedOnMode(testObject) {
2050
- if (isEager() && hasErrors(testObject.fieldName))
2060
+ if (isEager() && hasErrorsByTestObjects(testObject.fieldName))
2051
2061
  return true;
2052
2062
  return false;
2053
2063
  }
@@ -2096,22 +2106,21 @@
2096
2106
  * });
2097
2107
  */
2098
2108
  function optional(optionals) {
2099
- var _a = useOptionalFields(), setOptionalFields = _a[1];
2100
- setOptionalFields(function (state) {
2101
- if (!isArray(optionals) && !isStringValue(optionals)) {
2102
- var optionalFunctions = optionals;
2103
- for (var field in optionalFunctions) {
2104
- var predicate = optionalFunctions[field];
2105
- state[field] = predicate;
2106
- }
2107
- }
2108
- else {
2109
- asArray(optionals).forEach(function (optionalField) {
2110
- state[optionalField] = true;
2111
- });
2109
+ // When the optional is given as a string or a list of strings
2110
+ // we just add them to the list of optional fields.
2111
+ if (isArray(optionals) || isStringValue(optionals)) {
2112
+ asArray(optionals).forEach(function (optionalField) {
2113
+ useSetOptionalField(optionalField, [true, false]);
2114
+ });
2115
+ }
2116
+ else {
2117
+ // if it's an object, we iterate over the keys and add them to the list
2118
+ var optionalFunctions = optionals;
2119
+ for (var field in optionalFunctions) {
2120
+ var predicate = optionalFunctions[field];
2121
+ useSetOptionalField(field, [predicate, false]);
2112
2122
  }
2113
- return state;
2114
- });
2123
+ }
2115
2124
  }
2116
2125
 
2117
2126
  function isPromise(value) {
@@ -2159,6 +2168,8 @@
2159
2168
  asyncTest.then(done, fail);
2160
2169
  }
2161
2170
  catch (e) {
2171
+ // We will probably never get here, unless the consumer uses a buggy custom Promise
2172
+ // implementation that behaves differently than the native one, or if they for some
2162
2173
  fail();
2163
2174
  }
2164
2175
  }
@@ -2167,22 +2178,7 @@
2167
2178
  * Runs sync tests - or extracts promise.
2168
2179
  */
2169
2180
  function runSyncTest(testObject) {
2170
- return context.run({ currentTest: testObject }, function () {
2171
- var result;
2172
- try {
2173
- result = testObject.testFn();
2174
- }
2175
- catch (e) {
2176
- if (shouldUseErrorAsMessage(testObject.message, e)) {
2177
- testObject.message = e;
2178
- }
2179
- result = false;
2180
- }
2181
- if (result === false) {
2182
- testObject.fail();
2183
- }
2184
- return result;
2185
- });
2181
+ return context.run({ currentTest: testObject }, function () { return testObject.run(); });
2186
2182
  }
2187
2183
 
2188
2184
  /**
@@ -2401,7 +2397,7 @@
2401
2397
  ctx.currentTest.warn();
2402
2398
  }
2403
2399
 
2404
- var VERSION = "4.3.1";
2400
+ var VERSION = "4.3.3";
2405
2401
 
2406
2402
  exports.VERSION = VERSION;
2407
2403
  exports.context = context;