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
@@ -1,5 +1,5 @@
1
1
  export { enforce } from 'n4s';
2
- import { isUndefined, isStringValue, assign, cache as cache$2, optionalFunctionValue, nestedArray, asArray, genId, isFunction, isNullish, deferThrow, invariant, bindNot, either, isEmpty, isNotEmpty, isPositive, hasOwnProperty, isArray, callEach, bus, defaultTo, isPromise, isNull } from 'vest-utils';
2
+ import { isUndefined, isStringValue, assign, cache as cache$2, nestedArray, asArray, seq, optionalFunctionValue, isFunction, isNullish, deferThrow, invariant, bindNot, either, isArray, isEmpty, isNotEmpty, isPositive, numberEquals, hasOwnProperty, callEach, bus, defaultTo, isPromise, isNull } from 'vest-utils';
3
3
  import { createContext } from 'context';
4
4
 
5
5
  function shouldUseErrorAsMessage(message, error) {
@@ -61,7 +61,7 @@ function generateIsolate(type, path) {
61
61
  var context = createContext(function (ctxRef, parentContext) {
62
62
  return parentContext
63
63
  ? null
64
- : assign({}, {
64
+ : assign({
65
65
  exclusion: {
66
66
  tests: {},
67
67
  groups: {}
@@ -88,29 +88,22 @@ function useTestCallbacks() {
88
88
  return useStateRef().testCallbacks();
89
89
  }
90
90
  // OPTIONAL FIELDS
91
- function useOptionalField(fieldName) {
92
- var optionalFields = useOptionalFields()[0];
93
- return optionalFields[fieldName];
94
- }
95
91
  function useOptionalFields() {
96
92
  return useStateRef().optionalFields();
97
93
  }
98
94
  function useSetOptionalField(fieldName, setter) {
99
95
  var _a = useOptionalFields(), setOptionalFields = _a[1];
100
- setOptionalFields(function (optionalFields) {
96
+ setOptionalFields(function (prev) {
101
97
  var _a;
102
- return assign(optionalFields, (_a = {},
103
- _a[fieldName] = optionalFunctionValue(setter, optionalFields[fieldName]),
98
+ return assign(prev, (_a = {},
99
+ _a[fieldName] = assign({}, prev[fieldName], setter(prev[fieldName])),
104
100
  _a));
105
101
  });
106
102
  }
107
- function useOptionalFieldApplied(fieldName) {
108
- var _a;
109
- return (_a = useOptionalField(fieldName)) === null || _a === void 0 ? void 0 : _a[1];
110
- }
111
- function useOptionalFieldConfig(fieldName) {
103
+ function useOptionalField(fieldName) {
112
104
  var _a;
113
- return (_a = useOptionalField(fieldName)) === null || _a === void 0 ? void 0 : _a[0];
105
+ var optionalFields = useOptionalFields()[0];
106
+ return (_a = optionalFields[fieldName]) !== null && _a !== void 0 ? _a : {};
114
107
  }
115
108
  function useTestObjects() {
116
109
  return useStateRef().testObjects();
@@ -152,7 +145,7 @@ var VestTest = /** @class */ (function () {
152
145
  function VestTest(fieldName, testFn, _a) {
153
146
  var _b = _a === void 0 ? {} : _a, message = _b.message, groupName = _b.groupName, key = _b.key;
154
147
  this.key = null;
155
- this.id = genId();
148
+ this.id = seq();
156
149
  this.severity = TestSeverity.Error;
157
150
  this.status = STATUS_UNTESTED;
158
151
  this.fieldName = fieldName;
@@ -240,18 +233,9 @@ var VestTest = /** @class */ (function () {
240
233
  VestTest.prototype.valueOf = function () {
241
234
  return !this.isFailing();
242
235
  };
243
- VestTest.prototype.hasFailures = function () {
244
- return this.isFailing() || this.isWarning();
245
- };
246
- VestTest.prototype.isNonActionable = function () {
247
- return this.isSkipped() || this.isOmitted() || this.isCanceled();
248
- };
249
236
  VestTest.prototype.isPending = function () {
250
237
  return this.statusEquals(STATUS_PENDING);
251
238
  };
252
- VestTest.prototype.isTested = function () {
253
- return this.hasFailures() || this.isPassing();
254
- };
255
239
  VestTest.prototype.isOmitted = function () {
256
240
  return this.statusEquals(STATUS_OMITTED);
257
241
  };
@@ -273,6 +257,20 @@ var VestTest = /** @class */ (function () {
273
257
  VestTest.prototype.isWarning = function () {
274
258
  return this.statusEquals(STATUS_WARNING);
275
259
  };
260
+ VestTest.prototype.hasFailures = function () {
261
+ return this.isFailing() || this.isWarning();
262
+ };
263
+ VestTest.prototype.isNonActionable = function () {
264
+ return this.isSkipped() || this.isOmitted() || this.isCanceled();
265
+ };
266
+ VestTest.prototype.isTested = function () {
267
+ return this.hasFailures() || this.isPassing();
268
+ };
269
+ VestTest.prototype.awaitsResolution = function () {
270
+ // Is the test in a state where it can still be run, or complete running
271
+ // and its final status is indeterminate?
272
+ return this.isSkipped() || this.isUntested() || this.isPending();
273
+ };
276
274
  VestTest.prototype.statusEquals = function (status) {
277
275
  return this.status === status;
278
276
  };
@@ -512,26 +510,85 @@ function hasFailuresByTestObject(testObject, severityKey, fieldName) {
512
510
  return true;
513
511
  }
514
512
 
513
+ /**
514
+ * Marks a field as optional, either just by name, or by a given condition.
515
+ *
516
+ * @example
517
+ *
518
+ * optional('field_name');
519
+ *
520
+ * optional({
521
+ * username: () => allowUsernameEmpty,
522
+ * });
523
+ */
524
+ function optional(optionals) {
525
+ // There are two types of optional field declarations:
526
+ // 1. Delayed: A string, which is the name of the field to be optional.
527
+ // We will only determine whether to omit the test after the suite is done running
528
+ //
529
+ // 2. Immediate: Either a boolean or a function, which is used to determine
530
+ // if the field should be optional.
531
+ // Delayed case (field name)
532
+ if (isArray(optionals) || isStringValue(optionals)) {
533
+ asArray(optionals).forEach(function (optionalField) {
534
+ useSetOptionalField(optionalField, function () { return ({
535
+ type: OptionalFieldTypes.Delayed,
536
+ applied: false,
537
+ rule: null
538
+ }); });
539
+ });
540
+ }
541
+ else {
542
+ var _loop_1 = function (field) {
543
+ var value = optionals[field];
544
+ useSetOptionalField(field, function () { return ({
545
+ type: OptionalFieldTypes.Immediate,
546
+ rule: value,
547
+ applied: optionalFunctionValue(value)
548
+ }); });
549
+ };
550
+ // Immediately case (function or boolean)
551
+ for (var field in optionals) {
552
+ _loop_1(field);
553
+ }
554
+ }
555
+ }
556
+ function optionalFiedIsApplied(fieldName) {
557
+ if (!fieldName) {
558
+ return false;
559
+ }
560
+ return useOptionalField(fieldName).applied;
561
+ }
562
+ var OptionalFieldTypes;
563
+ (function (OptionalFieldTypes) {
564
+ OptionalFieldTypes[OptionalFieldTypes["Immediate"] = 0] = "Immediate";
565
+ OptionalFieldTypes[OptionalFieldTypes["Delayed"] = 1] = "Delayed";
566
+ })(OptionalFieldTypes || (OptionalFieldTypes = {}));
567
+
515
568
  // eslint-disable-next-line max-statements, complexity
516
569
  function shouldAddValidProperty(fieldName) {
517
- if (fieldIsOmitted(fieldName)) {
570
+ // Is the field optional, and the optional condition is applied
571
+ if (optionalFiedIsApplied(fieldName)) {
518
572
  return true;
519
573
  }
520
- if (hasErrorsByTestObjects(fieldName)) {
521
- return false;
522
- }
523
574
  var testObjects = useTestsFlat();
575
+ // Are there no tests?
524
576
  if (isEmpty(testObjects)) {
525
577
  return false;
526
578
  }
579
+ // Does the field have any tests with errors?
580
+ if (hasErrorsByTestObjects(fieldName)) {
581
+ return false;
582
+ }
527
583
  // Does the given field have any pending tests that are not optional?
528
584
  if (hasNonOptionalIncomplete(fieldName)) {
529
585
  return false;
530
586
  }
587
+ // Does the field have no missing tests?
531
588
  return noMissingTests(fieldName);
532
589
  }
533
590
  function shouldAddValidPropertyInGroup(groupName, fieldName) {
534
- if (fieldIsOmitted(fieldName)) {
591
+ if (optionalFiedIsApplied(fieldName)) {
535
592
  return true;
536
593
  }
537
594
  if (hasGroupFailuresByTestObjects(Severity.ERRORS, groupName, fieldName)) {
@@ -543,16 +600,10 @@ function shouldAddValidPropertyInGroup(groupName, fieldName) {
543
600
  }
544
601
  return noMissingTestsByGroup(groupName, fieldName);
545
602
  }
546
- function fieldIsOmitted(fieldName) {
547
- if (!fieldName) {
548
- return false;
549
- }
550
- return useOptionalFieldApplied(fieldName) === true;
551
- }
552
603
  // Does the given field have any pending tests that are not optional?
553
604
  function hasNonOptionalIncomplete(fieldName) {
554
605
  return isNotEmpty(useAllIncomplete().filter(function (testObject) {
555
- return isOptionalFieldIncomplete(testObject, fieldName);
606
+ return isTestObjectOptional(testObject, fieldName);
556
607
  }));
557
608
  }
558
609
  // Do the given group/field have any pending tests that are not optional?
@@ -561,47 +612,58 @@ function hasNonOptionalIncompleteByGroup(groupName, fieldName) {
561
612
  if (nonMatchingGroupName(testObject, groupName)) {
562
613
  return false;
563
614
  }
564
- return isOptionalFieldIncomplete(testObject, fieldName);
615
+ return isTestObjectOptional(testObject, fieldName);
565
616
  }));
566
617
  }
567
- function isOptionalFieldIncomplete(testObject, fieldName) {
618
+ function isTestObjectOptional(testObject, fieldName) {
568
619
  if (nonMatchingFieldName(testObject, fieldName)) {
569
620
  return false;
570
621
  }
571
- return useOptionalFieldConfig(testObject.fieldName) !== true;
622
+ return optionalFiedIsApplied(fieldName);
572
623
  }
624
+ // Did all of the tests for the provided field run/omit?
625
+ // This makes sure that the fields are not skipped or pending.
573
626
  function noMissingTests(fieldName) {
574
627
  var testObjects = useTestsFlat();
575
628
  return testObjects.every(function (testObject) {
576
- if (nonMatchingFieldName(testObject, fieldName)) {
577
- return true;
578
- }
579
- return missingTestsLogic(testObject, fieldName);
629
+ return noMissingTestsLogic(testObject, fieldName);
580
630
  });
581
631
  }
632
+ // Does the group have no missing tests?
582
633
  function noMissingTestsByGroup(groupName, fieldName) {
583
634
  var testObjects = useTestsFlat();
584
635
  return testObjects.every(function (testObject) {
585
636
  if (nonMatchingGroupName(testObject, groupName)) {
586
637
  return true;
587
638
  }
588
- return missingTestsLogic(testObject, fieldName);
639
+ return noMissingTestsLogic(testObject, fieldName);
589
640
  });
590
641
  }
591
- function missingTestsLogic(testObject, fieldName) {
642
+ // Does the object qualify as either tested or omitted (but not skipped!)
643
+ function noMissingTestsLogic(testObject, fieldName) {
592
644
  if (nonMatchingFieldName(testObject, fieldName)) {
593
645
  return true;
594
646
  }
595
- return (useOptionalFieldConfig(testObject.fieldName) === true ||
647
+ /**
648
+ * The reason we're checking for the optional field here and not in "omitOptionalFields"
649
+ * is because that unlike the bool/function check we do there, here it only depends on
650
+ * whether the field was tested alredy or not.
651
+ *
652
+ * We qualify the test as not missing only if it was already run, if it is omitted,
653
+ * or if it is marked as optional, even if the optional check did not apply yet -
654
+ * but the test did not reach its final state.
655
+ */
656
+ return (optionalTestAwaitsResolution(testObject) ||
596
657
  testObject.isTested() ||
597
658
  testObject.isOmitted());
598
659
  }
599
-
600
- function useSummary() {
601
- var summary = context.useX().summary;
602
- invariant(summary);
603
- return summary;
660
+ function optionalTestAwaitsResolution(testObject) {
661
+ // Does the test belong to an optional field,
662
+ // and the test itself is still in an indeterminate state?
663
+ return (useOptionalField(testObject.fieldName).type ===
664
+ OptionalFieldTypes.Delayed && testObject.awaitsResolution());
604
665
  }
666
+
605
667
  /**
606
668
  * Reads the testObjects list and gets full validation result from it.
607
669
  */
@@ -713,57 +775,85 @@ function collectAll(testGroup, severityKey) {
713
775
  return output;
714
776
  }
715
777
 
716
- function getErrors(fieldName) {
717
- return getFailures(Severity.ERRORS, fieldName);
718
- }
719
- function getWarnings(fieldName) {
720
- return getFailures(Severity.WARNINGS, fieldName);
778
+ // eslint-disable-next-line max-lines-per-function, max-statements
779
+ function suiteSelectors(summary) {
780
+ var selectors = {
781
+ getErrors: getErrors,
782
+ getErrorsByGroup: getErrorsByGroup,
783
+ getWarnings: getWarnings,
784
+ getWarningsByGroup: getWarningsByGroup,
785
+ hasErrors: hasErrors,
786
+ hasErrorsByGroup: hasErrorsByGroup,
787
+ hasWarnings: hasWarnings,
788
+ hasWarningsByGroup: hasWarningsByGroup,
789
+ isValid: isValid,
790
+ isValidByGroup: isValidByGroup
791
+ };
792
+ return selectors;
793
+ // Booleans
794
+ function isValid(fieldName) {
795
+ var _a;
796
+ return fieldName ? Boolean((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.valid) : summary.valid;
797
+ }
798
+ function isValidByGroup(groupName, fieldName) {
799
+ var group = summary.groups[groupName];
800
+ if (!group) {
801
+ return false;
802
+ }
803
+ if (fieldName) {
804
+ return isFieldValid(group, fieldName);
805
+ }
806
+ for (var fieldName_1 in group) {
807
+ if (!isFieldValid(group, fieldName_1)) {
808
+ return false;
809
+ }
810
+ }
811
+ return true;
812
+ }
813
+ function hasWarnings(fieldName) {
814
+ return hasFailures(summary, SeverityCount.WARN_COUNT, fieldName);
815
+ }
816
+ function hasErrors(fieldName) {
817
+ return hasFailures(summary, SeverityCount.ERROR_COUNT, fieldName);
818
+ }
819
+ function hasWarningsByGroup(groupName, fieldName) {
820
+ return hasFailuresByGroup(summary, SeverityCount.WARN_COUNT, groupName, fieldName);
821
+ }
822
+ function hasErrorsByGroup(groupName, fieldName) {
823
+ return hasFailuresByGroup(summary, SeverityCount.ERROR_COUNT, groupName, fieldName);
824
+ }
825
+ function getWarnings(fieldName) {
826
+ return getFailures(summary, Severity.WARNINGS, fieldName);
827
+ }
828
+ function getErrors(fieldName) {
829
+ return getFailures(summary, Severity.ERRORS, fieldName);
830
+ }
831
+ function getErrorsByGroup(groupName, fieldName) {
832
+ return getFailuresByGroup(summary, Severity.ERRORS, groupName, fieldName);
833
+ }
834
+ function getWarningsByGroup(groupName, fieldName) {
835
+ return getFailuresByGroup(summary, Severity.WARNINGS, groupName, fieldName);
836
+ }
721
837
  }
722
- /**
723
- * @returns suite or field's errors or warnings.
724
- */
725
- function getFailures(severityKey, fieldName) {
726
- var summary = useSummary();
838
+ // Gathers all failures of a given severity
839
+ // With a fieldName, it will only gather failures for that field
840
+ function getFailures(summary, severityKey, fieldName) {
727
841
  return gatherFailures(summary.tests, severityKey, fieldName);
728
842
  }
729
-
730
- function getErrorsByGroup(groupName, fieldName) {
731
- return getFailuresByGroup(groupName, Severity.ERRORS, fieldName);
732
- }
733
- function getWarningsByGroup(groupName, fieldName) {
734
- return getFailuresByGroup(groupName, Severity.WARNINGS, fieldName);
735
- }
736
- function getFailuresByGroup(groupName, severityKey, fieldName) {
737
- var summary = useSummary();
843
+ // Gathers all failures of a given severity within a group
844
+ // With a fieldName, it will only gather failures for that field
845
+ function getFailuresByGroup(summary, severityKey, groupName, fieldName) {
738
846
  return gatherFailures(summary.groups[groupName], severityKey, fieldName);
739
847
  }
740
-
741
- function hasErrors(fieldName) {
742
- return hasFailures(SeverityCount.ERROR_COUNT, fieldName);
743
- }
744
- function hasWarnings(fieldName) {
745
- return hasFailures(SeverityCount.WARN_COUNT, fieldName);
746
- }
747
- function hasFailures(severityCount, fieldName) {
848
+ // Checks if a field is valid within a container object - can be within a group or top level
849
+ function isFieldValid(testContainer, fieldName) {
748
850
  var _a;
749
- var summary = useSummary();
750
- if (fieldName) {
751
- return isPositive((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
752
- }
753
- return isPositive(summary[severityCount]);
754
- }
755
-
756
- function hasErrorsByGroup(groupName, fieldName) {
757
- return hasFailuresByGroup(Severity.ERRORS, groupName, fieldName);
758
- }
759
- function hasWarningsByGroup(groupName, fieldName) {
760
- return hasFailuresByGroup(Severity.WARNINGS, groupName, fieldName);
851
+ return !!((_a = testContainer[fieldName]) === null || _a === void 0 ? void 0 : _a.valid);
761
852
  }
762
- // eslint-disable-next-line max-statements
763
- function hasFailuresByGroup(severityKey, groupName, fieldName) {
853
+ // Checks if a there are any failures of a given severity within a group
854
+ // If a fieldName is provided, it will only check for failures within that field
855
+ function hasFailuresByGroup(summary, severityCount, groupName, fieldName) {
764
856
  var _a, _b;
765
- var summary = useSummary();
766
- var severityCount = countKeyBySeverity(severityKey);
767
857
  var group = summary.groups[groupName];
768
858
  if (!group) {
769
859
  return false;
@@ -778,32 +868,14 @@ function hasFailuresByGroup(severityKey, groupName, fieldName) {
778
868
  }
779
869
  return false;
780
870
  }
781
-
782
- function isValid(fieldName) {
783
- var summary = useSummary();
784
- return fieldName
785
- ? Boolean(isFieldValid(summary.tests, fieldName))
786
- : summary.valid;
787
- }
788
- function isValidByGroup(groupName, fieldName) {
789
- var summary = useSummary();
790
- var group = summary.groups[groupName];
791
- if (!group) {
792
- return false;
793
- }
794
- if (fieldName) {
795
- return isFieldValid(group, fieldName);
796
- }
797
- for (var fieldName_1 in group) {
798
- if (!isFieldValid(group, fieldName_1)) {
799
- return false;
800
- }
801
- }
802
- return true;
803
- }
804
- function isFieldValid(testContainer, fieldName) {
871
+ // Checks if there are any failures of a given severity
872
+ // If a fieldName is provided, it will only check for failures within that field
873
+ function hasFailures(summary, countKey, fieldName) {
805
874
  var _a;
806
- return !!((_a = testContainer[fieldName]) === null || _a === void 0 ? void 0 : _a.valid);
875
+ var failureCount = fieldName
876
+ ? (_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[countKey]
877
+ : summary[countKey] || 0;
878
+ return isPositive(failureCount);
807
879
  }
808
880
 
809
881
  var cache$1 = cache$2(1);
@@ -813,18 +885,7 @@ function produceSuiteResult() {
813
885
  return cache$1([testObjects], context.bind(ctxRef, function () {
814
886
  var summary = genTestsSummary();
815
887
  var suiteName = useSuiteName();
816
- var ref = { summary: summary };
817
- return assign(summary, {
818
- getErrors: context.bind(ref, getErrors),
819
- getErrorsByGroup: context.bind(ref, getErrorsByGroup),
820
- getWarnings: context.bind(ref, getWarnings),
821
- getWarningsByGroup: context.bind(ref, getWarningsByGroup),
822
- hasErrors: context.bind(ref, hasErrors),
823
- hasErrorsByGroup: context.bind(ref, hasErrorsByGroup),
824
- hasWarnings: context.bind(ref, hasWarnings),
825
- hasWarningsByGroup: context.bind(ref, hasWarningsByGroup),
826
- isValid: context.bind(ref, isValid),
827
- isValidByGroup: context.bind(ref, isValidByGroup),
888
+ return assign(summary, suiteSelectors(summary), {
828
889
  suiteName: suiteName
829
890
  });
830
891
  }));
@@ -843,7 +904,7 @@ function hasRemainingTests(fieldName) {
843
904
  return matchingFieldName(testObject, fieldName);
844
905
  });
845
906
  }
846
- return isNotEmpty(allIncomplete);
907
+ return true;
847
908
  }
848
909
 
849
910
  var cache = cache$2(20);
@@ -860,10 +921,10 @@ function produceFullResult() {
860
921
  * DONE is here and not in its own module to prevent circular dependency issues.
861
922
  */
862
923
  function shouldSkipDoneRegistration(callback, fieldName, output) {
924
+ var _a;
863
925
  // If we do not have any test runs for the current field
864
926
  return !!(!isFunction(callback) ||
865
- (fieldName &&
866
- (!output.tests[fieldName] || isEmpty(output.tests[fieldName].testCount))));
927
+ (fieldName && numberEquals((_a = output.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.testCount, 0)));
867
928
  }
868
929
  function shouldRunDoneCallback(fieldName) {
869
930
  // is suite finished || field name exists, and test is finished;
@@ -905,34 +966,48 @@ function deferDoneCallback(doneCallback, fieldName) {
905
966
  });
906
967
  }
907
968
 
969
+ /**
970
+ * This module gets triggered once the suite is done running its sync tests.
971
+ *
972
+ * It goes over all the tests in the state, and checks if they need to be omitted.
973
+ */
908
974
  function omitOptionalFields() {
909
975
  var optionalFields = useOptionalFields()[0];
976
+ // If there are no optional fields, we don't need to do anything
910
977
  if (isEmpty(optionalFields)) {
911
978
  return;
912
979
  }
980
+ // Create an object to store the fields that need to be omitted
913
981
  var shouldOmit = {};
914
- useSetTests(function (tests) {
915
- return nestedArray.transform(tests, function (testObject) {
916
- var fieldName = testObject.fieldName;
917
- if (hasOwnProperty(shouldOmit, fieldName)) {
918
- verifyAndOmit(testObject);
919
- }
920
- else {
921
- runOptionalConfig(testObject);
922
- }
923
- return testObject;
924
- });
982
+ // iterate over each of the tests in the state
983
+ useTestsFlat().forEach(function (testObject) {
984
+ // If we already added the current field (not this test specifically)
985
+ // no need for further checks, go and omit the test
986
+ if (hasOwnProperty(shouldOmit, testObject.fieldName)) {
987
+ verifyAndOmit(testObject);
988
+ }
989
+ else {
990
+ // check if the field has an optional function
991
+ // if so, run it and verify/omit the test
992
+ runOptionalConfig(testObject);
993
+ }
925
994
  });
995
+ // refresh the tests in the state so that the omitted fields are applied
996
+ useRefreshTestObjects();
926
997
  function verifyAndOmit(testObject) {
927
998
  if (shouldOmit[testObject.fieldName]) {
928
999
  testObject.omit();
929
- useSetOptionalField(testObject.fieldName, function (current) { return [current[0], true]; });
1000
+ useSetOptionalField(testObject.fieldName, function () { return ({
1001
+ applied: true
1002
+ }); });
930
1003
  }
931
1004
  }
932
1005
  function runOptionalConfig(testObject) {
933
- var optionalConfig = useOptionalFieldConfig(testObject.fieldName);
934
- if (isFunction(optionalConfig)) {
935
- shouldOmit[testObject.fieldName] = optionalConfig();
1006
+ // Ge the optional configuration for the given field
1007
+ var optionalConfig = useOptionalField(testObject.fieldName);
1008
+ // If the optional was set to a function or a boolean, run it and verify/omit the test
1009
+ if (optionalConfig.type === OptionalFieldTypes.Immediate) {
1010
+ shouldOmit[testObject.fieldName] = optionalFunctionValue(optionalConfig.rule);
936
1011
  verifyAndOmit(testObject);
937
1012
  }
938
1013
  }
@@ -1038,7 +1113,7 @@ function create() {
1038
1113
  // State initialization
1039
1114
  var state = createState();
1040
1115
  // State reference - this holds the actual state values
1041
- var stateRef = createStateRef(state, { suiteId: genId(), suiteName: suiteName });
1116
+ var stateRef = createStateRef(state, { suiteId: seq(), suiteName: suiteName });
1042
1117
  // Create base context reference. All hooks will derive their data from this
1043
1118
  var ctxRef = { stateRef: stateRef, bus: bus };
1044
1119
  var suite = assign(
@@ -1152,7 +1227,7 @@ skip.group = function (item) {
1152
1227
  return addTo(1 /* ExclusionGroup.SKIP */, 'groups', item);
1153
1228
  };
1154
1229
  //Checks whether a certain test profile excluded by any of the exclusion groups.
1155
- // eslint-disable-next-line complexity, max-statements, max-lines-per-function
1230
+ // eslint-disable-next-line complexity, max-statements
1156
1231
  function isExcluded(testObject) {
1157
1232
  var fieldName = testObject.fieldName, groupName = testObject.groupName;
1158
1233
  if (isExcludedIndividually())
@@ -1356,44 +1431,16 @@ function setMode(nextMode) {
1356
1431
  function omitWhen(conditional, callback) {
1357
1432
  isolate({ type: IsolateTypes.OMIT_WHEN }, function () {
1358
1433
  context.run({
1359
- omitted: isOmitted() ||
1434
+ omitted: inActiveOmitWhen() ||
1360
1435
  optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
1361
1436
  }, function () { return callback(); });
1362
1437
  });
1363
1438
  }
1364
- function isOmitted() {
1439
+ // Checks that we're currently in an active omitWhen block
1440
+ function inActiveOmitWhen() {
1365
1441
  return !!context.useX().omitted;
1366
1442
  }
1367
1443
 
1368
- /**
1369
- * Marks a field as optional, either just by name, or by a given condition.
1370
- *
1371
- * @example
1372
- *
1373
- * optional('field_name');
1374
- *
1375
- * optional({
1376
- * username: () => allowUsernameEmpty,
1377
- * });
1378
- */
1379
- function optional(optionals) {
1380
- // When the optional is given as a string or a list of strings
1381
- // we just add them to the list of optional fields.
1382
- if (isArray(optionals) || isStringValue(optionals)) {
1383
- asArray(optionals).forEach(function (optionalField) {
1384
- useSetOptionalField(optionalField, [true, false]);
1385
- });
1386
- }
1387
- else {
1388
- // if it's an object, we iterate over the keys and add them to the list
1389
- var optionalFunctions = optionals;
1390
- for (var field in optionalFunctions) {
1391
- var predicate = optionalFunctions[field];
1392
- useSetOptionalField(field, [predicate, false]);
1393
- }
1394
- }
1395
- }
1396
-
1397
1444
  /******************************************************************************
1398
1445
  Copyright (c) Microsoft Corporation.
1399
1446
 
@@ -1419,8 +1466,6 @@ function __spreadArray(to, from, pack) {
1419
1466
  return to.concat(ar || Array.prototype.slice.call(from));
1420
1467
  }
1421
1468
 
1422
- bindNot(isStringValue);
1423
-
1424
1469
  function isSameProfileTest(testObject1, testObject2) {
1425
1470
  return (testObject1.fieldName === testObject2.fieldName &&
1426
1471
  testObject1.groupName === testObject2.groupName);
@@ -1583,7 +1628,7 @@ function registerPrevRunTest(testObject) {
1583
1628
  return testObject;
1584
1629
  }
1585
1630
  var prevRunTest = useTestAtCursor(testObject);
1586
- if (isOmitted()) {
1631
+ if (inActiveOmitWhen() || optionalFiedIsApplied(testObject.fieldName)) {
1587
1632
  prevRunTest.omit();
1588
1633
  cursor.next();
1589
1634
  return prevRunTest;
@@ -1614,7 +1659,6 @@ function registerTestObjectByTier(testObject) {
1614
1659
  }
1615
1660
 
1616
1661
  /* eslint-disable jest/valid-title */
1617
- // eslint-disable-next-line max-lines-per-function
1618
1662
  function bindTestMemo(test) {
1619
1663
  var cache = cache$2(10); // arbitrary cache size
1620
1664
  // eslint-disable-next-line max-statements
@@ -1685,6 +1729,6 @@ function warn() {
1685
1729
  ctx.currentTest.warn();
1686
1730
  }
1687
1731
 
1688
- var VERSION = "4.4.3-dev-c786f7";
1732
+ var VERSION = "4.6.0";
1689
1733
 
1690
- export { VERSION, context, create, each, eager, group, include, omitWhen, only, optional, skip, skipWhen, test, warn };
1734
+ export { VERSION, context, create, each, eager, group, include, omitWhen, only, optional, skip, skipWhen, suiteSelectors, test, warn };