vest 4.2.2 → 4.2.3-dev-87ebfa
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 +21 -8
- 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/promisify.development.js +21 -8
- package/dist/cjs/promisify.production.js +1 -1
- package/dist/cjs/vest.development.js +312 -304
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +21 -8
- 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/promisify.development.js +21 -8
- package/dist/es/promisify.production.js +1 -1
- package/dist/es/vest.development.js +312 -304
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +21 -8
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +73 -83
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +18 -20
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +18 -20
- package/dist/umd/enforce/schema.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 +269 -268
- package/dist/umd/vest.production.js +1 -1
- package/package.json +3 -3
- package/testUtils/mockThrowError.ts +3 -6
- package/types/classnames.d.ts +2 -1
- package/types/parser.d.ts +2 -1
- package/types/promisify.d.ts +2 -1
- package/types/vest.d.ts +56 -55
|
@@ -343,16 +343,18 @@
|
|
|
343
343
|
return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
|
|
344
344
|
}
|
|
345
345
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
346
|
+
function invariant(condition,
|
|
347
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
348
|
+
message) {
|
|
349
|
+
if (condition) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
// If message is a string object (rather than string literal)
|
|
353
|
+
// Throw the value directly as a string
|
|
354
|
+
// Alternatively, throw an error with the message
|
|
355
|
+
throw message instanceof String
|
|
356
|
+
? message.valueOf()
|
|
357
|
+
: new Error(message ? optionalFunctionValue(message) : message);
|
|
356
358
|
}
|
|
357
359
|
|
|
358
360
|
// eslint-disable-next-line max-lines-per-function
|
|
@@ -365,8 +367,8 @@
|
|
|
365
367
|
useX: useX
|
|
366
368
|
};
|
|
367
369
|
function useX(errorMessage) {
|
|
368
|
-
|
|
369
|
-
return
|
|
370
|
+
invariant(storage.ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
|
|
371
|
+
return storage.ctx;
|
|
370
372
|
}
|
|
371
373
|
function run(ctxRef, fn) {
|
|
372
374
|
var _a;
|
|
@@ -514,10 +516,7 @@
|
|
|
514
516
|
}
|
|
515
517
|
function validateResult(result) {
|
|
516
518
|
// if result is boolean, or if result.pass is boolean
|
|
517
|
-
|
|
518
|
-
return;
|
|
519
|
-
}
|
|
520
|
-
throwError('Incorrect return value for rule: ' + JSON.stringify(result));
|
|
519
|
+
invariant(isBoolean(result) || (result && isBoolean(result.pass)), 'Incorrect return value for rule: ' + JSON.stringify(result));
|
|
521
520
|
}
|
|
522
521
|
|
|
523
522
|
function enforceEager(value) {
|
|
@@ -546,15 +545,9 @@
|
|
|
546
545
|
var transformedResult = transformResult.apply(void 0, __spreadArray([ctx.run({ value: value }, function () { return rule.apply(void 0, __spreadArray([value], args, false)); }),
|
|
547
546
|
ruleName,
|
|
548
547
|
value], args, false));
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
}
|
|
553
|
-
else {
|
|
554
|
-
// Explicitly throw a string so that vest.test can pick it up as the validation error message
|
|
555
|
-
throw transformedResult.message;
|
|
556
|
-
}
|
|
557
|
-
}
|
|
548
|
+
invariant(transformedResult.pass, isEmpty(transformedResult.message)
|
|
549
|
+
? "enforce/".concat(ruleName, " failed with ").concat(JSON.stringify(value))
|
|
550
|
+
: new String(transformedResult.message));
|
|
558
551
|
return target;
|
|
559
552
|
};
|
|
560
553
|
}
|
|
@@ -693,100 +686,106 @@
|
|
|
693
686
|
return "".concat(n++);
|
|
694
687
|
}; })(0);
|
|
695
688
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
function asArray(possibleArg) {
|
|
702
|
-
return [].concat(possibleArg);
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* Creates a cache function
|
|
707
|
-
*/
|
|
708
|
-
function createCache(maxSize) {
|
|
709
|
-
if (maxSize === void 0) { maxSize = 1; }
|
|
710
|
-
var cacheStorage = [];
|
|
711
|
-
var cache = function (deps, cacheAction) {
|
|
712
|
-
var cacheHit = cache.get(deps);
|
|
713
|
-
// cache hit is not null
|
|
714
|
-
if (cacheHit)
|
|
715
|
-
return cacheHit[1];
|
|
716
|
-
var result = cacheAction();
|
|
717
|
-
cacheStorage.unshift([deps.concat(), result]);
|
|
718
|
-
if (longerThan(cacheStorage, maxSize))
|
|
719
|
-
cacheStorage.length = maxSize;
|
|
720
|
-
return result;
|
|
721
|
-
};
|
|
722
|
-
// invalidate an item in the cache by its dependencies
|
|
723
|
-
cache.invalidate = function (deps) {
|
|
724
|
-
var index = findIndex(deps);
|
|
725
|
-
if (index > -1)
|
|
726
|
-
cacheStorage.splice(index, 1);
|
|
689
|
+
// eslint-disable-next-line max-lines-per-function
|
|
690
|
+
function createState(onStateChange) {
|
|
691
|
+
var state = {
|
|
692
|
+
references: []
|
|
727
693
|
};
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
694
|
+
var registrations = [];
|
|
695
|
+
return {
|
|
696
|
+
registerStateKey: registerStateKey,
|
|
697
|
+
reset: reset
|
|
731
698
|
};
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
699
|
+
/**
|
|
700
|
+
* Registers a new key in the state, takes the initial value (may be a function that returns the initial value), returns a function.
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
*
|
|
704
|
+
* const useColor = state.registerStateKey("blue");
|
|
705
|
+
*
|
|
706
|
+
* let [color, setColor] = useColor(); // -> ["blue", Function]
|
|
707
|
+
*
|
|
708
|
+
* setColor("green");
|
|
709
|
+
*
|
|
710
|
+
* useColor()[0]; -> "green"
|
|
711
|
+
*/
|
|
712
|
+
function registerStateKey(initialState, onUpdate) {
|
|
713
|
+
var key = registrations.length;
|
|
714
|
+
registrations.push([initialState, onUpdate]);
|
|
715
|
+
return initKey(key, initialState);
|
|
716
|
+
}
|
|
717
|
+
function reset() {
|
|
718
|
+
var prev = current();
|
|
719
|
+
state.references = [];
|
|
720
|
+
registrations.forEach(function (_a, index) {
|
|
721
|
+
var initialValue = _a[0];
|
|
722
|
+
return initKey(index, initialValue, prev[index]);
|
|
738
723
|
});
|
|
739
724
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
725
|
+
function initKey(key, initialState, prevState) {
|
|
726
|
+
current().push();
|
|
727
|
+
set(key, optionalFunctionValue(initialState, prevState));
|
|
728
|
+
return function useStateKey() {
|
|
729
|
+
return [
|
|
730
|
+
current()[key],
|
|
731
|
+
function (nextState) {
|
|
732
|
+
return set(key, optionalFunctionValue(nextState, current()[key]));
|
|
733
|
+
},
|
|
734
|
+
];
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
function current() {
|
|
738
|
+
return state.references;
|
|
739
|
+
}
|
|
740
|
+
function set(index, value) {
|
|
741
|
+
var prevValue = state.references[index];
|
|
742
|
+
state.references[index] = value;
|
|
743
|
+
var _a = registrations[index], onUpdate = _a[1];
|
|
744
|
+
if (isFunction(onUpdate)) {
|
|
745
|
+
onUpdate(value, prevValue);
|
|
756
746
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
if (isNotNull(output)) {
|
|
760
|
-
res.push(output);
|
|
761
|
-
}
|
|
747
|
+
if (isFunction(onStateChange)) {
|
|
748
|
+
onStateChange();
|
|
762
749
|
}
|
|
763
750
|
}
|
|
764
|
-
return res;
|
|
765
|
-
}
|
|
766
|
-
function valueAtPath(array, path) {
|
|
767
|
-
return getCurrent(array, path)[last(path)];
|
|
768
751
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
752
|
+
|
|
753
|
+
var IsolateTypes;
|
|
754
|
+
(function (IsolateTypes) {
|
|
755
|
+
IsolateTypes[IsolateTypes["DEFAULT"] = 0] = "DEFAULT";
|
|
756
|
+
IsolateTypes[IsolateTypes["SUITE"] = 1] = "SUITE";
|
|
757
|
+
IsolateTypes[IsolateTypes["EACH"] = 2] = "EACH";
|
|
758
|
+
IsolateTypes[IsolateTypes["SKIP_WHEN"] = 3] = "SKIP_WHEN";
|
|
759
|
+
IsolateTypes[IsolateTypes["OMIT_WHEN"] = 4] = "OMIT_WHEN";
|
|
760
|
+
IsolateTypes[IsolateTypes["GROUP"] = 5] = "GROUP";
|
|
761
|
+
})(IsolateTypes || (IsolateTypes = {}));
|
|
762
|
+
|
|
763
|
+
function createStateRef(state, _a) {
|
|
764
|
+
var suiteId = _a.suiteId, suiteName = _a.suiteName;
|
|
765
|
+
return {
|
|
766
|
+
optionalFields: state.registerStateKey(function () { return ({}); }),
|
|
767
|
+
suiteId: state.registerStateKey(suiteId),
|
|
768
|
+
suiteName: state.registerStateKey(suiteName),
|
|
769
|
+
testCallbacks: state.registerStateKey(function () { return ({
|
|
770
|
+
fieldCallbacks: {},
|
|
771
|
+
doneCallbacks: []
|
|
772
|
+
}); }),
|
|
773
|
+
testObjects: state.registerStateKey(function (prev) {
|
|
774
|
+
return {
|
|
775
|
+
prev: prev ? prev.current : [],
|
|
776
|
+
current: []
|
|
777
|
+
};
|
|
778
|
+
})
|
|
779
|
+
};
|
|
773
780
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
return acc.concat(flatten(value));
|
|
778
|
-
}
|
|
779
|
-
return asArray(acc).concat(value);
|
|
780
|
-
}, []);
|
|
781
|
+
|
|
782
|
+
function asArray(possibleArg) {
|
|
783
|
+
return [].concat(possibleArg);
|
|
781
784
|
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
current[p] = defaultTo(current[p], []);
|
|
787
|
-
current = current[p];
|
|
788
|
-
}
|
|
789
|
-
return current;
|
|
785
|
+
|
|
786
|
+
function last(values) {
|
|
787
|
+
var valuesArray = asArray(values);
|
|
788
|
+
return valuesArray[valuesArray.length - 1];
|
|
790
789
|
}
|
|
791
790
|
|
|
792
791
|
function createCursor() {
|
|
@@ -823,16 +822,6 @@
|
|
|
823
822
|
};
|
|
824
823
|
}
|
|
825
824
|
|
|
826
|
-
var IsolateTypes;
|
|
827
|
-
(function (IsolateTypes) {
|
|
828
|
-
IsolateTypes[IsolateTypes["DEFAULT"] = 0] = "DEFAULT";
|
|
829
|
-
IsolateTypes[IsolateTypes["SUITE"] = 1] = "SUITE";
|
|
830
|
-
IsolateTypes[IsolateTypes["EACH"] = 2] = "EACH";
|
|
831
|
-
IsolateTypes[IsolateTypes["SKIP_WHEN"] = 3] = "SKIP_WHEN";
|
|
832
|
-
IsolateTypes[IsolateTypes["OMIT_WHEN"] = 4] = "OMIT_WHEN";
|
|
833
|
-
IsolateTypes[IsolateTypes["GROUP"] = 5] = "GROUP";
|
|
834
|
-
})(IsolateTypes || (IsolateTypes = {}));
|
|
835
|
-
|
|
836
825
|
var Modes;
|
|
837
826
|
(function (Modes) {
|
|
838
827
|
Modes[Modes["ALL"] = 0] = "ALL";
|
|
@@ -860,6 +849,99 @@
|
|
|
860
849
|
}, ctxRef);
|
|
861
850
|
});
|
|
862
851
|
|
|
852
|
+
// This is kind of a map/filter in one function.
|
|
853
|
+
// Normally, behaves like a nested-array map,
|
|
854
|
+
// but returning `null` will drop the element from the array
|
|
855
|
+
function transform(array, cb) {
|
|
856
|
+
var res = [];
|
|
857
|
+
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
|
|
858
|
+
var v = array_1[_i];
|
|
859
|
+
if (isArray(v)) {
|
|
860
|
+
res.push(transform(v, cb));
|
|
861
|
+
}
|
|
862
|
+
else {
|
|
863
|
+
var output = cb(v);
|
|
864
|
+
if (isNotNull(output)) {
|
|
865
|
+
res.push(output);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
return res;
|
|
870
|
+
}
|
|
871
|
+
function valueAtPath(array, path) {
|
|
872
|
+
return getCurrent(array, path)[last(path)];
|
|
873
|
+
}
|
|
874
|
+
function setValueAtPath(array, path, value) {
|
|
875
|
+
var current = getCurrent(array, path);
|
|
876
|
+
current[last(path)] = value;
|
|
877
|
+
return array;
|
|
878
|
+
}
|
|
879
|
+
function flatten(values) {
|
|
880
|
+
return asArray(values).reduce(function (acc, value) {
|
|
881
|
+
if (isArray(value)) {
|
|
882
|
+
return acc.concat(flatten(value));
|
|
883
|
+
}
|
|
884
|
+
return asArray(acc).concat(value);
|
|
885
|
+
}, []);
|
|
886
|
+
}
|
|
887
|
+
function getCurrent(array, path) {
|
|
888
|
+
var current = array;
|
|
889
|
+
for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) {
|
|
890
|
+
var p = _a[_i];
|
|
891
|
+
current[p] = defaultTo(current[p], []);
|
|
892
|
+
current = current[p];
|
|
893
|
+
}
|
|
894
|
+
return current;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
function deferThrow(message) {
|
|
898
|
+
setTimeout(function () {
|
|
899
|
+
throw new Error(message);
|
|
900
|
+
}, 0);
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
function shouldUseErrorAsMessage(message, error) {
|
|
904
|
+
// kind of cheating with this safe guard, but it does the job
|
|
905
|
+
return isUndefined(message) && isStringValue(error);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* Creates a cache function
|
|
910
|
+
*/
|
|
911
|
+
function createCache(maxSize) {
|
|
912
|
+
if (maxSize === void 0) { maxSize = 1; }
|
|
913
|
+
var cacheStorage = [];
|
|
914
|
+
var cache = function (deps, cacheAction) {
|
|
915
|
+
var cacheHit = cache.get(deps);
|
|
916
|
+
// cache hit is not null
|
|
917
|
+
if (cacheHit)
|
|
918
|
+
return cacheHit[1];
|
|
919
|
+
var result = cacheAction();
|
|
920
|
+
cacheStorage.unshift([deps.concat(), result]);
|
|
921
|
+
if (longerThan(cacheStorage, maxSize))
|
|
922
|
+
cacheStorage.length = maxSize;
|
|
923
|
+
return result;
|
|
924
|
+
};
|
|
925
|
+
// invalidate an item in the cache by its dependencies
|
|
926
|
+
cache.invalidate = function (deps) {
|
|
927
|
+
var index = findIndex(deps);
|
|
928
|
+
if (index > -1)
|
|
929
|
+
cacheStorage.splice(index, 1);
|
|
930
|
+
};
|
|
931
|
+
// Retrieves an item from the cache.
|
|
932
|
+
cache.get = function (deps) {
|
|
933
|
+
return cacheStorage[findIndex(deps)] || null;
|
|
934
|
+
};
|
|
935
|
+
return cache;
|
|
936
|
+
function findIndex(deps) {
|
|
937
|
+
return cacheStorage.findIndex(function (_a) {
|
|
938
|
+
var cachedDeps = _a[0];
|
|
939
|
+
return lengthEquals(deps, cachedDeps.length) &&
|
|
940
|
+
deps.every(function (dep, i) { return dep === cachedDeps[i]; });
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
|
|
863
945
|
// STATE REF
|
|
864
946
|
function useStateRef() {
|
|
865
947
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -1075,89 +1157,6 @@
|
|
|
1075
1157
|
var STATUS_CANCELED = 'CANCELED';
|
|
1076
1158
|
var STATUS_OMITTED = 'OMITTED';
|
|
1077
1159
|
|
|
1078
|
-
// eslint-disable-next-line max-lines-per-function
|
|
1079
|
-
function createState(onStateChange) {
|
|
1080
|
-
var state = {
|
|
1081
|
-
references: []
|
|
1082
|
-
};
|
|
1083
|
-
var registrations = [];
|
|
1084
|
-
return {
|
|
1085
|
-
registerStateKey: registerStateKey,
|
|
1086
|
-
reset: reset
|
|
1087
|
-
};
|
|
1088
|
-
/**
|
|
1089
|
-
* Registers a new key in the state, takes the initial value (may be a function that returns the initial value), returns a function.
|
|
1090
|
-
*
|
|
1091
|
-
* @example
|
|
1092
|
-
*
|
|
1093
|
-
* const useColor = state.registerStateKey("blue");
|
|
1094
|
-
*
|
|
1095
|
-
* let [color, setColor] = useColor(); // -> ["blue", Function]
|
|
1096
|
-
*
|
|
1097
|
-
* setColor("green");
|
|
1098
|
-
*
|
|
1099
|
-
* useColor()[0]; -> "green"
|
|
1100
|
-
*/
|
|
1101
|
-
function registerStateKey(initialState, onUpdate) {
|
|
1102
|
-
var key = registrations.length;
|
|
1103
|
-
registrations.push([initialState, onUpdate]);
|
|
1104
|
-
return initKey(key, initialState);
|
|
1105
|
-
}
|
|
1106
|
-
function reset() {
|
|
1107
|
-
var prev = current();
|
|
1108
|
-
state.references = [];
|
|
1109
|
-
registrations.forEach(function (_a, index) {
|
|
1110
|
-
var initialValue = _a[0];
|
|
1111
|
-
return initKey(index, initialValue, prev[index]);
|
|
1112
|
-
});
|
|
1113
|
-
}
|
|
1114
|
-
function initKey(key, initialState, prevState) {
|
|
1115
|
-
current().push();
|
|
1116
|
-
set(key, optionalFunctionValue(initialState, prevState));
|
|
1117
|
-
return function useStateKey() {
|
|
1118
|
-
return [
|
|
1119
|
-
current()[key],
|
|
1120
|
-
function (nextState) {
|
|
1121
|
-
return set(key, optionalFunctionValue(nextState, current()[key]));
|
|
1122
|
-
},
|
|
1123
|
-
];
|
|
1124
|
-
};
|
|
1125
|
-
}
|
|
1126
|
-
function current() {
|
|
1127
|
-
return state.references;
|
|
1128
|
-
}
|
|
1129
|
-
function set(index, value) {
|
|
1130
|
-
var prevValue = state.references[index];
|
|
1131
|
-
state.references[index] = value;
|
|
1132
|
-
var _a = registrations[index], onUpdate = _a[1];
|
|
1133
|
-
if (isFunction(onUpdate)) {
|
|
1134
|
-
onUpdate(value, prevValue);
|
|
1135
|
-
}
|
|
1136
|
-
if (isFunction(onStateChange)) {
|
|
1137
|
-
onStateChange();
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
function createStateRef(state, _a) {
|
|
1143
|
-
var suiteId = _a.suiteId, suiteName = _a.suiteName;
|
|
1144
|
-
return {
|
|
1145
|
-
optionalFields: state.registerStateKey(function () { return ({}); }),
|
|
1146
|
-
suiteId: state.registerStateKey(suiteId),
|
|
1147
|
-
suiteName: state.registerStateKey(suiteName),
|
|
1148
|
-
testCallbacks: state.registerStateKey(function () { return ({
|
|
1149
|
-
fieldCallbacks: {},
|
|
1150
|
-
doneCallbacks: []
|
|
1151
|
-
}); }),
|
|
1152
|
-
testObjects: state.registerStateKey(function (prev) {
|
|
1153
|
-
return {
|
|
1154
|
-
prev: prev ? prev.current : [],
|
|
1155
|
-
current: []
|
|
1156
|
-
};
|
|
1157
|
-
})
|
|
1158
|
-
};
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
1160
|
function usePath() {
|
|
1162
1161
|
var context$1 = context.useX();
|
|
1163
1162
|
return context$1.testCursor.getCursor();
|
|
@@ -1203,7 +1202,7 @@
|
|
|
1203
1202
|
current[key] = testObject;
|
|
1204
1203
|
}
|
|
1205
1204
|
else {
|
|
1206
|
-
|
|
1205
|
+
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."));
|
|
1207
1206
|
}
|
|
1208
1207
|
}
|
|
1209
1208
|
|
|
@@ -1236,6 +1235,11 @@
|
|
|
1236
1235
|
Severity["WARNINGS"] = "warnings";
|
|
1237
1236
|
Severity["ERRORS"] = "errors";
|
|
1238
1237
|
})(Severity || (Severity = {}));
|
|
1238
|
+
var SeverityCount;
|
|
1239
|
+
(function (SeverityCount) {
|
|
1240
|
+
SeverityCount["ERROR_COUNT"] = "errorCount";
|
|
1241
|
+
SeverityCount["WARN_COUNT"] = "warnCount";
|
|
1242
|
+
})(SeverityCount || (SeverityCount = {}));
|
|
1239
1243
|
|
|
1240
1244
|
/**
|
|
1241
1245
|
* Reads the testObjects list and gets full validation result from it.
|
|
@@ -1246,18 +1250,26 @@
|
|
|
1246
1250
|
groups: {},
|
|
1247
1251
|
tests: {}
|
|
1248
1252
|
});
|
|
1249
|
-
|
|
1253
|
+
testObjects.reduce(function (summary, testObject) {
|
|
1254
|
+
appendToTest(summary.tests, testObject);
|
|
1255
|
+
appendToGroup(summary.groups, testObject);
|
|
1256
|
+
return summary;
|
|
1257
|
+
}, summary);
|
|
1250
1258
|
return countFailures(summary);
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1259
|
+
}
|
|
1260
|
+
function appendToTest(tests, testObject) {
|
|
1261
|
+
tests[testObject.fieldName] = appendTestObject(tests, testObject);
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* Appends to a group object if within a group
|
|
1265
|
+
*/
|
|
1266
|
+
function appendToGroup(groups, testObject) {
|
|
1267
|
+
var groupName = testObject.groupName;
|
|
1268
|
+
if (!groupName) {
|
|
1269
|
+
return;
|
|
1260
1270
|
}
|
|
1271
|
+
groups[groupName] = groups[groupName] || {};
|
|
1272
|
+
groups[groupName][testObject.fieldName] = appendTestObject(groups[groupName], testObject);
|
|
1261
1273
|
}
|
|
1262
1274
|
/**
|
|
1263
1275
|
* Counts the failed tests and adds global counters
|
|
@@ -1270,29 +1282,36 @@
|
|
|
1270
1282
|
}
|
|
1271
1283
|
return summary;
|
|
1272
1284
|
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Appends the test to a results object
|
|
1287
|
+
*/
|
|
1273
1288
|
// eslint-disable-next-line max-statements
|
|
1274
|
-
function
|
|
1289
|
+
function appendTestObject(summaryKey, testObject) {
|
|
1275
1290
|
var fieldName = testObject.fieldName, message = testObject.message;
|
|
1276
1291
|
summaryKey[fieldName] = summaryKey[fieldName] || baseStats();
|
|
1277
1292
|
var testKey = summaryKey[fieldName];
|
|
1278
1293
|
if (testObject.isNonActionable())
|
|
1279
1294
|
return testKey;
|
|
1280
1295
|
summaryKey[fieldName].testCount++;
|
|
1281
|
-
// Adds to severity group
|
|
1282
|
-
function addTo(severity) {
|
|
1283
|
-
var countKey = severity === Severity.ERRORS ? 'errorCount' : 'warnCount';
|
|
1284
|
-
testKey[countKey]++;
|
|
1285
|
-
if (message) {
|
|
1286
|
-
testKey[severity] = (testKey[severity] || []).concat(message);
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
1296
|
if (testObject.isFailing()) {
|
|
1290
|
-
|
|
1297
|
+
incrementFailures(Severity.ERRORS);
|
|
1291
1298
|
}
|
|
1292
1299
|
else if (testObject.isWarning()) {
|
|
1293
|
-
|
|
1300
|
+
incrementFailures(Severity.WARNINGS);
|
|
1294
1301
|
}
|
|
1295
1302
|
return testKey;
|
|
1303
|
+
function incrementFailures(severity) {
|
|
1304
|
+
var countKey = getCountKey(severity);
|
|
1305
|
+
testKey[countKey]++;
|
|
1306
|
+
if (message) {
|
|
1307
|
+
testKey[severity] = (testKey[severity] || []).concat(message);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
function getCountKey(severity) {
|
|
1312
|
+
return severity === Severity.ERRORS
|
|
1313
|
+
? SeverityCount.ERROR_COUNT
|
|
1314
|
+
: SeverityCount.WARN_COUNT;
|
|
1296
1315
|
}
|
|
1297
1316
|
function baseStats() {
|
|
1298
1317
|
return {
|
|
@@ -1387,9 +1406,7 @@
|
|
|
1387
1406
|
* Gets failure messages by group.
|
|
1388
1407
|
*/
|
|
1389
1408
|
function getByGroup(severityKey, group, fieldName) {
|
|
1390
|
-
|
|
1391
|
-
throwError("get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
|
|
1392
|
-
}
|
|
1409
|
+
invariant(group, "get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
|
|
1393
1410
|
var testObjects = useTestsFlat();
|
|
1394
1411
|
return collectFailureMessages(severityKey, testObjects, {
|
|
1395
1412
|
group: group,
|
|
@@ -1445,18 +1462,18 @@
|
|
|
1445
1462
|
}
|
|
1446
1463
|
|
|
1447
1464
|
// eslint-disable-next-line max-statements, complexity
|
|
1448
|
-
function isValid(
|
|
1465
|
+
function isValid(fieldName) {
|
|
1449
1466
|
if (fieldIsOmitted(fieldName)) {
|
|
1450
1467
|
return true;
|
|
1451
1468
|
}
|
|
1452
|
-
if (
|
|
1469
|
+
if (hasErrors(fieldName)) {
|
|
1453
1470
|
return false;
|
|
1454
1471
|
}
|
|
1455
1472
|
var testObjects = useTestsFlat();
|
|
1456
1473
|
if (isEmpty(testObjects)) {
|
|
1457
1474
|
return false;
|
|
1458
1475
|
}
|
|
1459
|
-
if (fieldDoesNotExist(
|
|
1476
|
+
if (fieldDoesNotExist(fieldName)) {
|
|
1460
1477
|
return false;
|
|
1461
1478
|
}
|
|
1462
1479
|
if (hasNonOptionalIncomplete(fieldName)) {
|
|
@@ -1480,8 +1497,10 @@
|
|
|
1480
1497
|
return optionalFields[testObject.fieldName] !== true;
|
|
1481
1498
|
}));
|
|
1482
1499
|
}
|
|
1483
|
-
function fieldDoesNotExist(
|
|
1484
|
-
|
|
1500
|
+
function fieldDoesNotExist(fieldName) {
|
|
1501
|
+
var testObjects = useTestsFlat();
|
|
1502
|
+
return (!!fieldName &&
|
|
1503
|
+
!testObjects.find(function (testObject) { return testObject.fieldName === fieldName; }));
|
|
1485
1504
|
}
|
|
1486
1505
|
function noMissingTests(fieldName) {
|
|
1487
1506
|
var testObjects = useTestsFlat();
|
|
@@ -1511,9 +1530,7 @@
|
|
|
1511
1530
|
hasErrorsByGroup: context.bind(ctxRef, hasErrorsByGroup),
|
|
1512
1531
|
hasWarnings: context.bind(ctxRef, hasWarnings),
|
|
1513
1532
|
hasWarningsByGroup: context.bind(ctxRef, hasWarningsByGroup),
|
|
1514
|
-
isValid: context.bind(ctxRef,
|
|
1515
|
-
return isValid(produceSuiteResult(), fieldName);
|
|
1516
|
-
}),
|
|
1533
|
+
isValid: context.bind(ctxRef, isValid),
|
|
1517
1534
|
suiteName: suiteName
|
|
1518
1535
|
});
|
|
1519
1536
|
}));
|
|
@@ -1722,9 +1739,7 @@
|
|
|
1722
1739
|
}
|
|
1723
1740
|
function useBus() {
|
|
1724
1741
|
var context$1 = context.useX();
|
|
1725
|
-
|
|
1726
|
-
throwError();
|
|
1727
|
-
}
|
|
1742
|
+
invariant(context$1.bus);
|
|
1728
1743
|
return context$1.bus;
|
|
1729
1744
|
}
|
|
1730
1745
|
var Events;
|
|
@@ -1743,9 +1758,7 @@
|
|
|
1743
1758
|
args[_i] = arguments[_i];
|
|
1744
1759
|
}
|
|
1745
1760
|
var _a = args.reverse(), suiteCallback = _a[0], suiteName = _a[1];
|
|
1746
|
-
|
|
1747
|
-
throwError('vest.create: Expected callback to be a function.');
|
|
1748
|
-
}
|
|
1761
|
+
invariant(isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
|
|
1749
1762
|
// Event bus initialization
|
|
1750
1763
|
var bus = initBus();
|
|
1751
1764
|
// State initialization
|
|
@@ -1800,9 +1813,7 @@
|
|
|
1800
1813
|
* })
|
|
1801
1814
|
*/
|
|
1802
1815
|
function each(list, callback) {
|
|
1803
|
-
|
|
1804
|
-
throwError('each callback must be a function');
|
|
1805
|
-
}
|
|
1816
|
+
invariant(isFunction(callback), 'each callback must be a function');
|
|
1806
1817
|
isolate({ type: IsolateTypes.EACH }, function () {
|
|
1807
1818
|
list.forEach(function (arg, index) {
|
|
1808
1819
|
callback(arg, index);
|
|
@@ -1999,19 +2010,15 @@
|
|
|
1999
2010
|
* });
|
|
2000
2011
|
*/
|
|
2001
2012
|
function group(groupName, tests) {
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
}
|
|
2005
|
-
if (!isFunction(tests)) {
|
|
2006
|
-
throwGroupError('callback must be a function');
|
|
2007
|
-
}
|
|
2013
|
+
invariant(isStringValue(groupName), groupErrorMsg('name must be a string'));
|
|
2014
|
+
invariant(isFunction(tests), groupErrorMsg('callback must be a function'));
|
|
2008
2015
|
// Running with the context applied
|
|
2009
2016
|
isolate({ type: IsolateTypes.GROUP }, function () {
|
|
2010
2017
|
context.run({ groupName: groupName }, tests);
|
|
2011
2018
|
});
|
|
2012
2019
|
}
|
|
2013
|
-
function
|
|
2014
|
-
|
|
2020
|
+
function groupErrorMsg(error) {
|
|
2021
|
+
return "Wrong arguments passed to group. Group ".concat(error, ".");
|
|
2015
2022
|
}
|
|
2016
2023
|
|
|
2017
2024
|
function include(fieldName) {
|
|
@@ -2220,7 +2227,7 @@
|
|
|
2220
2227
|
}
|
|
2221
2228
|
}
|
|
2222
2229
|
catch (e) {
|
|
2223
|
-
|
|
2230
|
+
throw new Error("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(testObject), ".\n Error: ").concat(e, "."));
|
|
2224
2231
|
}
|
|
2225
2232
|
}
|
|
2226
2233
|
|
|
@@ -2247,7 +2254,7 @@
|
|
|
2247
2254
|
useSetTestAtCursor(nextTest_1);
|
|
2248
2255
|
return nextTest_1;
|
|
2249
2256
|
}
|
|
2250
|
-
if (
|
|
2257
|
+
if (testReorderDetected(prevTest, newTestObject)) {
|
|
2251
2258
|
throwTestOrderError(prevTest, newTestObject);
|
|
2252
2259
|
removeAllNextTestsInIsolate();
|
|
2253
2260
|
// Need to see if this has any effect at all.
|
|
@@ -2284,14 +2291,14 @@
|
|
|
2284
2291
|
var cursorPath = usePath();
|
|
2285
2292
|
return valueAtPath(tests, cursorPath);
|
|
2286
2293
|
}
|
|
2287
|
-
function
|
|
2294
|
+
function testReorderDetected(prevTest, newTest) {
|
|
2288
2295
|
return isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
|
|
2289
2296
|
}
|
|
2290
2297
|
function throwTestOrderError(prevTest, newTestObject) {
|
|
2291
2298
|
if (shouldAllowReorder()) {
|
|
2292
2299
|
return;
|
|
2293
2300
|
}
|
|
2294
|
-
|
|
2301
|
+
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."));
|
|
2295
2302
|
}
|
|
2296
2303
|
function handleKeyTest(key, newTestObject) {
|
|
2297
2304
|
var prevTestByKey = usePrevTestByKey(key);
|
|
@@ -2377,12 +2384,8 @@
|
|
|
2377
2384
|
args[_i - 1] = arguments[_i];
|
|
2378
2385
|
}
|
|
2379
2386
|
var _a = (isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
}
|
|
2383
|
-
if (!isFunction(testFn)) {
|
|
2384
|
-
throwIncompatibleParamsError('Test callback', 'function');
|
|
2385
|
-
}
|
|
2387
|
+
invariant(isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
|
|
2388
|
+
invariant(isFunction(testFn), incompatibleParamsError('Test callback', 'function'));
|
|
2386
2389
|
var context$1 = context.useX();
|
|
2387
2390
|
var testObject = new VestTest(fieldName, testFn, {
|
|
2388
2391
|
message: message,
|
|
@@ -2403,8 +2406,8 @@
|
|
|
2403
2406
|
var test = assign(testBase, {
|
|
2404
2407
|
memo: bindTestMemo(testBase)
|
|
2405
2408
|
});
|
|
2406
|
-
function
|
|
2407
|
-
|
|
2409
|
+
function incompatibleParamsError(name, expected) {
|
|
2410
|
+
return "Incompatible params passed to test function. ".concat(name, " must be a ").concat(expected);
|
|
2408
2411
|
}
|
|
2409
2412
|
|
|
2410
2413
|
var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won't have an effect."
|
|
@@ -2414,13 +2417,11 @@
|
|
|
2414
2417
|
*/
|
|
2415
2418
|
function warn() {
|
|
2416
2419
|
var ctx = context.useX('warn ' + ERROR_HOOK_CALLED_OUTSIDE);
|
|
2417
|
-
|
|
2418
|
-
throwError(ERROR_OUTSIDE_OF_TEST);
|
|
2419
|
-
}
|
|
2420
|
+
invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
|
|
2420
2421
|
ctx.currentTest.warn();
|
|
2421
2422
|
}
|
|
2422
2423
|
|
|
2423
|
-
var VERSION = "4.2.
|
|
2424
|
+
var VERSION = "4.2.3-dev-87ebfa";
|
|
2424
2425
|
|
|
2425
2426
|
exports.VERSION = VERSION;
|
|
2426
2427
|
exports.context = context;
|