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
@@ -35,6 +35,8 @@ function asArray(possibleArg) {
35
35
  return [].concat(possibleArg);
36
36
  }
37
37
 
38
+ var assign = Object.assign;
39
+
38
40
  function isNumeric(value) {
39
41
  var str = String(value);
40
42
  var num = Number(value);
@@ -174,8 +176,6 @@ function getCurrent(array, path) {
174
176
  return current;
175
177
  }
176
178
 
177
- var assign = Object.assign;
178
-
179
179
  function createCursor() {
180
180
  var storage = {
181
181
  cursor: []
@@ -262,22 +262,37 @@ function useSuiteName() {
262
262
  function useTestCallbacks() {
263
263
  return useStateRef().testCallbacks();
264
264
  }
265
+ // OPTIONAL FIELDS
266
+ function useOptionalField(fieldName) {
267
+ var optionalFields = useOptionalFields()[0];
268
+ return optionalFields[fieldName];
269
+ }
265
270
  function useOptionalFields() {
266
271
  return useStateRef().optionalFields();
267
272
  }
273
+ function useSetOptionalField(fieldName, setter) {
274
+ var _a = useOptionalFields(), setOptionalFields = _a[1];
275
+ setOptionalFields(function (optionalFields) {
276
+ var _a;
277
+ return assign(optionalFields, (_a = {},
278
+ _a[fieldName] = optionalFunctionValue(setter, optionalFields[fieldName]),
279
+ _a));
280
+ });
281
+ }
282
+ function useOptionalFieldApplied(fieldName) {
283
+ var _a;
284
+ return (_a = useOptionalField(fieldName)) === null || _a === void 0 ? void 0 : _a[1];
285
+ }
286
+ function useOptionalFieldConfig(fieldName) {
287
+ var _a;
288
+ return (_a = useOptionalField(fieldName)) === null || _a === void 0 ? void 0 : _a[0];
289
+ }
268
290
  function useTestObjects() {
269
291
  return useStateRef().testObjects();
270
292
  }
271
293
  // STATE ACTIONS
272
294
  function useRefreshTestObjects() {
273
- var _a = useTestObjects(), setTestObjects = _a[1];
274
- setTestObjects(function (_a) {
275
- var current = _a.current, prev = _a.prev;
276
- return ({
277
- prev: prev,
278
- current: asArray(current)
279
- });
280
- });
295
+ useSetTests(function (tests) { return tests; });
281
296
  }
282
297
  function useSetTests(handler) {
283
298
  var _a = useTestObjects(), testObjects = _a[1];
@@ -291,22 +306,7 @@ function useSetTests(handler) {
291
306
  }
292
307
  // Derived state
293
308
  function useAllIncomplete() {
294
- var current = useTestObjects()[0].current;
295
- return flatten(transform(current, function (testObject) {
296
- return testObject.isPending() ? testObject : null;
297
- }));
298
- }
299
- function useOmittedFields() {
300
- var testObjects = useTestsFlat();
301
- return testObjects.reduce(function (omittedFields, testObject) {
302
- if (omittedFields[testObject.fieldName]) {
303
- return omittedFields;
304
- }
305
- if (testObject.isOmitted()) {
306
- omittedFields[testObject.fieldName] = true;
307
- }
308
- return omittedFields;
309
- }, {});
309
+ return useTestsFlat().filter(function (test) { return test.isPending(); });
310
310
  }
311
311
  var flatCache = createCache();
312
312
  function useTestsFlat() {
@@ -620,9 +620,7 @@ function useRetainTestKey(key, testObject) {
620
620
 
621
621
  function isolate(_a, callback) {
622
622
  var _b = _a.type, type = _b === void 0 ? IsolateTypes.DEFAULT : _b;
623
- if (!isFunction(callback)) {
624
- return;
625
- }
623
+ invariant(isFunction(callback));
626
624
  var keys = {
627
625
  current: {},
628
626
  prev: {}
@@ -652,6 +650,11 @@ var SeverityCount;
652
650
  SeverityCount["ERROR_COUNT"] = "errorCount";
653
651
  SeverityCount["WARN_COUNT"] = "warnCount";
654
652
  })(SeverityCount || (SeverityCount = {}));
653
+ function countKeyBySeverity(severity) {
654
+ return severity === Severity.ERRORS
655
+ ? SeverityCount.ERROR_COUNT
656
+ : SeverityCount.WARN_COUNT;
657
+ }
655
658
 
656
659
  /**
657
660
  * A safe hasOwnProperty access
@@ -677,7 +680,7 @@ function isEmpty(value) {
677
680
  else if (typeof value === 'object') {
678
681
  return lengthEquals(Object.keys(value), 0);
679
682
  }
680
- return true;
683
+ return false;
681
684
  }
682
685
  var isNotEmpty = bindNot(isEmpty);
683
686
 
@@ -699,10 +702,23 @@ function nonMatchingSeverityProfile(severity, testObject) {
699
702
  return either(severity === Severity.WARNINGS, testObject.warns());
700
703
  }
701
704
 
705
+ /**
706
+ * The difference between this file and hasFailures is that hasFailures uses the static
707
+ * summary object, while this one uses the actual validation state
708
+ */
709
+ function hasErrorsByTestObjects(fieldName) {
710
+ return hasFailuresByTestObjects(Severity.ERRORS, fieldName);
711
+ }
712
+ function hasFailuresByTestObjects(severityKey, fieldName) {
713
+ var testObjects = useTestsFlat();
714
+ return testObjects.some(function (testObject) {
715
+ return hasFailuresByTestObject(testObject, severityKey, fieldName);
716
+ });
717
+ }
702
718
  /**
703
719
  * Determines whether a certain test profile has failures.
704
720
  */
705
- function hasFailuresLogic(testObject, severityKey, fieldName) {
721
+ function hasFailuresByTestObject(testObject, severityKey, fieldName) {
706
722
  if (!testObject.hasFailures()) {
707
723
  return false;
708
724
  }
@@ -715,79 +731,54 @@ function hasFailuresLogic(testObject, severityKey, fieldName) {
715
731
  return true;
716
732
  }
717
733
 
718
- function hasErrors(fieldName) {
719
- return has(Severity.ERRORS, fieldName);
720
- }
721
- function hasWarnings(fieldName) {
722
- return has(Severity.WARNINGS, fieldName);
723
- }
724
- function has(severityKey, fieldName) {
725
- var testObjects = useTestsFlat();
726
- return testObjects.some(function (testObject) {
727
- return hasFailuresLogic(testObject, severityKey, fieldName);
728
- });
729
- }
730
-
731
- function isValid(fieldName) {
732
- var _a, _b;
733
- var summary = context.useX().summary;
734
- invariant(summary);
735
- 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);
736
- }
737
734
  // eslint-disable-next-line max-statements, complexity
738
735
  function shouldAddValidProp(fieldName) {
739
736
  if (fieldIsOmitted(fieldName)) {
740
737
  return true;
741
738
  }
742
- if (hasErrors(fieldName)) {
739
+ if (hasErrorsByTestObjects(fieldName)) {
743
740
  return false;
744
741
  }
745
742
  var testObjects = useTestsFlat();
746
743
  if (isEmpty(testObjects)) {
747
744
  return false;
748
745
  }
749
- if (fieldDoesNotExist(fieldName)) {
750
- return false;
751
- }
752
746
  if (hasNonOptionalIncomplete(fieldName)) {
753
747
  return false;
754
748
  }
755
749
  return noMissingTests(fieldName);
756
750
  }
757
751
  function fieldIsOmitted(fieldName) {
758
- var omittedFields = useOmittedFields();
759
752
  if (!fieldName) {
760
753
  return false;
761
754
  }
762
- return !!omittedFields[fieldName];
755
+ return useOptionalFieldApplied(fieldName) === true;
763
756
  }
764
757
  function hasNonOptionalIncomplete(fieldName) {
765
- var optionalFields = useOptionalFields()[0];
766
758
  return isNotEmpty(useAllIncomplete().filter(function (testObject) {
767
759
  if (nonMatchingFieldName(testObject, fieldName)) {
768
760
  return false;
769
761
  }
770
- return optionalFields[testObject.fieldName] !== true;
762
+ return useOptionalFieldConfig(testObject.fieldName) !== true;
771
763
  }));
772
764
  }
773
- function fieldDoesNotExist(fieldName) {
774
- var testObjects = useTestsFlat();
775
- return (!!fieldName &&
776
- !testObjects.find(function (testObject) { return testObject.fieldName === fieldName; }));
777
- }
778
765
  function noMissingTests(fieldName) {
779
766
  var testObjects = useTestsFlat();
780
- var optionalFields = useOptionalFields()[0];
781
767
  return testObjects.every(function (testObject) {
782
768
  if (nonMatchingFieldName(testObject, fieldName)) {
783
769
  return true;
784
770
  }
785
- return (optionalFields[testObject.fieldName] === true ||
771
+ return (useOptionalFieldConfig(testObject.fieldName) === true ||
786
772
  testObject.isTested() ||
787
773
  testObject.isOmitted());
788
774
  });
789
775
  }
790
776
 
777
+ function useSummary() {
778
+ var summary = context.useX().summary;
779
+ invariant(summary);
780
+ return summary;
781
+ }
791
782
  /**
792
783
  * Reads the testObjects list and gets full validation result from it.
793
784
  */
@@ -836,13 +827,9 @@ function countFailures(summary) {
836
827
  }
837
828
  return summary;
838
829
  }
839
- /**
840
- * Appends the test to a results object
841
- */
842
- // eslint-disable-next-line max-statements
843
830
  function appendTestObject(summaryKey, testObject) {
844
831
  var fieldName = testObject.fieldName, message = testObject.message;
845
- summaryKey[fieldName] = summaryKey[fieldName] || baseStats();
832
+ summaryKey[fieldName] = summaryKey[fieldName] || baseTestStats();
846
833
  var testKey = summaryKey[fieldName];
847
834
  if (testObject.isNonActionable())
848
835
  return testKey;
@@ -855,18 +842,13 @@ function appendTestObject(summaryKey, testObject) {
855
842
  }
856
843
  return testKey;
857
844
  function incrementFailures(severity) {
858
- var countKey = getCountKey(severity);
845
+ var countKey = countKeyBySeverity(severity);
859
846
  testKey[countKey]++;
860
847
  if (message) {
861
848
  testKey[severity] = (testKey[severity] || []).concat(message);
862
849
  }
863
850
  }
864
851
  }
865
- function getCountKey(severity) {
866
- return severity === Severity.ERRORS
867
- ? SeverityCount.ERROR_COUNT
868
- : SeverityCount.WARN_COUNT;
869
- }
870
852
  function baseStats() {
871
853
  return {
872
854
  errorCount: 0,
@@ -874,6 +856,12 @@ function baseStats() {
874
856
  testCount: 0
875
857
  };
876
858
  }
859
+ function baseTestStats() {
860
+ return assign(baseStats(), {
861
+ errors: [],
862
+ warnings: []
863
+ });
864
+ }
877
865
 
878
866
  // calls collectAll or getByFieldName depending on whether fieldName is provided
879
867
  function gatherFailures(testGroup, severityKey, fieldName) {
@@ -886,10 +874,11 @@ function getByFieldName(testGroup, severityKey, fieldName) {
886
874
  return ((_a = testGroup === null || testGroup === void 0 ? void 0 : testGroup[fieldName]) === null || _a === void 0 ? void 0 : _a[severityKey]) || [];
887
875
  }
888
876
  function collectAll(testGroup, severityKey) {
889
- var _a;
890
877
  var output = {};
891
878
  for (var field in testGroup) {
892
- output[field] = ((_a = testGroup[field]) === null || _a === void 0 ? void 0 : _a[severityKey]) || [];
879
+ // We will probably never get to the fallback array
880
+ // leaving it just in case the implementation changes
881
+ output[field] = testGroup[field][severityKey] || [];
893
882
  }
894
883
  return output;
895
884
  }
@@ -904,8 +893,7 @@ function getWarnings(fieldName) {
904
893
  * @returns suite or field's errors or warnings.
905
894
  */
906
895
  function getFailures(severityKey, fieldName) {
907
- var summary = context.useX().summary;
908
- invariant(summary);
896
+ var summary = useSummary();
909
897
  return gatherFailures(summary.tests, severityKey, fieldName);
910
898
  }
911
899
 
@@ -916,27 +904,59 @@ function getWarningsByGroup(groupName, fieldName) {
916
904
  return getFailuresByGroup(groupName, Severity.WARNINGS, fieldName);
917
905
  }
918
906
  function getFailuresByGroup(groupName, severityKey, fieldName) {
919
- var summary = context.useX().summary;
920
- invariant(summary);
907
+ var summary = useSummary();
921
908
  return gatherFailures(summary.groups[groupName], severityKey, fieldName);
922
909
  }
923
910
 
911
+ function isPositive(value) {
912
+ return greaterThan(value, 0);
913
+ }
914
+
915
+ function hasErrors(fieldName) {
916
+ return hasFailures(SeverityCount.ERROR_COUNT, fieldName);
917
+ }
918
+ function hasWarnings(fieldName) {
919
+ return hasFailures(SeverityCount.WARN_COUNT, fieldName);
920
+ }
921
+ function hasFailures(severityCount, fieldName) {
922
+ var _a;
923
+ var summary = useSummary();
924
+ if (fieldName) {
925
+ return isPositive((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
926
+ }
927
+ return isPositive(summary[severityCount]);
928
+ }
929
+
924
930
  function hasErrorsByGroup(groupName, fieldName) {
925
- return hasByGroup(Severity.ERRORS, groupName, fieldName);
931
+ return hasFailuresByGroup(Severity.ERRORS, groupName, fieldName);
926
932
  }
927
933
  function hasWarningsByGroup(groupName, fieldName) {
928
- return hasByGroup(Severity.WARNINGS, groupName, fieldName);
934
+ return hasFailuresByGroup(Severity.WARNINGS, groupName, fieldName);
929
935
  }
930
- /**
931
- * Checks whether there are failures in a given group.
932
- */
933
- function hasByGroup(severityKey, group, fieldName) {
934
- var testObjects = useTestsFlat();
935
- return testObjects.some(function (testObject) {
936
- return group === testObject.groupName
937
- ? hasFailuresLogic(testObject, severityKey, fieldName)
938
- : false;
939
- });
936
+ // eslint-disable-next-line max-statements
937
+ function hasFailuresByGroup(severityKey, groupName, fieldName) {
938
+ var _a, _b;
939
+ var summary = useSummary();
940
+ var severityCount = countKeyBySeverity(severityKey);
941
+ var group = summary.groups[groupName];
942
+ if (!group) {
943
+ return false;
944
+ }
945
+ if (fieldName) {
946
+ return isPositive((_a = group[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
947
+ }
948
+ for (var field in group) {
949
+ if (isPositive((_b = group[field]) === null || _b === void 0 ? void 0 : _b[severityCount])) {
950
+ return true;
951
+ }
952
+ }
953
+ return false;
954
+ }
955
+
956
+ function isValid(fieldName) {
957
+ var _a;
958
+ var summary = useSummary();
959
+ return fieldName ? Boolean((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.valid) : summary.valid;
940
960
  }
941
961
 
942
962
  var cache$1 = createCache(1);
@@ -946,7 +966,7 @@ function produceSuiteResult() {
946
966
  return cache$1([testObjects], context.bind(ctxRef, function () {
947
967
  var summary = genTestsSummary();
948
968
  var suiteName = useSuiteName();
949
- var ref = assign({ summary: summary }, ctxRef);
969
+ var ref = { summary: summary };
950
970
  return assign(summary, {
951
971
  getErrors: context.bind(ref, getErrors),
952
972
  getErrorsByGroup: context.bind(ref, getErrorsByGroup),
@@ -1059,7 +1079,7 @@ function createBus() {
1059
1079
  }
1060
1080
  }
1061
1081
 
1062
- function omitOptionalTests() {
1082
+ function omitOptionalFields() {
1063
1083
  var optionalFields = useOptionalFields()[0];
1064
1084
  if (isEmpty(optionalFields)) {
1065
1085
  return;
@@ -1080,10 +1100,11 @@ function omitOptionalTests() {
1080
1100
  function verifyAndOmit(testObject) {
1081
1101
  if (shouldOmit[testObject.fieldName]) {
1082
1102
  testObject.omit();
1103
+ useSetOptionalField(testObject.fieldName, function (current) { return [current[0], true]; });
1083
1104
  }
1084
1105
  }
1085
1106
  function runOptionalConfig(testObject) {
1086
- var optionalConfig = optionalFields[testObject.fieldName];
1107
+ var optionalConfig = useOptionalFieldConfig(testObject.fieldName);
1087
1108
  if (isFunction(optionalConfig)) {
1088
1109
  shouldOmit[testObject.fieldName] = optionalConfig();
1089
1110
  verifyAndOmit(testObject);
@@ -1143,7 +1164,7 @@ function initBus() {
1143
1164
  // Async operations may still be running.
1144
1165
  bus.on(Events.SUITE_CALLBACK_DONE_RUNNING, function () {
1145
1166
  // Remove tests that are optional and need to be omitted
1146
- omitOptionalTests();
1167
+ omitOptionalFields();
1147
1168
  });
1148
1169
  // Called when all the tests, including async, are done running
1149
1170
  bus.on(Events.ALL_RUNNING_TESTS_FINISHED, function () {
@@ -1339,7 +1360,7 @@ function isExcluded(testObject) {
1339
1360
  return keyTests[fieldName] === false;
1340
1361
  }
1341
1362
  }
1342
- if (isMissingFromIncludedGroup(groupName)) {
1363
+ if (isTopLevelWhenThereIsAnIncludedGroup(groupName)) {
1343
1364
  return true;
1344
1365
  }
1345
1366
  // if field is only'ed
@@ -1348,39 +1369,13 @@ function isExcluded(testObject) {
1348
1369
  // If there is _ANY_ `only`ed test (and we already know this one isn't) return true
1349
1370
  if (hasIncludedTests(keyTests)) {
1350
1371
  // Check if inclusion rules for this field (`include` hook)
1372
+ // TODO: Check if this may need to be moved outside of the condition.
1373
+ // What if there are no included tests? This shouldn't run then?
1351
1374
  return !optionalFunctionValue(inclusion[fieldName]);
1352
1375
  }
1353
1376
  // We're done here. This field is not excluded
1354
1377
  return false;
1355
1378
  }
1356
- // eslint-disable-next-line max-statements
1357
- function isMissingFromIncludedGroup(groupName) {
1358
- var context$1 = context.useX();
1359
- var exclusion = context$1.exclusion;
1360
- if (!hasIncludedGroups()) {
1361
- return false;
1362
- }
1363
- if (!groupName) {
1364
- return true;
1365
- }
1366
- if (groupName in exclusion.groups) {
1367
- if (exclusion.groups[groupName]) {
1368
- return false;
1369
- }
1370
- return true;
1371
- }
1372
- return true;
1373
- }
1374
- function hasIncludedGroups() {
1375
- var context$1 = context.useX();
1376
- var exclusion = context$1.exclusion;
1377
- for (var group in exclusion.groups) {
1378
- if (exclusion.groups[group]) {
1379
- return true;
1380
- }
1381
- }
1382
- return false;
1383
- }
1384
1379
  /**
1385
1380
  * Checks whether a given group is excluded from running.
1386
1381
  */
@@ -1395,13 +1390,8 @@ function isGroupExcluded(groupName) {
1395
1390
  return keyGroups[groupName] === false;
1396
1391
  }
1397
1392
  // Group is not present
1398
- for (var group in keyGroups) {
1399
- // If any other group is only'ed
1400
- if (keyGroups[group] === true) {
1401
- return true;
1402
- }
1403
- }
1404
- return false;
1393
+ // Return whether other groups are included
1394
+ return hasIncludedGroups();
1405
1395
  }
1406
1396
  /**
1407
1397
  * Adds fields to a specified exclusion group.
@@ -1430,6 +1420,24 @@ function hasIncludedTests(keyTests) {
1430
1420
  }
1431
1421
  return false;
1432
1422
  }
1423
+ // are we not in a group and there is an included group?
1424
+ function isTopLevelWhenThereIsAnIncludedGroup(groupName) {
1425
+ if (!hasIncludedGroups()) {
1426
+ return false;
1427
+ }
1428
+ // Return whether there's an included group, and we're not inside a group
1429
+ return !groupName;
1430
+ }
1431
+ function hasIncludedGroups() {
1432
+ var context$1 = context.useX();
1433
+ var exclusion = context$1.exclusion;
1434
+ for (var group in exclusion.groups) {
1435
+ if (exclusion.groups[group]) {
1436
+ return true;
1437
+ }
1438
+ }
1439
+ return false;
1440
+ }
1433
1441
 
1434
1442
  /**
1435
1443
  * Runs tests within a group so that they can be controlled or queried separately.
@@ -1455,16 +1463,18 @@ function groupErrorMsg(error) {
1455
1463
  function include(fieldName) {
1456
1464
  var context$1 = context.useX();
1457
1465
  var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
1458
- if (!fieldName) {
1459
- return { when: when };
1460
- }
1466
+ invariant(isStringValue(fieldName));
1461
1467
  inclusion[fieldName] = defaultTo(exclusion.tests[fieldName], true);
1462
1468
  return { when: when };
1463
1469
  function when(condition) {
1464
1470
  var context$1 = context.useX();
1465
1471
  var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
1472
+ // This callback will run as part of the "isExcluded" series of checks
1466
1473
  inclusion[fieldName] = function () {
1467
1474
  if (hasOwnProperty(exclusion.tests, fieldName)) {
1475
+ // I suspect this code is technically unreachable because
1476
+ // if there are any skip/only rules applied to the current
1477
+ // field, the "isExcluded" function will have already bailed
1468
1478
  return defaultTo(exclusion.tests[fieldName], true);
1469
1479
  }
1470
1480
  if (isStringValue(condition)) {
@@ -1498,7 +1508,7 @@ function eager() {
1498
1508
  setMode(Modes.EAGER);
1499
1509
  }
1500
1510
  function shouldSkipBasedOnMode(testObject) {
1501
- if (isEager() && hasErrors(testObject.fieldName))
1511
+ if (isEager() && hasErrorsByTestObjects(testObject.fieldName))
1502
1512
  return true;
1503
1513
  return false;
1504
1514
  }
@@ -1547,22 +1557,21 @@ function isOmitted() {
1547
1557
  * });
1548
1558
  */
1549
1559
  function optional(optionals) {
1550
- var _a = useOptionalFields(), setOptionalFields = _a[1];
1551
- setOptionalFields(function (state) {
1552
- if (!isArray(optionals) && !isStringValue(optionals)) {
1553
- var optionalFunctions = optionals;
1554
- for (var field in optionalFunctions) {
1555
- var predicate = optionalFunctions[field];
1556
- state[field] = predicate;
1557
- }
1558
- }
1559
- else {
1560
- asArray(optionals).forEach(function (optionalField) {
1561
- state[optionalField] = true;
1562
- });
1560
+ // When the optional is given as a string or a list of strings
1561
+ // we just add them to the list of optional fields.
1562
+ if (isArray(optionals) || isStringValue(optionals)) {
1563
+ asArray(optionals).forEach(function (optionalField) {
1564
+ useSetOptionalField(optionalField, [true, false]);
1565
+ });
1566
+ }
1567
+ else {
1568
+ // if it's an object, we iterate over the keys and add them to the list
1569
+ var optionalFunctions = optionals;
1570
+ for (var field in optionalFunctions) {
1571
+ var predicate = optionalFunctions[field];
1572
+ useSetOptionalField(field, [predicate, false]);
1563
1573
  }
1564
- return state;
1565
- });
1574
+ }
1566
1575
  }
1567
1576
 
1568
1577
  /*! *****************************************************************************
@@ -1635,6 +1644,8 @@ function runAsyncTest(testObject) {
1635
1644
  asyncTest.then(done, fail);
1636
1645
  }
1637
1646
  catch (e) {
1647
+ // We will probably never get here, unless the consumer uses a buggy custom Promise
1648
+ // implementation that behaves differently than the native one, or if they for some
1638
1649
  fail();
1639
1650
  }
1640
1651
  }
@@ -1643,22 +1654,7 @@ function runAsyncTest(testObject) {
1643
1654
  * Runs sync tests - or extracts promise.
1644
1655
  */
1645
1656
  function runSyncTest(testObject) {
1646
- return context.run({ currentTest: testObject }, function () {
1647
- var result;
1648
- try {
1649
- result = testObject.testFn();
1650
- }
1651
- catch (e) {
1652
- if (shouldUseErrorAsMessage(testObject.message, e)) {
1653
- testObject.message = e;
1654
- }
1655
- result = false;
1656
- }
1657
- if (result === false) {
1658
- testObject.fail();
1659
- }
1660
- return result;
1661
- });
1657
+ return context.run({ currentTest: testObject }, function () { return testObject.run(); });
1662
1658
  }
1663
1659
 
1664
1660
  /**
@@ -1877,6 +1873,6 @@ function warn() {
1877
1873
  ctx.currentTest.warn();
1878
1874
  }
1879
1875
 
1880
- var VERSION = "4.3.1";
1876
+ var VERSION = "4.3.3";
1881
1877
 
1882
1878
  export { VERSION, context, create, each, eager, group, include, omitWhen, only, optional, skip, skipWhen, test, warn };