vest 4.4.3-dev-c786f7 → 4.6.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 (33) hide show
  1. package/dist/cjs/classnames.development.js +13 -36
  2. package/dist/cjs/classnames.production.js +1 -1
  3. package/dist/cjs/parser.development.js +13 -36
  4. package/dist/cjs/parser.production.js +1 -1
  5. package/dist/cjs/vest.development.js +232 -187
  6. package/dist/cjs/vest.production.js +1 -1
  7. package/dist/es/classnames.development.js +14 -37
  8. package/dist/es/classnames.production.js +1 -1
  9. package/dist/es/parser.development.js +14 -37
  10. package/dist/es/parser.production.js +1 -1
  11. package/dist/es/vest.development.js +233 -189
  12. package/dist/es/vest.production.js +1 -1
  13. package/dist/umd/classnames.development.js +19 -96
  14. package/dist/umd/classnames.production.js +1 -1
  15. package/dist/umd/enforce/compose.development.js +9 -665
  16. package/dist/umd/enforce/compose.production.js +1 -1
  17. package/dist/umd/enforce/compounds.development.js +17 -667
  18. package/dist/umd/enforce/compounds.production.js +1 -1
  19. package/dist/umd/enforce/schema.development.js +12 -668
  20. package/dist/umd/enforce/schema.production.js +1 -1
  21. package/dist/umd/parser.development.js +18 -95
  22. package/dist/umd/parser.production.js +1 -1
  23. package/dist/umd/promisify.development.js +5 -31
  24. package/dist/umd/promisify.production.js +1 -1
  25. package/dist/umd/vest.development.js +336 -1067
  26. package/dist/umd/vest.production.js +1 -1
  27. package/package.json +4 -4
  28. package/types/enforce/compose.d.ts +2 -1
  29. package/types/enforce/compounds.d.ts +8 -9
  30. package/types/enforce/schema.d.ts +7 -5
  31. package/types/parser.d.ts +8 -7
  32. package/types/promisify.d.ts +20 -35
  33. package/types/vest.d.ts +79 -81
@@ -65,7 +65,7 @@ function generateIsolate(type, path) {
65
65
  var context = context$1.createContext(function (ctxRef, parentContext) {
66
66
  return parentContext
67
67
  ? null
68
- : vestUtils.assign({}, {
68
+ : vestUtils.assign({
69
69
  exclusion: {
70
70
  tests: {},
71
71
  groups: {}
@@ -92,29 +92,22 @@ function useTestCallbacks() {
92
92
  return useStateRef().testCallbacks();
93
93
  }
94
94
  // OPTIONAL FIELDS
95
- function useOptionalField(fieldName) {
96
- var optionalFields = useOptionalFields()[0];
97
- return optionalFields[fieldName];
98
- }
99
95
  function useOptionalFields() {
100
96
  return useStateRef().optionalFields();
101
97
  }
102
98
  function useSetOptionalField(fieldName, setter) {
103
99
  var _a = useOptionalFields(), setOptionalFields = _a[1];
104
- setOptionalFields(function (optionalFields) {
100
+ setOptionalFields(function (prev) {
105
101
  var _a;
106
- return vestUtils.assign(optionalFields, (_a = {},
107
- _a[fieldName] = vestUtils.optionalFunctionValue(setter, optionalFields[fieldName]),
102
+ return vestUtils.assign(prev, (_a = {},
103
+ _a[fieldName] = vestUtils.assign({}, prev[fieldName], setter(prev[fieldName])),
108
104
  _a));
109
105
  });
110
106
  }
111
- function useOptionalFieldApplied(fieldName) {
112
- var _a;
113
- return (_a = useOptionalField(fieldName)) === null || _a === void 0 ? void 0 : _a[1];
114
- }
115
- function useOptionalFieldConfig(fieldName) {
107
+ function useOptionalField(fieldName) {
116
108
  var _a;
117
- return (_a = useOptionalField(fieldName)) === null || _a === void 0 ? void 0 : _a[0];
109
+ var optionalFields = useOptionalFields()[0];
110
+ return (_a = optionalFields[fieldName]) !== null && _a !== void 0 ? _a : {};
118
111
  }
119
112
  function useTestObjects() {
120
113
  return useStateRef().testObjects();
@@ -156,7 +149,7 @@ var VestTest = /** @class */ (function () {
156
149
  function VestTest(fieldName, testFn, _a) {
157
150
  var _b = _a === void 0 ? {} : _a, message = _b.message, groupName = _b.groupName, key = _b.key;
158
151
  this.key = null;
159
- this.id = vestUtils.genId();
152
+ this.id = vestUtils.seq();
160
153
  this.severity = TestSeverity.Error;
161
154
  this.status = STATUS_UNTESTED;
162
155
  this.fieldName = fieldName;
@@ -244,18 +237,9 @@ var VestTest = /** @class */ (function () {
244
237
  VestTest.prototype.valueOf = function () {
245
238
  return !this.isFailing();
246
239
  };
247
- VestTest.prototype.hasFailures = function () {
248
- return this.isFailing() || this.isWarning();
249
- };
250
- VestTest.prototype.isNonActionable = function () {
251
- return this.isSkipped() || this.isOmitted() || this.isCanceled();
252
- };
253
240
  VestTest.prototype.isPending = function () {
254
241
  return this.statusEquals(STATUS_PENDING);
255
242
  };
256
- VestTest.prototype.isTested = function () {
257
- return this.hasFailures() || this.isPassing();
258
- };
259
243
  VestTest.prototype.isOmitted = function () {
260
244
  return this.statusEquals(STATUS_OMITTED);
261
245
  };
@@ -277,6 +261,20 @@ var VestTest = /** @class */ (function () {
277
261
  VestTest.prototype.isWarning = function () {
278
262
  return this.statusEquals(STATUS_WARNING);
279
263
  };
264
+ VestTest.prototype.hasFailures = function () {
265
+ return this.isFailing() || this.isWarning();
266
+ };
267
+ VestTest.prototype.isNonActionable = function () {
268
+ return this.isSkipped() || this.isOmitted() || this.isCanceled();
269
+ };
270
+ VestTest.prototype.isTested = function () {
271
+ return this.hasFailures() || this.isPassing();
272
+ };
273
+ VestTest.prototype.awaitsResolution = function () {
274
+ // Is the test in a state where it can still be run, or complete running
275
+ // and its final status is indeterminate?
276
+ return this.isSkipped() || this.isUntested() || this.isPending();
277
+ };
280
278
  VestTest.prototype.statusEquals = function (status) {
281
279
  return this.status === status;
282
280
  };
@@ -516,26 +514,85 @@ function hasFailuresByTestObject(testObject, severityKey, fieldName) {
516
514
  return true;
517
515
  }
518
516
 
517
+ /**
518
+ * Marks a field as optional, either just by name, or by a given condition.
519
+ *
520
+ * @example
521
+ *
522
+ * optional('field_name');
523
+ *
524
+ * optional({
525
+ * username: () => allowUsernameEmpty,
526
+ * });
527
+ */
528
+ function optional(optionals) {
529
+ // There are two types of optional field declarations:
530
+ // 1. Delayed: A string, which is the name of the field to be optional.
531
+ // We will only determine whether to omit the test after the suite is done running
532
+ //
533
+ // 2. Immediate: Either a boolean or a function, which is used to determine
534
+ // if the field should be optional.
535
+ // Delayed case (field name)
536
+ if (vestUtils.isArray(optionals) || vestUtils.isStringValue(optionals)) {
537
+ vestUtils.asArray(optionals).forEach(function (optionalField) {
538
+ useSetOptionalField(optionalField, function () { return ({
539
+ type: OptionalFieldTypes.Delayed,
540
+ applied: false,
541
+ rule: null
542
+ }); });
543
+ });
544
+ }
545
+ else {
546
+ var _loop_1 = function (field) {
547
+ var value = optionals[field];
548
+ useSetOptionalField(field, function () { return ({
549
+ type: OptionalFieldTypes.Immediate,
550
+ rule: value,
551
+ applied: vestUtils.optionalFunctionValue(value)
552
+ }); });
553
+ };
554
+ // Immediately case (function or boolean)
555
+ for (var field in optionals) {
556
+ _loop_1(field);
557
+ }
558
+ }
559
+ }
560
+ function optionalFiedIsApplied(fieldName) {
561
+ if (!fieldName) {
562
+ return false;
563
+ }
564
+ return useOptionalField(fieldName).applied;
565
+ }
566
+ var OptionalFieldTypes;
567
+ (function (OptionalFieldTypes) {
568
+ OptionalFieldTypes[OptionalFieldTypes["Immediate"] = 0] = "Immediate";
569
+ OptionalFieldTypes[OptionalFieldTypes["Delayed"] = 1] = "Delayed";
570
+ })(OptionalFieldTypes || (OptionalFieldTypes = {}));
571
+
519
572
  // eslint-disable-next-line max-statements, complexity
520
573
  function shouldAddValidProperty(fieldName) {
521
- if (fieldIsOmitted(fieldName)) {
574
+ // Is the field optional, and the optional condition is applied
575
+ if (optionalFiedIsApplied(fieldName)) {
522
576
  return true;
523
577
  }
524
- if (hasErrorsByTestObjects(fieldName)) {
525
- return false;
526
- }
527
578
  var testObjects = useTestsFlat();
579
+ // Are there no tests?
528
580
  if (vestUtils.isEmpty(testObjects)) {
529
581
  return false;
530
582
  }
583
+ // Does the field have any tests with errors?
584
+ if (hasErrorsByTestObjects(fieldName)) {
585
+ return false;
586
+ }
531
587
  // Does the given field have any pending tests that are not optional?
532
588
  if (hasNonOptionalIncomplete(fieldName)) {
533
589
  return false;
534
590
  }
591
+ // Does the field have no missing tests?
535
592
  return noMissingTests(fieldName);
536
593
  }
537
594
  function shouldAddValidPropertyInGroup(groupName, fieldName) {
538
- if (fieldIsOmitted(fieldName)) {
595
+ if (optionalFiedIsApplied(fieldName)) {
539
596
  return true;
540
597
  }
541
598
  if (hasGroupFailuresByTestObjects(Severity.ERRORS, groupName, fieldName)) {
@@ -547,16 +604,10 @@ function shouldAddValidPropertyInGroup(groupName, fieldName) {
547
604
  }
548
605
  return noMissingTestsByGroup(groupName, fieldName);
549
606
  }
550
- function fieldIsOmitted(fieldName) {
551
- if (!fieldName) {
552
- return false;
553
- }
554
- return useOptionalFieldApplied(fieldName) === true;
555
- }
556
607
  // Does the given field have any pending tests that are not optional?
557
608
  function hasNonOptionalIncomplete(fieldName) {
558
609
  return vestUtils.isNotEmpty(useAllIncomplete().filter(function (testObject) {
559
- return isOptionalFieldIncomplete(testObject, fieldName);
610
+ return isTestObjectOptional(testObject, fieldName);
560
611
  }));
561
612
  }
562
613
  // Do the given group/field have any pending tests that are not optional?
@@ -565,47 +616,58 @@ function hasNonOptionalIncompleteByGroup(groupName, fieldName) {
565
616
  if (nonMatchingGroupName(testObject, groupName)) {
566
617
  return false;
567
618
  }
568
- return isOptionalFieldIncomplete(testObject, fieldName);
619
+ return isTestObjectOptional(testObject, fieldName);
569
620
  }));
570
621
  }
571
- function isOptionalFieldIncomplete(testObject, fieldName) {
622
+ function isTestObjectOptional(testObject, fieldName) {
572
623
  if (nonMatchingFieldName(testObject, fieldName)) {
573
624
  return false;
574
625
  }
575
- return useOptionalFieldConfig(testObject.fieldName) !== true;
626
+ return optionalFiedIsApplied(fieldName);
576
627
  }
628
+ // Did all of the tests for the provided field run/omit?
629
+ // This makes sure that the fields are not skipped or pending.
577
630
  function noMissingTests(fieldName) {
578
631
  var testObjects = useTestsFlat();
579
632
  return testObjects.every(function (testObject) {
580
- if (nonMatchingFieldName(testObject, fieldName)) {
581
- return true;
582
- }
583
- return missingTestsLogic(testObject, fieldName);
633
+ return noMissingTestsLogic(testObject, fieldName);
584
634
  });
585
635
  }
636
+ // Does the group have no missing tests?
586
637
  function noMissingTestsByGroup(groupName, fieldName) {
587
638
  var testObjects = useTestsFlat();
588
639
  return testObjects.every(function (testObject) {
589
640
  if (nonMatchingGroupName(testObject, groupName)) {
590
641
  return true;
591
642
  }
592
- return missingTestsLogic(testObject, fieldName);
643
+ return noMissingTestsLogic(testObject, fieldName);
593
644
  });
594
645
  }
595
- function missingTestsLogic(testObject, fieldName) {
646
+ // Does the object qualify as either tested or omitted (but not skipped!)
647
+ function noMissingTestsLogic(testObject, fieldName) {
596
648
  if (nonMatchingFieldName(testObject, fieldName)) {
597
649
  return true;
598
650
  }
599
- return (useOptionalFieldConfig(testObject.fieldName) === true ||
651
+ /**
652
+ * The reason we're checking for the optional field here and not in "omitOptionalFields"
653
+ * is because that unlike the bool/function check we do there, here it only depends on
654
+ * whether the field was tested alredy or not.
655
+ *
656
+ * We qualify the test as not missing only if it was already run, if it is omitted,
657
+ * or if it is marked as optional, even if the optional check did not apply yet -
658
+ * but the test did not reach its final state.
659
+ */
660
+ return (optionalTestAwaitsResolution(testObject) ||
600
661
  testObject.isTested() ||
601
662
  testObject.isOmitted());
602
663
  }
603
-
604
- function useSummary() {
605
- var summary = context.useX().summary;
606
- vestUtils.invariant(summary);
607
- return summary;
664
+ function optionalTestAwaitsResolution(testObject) {
665
+ // Does the test belong to an optional field,
666
+ // and the test itself is still in an indeterminate state?
667
+ return (useOptionalField(testObject.fieldName).type ===
668
+ OptionalFieldTypes.Delayed && testObject.awaitsResolution());
608
669
  }
670
+
609
671
  /**
610
672
  * Reads the testObjects list and gets full validation result from it.
611
673
  */
@@ -717,57 +779,85 @@ function collectAll(testGroup, severityKey) {
717
779
  return output;
718
780
  }
719
781
 
720
- function getErrors(fieldName) {
721
- return getFailures(Severity.ERRORS, fieldName);
722
- }
723
- function getWarnings(fieldName) {
724
- return getFailures(Severity.WARNINGS, fieldName);
782
+ // eslint-disable-next-line max-lines-per-function, max-statements
783
+ function suiteSelectors(summary) {
784
+ var selectors = {
785
+ getErrors: getErrors,
786
+ getErrorsByGroup: getErrorsByGroup,
787
+ getWarnings: getWarnings,
788
+ getWarningsByGroup: getWarningsByGroup,
789
+ hasErrors: hasErrors,
790
+ hasErrorsByGroup: hasErrorsByGroup,
791
+ hasWarnings: hasWarnings,
792
+ hasWarningsByGroup: hasWarningsByGroup,
793
+ isValid: isValid,
794
+ isValidByGroup: isValidByGroup
795
+ };
796
+ return selectors;
797
+ // Booleans
798
+ function isValid(fieldName) {
799
+ var _a;
800
+ return fieldName ? Boolean((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.valid) : summary.valid;
801
+ }
802
+ function isValidByGroup(groupName, fieldName) {
803
+ var group = summary.groups[groupName];
804
+ if (!group) {
805
+ return false;
806
+ }
807
+ if (fieldName) {
808
+ return isFieldValid(group, fieldName);
809
+ }
810
+ for (var fieldName_1 in group) {
811
+ if (!isFieldValid(group, fieldName_1)) {
812
+ return false;
813
+ }
814
+ }
815
+ return true;
816
+ }
817
+ function hasWarnings(fieldName) {
818
+ return hasFailures(summary, SeverityCount.WARN_COUNT, fieldName);
819
+ }
820
+ function hasErrors(fieldName) {
821
+ return hasFailures(summary, SeverityCount.ERROR_COUNT, fieldName);
822
+ }
823
+ function hasWarningsByGroup(groupName, fieldName) {
824
+ return hasFailuresByGroup(summary, SeverityCount.WARN_COUNT, groupName, fieldName);
825
+ }
826
+ function hasErrorsByGroup(groupName, fieldName) {
827
+ return hasFailuresByGroup(summary, SeverityCount.ERROR_COUNT, groupName, fieldName);
828
+ }
829
+ function getWarnings(fieldName) {
830
+ return getFailures(summary, Severity.WARNINGS, fieldName);
831
+ }
832
+ function getErrors(fieldName) {
833
+ return getFailures(summary, Severity.ERRORS, fieldName);
834
+ }
835
+ function getErrorsByGroup(groupName, fieldName) {
836
+ return getFailuresByGroup(summary, Severity.ERRORS, groupName, fieldName);
837
+ }
838
+ function getWarningsByGroup(groupName, fieldName) {
839
+ return getFailuresByGroup(summary, Severity.WARNINGS, groupName, fieldName);
840
+ }
725
841
  }
726
- /**
727
- * @returns suite or field's errors or warnings.
728
- */
729
- function getFailures(severityKey, fieldName) {
730
- var summary = useSummary();
842
+ // Gathers all failures of a given severity
843
+ // With a fieldName, it will only gather failures for that field
844
+ function getFailures(summary, severityKey, fieldName) {
731
845
  return gatherFailures(summary.tests, severityKey, fieldName);
732
846
  }
733
-
734
- function getErrorsByGroup(groupName, fieldName) {
735
- return getFailuresByGroup(groupName, Severity.ERRORS, fieldName);
736
- }
737
- function getWarningsByGroup(groupName, fieldName) {
738
- return getFailuresByGroup(groupName, Severity.WARNINGS, fieldName);
739
- }
740
- function getFailuresByGroup(groupName, severityKey, fieldName) {
741
- var summary = useSummary();
847
+ // Gathers all failures of a given severity within a group
848
+ // With a fieldName, it will only gather failures for that field
849
+ function getFailuresByGroup(summary, severityKey, groupName, fieldName) {
742
850
  return gatherFailures(summary.groups[groupName], severityKey, fieldName);
743
851
  }
744
-
745
- function hasErrors(fieldName) {
746
- return hasFailures(SeverityCount.ERROR_COUNT, fieldName);
747
- }
748
- function hasWarnings(fieldName) {
749
- return hasFailures(SeverityCount.WARN_COUNT, fieldName);
750
- }
751
- function hasFailures(severityCount, fieldName) {
852
+ // Checks if a field is valid within a container object - can be within a group or top level
853
+ function isFieldValid(testContainer, fieldName) {
752
854
  var _a;
753
- var summary = useSummary();
754
- if (fieldName) {
755
- return vestUtils.isPositive((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
756
- }
757
- return vestUtils.isPositive(summary[severityCount]);
758
- }
759
-
760
- function hasErrorsByGroup(groupName, fieldName) {
761
- return hasFailuresByGroup(Severity.ERRORS, groupName, fieldName);
762
- }
763
- function hasWarningsByGroup(groupName, fieldName) {
764
- return hasFailuresByGroup(Severity.WARNINGS, groupName, fieldName);
855
+ return !!((_a = testContainer[fieldName]) === null || _a === void 0 ? void 0 : _a.valid);
765
856
  }
766
- // eslint-disable-next-line max-statements
767
- function hasFailuresByGroup(severityKey, groupName, fieldName) {
857
+ // Checks if a there are any failures of a given severity within a group
858
+ // If a fieldName is provided, it will only check for failures within that field
859
+ function hasFailuresByGroup(summary, severityCount, groupName, fieldName) {
768
860
  var _a, _b;
769
- var summary = useSummary();
770
- var severityCount = countKeyBySeverity(severityKey);
771
861
  var group = summary.groups[groupName];
772
862
  if (!group) {
773
863
  return false;
@@ -782,32 +872,14 @@ function hasFailuresByGroup(severityKey, groupName, fieldName) {
782
872
  }
783
873
  return false;
784
874
  }
785
-
786
- function isValid(fieldName) {
787
- var summary = useSummary();
788
- return fieldName
789
- ? Boolean(isFieldValid(summary.tests, fieldName))
790
- : summary.valid;
791
- }
792
- function isValidByGroup(groupName, fieldName) {
793
- var summary = useSummary();
794
- var group = summary.groups[groupName];
795
- if (!group) {
796
- return false;
797
- }
798
- if (fieldName) {
799
- return isFieldValid(group, fieldName);
800
- }
801
- for (var fieldName_1 in group) {
802
- if (!isFieldValid(group, fieldName_1)) {
803
- return false;
804
- }
805
- }
806
- return true;
807
- }
808
- function isFieldValid(testContainer, fieldName) {
875
+ // Checks if there are any failures of a given severity
876
+ // If a fieldName is provided, it will only check for failures within that field
877
+ function hasFailures(summary, countKey, fieldName) {
809
878
  var _a;
810
- return !!((_a = testContainer[fieldName]) === null || _a === void 0 ? void 0 : _a.valid);
879
+ var failureCount = fieldName
880
+ ? (_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[countKey]
881
+ : summary[countKey] || 0;
882
+ return vestUtils.isPositive(failureCount);
811
883
  }
812
884
 
813
885
  var cache$1 = vestUtils.cache(1);
@@ -817,18 +889,7 @@ function produceSuiteResult() {
817
889
  return cache$1([testObjects], context.bind(ctxRef, function () {
818
890
  var summary = genTestsSummary();
819
891
  var suiteName = useSuiteName();
820
- var ref = { summary: summary };
821
- return vestUtils.assign(summary, {
822
- getErrors: context.bind(ref, getErrors),
823
- getErrorsByGroup: context.bind(ref, getErrorsByGroup),
824
- getWarnings: context.bind(ref, getWarnings),
825
- getWarningsByGroup: context.bind(ref, getWarningsByGroup),
826
- hasErrors: context.bind(ref, hasErrors),
827
- hasErrorsByGroup: context.bind(ref, hasErrorsByGroup),
828
- hasWarnings: context.bind(ref, hasWarnings),
829
- hasWarningsByGroup: context.bind(ref, hasWarningsByGroup),
830
- isValid: context.bind(ref, isValid),
831
- isValidByGroup: context.bind(ref, isValidByGroup),
892
+ return vestUtils.assign(summary, suiteSelectors(summary), {
832
893
  suiteName: suiteName
833
894
  });
834
895
  }));
@@ -847,7 +908,7 @@ function hasRemainingTests(fieldName) {
847
908
  return matchingFieldName(testObject, fieldName);
848
909
  });
849
910
  }
850
- return vestUtils.isNotEmpty(allIncomplete);
911
+ return true;
851
912
  }
852
913
 
853
914
  var cache = vestUtils.cache(20);
@@ -864,10 +925,10 @@ function produceFullResult() {
864
925
  * DONE is here and not in its own module to prevent circular dependency issues.
865
926
  */
866
927
  function shouldSkipDoneRegistration(callback, fieldName, output) {
928
+ var _a;
867
929
  // If we do not have any test runs for the current field
868
930
  return !!(!vestUtils.isFunction(callback) ||
869
- (fieldName &&
870
- (!output.tests[fieldName] || vestUtils.isEmpty(output.tests[fieldName].testCount))));
931
+ (fieldName && vestUtils.numberEquals((_a = output.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.testCount, 0)));
871
932
  }
872
933
  function shouldRunDoneCallback(fieldName) {
873
934
  // is suite finished || field name exists, and test is finished;
@@ -909,34 +970,48 @@ function deferDoneCallback(doneCallback, fieldName) {
909
970
  });
910
971
  }
911
972
 
973
+ /**
974
+ * This module gets triggered once the suite is done running its sync tests.
975
+ *
976
+ * It goes over all the tests in the state, and checks if they need to be omitted.
977
+ */
912
978
  function omitOptionalFields() {
913
979
  var optionalFields = useOptionalFields()[0];
980
+ // If there are no optional fields, we don't need to do anything
914
981
  if (vestUtils.isEmpty(optionalFields)) {
915
982
  return;
916
983
  }
984
+ // Create an object to store the fields that need to be omitted
917
985
  var shouldOmit = {};
918
- useSetTests(function (tests) {
919
- return vestUtils.nestedArray.transform(tests, function (testObject) {
920
- var fieldName = testObject.fieldName;
921
- if (vestUtils.hasOwnProperty(shouldOmit, fieldName)) {
922
- verifyAndOmit(testObject);
923
- }
924
- else {
925
- runOptionalConfig(testObject);
926
- }
927
- return testObject;
928
- });
986
+ // iterate over each of the tests in the state
987
+ useTestsFlat().forEach(function (testObject) {
988
+ // If we already added the current field (not this test specifically)
989
+ // no need for further checks, go and omit the test
990
+ if (vestUtils.hasOwnProperty(shouldOmit, testObject.fieldName)) {
991
+ verifyAndOmit(testObject);
992
+ }
993
+ else {
994
+ // check if the field has an optional function
995
+ // if so, run it and verify/omit the test
996
+ runOptionalConfig(testObject);
997
+ }
929
998
  });
999
+ // refresh the tests in the state so that the omitted fields are applied
1000
+ useRefreshTestObjects();
930
1001
  function verifyAndOmit(testObject) {
931
1002
  if (shouldOmit[testObject.fieldName]) {
932
1003
  testObject.omit();
933
- useSetOptionalField(testObject.fieldName, function (current) { return [current[0], true]; });
1004
+ useSetOptionalField(testObject.fieldName, function () { return ({
1005
+ applied: true
1006
+ }); });
934
1007
  }
935
1008
  }
936
1009
  function runOptionalConfig(testObject) {
937
- var optionalConfig = useOptionalFieldConfig(testObject.fieldName);
938
- if (vestUtils.isFunction(optionalConfig)) {
939
- shouldOmit[testObject.fieldName] = optionalConfig();
1010
+ // Ge the optional configuration for the given field
1011
+ var optionalConfig = useOptionalField(testObject.fieldName);
1012
+ // If the optional was set to a function or a boolean, run it and verify/omit the test
1013
+ if (optionalConfig.type === OptionalFieldTypes.Immediate) {
1014
+ shouldOmit[testObject.fieldName] = vestUtils.optionalFunctionValue(optionalConfig.rule);
940
1015
  verifyAndOmit(testObject);
941
1016
  }
942
1017
  }
@@ -1042,7 +1117,7 @@ function create() {
1042
1117
  // State initialization
1043
1118
  var state = createState();
1044
1119
  // State reference - this holds the actual state values
1045
- var stateRef = createStateRef(state, { suiteId: vestUtils.genId(), suiteName: suiteName });
1120
+ var stateRef = createStateRef(state, { suiteId: vestUtils.seq(), suiteName: suiteName });
1046
1121
  // Create base context reference. All hooks will derive their data from this
1047
1122
  var ctxRef = { stateRef: stateRef, bus: bus };
1048
1123
  var suite = vestUtils.assign(
@@ -1156,7 +1231,7 @@ skip.group = function (item) {
1156
1231
  return addTo(1 /* ExclusionGroup.SKIP */, 'groups', item);
1157
1232
  };
1158
1233
  //Checks whether a certain test profile excluded by any of the exclusion groups.
1159
- // eslint-disable-next-line complexity, max-statements, max-lines-per-function
1234
+ // eslint-disable-next-line complexity, max-statements
1160
1235
  function isExcluded(testObject) {
1161
1236
  var fieldName = testObject.fieldName, groupName = testObject.groupName;
1162
1237
  if (isExcludedIndividually())
@@ -1360,44 +1435,16 @@ function setMode(nextMode) {
1360
1435
  function omitWhen(conditional, callback) {
1361
1436
  isolate({ type: IsolateTypes.OMIT_WHEN }, function () {
1362
1437
  context.run({
1363
- omitted: isOmitted() ||
1438
+ omitted: inActiveOmitWhen() ||
1364
1439
  vestUtils.optionalFunctionValue(conditional, vestUtils.optionalFunctionValue(produceSuiteResult))
1365
1440
  }, function () { return callback(); });
1366
1441
  });
1367
1442
  }
1368
- function isOmitted() {
1443
+ // Checks that we're currently in an active omitWhen block
1444
+ function inActiveOmitWhen() {
1369
1445
  return !!context.useX().omitted;
1370
1446
  }
1371
1447
 
1372
- /**
1373
- * Marks a field as optional, either just by name, or by a given condition.
1374
- *
1375
- * @example
1376
- *
1377
- * optional('field_name');
1378
- *
1379
- * optional({
1380
- * username: () => allowUsernameEmpty,
1381
- * });
1382
- */
1383
- function optional(optionals) {
1384
- // When the optional is given as a string or a list of strings
1385
- // we just add them to the list of optional fields.
1386
- if (vestUtils.isArray(optionals) || vestUtils.isStringValue(optionals)) {
1387
- vestUtils.asArray(optionals).forEach(function (optionalField) {
1388
- useSetOptionalField(optionalField, [true, false]);
1389
- });
1390
- }
1391
- else {
1392
- // if it's an object, we iterate over the keys and add them to the list
1393
- var optionalFunctions = optionals;
1394
- for (var field in optionalFunctions) {
1395
- var predicate = optionalFunctions[field];
1396
- useSetOptionalField(field, [predicate, false]);
1397
- }
1398
- }
1399
- }
1400
-
1401
1448
  /******************************************************************************
1402
1449
  Copyright (c) Microsoft Corporation.
1403
1450
 
@@ -1423,8 +1470,6 @@ function __spreadArray(to, from, pack) {
1423
1470
  return to.concat(ar || Array.prototype.slice.call(from));
1424
1471
  }
1425
1472
 
1426
- vestUtils.bindNot(vestUtils.isStringValue);
1427
-
1428
1473
  function isSameProfileTest(testObject1, testObject2) {
1429
1474
  return (testObject1.fieldName === testObject2.fieldName &&
1430
1475
  testObject1.groupName === testObject2.groupName);
@@ -1587,7 +1632,7 @@ function registerPrevRunTest(testObject) {
1587
1632
  return testObject;
1588
1633
  }
1589
1634
  var prevRunTest = useTestAtCursor(testObject);
1590
- if (isOmitted()) {
1635
+ if (inActiveOmitWhen() || optionalFiedIsApplied(testObject.fieldName)) {
1591
1636
  prevRunTest.omit();
1592
1637
  cursor.next();
1593
1638
  return prevRunTest;
@@ -1618,7 +1663,6 @@ function registerTestObjectByTier(testObject) {
1618
1663
  }
1619
1664
 
1620
1665
  /* eslint-disable jest/valid-title */
1621
- // eslint-disable-next-line max-lines-per-function
1622
1666
  function bindTestMemo(test) {
1623
1667
  var cache = vestUtils.cache(10); // arbitrary cache size
1624
1668
  // eslint-disable-next-line max-statements
@@ -1689,7 +1733,7 @@ function warn() {
1689
1733
  ctx.currentTest.warn();
1690
1734
  }
1691
1735
 
1692
- var VERSION = "4.4.3-dev-c786f7";
1736
+ var VERSION = "4.6.0";
1693
1737
 
1694
1738
  Object.defineProperty(exports, 'enforce', {
1695
1739
  enumerable: true,
@@ -1709,5 +1753,6 @@ exports.only = only;
1709
1753
  exports.optional = optional;
1710
1754
  exports.skip = skip;
1711
1755
  exports.skipWhen = skipWhen;
1756
+ exports.suiteSelectors = suiteSelectors;
1712
1757
  exports.test = test;
1713
1758
  exports.warn = warn;