vest 4.0.0-dev-deabb8 → 4.0.0-dev-8851ff
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/CHANGELOG.md +49 -37
- package/README.md +113 -0
- package/dist/cjs/vest.development.js +416 -139
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/vest.development.js +416 -139
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/vest.development.js +416 -139
- package/dist/umd/vest.production.js +1 -1
- package/docs/README.md +113 -0
- package/docs/_assets/favicon.ico +0 -0
- package/docs/_assets/vest-logo.png +0 -0
- package/docs/_sidebar.md +1 -1
- package/docs/cross_field_validations.md +8 -81
- package/docs/getting_started.md +5 -7
- package/docs/group.md +2 -2
- package/docs/migration.md +7 -7
- package/docs/n4s/rules.md +1282 -0
- package/docs/node.md +1 -1
- package/docs/optional.md +58 -6
- package/docs/result.md +19 -3
- package/docs/state.md +6 -6
- package/docs/test.md +2 -2
- package/docs/utilities.md +8 -8
- package/docs/warn.md +1 -1
- package/package.json +31 -11
- package/testUtils/testObjects.ts +11 -2
- package/types/vest.d.ts +12 -4
|
@@ -230,8 +230,16 @@
|
|
|
230
230
|
return isNumeric(value) && isNumeric(gte) && Number(value) >= Number(gte);
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
+
// The module is named "isArrayValue" since it
|
|
234
|
+
// is conflicting with a nested npm dependency.
|
|
235
|
+
// We may need to revisit this in the future.
|
|
236
|
+
function isArray(value) {
|
|
237
|
+
return Boolean(Array.isArray(value));
|
|
238
|
+
}
|
|
239
|
+
var isNotArray = bindNot(isArray);
|
|
240
|
+
|
|
233
241
|
function inside(value, arg1) {
|
|
234
|
-
if (
|
|
242
|
+
if (isArray(arg1)) {
|
|
235
243
|
return arg1.indexOf(value) !== -1;
|
|
236
244
|
}
|
|
237
245
|
// both value and arg1 are strings
|
|
@@ -242,14 +250,6 @@
|
|
|
242
250
|
}
|
|
243
251
|
var notInside = bindNot(inside);
|
|
244
252
|
|
|
245
|
-
// The module is named "isArrayValue" since it
|
|
246
|
-
// is conflicting with a nested npm dependency.
|
|
247
|
-
// We may need to revisit this in the future.
|
|
248
|
-
function isArray(value) {
|
|
249
|
-
return Boolean(Array.isArray(value));
|
|
250
|
-
}
|
|
251
|
-
var isNotArray = bindNot(isArray);
|
|
252
|
-
|
|
253
253
|
function lessThanOrEquals(value, lte) {
|
|
254
254
|
return isNumeric(value) && isNumeric(lte) && Number(value) <= Number(lte);
|
|
255
255
|
}
|
|
@@ -259,6 +259,11 @@
|
|
|
259
259
|
}
|
|
260
260
|
var isNotBetween = bindNot(isBetween);
|
|
261
261
|
|
|
262
|
+
function isBlank(value) {
|
|
263
|
+
return isStringValue(value) && !value.trim();
|
|
264
|
+
}
|
|
265
|
+
var isNotBlank = bindNot(isBlank);
|
|
266
|
+
|
|
262
267
|
function isBoolean(value) {
|
|
263
268
|
return !!value === value;
|
|
264
269
|
}
|
|
@@ -397,6 +402,7 @@
|
|
|
397
402
|
inside: inside,
|
|
398
403
|
isArray: isArray,
|
|
399
404
|
isBetween: isBetween,
|
|
405
|
+
isBlank: isBlank,
|
|
400
406
|
isBoolean: isBoolean,
|
|
401
407
|
isEmpty: isEmpty,
|
|
402
408
|
isEven: isEven,
|
|
@@ -405,6 +411,7 @@
|
|
|
405
411
|
isNegative: isNegative,
|
|
406
412
|
isNotArray: isNotArray,
|
|
407
413
|
isNotBetween: isNotBetween,
|
|
414
|
+
isNotBlank: isNotBlank,
|
|
408
415
|
isNotBoolean: isNotBoolean,
|
|
409
416
|
isNotEmpty: isNotEmpty,
|
|
410
417
|
isNotNaN: isNotNaN,
|
|
@@ -447,6 +454,11 @@
|
|
|
447
454
|
function throwError(devMessage, productionMessage) {
|
|
448
455
|
throw new Error(devMessage );
|
|
449
456
|
}
|
|
457
|
+
function throwErrorDeferred(devMessage, productionMessage) {
|
|
458
|
+
setTimeout(function () {
|
|
459
|
+
throwError(devMessage);
|
|
460
|
+
}, 0);
|
|
461
|
+
}
|
|
450
462
|
|
|
451
463
|
// eslint-disable-next-line max-lines-per-function
|
|
452
464
|
function createContext(init) {
|
|
@@ -611,7 +623,7 @@
|
|
|
611
623
|
return ruleReturn(result);
|
|
612
624
|
}
|
|
613
625
|
else {
|
|
614
|
-
return ruleReturn(result.pass, optionalFunctionValue.apply(void 0, __spreadArray([result.message, ruleName, value], args
|
|
626
|
+
return ruleReturn(result.pass, optionalFunctionValue.apply(void 0, __spreadArray([result.message, ruleName, value], args)));
|
|
615
627
|
}
|
|
616
628
|
}
|
|
617
629
|
function validateResult(result) {
|
|
@@ -645,9 +657,9 @@
|
|
|
645
657
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
646
658
|
args[_i] = arguments[_i];
|
|
647
659
|
}
|
|
648
|
-
var transformedResult = transformResult.apply(void 0, __spreadArray([ctx$1.run({ value: value }, function () { return rule.apply(void 0, __spreadArray([value], args
|
|
660
|
+
var transformedResult = transformResult.apply(void 0, __spreadArray([ctx$1.run({ value: value }, function () { return rule.apply(void 0, __spreadArray([value], args)); }),
|
|
649
661
|
ruleName,
|
|
650
|
-
value], args
|
|
662
|
+
value], args));
|
|
651
663
|
if (!transformedResult.pass) {
|
|
652
664
|
if (isEmpty(transformedResult.message)) {
|
|
653
665
|
throwError("enforce/" + ruleName + " failed with " + JSON.stringify(value));
|
|
@@ -677,7 +689,7 @@
|
|
|
677
689
|
}
|
|
678
690
|
var rule = getRule(ruleName);
|
|
679
691
|
registeredRules.push(function (value) {
|
|
680
|
-
return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args
|
|
692
|
+
return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args)), ruleName, value], args));
|
|
681
693
|
});
|
|
682
694
|
var proxy = {
|
|
683
695
|
run: function (value) {
|
|
@@ -784,10 +796,6 @@
|
|
|
784
796
|
}
|
|
785
797
|
var enforce = genEnforce();
|
|
786
798
|
|
|
787
|
-
function asArray(possibleArg) {
|
|
788
|
-
return [].concat(possibleArg);
|
|
789
|
-
}
|
|
790
|
-
|
|
791
799
|
/**
|
|
792
800
|
* @returns a unique numeric id.
|
|
793
801
|
*/
|
|
@@ -824,15 +832,16 @@
|
|
|
824
832
|
return initKey(key, initialState);
|
|
825
833
|
}
|
|
826
834
|
function reset() {
|
|
835
|
+
var prev = current();
|
|
827
836
|
state.references = [];
|
|
828
837
|
registrations.forEach(function (_a, index) {
|
|
829
838
|
var initialValue = _a[0];
|
|
830
|
-
return initKey(index, initialValue);
|
|
839
|
+
return initKey(index, initialValue, prev[index]);
|
|
831
840
|
});
|
|
832
841
|
}
|
|
833
|
-
function initKey(key, initialState) {
|
|
842
|
+
function initKey(key, initialState, prevState) {
|
|
834
843
|
current().push();
|
|
835
|
-
set(key, optionalFunctionValue(initialState));
|
|
844
|
+
set(key, optionalFunctionValue(initialState, prevState));
|
|
836
845
|
return function useStateKey() {
|
|
837
846
|
return [
|
|
838
847
|
current()[key],
|
|
@@ -858,18 +867,74 @@
|
|
|
858
867
|
}
|
|
859
868
|
}
|
|
860
869
|
|
|
870
|
+
var IsolateTypes;
|
|
871
|
+
(function (IsolateTypes) {
|
|
872
|
+
IsolateTypes[IsolateTypes["DEFAULT"] = 0] = "DEFAULT";
|
|
873
|
+
IsolateTypes[IsolateTypes["SUITE"] = 1] = "SUITE";
|
|
874
|
+
IsolateTypes[IsolateTypes["EACH"] = 2] = "EACH";
|
|
875
|
+
IsolateTypes[IsolateTypes["SKIP_WHEN"] = 3] = "SKIP_WHEN";
|
|
876
|
+
IsolateTypes[IsolateTypes["GROUP"] = 4] = "GROUP";
|
|
877
|
+
})(IsolateTypes || (IsolateTypes = {}));
|
|
878
|
+
|
|
861
879
|
function createStateRef(state, _a) {
|
|
862
880
|
var suiteId = _a.suiteId;
|
|
863
881
|
return {
|
|
864
882
|
optionalFields: state.registerStateKey(function () { return ({}); }),
|
|
865
|
-
|
|
866
|
-
suiteId: state.registerStateKey(function () { return suiteId; }),
|
|
883
|
+
suiteId: state.registerStateKey(suiteId),
|
|
867
884
|
testCallbacks: state.registerStateKey(function () { return ({
|
|
868
885
|
fieldCallbacks: {},
|
|
869
886
|
doneCallbacks: []
|
|
870
887
|
}); }),
|
|
871
|
-
testObjects: state.registerStateKey(function () {
|
|
872
|
-
|
|
888
|
+
testObjects: state.registerStateKey(function (prev) {
|
|
889
|
+
return {
|
|
890
|
+
prev: (prev ? prev.current : []),
|
|
891
|
+
current: []
|
|
892
|
+
};
|
|
893
|
+
})
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
function asArray(possibleArg) {
|
|
898
|
+
return [].concat(possibleArg);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
function last(values) {
|
|
902
|
+
var valuesArray = asArray(values);
|
|
903
|
+
var _a = valuesArray, l = _a.length, _b = l - 1, lastValue = _a[_b];
|
|
904
|
+
return lastValue;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
function createCursor() {
|
|
908
|
+
var storage = {
|
|
909
|
+
cursor: []
|
|
910
|
+
};
|
|
911
|
+
function addLevel() {
|
|
912
|
+
storage.cursor.push(0);
|
|
913
|
+
}
|
|
914
|
+
function removeLevel() {
|
|
915
|
+
storage.cursor.pop();
|
|
916
|
+
}
|
|
917
|
+
function cursorAt() {
|
|
918
|
+
return last(storage.cursor);
|
|
919
|
+
}
|
|
920
|
+
function getCursor() {
|
|
921
|
+
return asArray(storage.cursor);
|
|
922
|
+
}
|
|
923
|
+
function next() {
|
|
924
|
+
storage.cursor[storage.cursor.length - 1]++;
|
|
925
|
+
return last(storage.cursor);
|
|
926
|
+
}
|
|
927
|
+
function reset() {
|
|
928
|
+
storage.cursor = [0];
|
|
929
|
+
}
|
|
930
|
+
reset();
|
|
931
|
+
return {
|
|
932
|
+
addLevel: addLevel,
|
|
933
|
+
cursorAt: cursorAt,
|
|
934
|
+
getCursor: getCursor,
|
|
935
|
+
next: next,
|
|
936
|
+
removeLevel: removeLevel,
|
|
937
|
+
reset: reset
|
|
873
938
|
};
|
|
874
939
|
}
|
|
875
940
|
|
|
@@ -877,6 +942,8 @@
|
|
|
877
942
|
return parentContext
|
|
878
943
|
? null
|
|
879
944
|
: assign({}, {
|
|
945
|
+
isolate: { type: IsolateTypes.DEFAULT },
|
|
946
|
+
testCursor: createCursor(),
|
|
880
947
|
exclusion: {
|
|
881
948
|
tests: {},
|
|
882
949
|
groups: {}
|
|
@@ -884,18 +951,56 @@
|
|
|
884
951
|
}, ctxRef);
|
|
885
952
|
});
|
|
886
953
|
|
|
887
|
-
|
|
888
|
-
|
|
954
|
+
// This is sort of a map/filter in one function.
|
|
955
|
+
// Normally, behaves like a nested-array map
|
|
956
|
+
// Returning `null` will drop the element from the array
|
|
957
|
+
function transform(array, cb) {
|
|
958
|
+
var res = [];
|
|
959
|
+
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
|
|
960
|
+
var v = array_1[_i];
|
|
961
|
+
if (isArray(v)) {
|
|
962
|
+
res.push(transform(v, cb));
|
|
963
|
+
}
|
|
964
|
+
else {
|
|
965
|
+
var output = cb(v);
|
|
966
|
+
if (isNotNull(output)) {
|
|
967
|
+
res.push(output);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
return res;
|
|
889
972
|
}
|
|
890
|
-
function
|
|
891
|
-
return
|
|
973
|
+
function valueAtPath(array, path) {
|
|
974
|
+
return getCurrent(array, path)[last(path)];
|
|
975
|
+
}
|
|
976
|
+
function setValueAtPath(array, path, value) {
|
|
977
|
+
var current = getCurrent(array, path);
|
|
978
|
+
current[last(path)] = value;
|
|
979
|
+
return array;
|
|
980
|
+
}
|
|
981
|
+
function flatten(values) {
|
|
982
|
+
return asArray(values).reduce(function (acc, value) {
|
|
983
|
+
if (isArray(value)) {
|
|
984
|
+
return acc.concat(flatten(value));
|
|
985
|
+
}
|
|
986
|
+
return asArray(acc).concat(value);
|
|
987
|
+
}, []);
|
|
988
|
+
}
|
|
989
|
+
function getCurrent(array, path) {
|
|
990
|
+
var current = array;
|
|
991
|
+
for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) {
|
|
992
|
+
var p = _a[_i];
|
|
993
|
+
current[p] = defaultTo(current[p], []);
|
|
994
|
+
current = current[p];
|
|
995
|
+
}
|
|
996
|
+
return current;
|
|
892
997
|
}
|
|
893
998
|
|
|
894
999
|
/**
|
|
895
1000
|
* Creates a cache function
|
|
896
1001
|
*/
|
|
897
1002
|
function createCache(maxSize) {
|
|
898
|
-
if (maxSize === void 0) { maxSize =
|
|
1003
|
+
if (maxSize === void 0) { maxSize = 1; }
|
|
899
1004
|
var cacheStorage = [];
|
|
900
1005
|
var cache = function (deps, cacheAction) {
|
|
901
1006
|
var cacheHit = cache.get(deps);
|
|
@@ -904,9 +1009,8 @@
|
|
|
904
1009
|
return cacheHit[1];
|
|
905
1010
|
var result = cacheAction();
|
|
906
1011
|
cacheStorage.unshift([deps.concat(), result]);
|
|
907
|
-
if (cacheStorage
|
|
1012
|
+
if (longerThan(cacheStorage, maxSize))
|
|
908
1013
|
cacheStorage.length = maxSize;
|
|
909
|
-
}
|
|
910
1014
|
return result;
|
|
911
1015
|
};
|
|
912
1016
|
// invalidate an item in the cache by its dependencies
|
|
@@ -930,6 +1034,12 @@
|
|
|
930
1034
|
return cache;
|
|
931
1035
|
}
|
|
932
1036
|
|
|
1037
|
+
// STATE REF
|
|
1038
|
+
function useStateRef() {
|
|
1039
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1040
|
+
return ctx.useX().stateRef; // I should revisit this
|
|
1041
|
+
}
|
|
1042
|
+
// STATE KEYS
|
|
933
1043
|
function useSuiteId() {
|
|
934
1044
|
return useStateRef().suiteId();
|
|
935
1045
|
}
|
|
@@ -939,58 +1049,133 @@
|
|
|
939
1049
|
function useOptionalFields() {
|
|
940
1050
|
return useStateRef().optionalFields();
|
|
941
1051
|
}
|
|
942
|
-
function useStateRef() {
|
|
943
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
944
|
-
return ctx.useX().stateRef; // I should revisit this
|
|
945
|
-
}
|
|
946
1052
|
function useTestObjects() {
|
|
947
1053
|
return useStateRef().testObjects();
|
|
948
1054
|
}
|
|
949
|
-
|
|
950
|
-
|
|
1055
|
+
// STATE ACTIONS
|
|
1056
|
+
function useRefreshTestObjects() {
|
|
1057
|
+
var _a = useTestObjects(), setTestObjects = _a[1];
|
|
1058
|
+
setTestObjects(function (_a) {
|
|
1059
|
+
var current = _a.current, prev = _a.prev;
|
|
1060
|
+
return ({
|
|
1061
|
+
prev: prev,
|
|
1062
|
+
current: asArray(current)
|
|
1063
|
+
});
|
|
1064
|
+
});
|
|
951
1065
|
}
|
|
952
|
-
function
|
|
953
|
-
var
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
1066
|
+
function useSetTests(handler) {
|
|
1067
|
+
var _a = useTestObjects(), testObjects = _a[1];
|
|
1068
|
+
testObjects(function (_a) {
|
|
1069
|
+
var current = _a.current, prev = _a.prev;
|
|
1070
|
+
return ({
|
|
1071
|
+
prev: prev,
|
|
1072
|
+
current: asArray(handler(current))
|
|
1073
|
+
});
|
|
1074
|
+
});
|
|
958
1075
|
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
var
|
|
962
|
-
|
|
1076
|
+
// Derived state
|
|
1077
|
+
function useAllIncomplete() {
|
|
1078
|
+
var current = useTestObjects()[0].current;
|
|
1079
|
+
return flatten(transform(current, function (testObject) {
|
|
1080
|
+
return testObject.isPending() ? testObject : null;
|
|
1081
|
+
}));
|
|
1082
|
+
}
|
|
1083
|
+
function useOmittedFields() {
|
|
1084
|
+
var testObjects = useTestsFlat();
|
|
1085
|
+
return testObjects.reduce(function (omittedFields, testObject) {
|
|
1086
|
+
if (omittedFields[testObject.fieldName]) {
|
|
1087
|
+
return omittedFields;
|
|
1088
|
+
}
|
|
1089
|
+
if (testObject.isOmitted()) {
|
|
1090
|
+
omittedFields[testObject.fieldName] = true;
|
|
1091
|
+
}
|
|
1092
|
+
return omittedFields;
|
|
1093
|
+
}, {});
|
|
1094
|
+
}
|
|
1095
|
+
var flatCache = createCache();
|
|
1096
|
+
function useTestsFlat() {
|
|
1097
|
+
var current = useTestObjects()[0].current;
|
|
1098
|
+
return flatCache([current], function () { return flatten(current); });
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
function usePath() {
|
|
1102
|
+
var context = ctx.useX();
|
|
1103
|
+
return context.testCursor.getCursor();
|
|
1104
|
+
}
|
|
1105
|
+
function useCursorAt() {
|
|
1106
|
+
var context = ctx.useX();
|
|
1107
|
+
return context.testCursor.cursorAt();
|
|
1108
|
+
}
|
|
1109
|
+
function moveForward() {
|
|
1110
|
+
var context = ctx.useX();
|
|
1111
|
+
return context.testCursor.next();
|
|
1112
|
+
}
|
|
1113
|
+
function addLevel() {
|
|
1114
|
+
var context = ctx.useX();
|
|
1115
|
+
context.testCursor.addLevel();
|
|
1116
|
+
}
|
|
1117
|
+
function removeLevel() {
|
|
1118
|
+
var context = ctx.useX();
|
|
1119
|
+
context.testCursor.removeLevel();
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
function isolate(_a, callback) {
|
|
1123
|
+
var _b = _a.type, type = _b === void 0 ? IsolateTypes.DEFAULT : _b;
|
|
1124
|
+
if (!isFunction(callback)) {
|
|
963
1125
|
return;
|
|
964
1126
|
}
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
return
|
|
1127
|
+
var path = usePath();
|
|
1128
|
+
return ctx.run({ isolate: { type: type } }, function () {
|
|
1129
|
+
addLevel();
|
|
1130
|
+
useSetTests(function (tests) { return setValueAtPath(tests, path, []); });
|
|
1131
|
+
var res = callback();
|
|
1132
|
+
removeLevel();
|
|
1133
|
+
moveForward();
|
|
1134
|
+
return res;
|
|
969
1135
|
});
|
|
970
1136
|
}
|
|
971
|
-
function
|
|
972
|
-
|
|
973
|
-
setCursorAt(function (cursorAt) { return cursorAt + 1; });
|
|
1137
|
+
function shouldAllowReorder() {
|
|
1138
|
+
return ctx.useX().isolate.type === IsolateTypes.EACH;
|
|
974
1139
|
}
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1140
|
+
|
|
1141
|
+
function nonMatchingFieldName(testObject, fieldName) {
|
|
1142
|
+
return !!fieldName && !matchingFieldName(testObject, fieldName);
|
|
978
1143
|
}
|
|
979
|
-
function
|
|
980
|
-
return
|
|
1144
|
+
function matchingFieldName(testObject, fieldName) {
|
|
1145
|
+
return !!(fieldName && testObject.fieldName === fieldName);
|
|
981
1146
|
}
|
|
982
|
-
|
|
1147
|
+
|
|
1148
|
+
function omitOptionalTests() {
|
|
983
1149
|
var optionalFields = useOptionalFields()[0];
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
var
|
|
988
|
-
|
|
989
|
-
|
|
1150
|
+
if (isEmpty(optionalFields)) {
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
var shouldOmit = {};
|
|
1154
|
+
useSetTests(function (tests) {
|
|
1155
|
+
return transform(tests, function (testObject) {
|
|
1156
|
+
var fieldName = testObject.fieldName;
|
|
1157
|
+
if (shouldOmit.hasOwnProperty(fieldName)) {
|
|
1158
|
+
omit(testObject);
|
|
1159
|
+
}
|
|
1160
|
+
else {
|
|
1161
|
+
var optionalConfig = optionalFields[fieldName];
|
|
1162
|
+
if (isFunction(optionalConfig)) {
|
|
1163
|
+
shouldOmit[fieldName] = optionalConfig();
|
|
1164
|
+
omit(testObject);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
return testObject;
|
|
1168
|
+
});
|
|
1169
|
+
});
|
|
1170
|
+
function omit(testObject) {
|
|
1171
|
+
if (shouldOmit[testObject.fieldName]) {
|
|
1172
|
+
testObject.omit();
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
990
1175
|
}
|
|
991
1176
|
|
|
992
1177
|
/**
|
|
993
|
-
* Checks if a given
|
|
1178
|
+
* Checks if a given field, or the suite as a whole still have remaining tests.
|
|
994
1179
|
*/
|
|
995
1180
|
function hasRemainingTests(fieldName) {
|
|
996
1181
|
var allIncomplete = useAllIncomplete();
|
|
@@ -1009,7 +1194,7 @@
|
|
|
1009
1194
|
* Reads the testObjects list and gets full validation result from it.
|
|
1010
1195
|
*/
|
|
1011
1196
|
function genTestsSummary() {
|
|
1012
|
-
var testObjects =
|
|
1197
|
+
var testObjects = useTestsFlat();
|
|
1013
1198
|
var summary = {
|
|
1014
1199
|
errorCount: 0,
|
|
1015
1200
|
groups: {},
|
|
@@ -1129,7 +1314,7 @@
|
|
|
1129
1314
|
* @returns suite or field's errors or warnings.
|
|
1130
1315
|
*/
|
|
1131
1316
|
function getFailures(severityKey, fieldName) {
|
|
1132
|
-
var testObjects =
|
|
1317
|
+
var testObjects = useTestsFlat();
|
|
1133
1318
|
var failureMessages = collectFailureMessages(severityKey, testObjects, {
|
|
1134
1319
|
fieldName: fieldName
|
|
1135
1320
|
});
|
|
@@ -1151,7 +1336,7 @@
|
|
|
1151
1336
|
if (!group) {
|
|
1152
1337
|
throwError("get" + severityKey[0].toUpperCase() + severityKey.slice(1) + "ByGroup requires a group name. Received `" + group + "` instead.");
|
|
1153
1338
|
}
|
|
1154
|
-
var testObjects =
|
|
1339
|
+
var testObjects = useTestsFlat();
|
|
1155
1340
|
var failureMessages = collectFailureMessages(severityKey, testObjects, {
|
|
1156
1341
|
group: group,
|
|
1157
1342
|
fieldName: fieldName
|
|
@@ -1182,7 +1367,7 @@
|
|
|
1182
1367
|
return has('warnings', fieldName);
|
|
1183
1368
|
}
|
|
1184
1369
|
function has(severityKey, fieldName) {
|
|
1185
|
-
var testObjects =
|
|
1370
|
+
var testObjects = useTestsFlat();
|
|
1186
1371
|
return testObjects.some(function (testObject) {
|
|
1187
1372
|
return hasFailuresLogic(testObject, severityKey, fieldName);
|
|
1188
1373
|
});
|
|
@@ -1198,7 +1383,7 @@
|
|
|
1198
1383
|
* Checks whether there are failures in a given group.
|
|
1199
1384
|
*/
|
|
1200
1385
|
function hasByGroup(severityKey, group, fieldName) {
|
|
1201
|
-
var testObjects =
|
|
1386
|
+
var testObjects = useTestsFlat();
|
|
1202
1387
|
return testObjects.some(function (testObject) {
|
|
1203
1388
|
return group === testObject.groupName
|
|
1204
1389
|
? hasFailuresLogic(testObject, severityKey, fieldName)
|
|
@@ -1206,46 +1391,61 @@
|
|
|
1206
1391
|
});
|
|
1207
1392
|
}
|
|
1208
1393
|
|
|
1394
|
+
// eslint-disable-next-line max-statements, complexity
|
|
1209
1395
|
function isValid(result, fieldName) {
|
|
1396
|
+
if (fieldIsOmitted(fieldName)) {
|
|
1397
|
+
return true;
|
|
1398
|
+
}
|
|
1210
1399
|
if (result.hasErrors(fieldName)) {
|
|
1211
1400
|
return false;
|
|
1212
1401
|
}
|
|
1213
|
-
var testObjects =
|
|
1402
|
+
var testObjects = useTestsFlat();
|
|
1214
1403
|
if (isEmpty(testObjects)) {
|
|
1215
1404
|
return false;
|
|
1216
1405
|
}
|
|
1217
1406
|
if (fieldDoesNotExist(result, fieldName)) {
|
|
1218
1407
|
return false;
|
|
1219
1408
|
}
|
|
1220
|
-
if (
|
|
1221
|
-
if (nonMatchingFieldName(testObject, fieldName)) {
|
|
1222
|
-
return false;
|
|
1223
|
-
}
|
|
1224
|
-
return !isOptionalField(testObject.fieldName);
|
|
1225
|
-
}))) {
|
|
1409
|
+
if (hasNonOptionalIncomplete(fieldName)) {
|
|
1226
1410
|
return false;
|
|
1227
1411
|
}
|
|
1228
1412
|
return noMissingTests(fieldName);
|
|
1229
1413
|
}
|
|
1414
|
+
function fieldIsOmitted(fieldName) {
|
|
1415
|
+
var omittedFields = useOmittedFields();
|
|
1416
|
+
if (!fieldName) {
|
|
1417
|
+
return false;
|
|
1418
|
+
}
|
|
1419
|
+
return !!omittedFields[fieldName];
|
|
1420
|
+
}
|
|
1421
|
+
function hasNonOptionalIncomplete(fieldName) {
|
|
1422
|
+
var optionalFields = useOptionalFields()[0];
|
|
1423
|
+
return isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
1424
|
+
if (nonMatchingFieldName(testObject, fieldName)) {
|
|
1425
|
+
return false;
|
|
1426
|
+
}
|
|
1427
|
+
return optionalFields[testObject.fieldName] !== true;
|
|
1428
|
+
}));
|
|
1429
|
+
}
|
|
1230
1430
|
function fieldDoesNotExist(result, fieldName) {
|
|
1231
1431
|
return !!fieldName && isEmpty(result.tests[fieldName]);
|
|
1232
1432
|
}
|
|
1233
1433
|
function noMissingTests(fieldName) {
|
|
1234
|
-
var testObjects =
|
|
1434
|
+
var testObjects = useTestsFlat();
|
|
1435
|
+
var optionalFields = useOptionalFields()[0];
|
|
1235
1436
|
return testObjects.every(function (testObject) {
|
|
1236
1437
|
if (nonMatchingFieldName(testObject, fieldName)) {
|
|
1237
1438
|
return true;
|
|
1238
1439
|
}
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
return testObject.isTested();
|
|
1440
|
+
return (optionalFields[testObject.fieldName] === true ||
|
|
1441
|
+
testObject.isTested() ||
|
|
1442
|
+
testObject.isOmitted());
|
|
1243
1443
|
});
|
|
1244
1444
|
}
|
|
1245
1445
|
|
|
1246
1446
|
var cache$1 = createCache(20);
|
|
1247
1447
|
function produceDraft() {
|
|
1248
|
-
var testObjects =
|
|
1448
|
+
var testObjects = useTestsFlat();
|
|
1249
1449
|
var ctxRef = { stateRef: useStateRef() };
|
|
1250
1450
|
return cache$1([testObjects], ctx.bind(ctxRef, function () {
|
|
1251
1451
|
return assign(genTestsSummary(), {
|
|
@@ -1266,7 +1466,7 @@
|
|
|
1266
1466
|
|
|
1267
1467
|
var cache = createCache(20);
|
|
1268
1468
|
function produceFullResult() {
|
|
1269
|
-
var testObjects =
|
|
1469
|
+
var testObjects = useTestsFlat();
|
|
1270
1470
|
var ctxRef = { stateRef: useStateRef() };
|
|
1271
1471
|
return cache([testObjects], ctx.bind(ctxRef, function () {
|
|
1272
1472
|
return assign({}, produceDraft(), {
|
|
@@ -1324,6 +1524,15 @@
|
|
|
1324
1524
|
});
|
|
1325
1525
|
}
|
|
1326
1526
|
|
|
1527
|
+
/**
|
|
1528
|
+
* Removes test object from suite state
|
|
1529
|
+
*/
|
|
1530
|
+
function removeTestFromState (testObject) {
|
|
1531
|
+
useSetTests(function (tests) {
|
|
1532
|
+
return transform(tests, function (test) { return (testObject !== test ? test : null); });
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1327
1536
|
function createBus() {
|
|
1328
1537
|
var listeners = {};
|
|
1329
1538
|
return {
|
|
@@ -1359,8 +1568,7 @@
|
|
|
1359
1568
|
function runFieldCallbacks(fieldName) {
|
|
1360
1569
|
var fieldCallbacks = useTestCallbacks()[0].fieldCallbacks;
|
|
1361
1570
|
if (fieldName) {
|
|
1362
|
-
if (!hasRemainingTests(fieldName) &&
|
|
1363
|
-
Array.isArray(fieldCallbacks[fieldName])) {
|
|
1571
|
+
if (!hasRemainingTests(fieldName) && isArray(fieldCallbacks[fieldName])) {
|
|
1364
1572
|
callEach(fieldCallbacks[fieldName]);
|
|
1365
1573
|
}
|
|
1366
1574
|
}
|
|
@@ -1412,22 +1620,23 @@
|
|
|
1412
1620
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1413
1621
|
args[_i] = arguments[_i];
|
|
1414
1622
|
}
|
|
1415
|
-
var prevTestObjects = useTestObjects()[0];
|
|
1416
|
-
var _a = usePrevTestObjects(), setPrevTestObjects = _a[1];
|
|
1417
1623
|
state.reset();
|
|
1418
|
-
setPrevTestObjects(function () { return prevTestObjects; });
|
|
1419
1624
|
// Run the consumer's callback
|
|
1420
|
-
|
|
1625
|
+
isolate({ type: IsolateTypes.SUITE }, function () {
|
|
1626
|
+
suiteCallback.apply(void 0, args);
|
|
1627
|
+
});
|
|
1628
|
+
omitOptionalTests();
|
|
1421
1629
|
var res = produceFullResult();
|
|
1422
1630
|
return res;
|
|
1423
1631
|
}), {
|
|
1424
1632
|
get: ctx.bind({ stateRef: stateRef }, produceDraft),
|
|
1425
1633
|
remove: ctx.bind({ stateRef: stateRef }, function (name) {
|
|
1426
|
-
var testObjects =
|
|
1634
|
+
var testObjects = useTestsFlat();
|
|
1427
1635
|
// We're mutating the array in `cancel`, so we have to first copy it.
|
|
1428
|
-
|
|
1636
|
+
testObjects.forEach(function (testObject) {
|
|
1429
1637
|
if (matchingFieldName(testObject, name)) {
|
|
1430
1638
|
testObject.cancel();
|
|
1639
|
+
removeTestFromState(testObject);
|
|
1431
1640
|
}
|
|
1432
1641
|
});
|
|
1433
1642
|
}),
|
|
@@ -1541,6 +1750,12 @@
|
|
|
1541
1750
|
return false;
|
|
1542
1751
|
}
|
|
1543
1752
|
|
|
1753
|
+
function skipWhen(conditional, callback) {
|
|
1754
|
+
isolate({ type: IsolateTypes.SKIP_WHEN }, function () {
|
|
1755
|
+
ctx.run({ skipped: optionalFunctionValue(conditional) }, function () { return callback(); });
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1544
1759
|
var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won't have an effect."
|
|
1545
1760
|
;
|
|
1546
1761
|
/**
|
|
@@ -1554,10 +1769,6 @@
|
|
|
1554
1769
|
ctx$1.currentTest.warn();
|
|
1555
1770
|
}
|
|
1556
1771
|
|
|
1557
|
-
function skipWhen(conditional, callback) {
|
|
1558
|
-
ctx.run({ skipped: optionalFunctionValue(conditional) }, function () { return callback(); });
|
|
1559
|
-
}
|
|
1560
|
-
|
|
1561
1772
|
/**
|
|
1562
1773
|
* Runs a group callback.
|
|
1563
1774
|
*/
|
|
@@ -1569,7 +1780,9 @@
|
|
|
1569
1780
|
throwGroupError('callback must be a function');
|
|
1570
1781
|
}
|
|
1571
1782
|
// Running with the context applied
|
|
1572
|
-
|
|
1783
|
+
isolate({ type: IsolateTypes.GROUP }, function () {
|
|
1784
|
+
ctx.run({ groupName: groupName }, tests);
|
|
1785
|
+
});
|
|
1573
1786
|
}
|
|
1574
1787
|
function throwGroupError(error) {
|
|
1575
1788
|
throwError("Wrong arguments passed to group. Group " + error + ".");
|
|
@@ -1578,36 +1791,22 @@
|
|
|
1578
1791
|
function optional(optionals) {
|
|
1579
1792
|
var _a = useOptionalFields(), setOptionalFields = _a[1];
|
|
1580
1793
|
setOptionalFields(function (state) {
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1794
|
+
if (!isArray(optionals) && !isStringValue(optionals)) {
|
|
1795
|
+
var optionalFunctions = optionals;
|
|
1796
|
+
for (var field in optionalFunctions) {
|
|
1797
|
+
var predicate = optionalFunctions[field];
|
|
1798
|
+
state[field] = predicate;
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
else {
|
|
1802
|
+
asArray(optionals).forEach(function (optionalField) {
|
|
1803
|
+
state[optionalField] = true;
|
|
1804
|
+
});
|
|
1805
|
+
}
|
|
1584
1806
|
return state;
|
|
1585
1807
|
});
|
|
1586
1808
|
}
|
|
1587
1809
|
|
|
1588
|
-
/**
|
|
1589
|
-
* Removes first found element from array
|
|
1590
|
-
* WARNING: Mutates array
|
|
1591
|
-
*/
|
|
1592
|
-
function removeElementFromArray(array, element) {
|
|
1593
|
-
var index = array.indexOf(element);
|
|
1594
|
-
if (index !== -1) {
|
|
1595
|
-
array.splice(index, 1);
|
|
1596
|
-
}
|
|
1597
|
-
return array;
|
|
1598
|
-
}
|
|
1599
|
-
|
|
1600
|
-
/**
|
|
1601
|
-
* Removes test object from suite state
|
|
1602
|
-
*/
|
|
1603
|
-
function removeTestFromState (testObject) {
|
|
1604
|
-
var _a = useTestObjects(), setTestObjects = _a[1];
|
|
1605
|
-
setTestObjects(function (testObjects) {
|
|
1606
|
-
// using asArray to clear the cache.
|
|
1607
|
-
return asArray(removeElementFromArray(testObjects, testObject));
|
|
1608
|
-
});
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
1810
|
function shouldUseErrorAsMessage(message, error) {
|
|
1612
1811
|
// kind of cheating with this safe guard, but it does the job
|
|
1613
1812
|
return isUndefined(message) && isStringValue(error);
|
|
@@ -1645,7 +1844,7 @@
|
|
|
1645
1844
|
return result;
|
|
1646
1845
|
};
|
|
1647
1846
|
VestTest.prototype.setStatus = function (status) {
|
|
1648
|
-
if (this.
|
|
1847
|
+
if (this.isFinalStatus() && status !== STATUS_OMITTED) {
|
|
1649
1848
|
return;
|
|
1650
1849
|
}
|
|
1651
1850
|
this.status = status;
|
|
@@ -1657,7 +1856,7 @@
|
|
|
1657
1856
|
this.setStatus(this.warns ? STATUS_WARNING : STATUS_FAILED);
|
|
1658
1857
|
};
|
|
1659
1858
|
VestTest.prototype.done = function () {
|
|
1660
|
-
if (this.
|
|
1859
|
+
if (this.isFinalStatus()) {
|
|
1661
1860
|
return;
|
|
1662
1861
|
}
|
|
1663
1862
|
this.setStatus(STATUS_PASSING);
|
|
@@ -1665,12 +1864,18 @@
|
|
|
1665
1864
|
VestTest.prototype.warn = function () {
|
|
1666
1865
|
this.warns = true;
|
|
1667
1866
|
};
|
|
1867
|
+
VestTest.prototype.isFinalStatus = function () {
|
|
1868
|
+
return this.hasFailures() || this.isCanceled() || this.isPassing();
|
|
1869
|
+
};
|
|
1668
1870
|
VestTest.prototype.skip = function () {
|
|
1669
1871
|
this.setStatus(STATUS_SKIPPED);
|
|
1670
1872
|
};
|
|
1671
1873
|
VestTest.prototype.cancel = function () {
|
|
1672
1874
|
this.setStatus(STATUS_CANCELED);
|
|
1673
|
-
|
|
1875
|
+
useRefreshTestObjects();
|
|
1876
|
+
};
|
|
1877
|
+
VestTest.prototype.omit = function () {
|
|
1878
|
+
this.setStatus(STATUS_OMITTED);
|
|
1674
1879
|
};
|
|
1675
1880
|
VestTest.prototype.valueOf = function () {
|
|
1676
1881
|
return !this.isFailing();
|
|
@@ -1684,6 +1889,9 @@
|
|
|
1684
1889
|
VestTest.prototype.isTested = function () {
|
|
1685
1890
|
return this.hasFailures() || this.isPassing();
|
|
1686
1891
|
};
|
|
1892
|
+
VestTest.prototype.isOmitted = function () {
|
|
1893
|
+
return this.status === STATUS_OMITTED;
|
|
1894
|
+
};
|
|
1687
1895
|
VestTest.prototype.isUntested = function () {
|
|
1688
1896
|
return this.status === STATUS_UNTESTED;
|
|
1689
1897
|
};
|
|
@@ -1711,6 +1919,7 @@
|
|
|
1711
1919
|
var STATUS_PASSING = 'PASSING';
|
|
1712
1920
|
var STATUS_PENDING = 'PENDING';
|
|
1713
1921
|
var STATUS_CANCELED = 'CANCELED';
|
|
1922
|
+
var STATUS_OMITTED = 'OMITTED';
|
|
1714
1923
|
|
|
1715
1924
|
function isPromise(value) {
|
|
1716
1925
|
return value && isFunction(value.then);
|
|
@@ -1739,6 +1948,8 @@
|
|
|
1739
1948
|
var emit = useBus().emit;
|
|
1740
1949
|
var stateRef = useStateRef();
|
|
1741
1950
|
var done = ctx.bind({ stateRef: stateRef }, function () {
|
|
1951
|
+
// invalidating the "produce" cache
|
|
1952
|
+
useRefreshTestObjects();
|
|
1742
1953
|
emit(Events.TEST_COMPLETED, testObject);
|
|
1743
1954
|
});
|
|
1744
1955
|
var fail = ctx.bind({ stateRef: stateRef }, function (rejectionMessage) {
|
|
@@ -1749,8 +1960,6 @@
|
|
|
1749
1960
|
? rejectionMessage
|
|
1750
1961
|
: message;
|
|
1751
1962
|
testObject.fail();
|
|
1752
|
-
// invalidating the "produce" cache
|
|
1753
|
-
useRefreshTestObjects();
|
|
1754
1963
|
done();
|
|
1755
1964
|
});
|
|
1756
1965
|
try {
|
|
@@ -1804,21 +2013,86 @@
|
|
|
1804
2013
|
emit(Events.TEST_COMPLETED, testObject);
|
|
1805
2014
|
}
|
|
1806
2015
|
}
|
|
1807
|
-
catch (
|
|
2016
|
+
catch (e) {
|
|
1808
2017
|
throwError("Your test function " + testObject.fieldName + " returned " + JSON.stringify(result) + ". Only \"false\" or a Promise are supported. Return values may cause unexpected behavior.");
|
|
1809
2018
|
}
|
|
1810
2019
|
}
|
|
1811
2020
|
|
|
2021
|
+
/**
|
|
2022
|
+
* This module serves as the "collision detection" mechanism for Vest.
|
|
2023
|
+
* It is used to ensure that tests are not called in a different order than
|
|
2024
|
+
* they were called in the previous run.
|
|
2025
|
+
* If they are, it will throw a deferred error unless explicitly allowed.
|
|
2026
|
+
*
|
|
2027
|
+
* For now it seems pretty safe, and it covers most common use cases, but it can
|
|
2028
|
+
* be improved in the future both in terms of performance and scenarios it covers.
|
|
2029
|
+
*/
|
|
2030
|
+
// eslint-disable-next-line max-statements, max-lines-per-function
|
|
2031
|
+
function useTestAtCursor(newTestObject) {
|
|
2032
|
+
var _a = useTestObjects(), testObjects = _a[0], setTestObjects = _a[1];
|
|
2033
|
+
var prevTests = testObjects.prev;
|
|
2034
|
+
if (isEmpty(prevTests)) {
|
|
2035
|
+
useSetTestAtCursor(newTestObject);
|
|
2036
|
+
return newTestObject;
|
|
2037
|
+
}
|
|
2038
|
+
var prevTest = useGetTestAtCursor(prevTests);
|
|
2039
|
+
if (shouldPurgePrevTest(prevTest, newTestObject)) {
|
|
2040
|
+
throwTestOrderError(prevTest, newTestObject);
|
|
2041
|
+
// Here we handle just the omission of tests in the middle of the test suite.
|
|
2042
|
+
// We need to also handle a case in which tests are added in between other tests.
|
|
2043
|
+
// At the moment all we can do is just splice the tests out of the array when this happens.
|
|
2044
|
+
// A viable solution would be to use something like React's key prop to identify tests regardless
|
|
2045
|
+
// of their position in the suite. https://reactjs.org/docs/lists-and-keys.html#keys
|
|
2046
|
+
var current = getCurrent(prevTests, usePath());
|
|
2047
|
+
var cursorAt = useCursorAt();
|
|
2048
|
+
current.splice(cursorAt);
|
|
2049
|
+
// We actually don't mind mutating the state directly (as can be seen above). There is no harm in it
|
|
2050
|
+
// since we're only touching the "prev" state. The reason we still use the setter function is
|
|
2051
|
+
// to prevent future headaches if we ever do need to rely on prev-state immutability.
|
|
2052
|
+
setTestObjects(function (_a) {
|
|
2053
|
+
var current = _a.current;
|
|
2054
|
+
return ({
|
|
2055
|
+
prev: prevTests,
|
|
2056
|
+
current: current
|
|
2057
|
+
});
|
|
2058
|
+
});
|
|
2059
|
+
// Need to see if this has any effect at all.
|
|
2060
|
+
prevTest = null;
|
|
2061
|
+
}
|
|
2062
|
+
var nextTest = defaultTo(prevTest, newTestObject);
|
|
2063
|
+
useSetTestAtCursor(nextTest);
|
|
2064
|
+
return nextTest;
|
|
2065
|
+
}
|
|
2066
|
+
function useSetTestAtCursor(testObject) {
|
|
2067
|
+
var cursorPath = usePath();
|
|
2068
|
+
useSetTests(function (tests) {
|
|
2069
|
+
return setValueAtPath(tests, cursorPath, testObject);
|
|
2070
|
+
});
|
|
2071
|
+
}
|
|
2072
|
+
function useGetTestAtCursor(tests) {
|
|
2073
|
+
var cursorPath = usePath();
|
|
2074
|
+
return valueAtPath(tests, cursorPath);
|
|
2075
|
+
}
|
|
2076
|
+
function shouldPurgePrevTest(prevTest, newTest) {
|
|
2077
|
+
return isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
|
|
2078
|
+
}
|
|
2079
|
+
function throwTestOrderError(prevTest, newTestObject) {
|
|
2080
|
+
if (shouldAllowReorder()) {
|
|
2081
|
+
return;
|
|
2082
|
+
}
|
|
2083
|
+
throwErrorDeferred("Vest Critical Error: Tests called in different order than previous run.\n expected: " + prevTest.fieldName + "\n received: " + newTestObject.fieldName + "\n This happens when you conditionally call your tests using if/else.\n This might lead to incorrect validation results.\n Replacing if/else with skipWhen solves these issues.");
|
|
2084
|
+
}
|
|
2085
|
+
|
|
1812
2086
|
function registerPrevRunTest(testObject) {
|
|
1813
2087
|
var prevRunTest = useTestAtCursor(testObject);
|
|
1814
2088
|
if (isExcluded(testObject)) {
|
|
1815
2089
|
testObject.skip();
|
|
1816
|
-
|
|
2090
|
+
moveForward();
|
|
1817
2091
|
return prevRunTest;
|
|
1818
2092
|
}
|
|
1819
2093
|
cancelOverriddenPendingTest(prevRunTest, testObject);
|
|
1820
2094
|
useSetTestAtCursor(testObject);
|
|
1821
|
-
|
|
2095
|
+
moveForward();
|
|
1822
2096
|
registerTestObjectByTier(testObject);
|
|
1823
2097
|
return testObject;
|
|
1824
2098
|
}
|
|
@@ -1837,7 +2111,7 @@
|
|
|
1837
2111
|
* Run multiple tests using a parameter table
|
|
1838
2112
|
*/
|
|
1839
2113
|
function each(table) {
|
|
1840
|
-
if (!
|
|
2114
|
+
if (!isArray(table)) {
|
|
1841
2115
|
throwError('test.each: Expected table to be an array.');
|
|
1842
2116
|
}
|
|
1843
2117
|
function eachReturn(fieldName) {
|
|
@@ -1846,9 +2120,12 @@
|
|
|
1846
2120
|
args[_i - 1] = arguments[_i];
|
|
1847
2121
|
}
|
|
1848
2122
|
var _a = args.reverse(), testFn = _a[0], message = _a[1];
|
|
1849
|
-
return
|
|
1850
|
-
|
|
1851
|
-
|
|
2123
|
+
return isolate({ type: IsolateTypes.EACH }, function () {
|
|
2124
|
+
return table.map(function (item) {
|
|
2125
|
+
item = asArray(item);
|
|
2126
|
+
return test(optionalFunctionValue.apply(void 0, __spreadArray([fieldName], item)), optionalFunctionValue.apply(void 0, __spreadArray([message], item)), function () { return testFn.apply(void 0, item); } // eslint-disable-line max-nested-callbacks
|
|
2127
|
+
);
|
|
2128
|
+
});
|
|
1852
2129
|
});
|
|
1853
2130
|
}
|
|
1854
2131
|
return eachReturn;
|
|
@@ -1866,7 +2143,7 @@
|
|
|
1866
2143
|
args[_i - 1] = arguments[_i];
|
|
1867
2144
|
}
|
|
1868
2145
|
var suiteId = useSuiteId()[0];
|
|
1869
|
-
var cursorAt = useCursorAt()
|
|
2146
|
+
var cursorAt = useCursorAt();
|
|
1870
2147
|
var _a = args.reverse(), deps = _a[0], testFn = _a[1], msg = _a[2];
|
|
1871
2148
|
// Implicit dependency for more specificity
|
|
1872
2149
|
var dependencies = [suiteId, fieldName, cursorAt].concat(deps);
|
|
@@ -1903,7 +2180,7 @@
|
|
|
1903
2180
|
memo: bindTestMemo(testBase)
|
|
1904
2181
|
});
|
|
1905
2182
|
|
|
1906
|
-
var VERSION = "4.0.0-dev-
|
|
2183
|
+
var VERSION = "4.0.0-dev-8851ff";
|
|
1907
2184
|
|
|
1908
2185
|
exports.VERSION = VERSION;
|
|
1909
2186
|
exports.create = create;
|