vest 4.2.1 → 4.3.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.
- package/dist/cjs/classnames.development.js +76 -28
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/enforce/compose.development.js +27 -59
- package/dist/cjs/enforce/compose.production.js +1 -1
- package/dist/cjs/parser.development.js +84 -22
- package/dist/cjs/parser.production.js +1 -1
- package/dist/cjs/promisify.development.js +21 -8
- package/dist/cjs/promisify.production.js +1 -1
- package/dist/cjs/vest.development.js +219 -203
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +76 -28
- package/dist/es/classnames.production.js +1 -1
- package/dist/es/enforce/compose.development.js +27 -59
- package/dist/es/enforce/compose.production.js +1 -1
- package/dist/es/parser.development.js +84 -22
- package/dist/es/parser.production.js +1 -1
- package/dist/es/promisify.development.js +21 -8
- package/dist/es/promisify.production.js +1 -1
- package/dist/es/vest.development.js +219 -203
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +76 -28
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +89 -99
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +34 -36
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +34 -36
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/parser.development.js +84 -22
- package/dist/umd/parser.production.js +1 -1
- package/dist/umd/promisify.development.js +21 -8
- package/dist/umd/promisify.production.js +1 -1
- package/dist/umd/vest.development.js +213 -204
- package/dist/umd/vest.production.js +1 -1
- package/package.json +3 -3
- package/testUtils/mockThrowError.ts +3 -6
- package/testUtils/suiteDummy.ts +5 -1
- package/types/classnames.d.ts +13 -54
- package/types/enforce/compose.d.ts +2 -1
- package/types/enforce/compounds.d.ts +2 -1
- package/types/enforce/schema.d.ts +2 -1
- package/types/parser.d.ts +12 -53
- package/types/promisify.d.ts +12 -9
- package/types/vest.d.ts +17 -14
|
@@ -451,16 +451,18 @@ var STATUS_PENDING = 'PENDING';
|
|
|
451
451
|
var STATUS_CANCELED = 'CANCELED';
|
|
452
452
|
var STATUS_OMITTED = 'OMITTED';
|
|
453
453
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
454
|
+
function invariant(condition,
|
|
455
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
456
|
+
message) {
|
|
457
|
+
if (condition) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
// If message is a string object (rather than string literal)
|
|
461
|
+
// Throw the value directly as a string
|
|
462
|
+
// Alternatively, throw an error with the message
|
|
463
|
+
throw message instanceof String
|
|
464
|
+
? message.valueOf()
|
|
465
|
+
: new Error(message ? optionalFunctionValue(message) : message);
|
|
464
466
|
}
|
|
465
467
|
|
|
466
468
|
// eslint-disable-next-line max-lines-per-function
|
|
@@ -550,6 +552,12 @@ function isNullish(value) {
|
|
|
550
552
|
return isNull(value) || isUndefined(value);
|
|
551
553
|
}
|
|
552
554
|
|
|
555
|
+
function deferThrow(message) {
|
|
556
|
+
setTimeout(function () {
|
|
557
|
+
throw new Error(message);
|
|
558
|
+
}, 0);
|
|
559
|
+
}
|
|
560
|
+
|
|
553
561
|
function usePath() {
|
|
554
562
|
var context$1 = context.useX();
|
|
555
563
|
return context$1.testCursor.getCursor();
|
|
@@ -595,7 +603,7 @@ function useRetainTestKey(key, testObject) {
|
|
|
595
603
|
current[key] = testObject;
|
|
596
604
|
}
|
|
597
605
|
else {
|
|
598
|
-
|
|
606
|
+
deferThrow("Encountered the same test key \"".concat(key, "\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."));
|
|
599
607
|
}
|
|
600
608
|
}
|
|
601
609
|
|
|
@@ -628,6 +636,140 @@ var Severity;
|
|
|
628
636
|
Severity["WARNINGS"] = "warnings";
|
|
629
637
|
Severity["ERRORS"] = "errors";
|
|
630
638
|
})(Severity || (Severity = {}));
|
|
639
|
+
var SeverityCount;
|
|
640
|
+
(function (SeverityCount) {
|
|
641
|
+
SeverityCount["ERROR_COUNT"] = "errorCount";
|
|
642
|
+
SeverityCount["WARN_COUNT"] = "warnCount";
|
|
643
|
+
})(SeverityCount || (SeverityCount = {}));
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* A safe hasOwnProperty access
|
|
647
|
+
*/
|
|
648
|
+
function hasOwnProperty(obj, key) {
|
|
649
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
function isNumber(value) {
|
|
653
|
+
return Boolean(typeof value === 'number');
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function isEmpty(value) {
|
|
657
|
+
if (!value) {
|
|
658
|
+
return true;
|
|
659
|
+
}
|
|
660
|
+
else if (isNumber(value)) {
|
|
661
|
+
return value === 0;
|
|
662
|
+
}
|
|
663
|
+
else if (hasOwnProperty(value, 'length')) {
|
|
664
|
+
return lengthEquals(value, 0);
|
|
665
|
+
}
|
|
666
|
+
else if (typeof value === 'object') {
|
|
667
|
+
return lengthEquals(Object.keys(value), 0);
|
|
668
|
+
}
|
|
669
|
+
return true;
|
|
670
|
+
}
|
|
671
|
+
var isNotEmpty = bindNot(isEmpty);
|
|
672
|
+
|
|
673
|
+
function nonMatchingFieldName(testObject, fieldName) {
|
|
674
|
+
return !!fieldName && !matchingFieldName(testObject, fieldName);
|
|
675
|
+
}
|
|
676
|
+
function matchingFieldName(testObject, fieldName) {
|
|
677
|
+
return !!(fieldName && testObject.fieldName === fieldName);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
function either(a, b) {
|
|
681
|
+
return !!a !== !!b;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Checks that a given test object matches the currently specified severity level
|
|
686
|
+
*/
|
|
687
|
+
function nonMatchingSeverityProfile(severity, testObject) {
|
|
688
|
+
return either(severity === Severity.WARNINGS, testObject.warns());
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Determines whether a certain test profile has failures.
|
|
693
|
+
*/
|
|
694
|
+
function hasFailuresLogic(testObject, severityKey, fieldName) {
|
|
695
|
+
if (!testObject.hasFailures()) {
|
|
696
|
+
return false;
|
|
697
|
+
}
|
|
698
|
+
if (nonMatchingFieldName(testObject, fieldName)) {
|
|
699
|
+
return false;
|
|
700
|
+
}
|
|
701
|
+
if (nonMatchingSeverityProfile(severityKey, testObject)) {
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
return true;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
function hasErrors(fieldName) {
|
|
708
|
+
return has(Severity.ERRORS, fieldName);
|
|
709
|
+
}
|
|
710
|
+
function hasWarnings(fieldName) {
|
|
711
|
+
return has(Severity.WARNINGS, fieldName);
|
|
712
|
+
}
|
|
713
|
+
function has(severityKey, fieldName) {
|
|
714
|
+
var testObjects = useTestsFlat();
|
|
715
|
+
return testObjects.some(function (testObject) {
|
|
716
|
+
return hasFailuresLogic(testObject, severityKey, fieldName);
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// eslint-disable-next-line max-statements, complexity
|
|
721
|
+
function isValid(fieldName) {
|
|
722
|
+
if (fieldIsOmitted(fieldName)) {
|
|
723
|
+
return true;
|
|
724
|
+
}
|
|
725
|
+
if (hasErrors(fieldName)) {
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
var testObjects = useTestsFlat();
|
|
729
|
+
if (isEmpty(testObjects)) {
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
if (fieldDoesNotExist(fieldName)) {
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
735
|
+
if (hasNonOptionalIncomplete(fieldName)) {
|
|
736
|
+
return false;
|
|
737
|
+
}
|
|
738
|
+
return noMissingTests(fieldName);
|
|
739
|
+
}
|
|
740
|
+
function fieldIsOmitted(fieldName) {
|
|
741
|
+
var omittedFields = useOmittedFields();
|
|
742
|
+
if (!fieldName) {
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
return !!omittedFields[fieldName];
|
|
746
|
+
}
|
|
747
|
+
function hasNonOptionalIncomplete(fieldName) {
|
|
748
|
+
var optionalFields = useOptionalFields()[0];
|
|
749
|
+
return isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
750
|
+
if (nonMatchingFieldName(testObject, fieldName)) {
|
|
751
|
+
return false;
|
|
752
|
+
}
|
|
753
|
+
return optionalFields[testObject.fieldName] !== true;
|
|
754
|
+
}));
|
|
755
|
+
}
|
|
756
|
+
function fieldDoesNotExist(fieldName) {
|
|
757
|
+
var testObjects = useTestsFlat();
|
|
758
|
+
return (!!fieldName &&
|
|
759
|
+
!testObjects.find(function (testObject) { return testObject.fieldName === fieldName; }));
|
|
760
|
+
}
|
|
761
|
+
function noMissingTests(fieldName) {
|
|
762
|
+
var testObjects = useTestsFlat();
|
|
763
|
+
var optionalFields = useOptionalFields()[0];
|
|
764
|
+
return testObjects.every(function (testObject) {
|
|
765
|
+
if (nonMatchingFieldName(testObject, fieldName)) {
|
|
766
|
+
return true;
|
|
767
|
+
}
|
|
768
|
+
return (optionalFields[testObject.fieldName] === true ||
|
|
769
|
+
testObject.isTested() ||
|
|
770
|
+
testObject.isOmitted());
|
|
771
|
+
});
|
|
772
|
+
}
|
|
631
773
|
|
|
632
774
|
/**
|
|
633
775
|
* Reads the testObjects list and gets full validation result from it.
|
|
@@ -636,20 +778,35 @@ function genTestsSummary() {
|
|
|
636
778
|
var testObjects = useTestsFlat();
|
|
637
779
|
var summary = assign(baseStats(), {
|
|
638
780
|
groups: {},
|
|
639
|
-
tests: {}
|
|
781
|
+
tests: {},
|
|
782
|
+
valid: false
|
|
640
783
|
});
|
|
641
|
-
|
|
784
|
+
testObjects.reduce(function (summary, testObject) {
|
|
785
|
+
appendToTest(summary.tests, testObject);
|
|
786
|
+
appendToGroup(summary.groups, testObject);
|
|
787
|
+
return summary;
|
|
788
|
+
}, summary);
|
|
789
|
+
summary.valid = isValid();
|
|
642
790
|
return countFailures(summary);
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
791
|
+
}
|
|
792
|
+
function appendToTest(tests, testObject) {
|
|
793
|
+
tests[testObject.fieldName] = appendTestObject(tests, testObject);
|
|
794
|
+
// If `valid` is false to begin with, keep it that way. Otherwise, assess.
|
|
795
|
+
tests[testObject.fieldName].valid =
|
|
796
|
+
tests[testObject.fieldName].valid === false
|
|
797
|
+
? false
|
|
798
|
+
: isValid(testObject.fieldName);
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Appends to a group object if within a group
|
|
802
|
+
*/
|
|
803
|
+
function appendToGroup(groups, testObject) {
|
|
804
|
+
var groupName = testObject.groupName;
|
|
805
|
+
if (!groupName) {
|
|
806
|
+
return;
|
|
652
807
|
}
|
|
808
|
+
groups[groupName] = groups[groupName] || {};
|
|
809
|
+
groups[groupName][testObject.fieldName] = appendTestObject(groups[groupName], testObject);
|
|
653
810
|
}
|
|
654
811
|
/**
|
|
655
812
|
* Counts the failed tests and adds global counters
|
|
@@ -662,29 +819,36 @@ function countFailures(summary) {
|
|
|
662
819
|
}
|
|
663
820
|
return summary;
|
|
664
821
|
}
|
|
822
|
+
/**
|
|
823
|
+
* Appends the test to a results object
|
|
824
|
+
*/
|
|
665
825
|
// eslint-disable-next-line max-statements
|
|
666
|
-
function
|
|
826
|
+
function appendTestObject(summaryKey, testObject) {
|
|
667
827
|
var fieldName = testObject.fieldName, message = testObject.message;
|
|
668
828
|
summaryKey[fieldName] = summaryKey[fieldName] || baseStats();
|
|
669
829
|
var testKey = summaryKey[fieldName];
|
|
670
830
|
if (testObject.isNonActionable())
|
|
671
831
|
return testKey;
|
|
672
832
|
summaryKey[fieldName].testCount++;
|
|
673
|
-
// Adds to severity group
|
|
674
|
-
function addTo(severity) {
|
|
675
|
-
var countKey = severity === Severity.ERRORS ? 'errorCount' : 'warnCount';
|
|
676
|
-
testKey[countKey]++;
|
|
677
|
-
if (message) {
|
|
678
|
-
testKey[severity] = (testKey[severity] || []).concat(message);
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
833
|
if (testObject.isFailing()) {
|
|
682
|
-
|
|
834
|
+
incrementFailures(Severity.ERRORS);
|
|
683
835
|
}
|
|
684
836
|
else if (testObject.isWarning()) {
|
|
685
|
-
|
|
837
|
+
incrementFailures(Severity.WARNINGS);
|
|
686
838
|
}
|
|
687
839
|
return testKey;
|
|
840
|
+
function incrementFailures(severity) {
|
|
841
|
+
var countKey = getCountKey(severity);
|
|
842
|
+
testKey[countKey]++;
|
|
843
|
+
if (message) {
|
|
844
|
+
testKey[severity] = (testKey[severity] || []).concat(message);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
function getCountKey(severity) {
|
|
849
|
+
return severity === Severity.ERRORS
|
|
850
|
+
? SeverityCount.ERROR_COUNT
|
|
851
|
+
: SeverityCount.WARN_COUNT;
|
|
688
852
|
}
|
|
689
853
|
function baseStats() {
|
|
690
854
|
return {
|
|
@@ -730,24 +894,6 @@ function __spreadArray(to, from, pack) {
|
|
|
730
894
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
731
895
|
}
|
|
732
896
|
|
|
733
|
-
function nonMatchingFieldName(testObject, fieldName) {
|
|
734
|
-
return !!fieldName && !matchingFieldName(testObject, fieldName);
|
|
735
|
-
}
|
|
736
|
-
function matchingFieldName(testObject, fieldName) {
|
|
737
|
-
return !!(fieldName && testObject.fieldName === fieldName);
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
function either(a, b) {
|
|
741
|
-
return !!a !== !!b;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
/**
|
|
745
|
-
* Checks that a given test object matches the currently specified severity level
|
|
746
|
-
*/
|
|
747
|
-
function nonMatchingSeverityProfile(severity, testObject) {
|
|
748
|
-
return either(severity === Severity.WARNINGS, testObject.warns());
|
|
749
|
-
}
|
|
750
|
-
|
|
751
897
|
function collectFailureMessages(severity, testObjects, options) {
|
|
752
898
|
var _a;
|
|
753
899
|
if (options === void 0) { options = {}; }
|
|
@@ -815,9 +961,7 @@ function getWarningsByGroup(groupName, fieldName) {
|
|
|
815
961
|
* Gets failure messages by group.
|
|
816
962
|
*/
|
|
817
963
|
function getByGroup(severityKey, group, fieldName) {
|
|
818
|
-
|
|
819
|
-
throwError("get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
|
|
820
|
-
}
|
|
964
|
+
invariant(group, "get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
|
|
821
965
|
var testObjects = useTestsFlat();
|
|
822
966
|
return collectFailureMessages(severityKey, testObjects, {
|
|
823
967
|
group: group,
|
|
@@ -825,35 +969,6 @@ function getByGroup(severityKey, group, fieldName) {
|
|
|
825
969
|
});
|
|
826
970
|
}
|
|
827
971
|
|
|
828
|
-
/**
|
|
829
|
-
* Determines whether a certain test profile has failures.
|
|
830
|
-
*/
|
|
831
|
-
function hasFailuresLogic(testObject, severityKey, fieldName) {
|
|
832
|
-
if (!testObject.hasFailures()) {
|
|
833
|
-
return false;
|
|
834
|
-
}
|
|
835
|
-
if (nonMatchingFieldName(testObject, fieldName)) {
|
|
836
|
-
return false;
|
|
837
|
-
}
|
|
838
|
-
if (nonMatchingSeverityProfile(severityKey, testObject)) {
|
|
839
|
-
return false;
|
|
840
|
-
}
|
|
841
|
-
return true;
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
function hasErrors(fieldName) {
|
|
845
|
-
return has(Severity.ERRORS, fieldName);
|
|
846
|
-
}
|
|
847
|
-
function hasWarnings(fieldName) {
|
|
848
|
-
return has(Severity.WARNINGS, fieldName);
|
|
849
|
-
}
|
|
850
|
-
function has(severityKey, fieldName) {
|
|
851
|
-
var testObjects = useTestsFlat();
|
|
852
|
-
return testObjects.some(function (testObject) {
|
|
853
|
-
return hasFailuresLogic(testObject, severityKey, fieldName);
|
|
854
|
-
});
|
|
855
|
-
}
|
|
856
|
-
|
|
857
972
|
function hasErrorsByGroup(groupName, fieldName) {
|
|
858
973
|
return hasByGroup(Severity.ERRORS, groupName, fieldName);
|
|
859
974
|
}
|
|
@@ -872,86 +987,6 @@ function hasByGroup(severityKey, group, fieldName) {
|
|
|
872
987
|
});
|
|
873
988
|
}
|
|
874
989
|
|
|
875
|
-
/**
|
|
876
|
-
* A safe hasOwnProperty access
|
|
877
|
-
*/
|
|
878
|
-
function hasOwnProperty(obj, key) {
|
|
879
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
function isNumber(value) {
|
|
883
|
-
return Boolean(typeof value === 'number');
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
function isEmpty(value) {
|
|
887
|
-
if (!value) {
|
|
888
|
-
return true;
|
|
889
|
-
}
|
|
890
|
-
else if (isNumber(value)) {
|
|
891
|
-
return value === 0;
|
|
892
|
-
}
|
|
893
|
-
else if (hasOwnProperty(value, 'length')) {
|
|
894
|
-
return lengthEquals(value, 0);
|
|
895
|
-
}
|
|
896
|
-
else if (typeof value === 'object') {
|
|
897
|
-
return lengthEquals(Object.keys(value), 0);
|
|
898
|
-
}
|
|
899
|
-
return true;
|
|
900
|
-
}
|
|
901
|
-
var isNotEmpty = bindNot(isEmpty);
|
|
902
|
-
|
|
903
|
-
// eslint-disable-next-line max-statements, complexity
|
|
904
|
-
function isValid(result, fieldName) {
|
|
905
|
-
if (fieldIsOmitted(fieldName)) {
|
|
906
|
-
return true;
|
|
907
|
-
}
|
|
908
|
-
if (result.hasErrors(fieldName)) {
|
|
909
|
-
return false;
|
|
910
|
-
}
|
|
911
|
-
var testObjects = useTestsFlat();
|
|
912
|
-
if (isEmpty(testObjects)) {
|
|
913
|
-
return false;
|
|
914
|
-
}
|
|
915
|
-
if (fieldDoesNotExist(result, fieldName)) {
|
|
916
|
-
return false;
|
|
917
|
-
}
|
|
918
|
-
if (hasNonOptionalIncomplete(fieldName)) {
|
|
919
|
-
return false;
|
|
920
|
-
}
|
|
921
|
-
return noMissingTests(fieldName);
|
|
922
|
-
}
|
|
923
|
-
function fieldIsOmitted(fieldName) {
|
|
924
|
-
var omittedFields = useOmittedFields();
|
|
925
|
-
if (!fieldName) {
|
|
926
|
-
return false;
|
|
927
|
-
}
|
|
928
|
-
return !!omittedFields[fieldName];
|
|
929
|
-
}
|
|
930
|
-
function hasNonOptionalIncomplete(fieldName) {
|
|
931
|
-
var optionalFields = useOptionalFields()[0];
|
|
932
|
-
return isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
933
|
-
if (nonMatchingFieldName(testObject, fieldName)) {
|
|
934
|
-
return false;
|
|
935
|
-
}
|
|
936
|
-
return optionalFields[testObject.fieldName] !== true;
|
|
937
|
-
}));
|
|
938
|
-
}
|
|
939
|
-
function fieldDoesNotExist(result, fieldName) {
|
|
940
|
-
return !!fieldName && isEmpty(result.tests[fieldName]);
|
|
941
|
-
}
|
|
942
|
-
function noMissingTests(fieldName) {
|
|
943
|
-
var testObjects = useTestsFlat();
|
|
944
|
-
var optionalFields = useOptionalFields()[0];
|
|
945
|
-
return testObjects.every(function (testObject) {
|
|
946
|
-
if (nonMatchingFieldName(testObject, fieldName)) {
|
|
947
|
-
return true;
|
|
948
|
-
}
|
|
949
|
-
return (optionalFields[testObject.fieldName] === true ||
|
|
950
|
-
testObject.isTested() ||
|
|
951
|
-
testObject.isOmitted());
|
|
952
|
-
});
|
|
953
|
-
}
|
|
954
|
-
|
|
955
990
|
var cache$1 = createCache(20);
|
|
956
991
|
function produceSuiteResult() {
|
|
957
992
|
var testObjects = useTestsFlat();
|
|
@@ -967,9 +1002,7 @@ function produceSuiteResult() {
|
|
|
967
1002
|
hasErrorsByGroup: context.bind(ctxRef, hasErrorsByGroup),
|
|
968
1003
|
hasWarnings: context.bind(ctxRef, hasWarnings),
|
|
969
1004
|
hasWarningsByGroup: context.bind(ctxRef, hasWarningsByGroup),
|
|
970
|
-
isValid: context.bind(ctxRef,
|
|
971
|
-
return isValid(produceSuiteResult(), fieldName);
|
|
972
|
-
}),
|
|
1005
|
+
isValid: context.bind(ctxRef, isValid),
|
|
973
1006
|
suiteName: suiteName
|
|
974
1007
|
});
|
|
975
1008
|
}));
|
|
@@ -1178,9 +1211,7 @@ function initBus() {
|
|
|
1178
1211
|
}
|
|
1179
1212
|
function useBus() {
|
|
1180
1213
|
var context$1 = context.useX();
|
|
1181
|
-
|
|
1182
|
-
throwError();
|
|
1183
|
-
}
|
|
1214
|
+
invariant(context$1.bus);
|
|
1184
1215
|
return context$1.bus;
|
|
1185
1216
|
}
|
|
1186
1217
|
var Events;
|
|
@@ -1199,9 +1230,7 @@ function create() {
|
|
|
1199
1230
|
args[_i] = arguments[_i];
|
|
1200
1231
|
}
|
|
1201
1232
|
var _a = args.reverse(), suiteCallback = _a[0], suiteName = _a[1];
|
|
1202
|
-
|
|
1203
|
-
throwError('vest.create: Expected callback to be a function.');
|
|
1204
|
-
}
|
|
1233
|
+
invariant(isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
|
|
1205
1234
|
// Event bus initialization
|
|
1206
1235
|
var bus = initBus();
|
|
1207
1236
|
// State initialization
|
|
@@ -1256,9 +1285,7 @@ function create() {
|
|
|
1256
1285
|
* })
|
|
1257
1286
|
*/
|
|
1258
1287
|
function each(list, callback) {
|
|
1259
|
-
|
|
1260
|
-
throwError('each callback must be a function');
|
|
1261
|
-
}
|
|
1288
|
+
invariant(isFunction(callback), 'each callback must be a function');
|
|
1262
1289
|
isolate({ type: IsolateTypes.EACH }, function () {
|
|
1263
1290
|
list.forEach(function (arg, index) {
|
|
1264
1291
|
callback(arg, index);
|
|
@@ -1455,19 +1482,15 @@ function hasIncludedTests(keyTests) {
|
|
|
1455
1482
|
* });
|
|
1456
1483
|
*/
|
|
1457
1484
|
function group(groupName, tests) {
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
}
|
|
1461
|
-
if (!isFunction(tests)) {
|
|
1462
|
-
throwGroupError('callback must be a function');
|
|
1463
|
-
}
|
|
1485
|
+
invariant(isStringValue(groupName), groupErrorMsg('name must be a string'));
|
|
1486
|
+
invariant(isFunction(tests), groupErrorMsg('callback must be a function'));
|
|
1464
1487
|
// Running with the context applied
|
|
1465
1488
|
isolate({ type: IsolateTypes.GROUP }, function () {
|
|
1466
1489
|
context.run({ groupName: groupName }, tests);
|
|
1467
1490
|
});
|
|
1468
1491
|
}
|
|
1469
|
-
function
|
|
1470
|
-
|
|
1492
|
+
function groupErrorMsg(error) {
|
|
1493
|
+
return "Wrong arguments passed to group. Group ".concat(error, ".");
|
|
1471
1494
|
}
|
|
1472
1495
|
|
|
1473
1496
|
function include(fieldName) {
|
|
@@ -1583,8 +1606,6 @@ function optional(optionals) {
|
|
|
1583
1606
|
});
|
|
1584
1607
|
}
|
|
1585
1608
|
|
|
1586
|
-
var isNotString = bindNot(isStringValue);
|
|
1587
|
-
|
|
1588
1609
|
function isPromise(value) {
|
|
1589
1610
|
return value && isFunction(value.then);
|
|
1590
1611
|
}
|
|
@@ -1678,7 +1699,7 @@ function registerTest(testObject) {
|
|
|
1678
1699
|
}
|
|
1679
1700
|
}
|
|
1680
1701
|
catch (e) {
|
|
1681
|
-
|
|
1702
|
+
throw new Error("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(testObject), ".\n Error: ").concat(e, "."));
|
|
1682
1703
|
}
|
|
1683
1704
|
}
|
|
1684
1705
|
|
|
@@ -1705,7 +1726,7 @@ function useTestAtCursor(newTestObject) {
|
|
|
1705
1726
|
useSetTestAtCursor(nextTest_1);
|
|
1706
1727
|
return nextTest_1;
|
|
1707
1728
|
}
|
|
1708
|
-
if (
|
|
1729
|
+
if (testReorderDetected(prevTest, newTestObject)) {
|
|
1709
1730
|
throwTestOrderError(prevTest, newTestObject);
|
|
1710
1731
|
removeAllNextTestsInIsolate();
|
|
1711
1732
|
// Need to see if this has any effect at all.
|
|
@@ -1742,14 +1763,14 @@ function useGetTestAtCursor(tests) {
|
|
|
1742
1763
|
var cursorPath = usePath();
|
|
1743
1764
|
return valueAtPath(tests, cursorPath);
|
|
1744
1765
|
}
|
|
1745
|
-
function
|
|
1766
|
+
function testReorderDetected(prevTest, newTest) {
|
|
1746
1767
|
return isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
|
|
1747
1768
|
}
|
|
1748
1769
|
function throwTestOrderError(prevTest, newTestObject) {
|
|
1749
1770
|
if (shouldAllowReorder()) {
|
|
1750
1771
|
return;
|
|
1751
1772
|
}
|
|
1752
|
-
|
|
1773
|
+
deferThrow("Vest Critical Error: Tests called in different order than previous run.\n expected: ".concat(prevTest.fieldName, "\n received: ").concat(newTestObject.fieldName, "\n This can happen on one of two reasons:\n 1. You're using if/else statements to conditionally select tests. Instead, use \"skipWhen\".\n 2. You are iterating over a list of tests, and their order changed. Use \"each\" and a custom key prop so that Vest retains their state."));
|
|
1753
1774
|
}
|
|
1754
1775
|
function handleKeyTest(key, newTestObject) {
|
|
1755
1776
|
var prevTestByKey = usePrevTestByKey(key);
|
|
@@ -1763,12 +1784,13 @@ function handleKeyTest(key, newTestObject) {
|
|
|
1763
1784
|
|
|
1764
1785
|
// eslint-disable-next-line max-statements
|
|
1765
1786
|
function registerPrevRunTest(testObject) {
|
|
1766
|
-
var prevRunTest = useTestAtCursor(testObject);
|
|
1767
1787
|
if (shouldSkipBasedOnMode(testObject)) {
|
|
1768
|
-
moveForward();
|
|
1769
1788
|
testObject.skip();
|
|
1789
|
+
useTestAtCursor(testObject);
|
|
1790
|
+
moveForward();
|
|
1770
1791
|
return testObject;
|
|
1771
1792
|
}
|
|
1793
|
+
var prevRunTest = useTestAtCursor(testObject);
|
|
1772
1794
|
if (isOmitted()) {
|
|
1773
1795
|
prevRunTest.omit();
|
|
1774
1796
|
moveForward();
|
|
@@ -1834,12 +1856,8 @@ function testBase(fieldName) {
|
|
|
1834
1856
|
args[_i - 1] = arguments[_i];
|
|
1835
1857
|
}
|
|
1836
1858
|
var _a = (isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
}
|
|
1840
|
-
if (!isFunction(testFn)) {
|
|
1841
|
-
throwIncompatibleParamsError('Test callback', 'function');
|
|
1842
|
-
}
|
|
1859
|
+
invariant(isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
|
|
1860
|
+
invariant(isFunction(testFn), incompatibleParamsError('Test callback', 'function'));
|
|
1843
1861
|
var context$1 = context.useX();
|
|
1844
1862
|
var testObject = new VestTest(fieldName, testFn, {
|
|
1845
1863
|
message: message,
|
|
@@ -1860,8 +1878,8 @@ function testBase(fieldName) {
|
|
|
1860
1878
|
var test = assign(testBase, {
|
|
1861
1879
|
memo: bindTestMemo(testBase)
|
|
1862
1880
|
});
|
|
1863
|
-
function
|
|
1864
|
-
|
|
1881
|
+
function incompatibleParamsError(name, expected) {
|
|
1882
|
+
return "Incompatible params passed to test function. ".concat(name, " must be a ").concat(expected);
|
|
1865
1883
|
}
|
|
1866
1884
|
|
|
1867
1885
|
var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won't have an effect."
|
|
@@ -1871,13 +1889,11 @@ var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won
|
|
|
1871
1889
|
*/
|
|
1872
1890
|
function warn() {
|
|
1873
1891
|
var ctx = context.useX('warn ' + ERROR_HOOK_CALLED_OUTSIDE);
|
|
1874
|
-
|
|
1875
|
-
throwError(ERROR_OUTSIDE_OF_TEST);
|
|
1876
|
-
}
|
|
1892
|
+
invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
|
|
1877
1893
|
ctx.currentTest.warn();
|
|
1878
1894
|
}
|
|
1879
1895
|
|
|
1880
|
-
var VERSION = "4.
|
|
1896
|
+
var VERSION = "4.3.0";
|
|
1881
1897
|
|
|
1882
1898
|
Object.defineProperty(exports, 'enforce', {
|
|
1883
1899
|
enumerable: true,
|