vest 4.1.0 → 4.2.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/classnames/package.json +2 -0
- package/dist/cjs/vest.development.js +158 -91
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/vest.development.js +158 -92
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +5 -5
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +5 -5
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +5 -5
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/vest.development.js +163 -96
- package/dist/umd/vest.production.js +1 -1
- package/enforce/compose/package.json +2 -0
- package/enforce/compounds/package.json +2 -0
- package/enforce/schema/package.json +2 -0
- package/package.json +5 -3
- package/parser/package.json +2 -0
- package/promisify/package.json +2 -0
- package/types/vest.d.ts +30 -2
|
@@ -7,7 +7,7 @@ var assign = Object.assign;
|
|
|
7
7
|
* @returns a unique numeric id.
|
|
8
8
|
*/
|
|
9
9
|
var genId = (function (n) { return function () {
|
|
10
|
-
return ""
|
|
10
|
+
return "".concat(n++);
|
|
11
11
|
}; })(0);
|
|
12
12
|
|
|
13
13
|
function isFunction(value) {
|
|
@@ -175,6 +175,12 @@ function createCursor() {
|
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
var Modes;
|
|
179
|
+
(function (Modes) {
|
|
180
|
+
Modes[Modes["ALL"] = 0] = "ALL";
|
|
181
|
+
Modes[Modes["EAGER"] = 1] = "EAGER";
|
|
182
|
+
})(Modes || (Modes = {}));
|
|
183
|
+
|
|
178
184
|
var context = createContext(function (ctxRef, parentContext) {
|
|
179
185
|
return parentContext
|
|
180
186
|
? null
|
|
@@ -191,6 +197,7 @@ var context = createContext(function (ctxRef, parentContext) {
|
|
|
191
197
|
prev: {}
|
|
192
198
|
}
|
|
193
199
|
},
|
|
200
|
+
mode: [Modes.ALL],
|
|
194
201
|
testCursor: createCursor()
|
|
195
202
|
}, ctxRef);
|
|
196
203
|
});
|
|
@@ -217,9 +224,9 @@ function isNull(value) {
|
|
|
217
224
|
}
|
|
218
225
|
var isNotNull = bindNot(isNull);
|
|
219
226
|
|
|
220
|
-
// This is
|
|
221
|
-
// Normally, behaves like a nested-array map
|
|
222
|
-
//
|
|
227
|
+
// This is kind of a map/filter in one function.
|
|
228
|
+
// Normally, behaves like a nested-array map,
|
|
229
|
+
// but returning `null` will drop the element from the array
|
|
223
230
|
function transform(array, cb) {
|
|
224
231
|
var res = [];
|
|
225
232
|
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
|
|
@@ -306,23 +313,22 @@ function createCache(maxSize) {
|
|
|
306
313
|
};
|
|
307
314
|
// invalidate an item in the cache by its dependencies
|
|
308
315
|
cache.invalidate = function (deps) {
|
|
309
|
-
var index =
|
|
310
|
-
var cachedDeps = _a[0];
|
|
311
|
-
return lengthEquals(deps, cachedDeps.length) &&
|
|
312
|
-
deps.every(function (dep, i) { return dep === cachedDeps[i]; });
|
|
313
|
-
});
|
|
316
|
+
var index = findIndex(deps);
|
|
314
317
|
if (index > -1)
|
|
315
318
|
cacheStorage.splice(index, 1);
|
|
316
319
|
};
|
|
317
320
|
// Retrieves an item from the cache.
|
|
318
321
|
cache.get = function (deps) {
|
|
319
|
-
return cacheStorage[
|
|
322
|
+
return cacheStorage[findIndex(deps)] || null;
|
|
323
|
+
};
|
|
324
|
+
return cache;
|
|
325
|
+
function findIndex(deps) {
|
|
326
|
+
return cacheStorage.findIndex(function (_a) {
|
|
320
327
|
var cachedDeps = _a[0];
|
|
321
328
|
return lengthEquals(deps, cachedDeps.length) &&
|
|
322
329
|
deps.every(function (dep, i) { return dep === cachedDeps[i]; });
|
|
323
|
-
})
|
|
324
|
-
}
|
|
325
|
-
return cache;
|
|
330
|
+
});
|
|
331
|
+
}
|
|
326
332
|
}
|
|
327
333
|
|
|
328
334
|
// STATE REF
|
|
@@ -500,31 +506,34 @@ var VestTest = /** @class */ (function () {
|
|
|
500
506
|
return this.isSkipped() || this.isOmitted() || this.isCanceled();
|
|
501
507
|
};
|
|
502
508
|
VestTest.prototype.isPending = function () {
|
|
503
|
-
return this.
|
|
509
|
+
return this.statusEquals(STATUS_PENDING);
|
|
504
510
|
};
|
|
505
511
|
VestTest.prototype.isTested = function () {
|
|
506
512
|
return this.hasFailures() || this.isPassing();
|
|
507
513
|
};
|
|
508
514
|
VestTest.prototype.isOmitted = function () {
|
|
509
|
-
return this.
|
|
515
|
+
return this.statusEquals(STATUS_OMITTED);
|
|
510
516
|
};
|
|
511
517
|
VestTest.prototype.isUntested = function () {
|
|
512
|
-
return this.
|
|
518
|
+
return this.statusEquals(STATUS_UNTESTED);
|
|
513
519
|
};
|
|
514
520
|
VestTest.prototype.isFailing = function () {
|
|
515
|
-
return this.
|
|
521
|
+
return this.statusEquals(STATUS_FAILED);
|
|
516
522
|
};
|
|
517
523
|
VestTest.prototype.isCanceled = function () {
|
|
518
|
-
return this.
|
|
524
|
+
return this.statusEquals(STATUS_CANCELED);
|
|
519
525
|
};
|
|
520
526
|
VestTest.prototype.isSkipped = function () {
|
|
521
|
-
return this.
|
|
527
|
+
return this.statusEquals(STATUS_SKIPPED);
|
|
522
528
|
};
|
|
523
529
|
VestTest.prototype.isPassing = function () {
|
|
524
|
-
return this.
|
|
530
|
+
return this.statusEquals(STATUS_PASSING);
|
|
525
531
|
};
|
|
526
532
|
VestTest.prototype.isWarning = function () {
|
|
527
|
-
return this.
|
|
533
|
+
return this.statusEquals(STATUS_WARNING);
|
|
534
|
+
};
|
|
535
|
+
VestTest.prototype.statusEquals = function (status) {
|
|
536
|
+
return this.status === status;
|
|
528
537
|
};
|
|
529
538
|
return VestTest;
|
|
530
539
|
}());
|
|
@@ -582,7 +591,7 @@ function useRetainTestKey(key, testObject) {
|
|
|
582
591
|
current[key] = testObject;
|
|
583
592
|
}
|
|
584
593
|
else {
|
|
585
|
-
throwErrorDeferred("Encountered the same test key \""
|
|
594
|
+
throwErrorDeferred("Encountered the same test key \"".concat(key, "\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."));
|
|
586
595
|
}
|
|
587
596
|
}
|
|
588
597
|
|
|
@@ -661,18 +670,21 @@ function hasRemainingTests(fieldName) {
|
|
|
661
670
|
return isNotEmpty(allIncomplete);
|
|
662
671
|
}
|
|
663
672
|
|
|
673
|
+
var Severity;
|
|
674
|
+
(function (Severity) {
|
|
675
|
+
Severity["WARNINGS"] = "warnings";
|
|
676
|
+
Severity["ERRORS"] = "errors";
|
|
677
|
+
})(Severity || (Severity = {}));
|
|
678
|
+
|
|
664
679
|
/**
|
|
665
680
|
* Reads the testObjects list and gets full validation result from it.
|
|
666
681
|
*/
|
|
667
682
|
function genTestsSummary() {
|
|
668
683
|
var testObjects = useTestsFlat();
|
|
669
|
-
var summary = {
|
|
670
|
-
errorCount: 0,
|
|
684
|
+
var summary = assign(baseStats(), {
|
|
671
685
|
groups: {},
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
warnCount: 0
|
|
675
|
-
};
|
|
686
|
+
tests: {}
|
|
687
|
+
});
|
|
676
688
|
appendSummary(testObjects);
|
|
677
689
|
return countFailures(summary);
|
|
678
690
|
function appendSummary(testObjects) {
|
|
@@ -700,30 +712,34 @@ function countFailures(summary) {
|
|
|
700
712
|
// eslint-disable-next-line max-statements
|
|
701
713
|
function genTestObject(summaryKey, testObject) {
|
|
702
714
|
var fieldName = testObject.fieldName, message = testObject.message;
|
|
703
|
-
summaryKey[fieldName] = summaryKey[fieldName] ||
|
|
704
|
-
errorCount: 0,
|
|
705
|
-
warnCount: 0,
|
|
706
|
-
testCount: 0
|
|
707
|
-
};
|
|
715
|
+
summaryKey[fieldName] = summaryKey[fieldName] || baseStats();
|
|
708
716
|
var testKey = summaryKey[fieldName];
|
|
709
717
|
if (testObject.isNonActionable())
|
|
710
718
|
return testKey;
|
|
711
719
|
summaryKey[fieldName].testCount++;
|
|
712
720
|
// Adds to severity group
|
|
713
|
-
function addTo(
|
|
721
|
+
function addTo(severity) {
|
|
722
|
+
var countKey = severity === Severity.ERRORS ? 'errorCount' : 'warnCount';
|
|
714
723
|
testKey[countKey]++;
|
|
715
724
|
if (message) {
|
|
716
|
-
testKey[
|
|
725
|
+
testKey[severity] = (testKey[severity] || []).concat(message);
|
|
717
726
|
}
|
|
718
727
|
}
|
|
719
728
|
if (testObject.isFailing()) {
|
|
720
|
-
addTo(
|
|
729
|
+
addTo(Severity.ERRORS);
|
|
721
730
|
}
|
|
722
731
|
else if (testObject.isWarning()) {
|
|
723
|
-
addTo(
|
|
732
|
+
addTo(Severity.WARNINGS);
|
|
724
733
|
}
|
|
725
734
|
return testKey;
|
|
726
735
|
}
|
|
736
|
+
function baseStats() {
|
|
737
|
+
return {
|
|
738
|
+
errorCount: 0,
|
|
739
|
+
warnCount: 0,
|
|
740
|
+
testCount: 0
|
|
741
|
+
};
|
|
742
|
+
}
|
|
727
743
|
|
|
728
744
|
/*! *****************************************************************************
|
|
729
745
|
Copyright (c) Microsoft Corporation.
|
|
@@ -769,7 +785,7 @@ function either(a, b) {
|
|
|
769
785
|
* Checks that a given test object matches the currently specified severity level
|
|
770
786
|
*/
|
|
771
787
|
function nonMatchingSeverityProfile(severity, testObject) {
|
|
772
|
-
return either(severity ===
|
|
788
|
+
return either(severity === Severity.WARNINGS, testObject.warns());
|
|
773
789
|
}
|
|
774
790
|
|
|
775
791
|
function collectFailureMessages(severity, testObjects, options) {
|
|
@@ -811,10 +827,10 @@ function getFailuresArrayOrObject(group, fieldName) {
|
|
|
811
827
|
}
|
|
812
828
|
|
|
813
829
|
function getErrors(fieldName) {
|
|
814
|
-
return getFailures(
|
|
830
|
+
return getFailures(Severity.ERRORS, fieldName);
|
|
815
831
|
}
|
|
816
832
|
function getWarnings(fieldName) {
|
|
817
|
-
return getFailures(
|
|
833
|
+
return getFailures(Severity.WARNINGS, fieldName);
|
|
818
834
|
}
|
|
819
835
|
/**
|
|
820
836
|
* @returns suite or field's errors or warnings.
|
|
@@ -828,11 +844,11 @@ function getFailures(severityKey, fieldName) {
|
|
|
828
844
|
}
|
|
829
845
|
|
|
830
846
|
function getErrorsByGroup(groupName, fieldName) {
|
|
831
|
-
var errors = getByGroup(
|
|
847
|
+
var errors = getByGroup(Severity.ERRORS, groupName, fieldName);
|
|
832
848
|
return getFailuresArrayOrObject(errors, fieldName);
|
|
833
849
|
}
|
|
834
850
|
function getWarningsByGroup(groupName, fieldName) {
|
|
835
|
-
var warnings = getByGroup(
|
|
851
|
+
var warnings = getByGroup(Severity.WARNINGS, groupName, fieldName);
|
|
836
852
|
return getFailuresArrayOrObject(warnings, fieldName);
|
|
837
853
|
}
|
|
838
854
|
/**
|
|
@@ -840,7 +856,7 @@ function getWarningsByGroup(groupName, fieldName) {
|
|
|
840
856
|
*/
|
|
841
857
|
function getByGroup(severityKey, group, fieldName) {
|
|
842
858
|
if (!group) {
|
|
843
|
-
throwError("get"
|
|
859
|
+
throwError("get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
|
|
844
860
|
}
|
|
845
861
|
var testObjects = useTestsFlat();
|
|
846
862
|
return collectFailureMessages(severityKey, testObjects, {
|
|
@@ -866,10 +882,10 @@ function hasFailuresLogic(testObject, severityKey, fieldName) {
|
|
|
866
882
|
}
|
|
867
883
|
|
|
868
884
|
function hasErrors(fieldName) {
|
|
869
|
-
return has(
|
|
885
|
+
return has(Severity.ERRORS, fieldName);
|
|
870
886
|
}
|
|
871
887
|
function hasWarnings(fieldName) {
|
|
872
|
-
return has(
|
|
888
|
+
return has(Severity.WARNINGS, fieldName);
|
|
873
889
|
}
|
|
874
890
|
function has(severityKey, fieldName) {
|
|
875
891
|
var testObjects = useTestsFlat();
|
|
@@ -879,10 +895,10 @@ function has(severityKey, fieldName) {
|
|
|
879
895
|
}
|
|
880
896
|
|
|
881
897
|
function hasErrorsByGroup(groupName, fieldName) {
|
|
882
|
-
return hasByGroup(
|
|
898
|
+
return hasByGroup(Severity.ERRORS, groupName, fieldName);
|
|
883
899
|
}
|
|
884
900
|
function hasWarningsByGroup(groupName, fieldName) {
|
|
885
|
-
return hasByGroup(
|
|
901
|
+
return hasByGroup(Severity.WARNINGS, groupName, fieldName);
|
|
886
902
|
}
|
|
887
903
|
/**
|
|
888
904
|
* Checks whether there are failures in a given group.
|
|
@@ -1035,18 +1051,12 @@ function createBus() {
|
|
|
1035
1051
|
var listeners = {};
|
|
1036
1052
|
return {
|
|
1037
1053
|
emit: function (event, data) {
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
}
|
|
1041
|
-
listeners[event].forEach(function (listener) {
|
|
1042
|
-
listener(data);
|
|
1054
|
+
(listeners[event] || []).forEach(function (handler) {
|
|
1055
|
+
handler(data);
|
|
1043
1056
|
});
|
|
1044
1057
|
},
|
|
1045
1058
|
on: function (event, handler) {
|
|
1046
|
-
|
|
1047
|
-
listeners[event] = [];
|
|
1048
|
-
}
|
|
1049
|
-
listeners[event].push(handler);
|
|
1059
|
+
listeners[event] = (listeners[event] || []).concat(handler);
|
|
1050
1060
|
return {
|
|
1051
1061
|
off: function () {
|
|
1052
1062
|
listeners[event] = listeners[event].filter(function (h) { return h !== handler; });
|
|
@@ -1114,9 +1124,7 @@ function runFieldCallbacks(fieldName) {
|
|
|
1114
1124
|
*/
|
|
1115
1125
|
function runDoneCallbacks() {
|
|
1116
1126
|
var doneCallbacks = useTestCallbacks()[0].doneCallbacks;
|
|
1117
|
-
|
|
1118
|
-
callEach(doneCallbacks);
|
|
1119
|
-
}
|
|
1127
|
+
callEach(doneCallbacks);
|
|
1120
1128
|
}
|
|
1121
1129
|
|
|
1122
1130
|
// eslint-disable-next-line max-lines-per-function
|
|
@@ -1130,14 +1138,21 @@ function initBus() {
|
|
|
1130
1138
|
}
|
|
1131
1139
|
testObject.done();
|
|
1132
1140
|
runFieldCallbacks(testObject.fieldName);
|
|
1133
|
-
|
|
1141
|
+
if (!hasRemainingTests()) {
|
|
1142
|
+
// When no more tests are running, emit the done event
|
|
1143
|
+
bus.emit(Events.ALL_RUNNING_TESTS_FINISHED);
|
|
1144
|
+
}
|
|
1134
1145
|
});
|
|
1135
1146
|
// Report that the suite completed its synchronous test run.
|
|
1136
1147
|
// Async operations may still be running.
|
|
1137
|
-
bus.on(Events.
|
|
1148
|
+
bus.on(Events.SUITE_CALLBACK_DONE_RUNNING, function () {
|
|
1138
1149
|
// Remove tests that are optional and need to be omitted
|
|
1139
1150
|
omitOptionalTests();
|
|
1140
1151
|
});
|
|
1152
|
+
// Called when all the tests, including async, are done running
|
|
1153
|
+
bus.on(Events.ALL_RUNNING_TESTS_FINISHED, function () {
|
|
1154
|
+
runDoneCallbacks();
|
|
1155
|
+
});
|
|
1141
1156
|
// Removes a certain field from the state.
|
|
1142
1157
|
bus.on(Events.REMOVE_FIELD, function (fieldName) {
|
|
1143
1158
|
useEachTestObject(function (testObject) {
|
|
@@ -1167,9 +1182,10 @@ function useBus() {
|
|
|
1167
1182
|
var Events;
|
|
1168
1183
|
(function (Events) {
|
|
1169
1184
|
Events["TEST_COMPLETED"] = "test_completed";
|
|
1185
|
+
Events["ALL_RUNNING_TESTS_FINISHED"] = "all_running_tests_finished";
|
|
1170
1186
|
Events["REMOVE_FIELD"] = "remove_field";
|
|
1171
1187
|
Events["RESET_FIELD"] = "reset_field";
|
|
1172
|
-
Events["
|
|
1188
|
+
Events["SUITE_CALLBACK_DONE_RUNNING"] = "suite_callback_done_running";
|
|
1173
1189
|
})(Events || (Events = {}));
|
|
1174
1190
|
|
|
1175
1191
|
// eslint-disable-next-line max-lines-per-function
|
|
@@ -1206,7 +1222,7 @@ function create() {
|
|
|
1206
1222
|
});
|
|
1207
1223
|
// Report the suite is done registering tests
|
|
1208
1224
|
// Async tests may still be running
|
|
1209
|
-
bus.emit(Events.
|
|
1225
|
+
bus.emit(Events.SUITE_CALLBACK_DONE_RUNNING);
|
|
1210
1226
|
// Return the result
|
|
1211
1227
|
return produceFullResult();
|
|
1212
1228
|
}), {
|
|
@@ -1237,7 +1253,7 @@ function create() {
|
|
|
1237
1253
|
*/
|
|
1238
1254
|
function each(list, callback) {
|
|
1239
1255
|
if (!isFunction(callback)) {
|
|
1240
|
-
throwError('callback must be a function');
|
|
1256
|
+
throwError('each callback must be a function');
|
|
1241
1257
|
}
|
|
1242
1258
|
isolate({ type: IsolateTypes.EACH }, function () {
|
|
1243
1259
|
list.forEach(function (arg, index) {
|
|
@@ -1251,6 +1267,31 @@ function each(list, callback) {
|
|
|
1251
1267
|
*/
|
|
1252
1268
|
var ERROR_HOOK_CALLED_OUTSIDE = 'hook called outside of a running suite.';
|
|
1253
1269
|
|
|
1270
|
+
/**
|
|
1271
|
+
* Conditionally skips running tests within the callback.
|
|
1272
|
+
*
|
|
1273
|
+
* @example
|
|
1274
|
+
*
|
|
1275
|
+
* skipWhen(res => res.hasErrors('username'), () => {
|
|
1276
|
+
* test('username', 'User already taken', async () => await doesUserExist(username)
|
|
1277
|
+
* });
|
|
1278
|
+
*/
|
|
1279
|
+
function skipWhen(conditional, callback) {
|
|
1280
|
+
isolate({ type: IsolateTypes.SKIP_WHEN }, function () {
|
|
1281
|
+
context.run({
|
|
1282
|
+
skipped:
|
|
1283
|
+
// Checking for nested conditional. If we're in a nested skipWhen,
|
|
1284
|
+
// we should skip the test if the parent conditional is true.
|
|
1285
|
+
isExcludedIndividually() ||
|
|
1286
|
+
// Otherwise, we should skip the test if the conditional is true.
|
|
1287
|
+
optionalFunctionValue(conditional, optionalFunctionValue(produceDraft))
|
|
1288
|
+
}, function () { return callback(); });
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
function isExcludedIndividually() {
|
|
1292
|
+
return !!context.useX().skipped;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1254
1295
|
/**
|
|
1255
1296
|
* Adds a field or a list of fields into the inclusion list
|
|
1256
1297
|
*
|
|
@@ -1277,9 +1318,6 @@ function skip(item) {
|
|
|
1277
1318
|
skip.group = function (item) {
|
|
1278
1319
|
return addTo(1 /* SKIP */, 'groups', item);
|
|
1279
1320
|
};
|
|
1280
|
-
function isExcludedIndividually() {
|
|
1281
|
-
return !!context.useX().skipped;
|
|
1282
|
-
}
|
|
1283
1321
|
//Checks whether a certain test profile excluded by any of the exclusion groups.
|
|
1284
1322
|
// eslint-disable-next-line complexity, max-statements, max-lines-per-function
|
|
1285
1323
|
function isExcluded(testObject) {
|
|
@@ -1425,7 +1463,7 @@ function group(groupName, tests) {
|
|
|
1425
1463
|
});
|
|
1426
1464
|
}
|
|
1427
1465
|
function throwGroupError(error) {
|
|
1428
|
-
throwError("Wrong arguments passed to group. Group "
|
|
1466
|
+
throwError("Wrong arguments passed to group. Group ".concat(error, "."));
|
|
1429
1467
|
}
|
|
1430
1468
|
|
|
1431
1469
|
function include(fieldName) {
|
|
@@ -1451,6 +1489,45 @@ function include(fieldName) {
|
|
|
1451
1489
|
}
|
|
1452
1490
|
}
|
|
1453
1491
|
|
|
1492
|
+
/**
|
|
1493
|
+
* Sets the suite to "eager" (fail fast) mode.
|
|
1494
|
+
* Eager mode will skip running subsequent tests of a failing fields.
|
|
1495
|
+
*
|
|
1496
|
+
* @example
|
|
1497
|
+
* // in the following example, the second test of username will not run
|
|
1498
|
+
* // if the first test of username failed.
|
|
1499
|
+
* const suite = create((data) => {
|
|
1500
|
+
* eager();
|
|
1501
|
+
*
|
|
1502
|
+
* test('username', 'username is required', () => {
|
|
1503
|
+
* enforce(data.username).isNotBlank();
|
|
1504
|
+
* });
|
|
1505
|
+
*
|
|
1506
|
+
* test('username', 'username is too short', () => {
|
|
1507
|
+
* enforce(data.username).longerThan(2);
|
|
1508
|
+
* });
|
|
1509
|
+
* });
|
|
1510
|
+
*/
|
|
1511
|
+
function eager() {
|
|
1512
|
+
setMode(Modes.EAGER);
|
|
1513
|
+
}
|
|
1514
|
+
function shouldSkipBasedOnMode(testObject) {
|
|
1515
|
+
if (isEager() && hasErrors(testObject.fieldName))
|
|
1516
|
+
return true;
|
|
1517
|
+
return false;
|
|
1518
|
+
}
|
|
1519
|
+
function isEager() {
|
|
1520
|
+
return isMode(Modes.EAGER);
|
|
1521
|
+
}
|
|
1522
|
+
function isMode(mode) {
|
|
1523
|
+
var currentMode = context.useX().mode;
|
|
1524
|
+
return currentMode[0] === mode;
|
|
1525
|
+
}
|
|
1526
|
+
function setMode(nextMode) {
|
|
1527
|
+
var mode = context.useX().mode;
|
|
1528
|
+
mode[0] = nextMode;
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1454
1531
|
/**
|
|
1455
1532
|
* Conditionally omits tests from the suite.
|
|
1456
1533
|
*
|
|
@@ -1463,7 +1540,8 @@ function include(fieldName) {
|
|
|
1463
1540
|
function omitWhen(conditional, callback) {
|
|
1464
1541
|
isolate({ type: IsolateTypes.OMIT_WHEN }, function () {
|
|
1465
1542
|
context.run({
|
|
1466
|
-
omitted:
|
|
1543
|
+
omitted: isOmitted() ||
|
|
1544
|
+
optionalFunctionValue(conditional, optionalFunctionValue(produceDraft))
|
|
1467
1545
|
}, function () { return callback(); });
|
|
1468
1546
|
});
|
|
1469
1547
|
}
|
|
@@ -1501,23 +1579,6 @@ function optional(optionals) {
|
|
|
1501
1579
|
});
|
|
1502
1580
|
}
|
|
1503
1581
|
|
|
1504
|
-
/**
|
|
1505
|
-
* Conditionally skips running tests within the callback.
|
|
1506
|
-
*
|
|
1507
|
-
* @example
|
|
1508
|
-
*
|
|
1509
|
-
* skipWhen(res => res.hasErrors('username'), () => {
|
|
1510
|
-
* test('username', 'User already taken', async () => await doesUserExist(username)
|
|
1511
|
-
* });
|
|
1512
|
-
*/
|
|
1513
|
-
function skipWhen(conditional, callback) {
|
|
1514
|
-
isolate({ type: IsolateTypes.SKIP_WHEN }, function () {
|
|
1515
|
-
context.run({
|
|
1516
|
-
skipped: optionalFunctionValue(conditional, optionalFunctionValue(produceDraft))
|
|
1517
|
-
}, function () { return callback(); });
|
|
1518
|
-
});
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
1582
|
var isNotString = bindNot(isStringValue);
|
|
1522
1583
|
|
|
1523
1584
|
function isPromise(value) {
|
|
@@ -1613,7 +1674,7 @@ function registerTest(testObject) {
|
|
|
1613
1674
|
}
|
|
1614
1675
|
}
|
|
1615
1676
|
catch (e) {
|
|
1616
|
-
throwError("
|
|
1677
|
+
throwError("Unexpected error encountered during test registration.\n Test Object: ".concat(testObject, ".\n Error: ").concat(e, "."));
|
|
1617
1678
|
}
|
|
1618
1679
|
}
|
|
1619
1680
|
|
|
@@ -1684,7 +1745,7 @@ function throwTestOrderError(prevTest, newTestObject) {
|
|
|
1684
1745
|
if (shouldAllowReorder()) {
|
|
1685
1746
|
return;
|
|
1686
1747
|
}
|
|
1687
|
-
throwErrorDeferred("Vest Critical Error: Tests called in different order than previous run.\n expected: "
|
|
1748
|
+
throwErrorDeferred("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."));
|
|
1688
1749
|
}
|
|
1689
1750
|
function handleKeyTest(key, newTestObject) {
|
|
1690
1751
|
var prevTestByKey = usePrevTestByKey(key);
|
|
@@ -1699,6 +1760,11 @@ function handleKeyTest(key, newTestObject) {
|
|
|
1699
1760
|
// eslint-disable-next-line max-statements
|
|
1700
1761
|
function registerPrevRunTest(testObject) {
|
|
1701
1762
|
var prevRunTest = useTestAtCursor(testObject);
|
|
1763
|
+
if (shouldSkipBasedOnMode(testObject)) {
|
|
1764
|
+
moveForward();
|
|
1765
|
+
testObject.skip();
|
|
1766
|
+
return testObject;
|
|
1767
|
+
}
|
|
1702
1768
|
if (isOmitted()) {
|
|
1703
1769
|
prevRunTest.omit();
|
|
1704
1770
|
moveForward();
|
|
@@ -1763,7 +1829,7 @@ function testBase(fieldName) {
|
|
|
1763
1829
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1764
1830
|
args[_i - 1] = arguments[_i];
|
|
1765
1831
|
}
|
|
1766
|
-
var _a = (isFunction(args[1]) ? args : __spreadArray([undefined], args)), message = _a[0], testFn = _a[1], key = _a[2];
|
|
1832
|
+
var _a = (isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
|
|
1767
1833
|
if (isNotString(fieldName)) {
|
|
1768
1834
|
throwIncompatibleParamsError('fieldName', 'string');
|
|
1769
1835
|
}
|
|
@@ -1791,7 +1857,7 @@ var test = assign(testBase, {
|
|
|
1791
1857
|
memo: bindTestMemo(testBase)
|
|
1792
1858
|
});
|
|
1793
1859
|
function throwIncompatibleParamsError(name, expected) {
|
|
1794
|
-
throwError("Incompatible params passed to test function. "
|
|
1860
|
+
throwError("Incompatible params passed to test function. ".concat(name, " must be a ").concat(expected));
|
|
1795
1861
|
}
|
|
1796
1862
|
|
|
1797
1863
|
var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won't have an effect."
|
|
@@ -1807,6 +1873,6 @@ function warn() {
|
|
|
1807
1873
|
ctx.currentTest.warn();
|
|
1808
1874
|
}
|
|
1809
1875
|
|
|
1810
|
-
var VERSION = "4.0
|
|
1876
|
+
var VERSION = "4.2.0";
|
|
1811
1877
|
|
|
1812
|
-
export { VERSION, context, create, each, group, include, omitWhen, only, optional, skip, skipWhen, test, warn };
|
|
1878
|
+
export { VERSION, context, create, each, eager, group, include, omitWhen, only, optional, skip, skipWhen, test, warn };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createContext as t}from"context";export{enforce}from"n4s";var n,e=Object.assign,r=(n=0,function(){return""+n++});function u(t){return"function"==typeof t}function i(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return u(t)?t.apply(void 0,n):t}function o(t,n){var e;return null!==(e=i(t))&&void 0!==e?e:n}function s(t,n){throw Error(o(n,t))}function a(t,n){setTimeout((function(){s(t,n)}),0)}function c(t){function n(t,n,u){return r.references.push(),e(t,i(n,u)),function(){return[r.references[t],function(n){return e(t,i(n,r.references[t]))}]}}function e(n,e){var i=r.references[n];r.references[n]=e,u(n=o[n][1])&&n(e,i),u(t)&&t()}var r={references:[]},o=[];return{registerStateKey:function(t,e){var r=o.length;return o.push([t,e]),n(r,t)},reset:function(){var t=r.references;r.references=[],o.forEach((function(e,r){return n(r,e[0],t[r])}))}}}var f,l=f||(f={});function p(t,n){var e=n.suiteId;return n=n.suiteName,{optionalFields:t.registerStateKey((function(){return{}})),suiteId:t.registerStateKey(e),suiteName:t.registerStateKey(n),testCallbacks:t.registerStateKey((function(){return{fieldCallbacks:{},doneCallbacks:[]}})),testObjects:t.registerStateKey((function(t){return{prev:t?t.current:[],current:[]}}))}}function d(t){return(t=[].concat(t))[t.length-1]}function v(){function t(){n=[0]}var n=[];return t(),{addLevel:function(){n.push(0)},cursorAt:function(){return d(n)},getCursor:function(){return[].concat(n)},next:function(){return n[n.length-1]++,d(n)},removeLevel:function(){n.pop()},reset:t}}l[l.DEFAULT=0]="DEFAULT",l[l.SUITE=1]="SUITE",l[l.EACH=2]="EACH",l[l.SKIP_WHEN=3]="SKIP_WHEN",l[l.OMIT_WHEN=4]="OMIT_WHEN",l[l.GROUP=5]="GROUP";var g=t((function(t,n){return n?null:e({},{exclusion:{tests:{},groups:{}},inclusion:{},isolate:{type:f.DEFAULT,keys:{current:{},prev:{}}},testCursor:v()},t)}));function h(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return!t.apply(void 0,n)}}var m=h((function(t){return null===t}));function y(t,n){for(var e=[],r=0;r<t.length;r++){var u=t[r];Array.isArray(u)?e.push(y(u,n)):(u=n(u),m(u)&&e.push(u))}return e}function E(t){return[].concat(t).reduce((function(t,n){return Array.isArray(n)?t.concat(E(n)):[].concat(t).concat(n)}),[])}function b(t,n){var e=0;for(n=n.slice(0,-1);e<n.length;e++){var r=n[e];t[r]=o(t[r],[]),t=t[r]}return t}function N(t){return null==t}function C(t){return String(t)===t}function T(t){function n(r,u){var i=n.get(r);return i?i[1]:(u=u(),e.unshift([r.concat(),u]),e.length>Number(t)&&(e.length=t),u)}void 0===t&&(t=1);var e=[];return n.invalidate=function(t){var n=e.findIndex((function(n){var e=n[0];return t.length===Number(e.length)&&t.every((function(t,n){return t===e[n]}))}));-1<n&&e.splice(n,1)},n.get=function(t){return e[e.findIndex((function(n){var e=n[0];return t.length===Number(e.length)&&t.every((function(t,n){return t===e[n]}))}))]||null},n}function k(){return g.useX().stateRef}function S(){return k().testObjects()}function O(){(0,S()[1])((function(t){return{prev:t.prev,current:[].concat(t.current)}}))}function P(t){(0,S()[1])((function(n){return{prev:n.prev,current:[].concat(t(n.current))}}))}function w(){return E(y(S()[0].current,(function(t){return t.isPending()?t:null})))}var F=T();function I(){var t=S()[0].current;return F([t],(function(){return E(t)}))}var A,D=A||(A={});D.Error="error",D.Warning="warning";var L=function(){function t(t,n,e){var u=void 0===e?{}:e;e=u.message;var i=u.groupName;u=u.key,this.key=null,this.id=r(),this.severity=A.Error,this.status=X,this.fieldName=t,this.testFn=n,i&&(this.groupName=i),e&&(this.message=e),u&&(this.key=u)}return t.prototype.run=function(){try{var t=this.testFn()}catch(n){t=n,void 0===this.message&&C(t)&&(this.message=n),t=!1}return!1===t&&this.fail(),t},t.prototype.setStatus=function(t){this.isFinalStatus()&&t!==G||(this.status=t)},t.prototype.warns=function(){return this.severity===A.Warning},t.prototype.setPending=function(){this.setStatus(R)},t.prototype.fail=function(){this.setStatus(this.warns()?W:x)},t.prototype.done=function(){this.isFinalStatus()||this.setStatus(U)},t.prototype.warn=function(){this.severity=A.Warning},t.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},t.prototype.skip=function(t){this.isPending()&&!t||this.setStatus(_)},t.prototype.cancel=function(){this.setStatus(M),O()},t.prototype.reset=function(){this.status=X,O()},t.prototype.omit=function(){this.setStatus(G)},t.prototype.valueOf=function(){return!this.isFailing()},t.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},t.prototype.isNonActionable=function(){return this.isSkipped()||this.isOmitted()||this.isCanceled()},t.prototype.isPending=function(){return this.status===R},t.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},t.prototype.isOmitted=function(){return this.status===G},t.prototype.isUntested=function(){return this.status===X},t.prototype.isFailing=function(){return this.status===x},t.prototype.isCanceled=function(){return this.status===M},t.prototype.isSkipped=function(){return this.status===_},t.prototype.isPassing=function(){return this.status===U},t.prototype.isWarning=function(){return this.status===W},t}(),X="UNTESTED",_="SKIPPED",x="FAILED",W="WARNING",U="PASSING",R="PENDING",M="CANCELED",G="OMITTED";function j(){return g.useX().testCursor.getCursor()}function H(){return g.useX().testCursor.next()}function K(t,n){if(t=void 0===(t=t.type)?f.DEFAULT:t,u(n)){var e={current:{},prev:{}},r=j();return g.run({isolate:{type:t,keys:e}},(function(){g.useX().testCursor.addLevel(),e.prev=function(){var t=S()[0].prev;return[].concat(b(t,j())).reduce((function(t,n){return n instanceof L&&!N(n.key)?(t[n.key]=n,t):t}),{})}(),P((function(t){return b(t,r)[d(r)]=[],t}));var t=n();return g.useX().testCursor.removeLevel(),H(),t}))}}function V(t){if(t){if("number"==typeof t)return 0===t;if(Object.prototype.hasOwnProperty.call(t,"length"))return t.length===Number(0);if("object"==typeof t)return Object.keys(t).length===Number(0)}return!0}var B=h(V);function Y(t,n){return!(!n||t.fieldName!==n)}function q(t){var n=w();return!V(n)&&(t?n.some((function(n){return Y(n,t)})):B(n))}function z(t,n){function e(t,n){i[t]++,u&&(i[n]=(i[n]||[]).concat(u))}var r=n.fieldName,u=n.message;t[r]=t[r]||{errorCount:0,warnCount:0,testCount:0};var i=t[r];return n.isNonActionable()||(t[r].testCount++,n.isFailing()?e("errorCount","errors"):n.isWarning()&&e("warnCount","warnings")),i}function J(){return(J=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var u in n=arguments[e])Object.prototype.hasOwnProperty.call(n,u)&&(t[u]=n[u]);return t}).apply(this,arguments)}function Q(t,n,e){if(e||2===arguments.length)for(var r,u=0,i=n.length;u<i;u++)!r&&u in n||(r||(r=Array.prototype.slice.call(n,0,u)),r[u]=n[u]);return t.concat(r||Array.prototype.slice.call(n))}function Z(t,n,e){var r;void 0===e&&(e={});var u=(e=e||{}).group,i=e.fieldName;return n.reduce((function(n,e){if(u&&e.groupName!==u)var r=!0;else i&&!Y(e,i)?r=!0:(r=e.warns(),r="warnings"===t!=!!r);return r||!e.hasFailures()||(n[e.fieldName]=(n[e.fieldName]||[]).concat(e.message||[])),n}),J({},i&&((r={})[i]=[],r)))}function $(t){return nt("errors",t)}function tt(t){return nt("warnings",t)}function nt(t,n){return t=Z(t,I(),{fieldName:n}),n?t[n]:t}function et(t,n){return t=ut("errors",t,n),n?t[n]:t}function rt(t,n){return t=ut("warnings",t,n),n?t[n]:t}function ut(t,n,e){return n||s("get"+t[0].toUpperCase()+t.slice(1)+"ByGroup requires a group name. Received `"+n+"` instead."),Z(t,I(),{group:n,fieldName:e})}function it(t,n,e){return(e=!t.hasFailures()||e&&!Y(t,e))||(e="warnings"===n!=!!(t=t.warns())),!e}function ot(t){return at("errors",t)}function st(t){return at("warnings",t)}function at(t,n){return I().some((function(e){return it(e,t,n)}))}function ct(t,n){return lt("errors",t,n)}function ft(t,n){return lt("warnings",t,n)}function lt(t,n,e){return I().some((function(r){return n===r.groupName&&it(r,t,e)}))}var pt=T(20);function dt(){var t=I(),n={stateRef:k()};return pt([t],g.bind(n,(function(){var t=k().suiteName()[0];return e(function(){var t={errorCount:0,groups:{},testCount:0,tests:{},warnCount:0};return I().forEach((function(n){var e=n.fieldName,r=n.groupName;t.tests[e]=z(t.tests,n),r&&(t.groups[r]=t.groups[r]||{},t.groups[r][e]=z(t.groups[r],n))})),function(t){for(var n in t.tests)t.errorCount+=t.tests[n].errorCount,t.warnCount+=t.tests[n].warnCount,t.testCount+=t.tests[n].testCount;return t}(t)}(),{getErrors:g.bind(n,$),getErrorsByGroup:g.bind(n,et),getWarnings:g.bind(n,tt),getWarningsByGroup:g.bind(n,rt),hasErrors:g.bind(n,ot),hasErrorsByGroup:g.bind(n,ct),hasWarnings:g.bind(n,st),hasWarningsByGroup:g.bind(n,ft),isValid:g.bind(n,(function(t){var n=dt(),e=I().reduce((function(t,n){return t[n.fieldName]||n.isOmitted()&&(t[n.fieldName]=!0),t}),{});return(e=!!t&&!!e[t])?t=!0:n.hasErrors(t)?t=!1:t=!(V(e=I())||t&&V(n.tests[t])||function(t){var n=k().optionalFields()[0];return B(w().filter((function(e){return!(t&&!Y(e,t))&&!0!==n[e.fieldName]})))}(t))&&function(t){var n=I(),e=k().optionalFields()[0];return n.every((function(n){return!(!t||Y(n,t))||!0===e[n.fieldName]||n.isTested()||n.isOmitted()}))}(t),t})),suiteName:t})})))}var vt=T(20);function gt(){var t=I(),n={stateRef:k()};return vt([t],g.bind(n,(function(){return e({},dt(),{done:g.bind(n,yt)})})))}function ht(t,n,e){return!(u(t)&&(!n||e.tests[n]&&!V(e.tests[n].testCount)))}function mt(t){return!(q()&&(!t||q(t)))}function yt(){function t(){return r(dt())}for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var r=(n=n.reverse())[0];return n=n[1],e=gt(),ht(r,n,e)?e:mt(n)?(t(),e):(Et(t,n),e)}function Et(t,n){var e=g.bind({},t);(0,k().testCallbacks()[1])((function(t){return n?t.fieldCallbacks[n]=(t.fieldCallbacks[n]||[]).concat(e):t.doneCallbacks.push(e),t}))}function bt(t){return t.forEach((function(t){return t()}))}function Nt(){var t=function(){var t={};return{emit:function(n,e){t[n]&&t[n].forEach((function(t){t(e)}))},on:function(n,e){return t[n]||(t[n]=[]),t[n].push(e),{off:function(){t[n]=t[n].filter((function(t){return t!==e}))}}}}}();return t.on(Tt.TEST_COMPLETED,(function(t){if(!t.isCanceled()){t.done(),t=t.fieldName;var n=k().testCallbacks()[0].fieldCallbacks;t&&!q(t)&&Array.isArray(n[t])&&bt(n[t]),t=k().testCallbacks()[0].doneCallbacks,q()||bt(t)}})),t.on(Tt.SUITE_COMPLETED,(function(){!function(){var t=k().optionalFields()[0];if(!V(t)){var n={};P((function(e){return y(e,(function(e){var r=e.fieldName;if(n.hasOwnProperty(r))n[e.fieldName]&&e.omit();else{var i=t[r];u(i)&&(n[r]=i(),n[e.fieldName]&&e.omit())}return e}))}))}}()})),t.on(Tt.REMOVE_FIELD,(function(t){I().forEach((function(n){Y(n,t)&&(n.cancel(),function(t){P((function(n){return y(n,(function(n){return t!==n?n:null}))}))}(n))}))})),t.on(Tt.RESET_FIELD,(function(t){I().forEach((function(n){Y(n,t)&&n.reset()}))})),t}function Ct(){var t=g.useX();return t.bus||s(),t.bus}var Tt,kt=Tt||(Tt={});function St(t){return Pt(0,"tests",t)}function Ot(t){return Pt(1,"tests",t)}function Pt(t,n,e){var r=g.useX("hook called outside of a running suite.");e&&[].concat(e).forEach((function(e){C(e)&&(r.exclusion[n][e]=0===t)}))}function wt(t){for(var n in t)if(!0===t[n])return!0;return!1}function Ft(t){s("Wrong arguments passed to group. Group "+t+".")}kt.TEST_COMPLETED="test_completed",kt.REMOVE_FIELD="remove_field",kt.RESET_FIELD="reset_field",kt.SUITE_COMPLETED="suite_completed",St.group=function(t){return Pt(0,"groups",t)},Ot.group=function(t){return Pt(1,"groups",t)};var It=h(C);function At(t){var n=t.asyncTest,e=t.message;if(n&&u(n.then)){var r=Ct().emit,i=k(),o=g.bind({stateRef:i},(function(){O(),r(Tt.TEST_COMPLETED,t)}));i=g.bind({stateRef:i},(function(n){t.isCanceled()||(t.message=C(n)?n:e,t.fail(),o())}));try{n.then(o,i)}catch(t){i()}}}function Dt(t){var n=j();P((function(e){return b(e,n)[d(n)]=t,e}))}function Lt(t){var n=S()[0].prev;if(V(n))Dt(t),n=t;else{var e=j();if(n=b(n,e)[d(e)],N(t.key))!B(e=n)||e.fieldName===t.fieldName&&e.groupName===t.groupName||(g.useX().isolate.type!==f.EACH&&a("Vest Critical Error: Tests called in different order than previous run.\n expected: "+n.fieldName+"\n received: "+t.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.'),function(){var t=S(),n=t[1],e=t[0].prev;t=b(e,j());var r=g.useX().testCursor.cursorAt();t.splice(r),n((function(t){return{prev:e,current:t.current}}))}(),n=null),Dt(n=o(n,t));else{n=t.key;var r=g.useX().isolate.keys.prev[n];e=t,r&&(e=r),r=e;var c=g.useX().isolate.keys.current;N(c[n])?c[n]=r:a('Encountered the same test key "'+n+"\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."),Dt(n=e)}}if(g.useX().omitted)return n.omit(),H(),n;if(function(t){var n=t.fieldName;if(t=t.groupName,g.useX().skipped)return!0;var e=g.useX(),r=e.exclusion;e=e.inclusion;var u=r.tests,o=u[n];if(!1===o)return!0;if(o=!0===o,t){t:{var s=g.useX().exclusion.groups;if(Object.prototype.hasOwnProperty.call(s,t))var a=!1===s[t];else{for(a in s)if(!0===s[a]){a=!0;break t}a=!1}}if(a)return!0;if(!0===r.groups[t])return!(o||!wt(u)&&!1!==u[n])}r=g.useX().exclusion;t:{for(c in(a=g.useX().exclusion).groups)if(a.groups[c]){var c=!0;break t}c=!1}return!(!c||t&&t in r.groups&&r.groups[t])||!o&&!!wt(u)&&!i(e[n])}(t))return n.skip(!!g.useX().skipped),H(),n;if(t!==n&&n.fieldName===t.fieldName&&n.groupName===t.groupName&&n.isPending()&&n.cancel(),Dt(t),H(),t.isUntested()){n=Ct(),e=function(t){return g.run({currentTest:t},(function(){try{var n=t.testFn()}catch(e){n=e,void 0===t.message&&C(n)&&(t.message=e),n=!1}return!1===n&&t.fail(),n}))}(t);try{e&&u(e.then)?(t.asyncTest=e,t.setPending(),At(t)):n.emit(Tt.TEST_COMPLETED,t)}catch(n){s("Your test function "+t.fieldName+' returned a value. Only "false" or Promise returns are supported.')}}else(n=t.asyncTest)&&u(n.then)&&(t.setPending(),At(t));return t}function Xt(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];var r=u(n[1])?n:Q([void 0],n);n=r[0],e=r[1],r=r[2],It(t)&&xt("fieldName","string"),u(e)||xt("Test callback","function");var i=g.useX();return Lt(n=new L(t,e,{message:n,groupName:i.groupName,key:r}))}var _t=e(Xt,{memo:function(t){var n=T(100);return function(e){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];u=g.useX().testCursor.cursorAt();var i=(r=r.reverse())[0],o=r[1],s=r[2];return u=[k().suiteId()[0],e,u].concat(i),null===(r=n.get(u))?n(u,(function(){return t(e,s,o)})):r[1].isCanceled()?(n.invalidate(u),n(u,(function(){return t(e,s,o)}))):Lt(r[1])}}(Xt)});function xt(t,n){s("Incompatible params passed to test function. "+t+" must be a "+n)}var Wt="4.0.3";function Ut(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var i=(t=t.reverse())[0];t=t[1],u(i)||s("vest.create: Expected callback to be a function.");var o=Nt(),a=c();return t={stateRef:p(a,{suiteId:r(),suiteName:t}),bus:o},e(g.bind(t,(function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return a.reset(),K({type:f.SUITE},(function(){i.apply(void 0,t)})),o.emit(Tt.SUITE_COMPLETED),gt()})),{get:g.bind(t,dt),remove:g.bind(t,(function(t){o.emit(Tt.REMOVE_FIELD,t)})),reset:a.reset,resetField:g.bind(t,(function(t){o.emit(Tt.RESET_FIELD,t)}))})}function Rt(t,n){u(n)||s("callback must be a function"),K({type:f.EACH},(function(){t.forEach((function(t,e){n(t,e)}))}))}function Mt(t,n){C(t)||Ft("name must be a string"),u(n)||Ft("callback must be a function"),K({type:f.GROUP},(function(){g.run({groupName:t},n)}))}function Gt(t){function n(n){var e=g.useX(),r=e.exclusion;e.inclusion[t]=function(){return Object.prototype.hasOwnProperty.call(r.tests,t)?o(r.tests[t],!0):C(n)?!!r.tests[n]:i(n,i(dt))}}var e=g.useX();return t?(e.inclusion[t]=o(e.exclusion.tests[t],!0),{when:n}):{when:n}}function jt(t,n){K({type:f.OMIT_WHEN},(function(){g.run({omitted:i(t,i(dt))},(function(){return n()}))}))}function Ht(t){(0,k().optionalFields()[1])((function(n){if(Array.isArray(t)||C(t))[].concat(t).forEach((function(t){n[t]=!0}));else for(var e in t)n[e]=t[e];return n}))}function Kt(t,n){K({type:f.SKIP_WHEN},(function(){g.run({skipped:i(t,i(dt))},(function(){return n()}))}))}function Vt(){var t=g.useX("warn hook called outside of a running suite.");t.currentTest||s("warn called outside of a test."),t.currentTest.warn()}export{Wt as VERSION,g as context,Ut as create,Rt as each,Mt as group,Gt as include,jt as omitWhen,St as only,Ht as optional,Ot as skip,Kt as skipWhen,_t as test,Vt as warn};
|
|
1
|
+
import{createContext as t}from"context";export{enforce}from"n4s";var n,e=Object.assign,r=(n=0,function(){return"".concat(n++)});function u(t){return"function"==typeof t}function i(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return u(t)?t.apply(void 0,n):t}function o(t,n){var e;return null!==(e=i(t))&&void 0!==e?e:n}function s(t,n){throw Error(o(n,t))}function a(t,n){setTimeout((function(){s(t,n)}),0)}function c(t){function n(t,n,u){return r.references.push(),e(t,i(n,u)),function(){return[r.references[t],function(n){return e(t,i(n,r.references[t]))}]}}function e(n,e){var i=r.references[n];r.references[n]=e,u(n=o[n][1])&&n(e,i),u(t)&&t()}var r={references:[]},o=[];return{registerStateKey:function(t,e){var r=o.length;return o.push([t,e]),n(r,t)},reset:function(){var t=r.references;r.references=[],o.forEach((function(e,r){return n(r,e[0],t[r])}))}}}var f,l=f||(f={});function p(t,n){var e=n.suiteId;return n=n.suiteName,{optionalFields:t.registerStateKey((function(){return{}})),suiteId:t.registerStateKey(e),suiteName:t.registerStateKey(n),testCallbacks:t.registerStateKey((function(){return{fieldCallbacks:{},doneCallbacks:[]}})),testObjects:t.registerStateKey((function(t){return{prev:t?t.current:[],current:[]}}))}}function d(t){return(t=[].concat(t))[t.length-1]}function v(){function t(){n=[0]}var n=[];return t(),{addLevel:function(){n.push(0)},cursorAt:function(){return d(n)},getCursor:function(){return[].concat(n)},next:function(){return n[n.length-1]++,d(n)},removeLevel:function(){n.pop()},reset:t}}l[l.DEFAULT=0]="DEFAULT",l[l.SUITE=1]="SUITE",l[l.EACH=2]="EACH",l[l.SKIP_WHEN=3]="SKIP_WHEN",l[l.OMIT_WHEN=4]="OMIT_WHEN",l[l.GROUP=5]="GROUP";var h,g=h||(h={});g[g.ALL=0]="ALL",g[g.EAGER=1]="EAGER";var E=t((function(t,n){return n?null:e({},{exclusion:{tests:{},groups:{}},inclusion:{},isolate:{type:f.DEFAULT,keys:{current:{},prev:{}}},mode:[h.ALL],testCursor:v()},t)}));function m(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return!t.apply(void 0,n)}}var y=m((function(t){return null===t}));function N(t,n){for(var e=[],r=0;r<t.length;r++){var u=t[r];Array.isArray(u)?e.push(N(u,n)):(u=n(u),y(u)&&e.push(u))}return e}function b(t){return[].concat(t).reduce((function(t,n){return Array.isArray(n)?t.concat(b(n)):[].concat(t).concat(n)}),[])}function S(t,n){var e=0;for(n=n.slice(0,-1);e<n.length;e++){var r=n[e];t[r]=o(t[r],[]),t=t[r]}return t}function C(t){return null==t}function R(t){return String(t)===t}function T(t){function n(e,u){var i=n.get(e);return i?i[1]:(u=u(),r.unshift([e.concat(),u]),r.length>Number(t)&&(r.length=t),u)}function e(t){return r.findIndex((function(n){var e=n[0];return t.length===Number(e.length)&&t.every((function(t,n){return t===e[n]}))}))}void 0===t&&(t=1);var r=[];return n.invalidate=function(t){-1<(t=e(t))&&r.splice(t,1)},n.get=function(t){return r[e(t)]||null},n}function A(){return E.useX().stateRef}function I(){return A().testObjects()}function k(){(0,I()[1])((function(t){return{prev:t.prev,current:[].concat(t.current)}}))}function O(t){(0,I()[1])((function(n){return{prev:n.prev,current:[].concat(t(n.current))}}))}function _(){return b(N(I()[0].current,(function(t){return t.isPending()?t:null})))}var L=T();function F(){var t=I()[0].current;return L([t],(function(){return b(t)}))}var G,P=G||(G={});P.Error="error",P.Warning="warning";var W=function(){function t(t,n,e){var u=void 0===e?{}:e;e=u.message;var i=u.groupName;u=u.key,this.key=null,this.id=r(),this.severity=G.Error,this.status=X,this.fieldName=t,this.testFn=n,i&&(this.groupName=i),e&&(this.message=e),u&&(this.key=u)}return t.prototype.run=function(){try{var t=this.testFn()}catch(n){t=n,void 0===this.message&&R(t)&&(this.message=n),t=!1}return!1===t&&this.fail(),t},t.prototype.setStatus=function(t){this.isFinalStatus()&&t!==j||(this.status=t)},t.prototype.warns=function(){return this.severity===G.Warning},t.prototype.setPending=function(){this.setStatus(H)},t.prototype.fail=function(){this.setStatus(this.warns()?U:D)},t.prototype.done=function(){this.isFinalStatus()||this.setStatus(x)},t.prototype.warn=function(){this.severity=G.Warning},t.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},t.prototype.skip=function(t){this.isPending()&&!t||this.setStatus(w)},t.prototype.cancel=function(){this.setStatus(K),k()},t.prototype.reset=function(){this.status=X,k()},t.prototype.omit=function(){this.setStatus(j)},t.prototype.valueOf=function(){return!this.isFailing()},t.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},t.prototype.isNonActionable=function(){return this.isSkipped()||this.isOmitted()||this.isCanceled()},t.prototype.isPending=function(){return this.statusEquals(H)},t.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},t.prototype.isOmitted=function(){return this.statusEquals(j)},t.prototype.isUntested=function(){return this.statusEquals(X)},t.prototype.isFailing=function(){return this.statusEquals(D)},t.prototype.isCanceled=function(){return this.statusEquals(K)},t.prototype.isSkipped=function(){return this.statusEquals(w)},t.prototype.isPassing=function(){return this.statusEquals(x)},t.prototype.isWarning=function(){return this.statusEquals(U)},t.prototype.statusEquals=function(t){return this.status===t},t}(),X="UNTESTED",w="SKIPPED",D="FAILED",U="WARNING",x="PASSING",H="PENDING",K="CANCELED",j="OMITTED";function M(){return E.useX().testCursor.getCursor()}function q(){return E.useX().testCursor.next()}function B(t,n){if(t=void 0===(t=t.type)?f.DEFAULT:t,u(n)){var e={current:{},prev:{}},r=M();return E.run({isolate:{type:t,keys:e}},(function(){E.useX().testCursor.addLevel(),e.prev=function(){var t=I()[0].prev;return[].concat(S(t,M())).reduce((function(t,n){return n instanceof W&&!C(n.key)?(t[n.key]=n,t):t}),{})}(),O((function(t){return S(t,r)[d(r)]=[],t}));var t=n();return E.useX().testCursor.removeLevel(),q(),t}))}}function V(t){if(t){if("number"==typeof t)return 0===t;if(Object.prototype.hasOwnProperty.call(t,"length"))return t.length===Number(0);if("object"==typeof t)return Object.keys(t).length===Number(0)}return!0}var Y=m(V);function z(t,n){return!(!n||t.fieldName!==n)}function J(t){var n=_();return!V(n)&&(t?n.some((function(n){return z(n,t)})):Y(n))}var Q,Z=Q||(Q={});function $(t,n){function e(t){i[t===Q.ERRORS?"errorCount":"warnCount"]++,u&&(i[t]=(i[t]||[]).concat(u))}var r=n.fieldName,u=n.message;t[r]=t[r]||{errorCount:0,warnCount:0,testCount:0};var i=t[r];return n.isNonActionable()||(t[r].testCount++,n.isFailing()?e(Q.ERRORS):n.isWarning()&&e(Q.WARNINGS)),i}function tt(){return(tt=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var u in n=arguments[e])Object.prototype.hasOwnProperty.call(n,u)&&(t[u]=n[u]);return t}).apply(this,arguments)}function nt(t,n,e){if(e||2===arguments.length)for(var r,u=0,i=n.length;u<i;u++)!r&&u in n||(r||(r=Array.prototype.slice.call(n,0,u)),r[u]=n[u]);return t.concat(r||Array.prototype.slice.call(n))}function et(t,n,e){var r;void 0===e&&(e={});var u=(e=e||{}).group,i=e.fieldName;return n.reduce((function(n,e){if(u&&e.groupName!==u)var r=!0;else i&&!z(e,i)?r=!0:(r=e.warns(),r=t===Q.WARNINGS!=!!r);return r||!e.hasFailures()||(n[e.fieldName]=(n[e.fieldName]||[]).concat(e.message||[])),n}),tt({},i&&((r={})[i]=[],r)))}function rt(t){return it(Q.ERRORS,t)}function ut(t){return it(Q.WARNINGS,t)}function it(t,n){return t=et(t,F(),{fieldName:n}),n?t[n]:t}function ot(t,n){return t=at(Q.ERRORS,t,n),n?t[n]:t}function st(t,n){return t=at(Q.WARNINGS,t,n),n?t[n]:t}function at(t,n,e){return n||s("get".concat(t[0].toUpperCase()).concat(t.slice(1),"ByGroup requires a group name. Received `").concat(n,"` instead.")),et(t,F(),{group:n,fieldName:e})}function ct(t,n,e){return(e=!t.hasFailures()||e&&!z(t,e))||(t=t.warns(),e=n===Q.WARNINGS!=!!t),!e}function ft(t){return pt(Q.ERRORS,t)}function lt(t){return pt(Q.WARNINGS,t)}function pt(t,n){return F().some((function(e){return ct(e,t,n)}))}function dt(t,n){return ht(Q.ERRORS,t,n)}function vt(t,n){return ht(Q.WARNINGS,t,n)}function ht(t,n,e){return F().some((function(r){return n===r.groupName&&ct(r,t,e)}))}Z.WARNINGS="warnings",Z.ERRORS="errors";var gt=T(20);function Et(){var t=F(),n={stateRef:A()};return gt([t],E.bind(n,(function(){var t=A().suiteName()[0];return e(function(){var t=F(),n=e({errorCount:0,warnCount:0,testCount:0},{groups:{},tests:{}});return t.forEach((function(t){var e=t.fieldName,r=t.groupName;n.tests[e]=$(n.tests,t),r&&(n.groups[r]=n.groups[r]||{},n.groups[r][e]=$(n.groups[r],t))})),function(t){for(var n in t.tests)t.errorCount+=t.tests[n].errorCount,t.warnCount+=t.tests[n].warnCount,t.testCount+=t.tests[n].testCount;return t}(n)}(),{getErrors:E.bind(n,rt),getErrorsByGroup:E.bind(n,ot),getWarnings:E.bind(n,ut),getWarningsByGroup:E.bind(n,st),hasErrors:E.bind(n,ft),hasErrorsByGroup:E.bind(n,dt),hasWarnings:E.bind(n,lt),hasWarningsByGroup:E.bind(n,vt),isValid:E.bind(n,(function(t){var n=Et(),e=F().reduce((function(t,n){return t[n.fieldName]||n.isOmitted()&&(t[n.fieldName]=!0),t}),{});return(e=!!t&&!!e[t])?t=!0:n.hasErrors(t)?t=!1:t=!(V(e=F())||t&&V(n.tests[t])||function(t){var n=A().optionalFields()[0];return Y(_().filter((function(e){return!(t&&!z(e,t))&&!0!==n[e.fieldName]})))}(t))&&function(t){var n=F(),e=A().optionalFields()[0];return n.every((function(n){return!(!t||z(n,t))||!0===e[n.fieldName]||n.isTested()||n.isOmitted()}))}(t),t})),suiteName:t})})))}var mt=T(20);function yt(){var t=F(),n={stateRef:A()};return mt([t],E.bind(n,(function(){return e({},Et(),{done:E.bind(n,St)})})))}function Nt(t,n,e){return!(u(t)&&(!n||e.tests[n]&&!V(e.tests[n].testCount)))}function bt(t){return!(J()&&(!t||J(t)))}function St(){function t(){return r(Et())}for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var r=(n=n.reverse())[0];return n=n[1],e=yt(),Nt(r,n,e)?e:bt(n)?(t(),e):(Ct(t,n),e)}function Ct(t,n){var e=E.bind({},t);(0,A().testCallbacks()[1])((function(t){return n?t.fieldCallbacks[n]=(t.fieldCallbacks[n]||[]).concat(e):t.doneCallbacks.push(e),t}))}function Rt(t){return t.forEach((function(t){return t()}))}function Tt(){var t=function(){var t={};return{emit:function(n,e){(t[n]||[]).forEach((function(t){t(e)}))},on:function(n,e){return t[n]=(t[n]||[]).concat(e),{off:function(){t[n]=t[n].filter((function(t){return t!==e}))}}}}}();return t.on(It.TEST_COMPLETED,(function(n){if(!n.isCanceled()){n.done(),n=n.fieldName;var e=A().testCallbacks()[0].fieldCallbacks;n&&!J(n)&&Array.isArray(e[n])&&Rt(e[n]),J()||t.emit(It.ALL_RUNNING_TESTS_FINISHED)}})),t.on(It.SUITE_CALLBACK_DONE_RUNNING,(function(){!function(){var t=A().optionalFields()[0];if(!V(t)){var n={};O((function(e){return N(e,(function(e){var r=e.fieldName;if(n.hasOwnProperty(r))n[e.fieldName]&&e.omit();else{var i=t[r];u(i)&&(n[r]=i(),n[e.fieldName]&&e.omit())}return e}))}))}}()})),t.on(It.ALL_RUNNING_TESTS_FINISHED,(function(){Rt(A().testCallbacks()[0].doneCallbacks)})),t.on(It.REMOVE_FIELD,(function(t){F().forEach((function(n){z(n,t)&&(n.cancel(),function(t){O((function(n){return N(n,(function(n){return t!==n?n:null}))}))}(n))}))})),t.on(It.RESET_FIELD,(function(t){F().forEach((function(n){z(n,t)&&n.reset()}))})),t}function At(){var t=E.useX();return t.bus||s(),t.bus}var It,kt=It||(It={});function Ot(t){return Lt(0,"tests",t)}function _t(t){return Lt(1,"tests",t)}function Lt(t,n,e){var r=E.useX("hook called outside of a running suite.");e&&[].concat(e).forEach((function(e){R(e)&&(r.exclusion[n][e]=0===t)}))}function Ft(t){for(var n in t)if(!0===t[n])return!0;return!1}function Gt(t){s("Wrong arguments passed to group. Group ".concat(t,"."))}kt.TEST_COMPLETED="test_completed",kt.ALL_RUNNING_TESTS_FINISHED="all_running_tests_finished",kt.REMOVE_FIELD="remove_field",kt.RESET_FIELD="reset_field",kt.SUITE_CALLBACK_DONE_RUNNING="suite_callback_done_running",Ot.group=function(t){return Lt(0,"groups",t)},_t.group=function(t){return Lt(1,"groups",t)};var Pt=m(R);function Wt(t){var n=t.asyncTest,e=t.message;if(n&&u(n.then)){var r=At().emit,i=A(),o=E.bind({stateRef:i},(function(){k(),r(It.TEST_COMPLETED,t)}));i=E.bind({stateRef:i},(function(n){t.isCanceled()||(t.message=R(n)?n:e,t.fail(),o())}));try{n.then(o,i)}catch(t){i()}}}function Xt(t){var n=M();O((function(e){return S(e,n)[d(n)]=t,e}))}function wt(t){var n=I()[0].prev;if(V(n))Xt(t),n=t;else{var e=M();if(n=S(n,e)[d(e)],C(t.key))!Y(e=n)||e.fieldName===t.fieldName&&e.groupName===t.groupName||(E.useX().isolate.type!==f.EACH&&a("Vest Critical Error: Tests called in different order than previous run.\n expected: ".concat(n.fieldName,"\n received: ").concat(t.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.')),function(){var t=I(),n=t[1],e=t[0].prev;t=S(e,M());var r=E.useX().testCursor.cursorAt();t.splice(r),n((function(t){return{prev:e,current:t.current}}))}(),n=null),Xt(n=o(n,t));else{n=t.key;var r=E.useX().isolate.keys.prev[n];e=t,r&&(e=r),r=e;var c=E.useX().isolate.keys.current;C(c[n])?c[n]=r:a('Encountered the same test key "'.concat(n,"\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.")),Xt(n=e)}}if(e=h.EAGER,e=!(E.useX().mode[0]!==e||!ft(t.fieldName)))return q(),t.skip(),t;if(E.useX().omitted)return n.omit(),q(),n;if(function(t){var n=t.fieldName;if(t=t.groupName,E.useX().skipped)return!0;var e=E.useX(),r=e.exclusion;e=e.inclusion;var u=r.tests,o=u[n];if(!1===o)return!0;if(o=!0===o,t){t:{var s=E.useX().exclusion.groups;if(Object.prototype.hasOwnProperty.call(s,t))var a=!1===s[t];else{for(a in s)if(!0===s[a]){a=!0;break t}a=!1}}if(a)return!0;if(!0===r.groups[t])return!(o||!Ft(u)&&!1!==u[n])}r=E.useX().exclusion;t:{for(c in(a=E.useX().exclusion).groups)if(a.groups[c]){var c=!0;break t}c=!1}return!(!c||t&&t in r.groups&&r.groups[t])||!o&&!!Ft(u)&&!i(e[n])}(t))return n.skip(!!E.useX().skipped),q(),n;if(t!==n&&n.fieldName===t.fieldName&&n.groupName===t.groupName&&n.isPending()&&n.cancel(),Xt(t),q(),t.isUntested()){n=At(),e=function(t){return E.run({currentTest:t},(function(){try{var n=t.testFn()}catch(e){n=e,void 0===t.message&&R(n)&&(t.message=e),n=!1}return!1===n&&t.fail(),n}))}(t);try{e&&u(e.then)?(t.asyncTest=e,t.setPending(),Wt(t)):n.emit(It.TEST_COMPLETED,t)}catch(n){s("Unexpected error encountered during test registration.\n Test Object: ".concat(t,".\n Error: ").concat(n,"."))}}else(n=t.asyncTest)&&u(n.then)&&(t.setPending(),Wt(t));return t}function Dt(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];var r=u(n[1])?n:nt([void 0],n,!0);n=r[0],e=r[1],r=r[2],Pt(t)&&xt("fieldName","string"),u(e)||xt("Test callback","function");var i=E.useX();return wt(n=new W(t,e,{message:n,groupName:i.groupName,key:r}))}var Ut=e(Dt,{memo:function(t){var n=T(100);return function(e){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];u=E.useX().testCursor.cursorAt();var i=(r=r.reverse())[0],o=r[1],s=r[2];return u=[A().suiteId()[0],e,u].concat(i),null===(r=n.get(u))?n(u,(function(){return t(e,s,o)})):r[1].isCanceled()?(n.invalidate(u),n(u,(function(){return t(e,s,o)}))):wt(r[1])}}(Dt)});function xt(t,n){s("Incompatible params passed to test function. ".concat(t," must be a ").concat(n))}var Ht="4.2.0";function Kt(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var i=(t=t.reverse())[0];t=t[1],u(i)||s("vest.create: Expected callback to be a function.");var o=Tt(),a=c();return t={stateRef:p(a,{suiteId:r(),suiteName:t}),bus:o},e(E.bind(t,(function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return a.reset(),B({type:f.SUITE},(function(){i.apply(void 0,t)})),o.emit(It.SUITE_CALLBACK_DONE_RUNNING),yt()})),{get:E.bind(t,Et),remove:E.bind(t,(function(t){o.emit(It.REMOVE_FIELD,t)})),reset:a.reset,resetField:E.bind(t,(function(t){o.emit(It.RESET_FIELD,t)}))})}function jt(t,n){u(n)||s("each callback must be a function"),B({type:f.EACH},(function(){t.forEach((function(t,e){n(t,e)}))}))}function Mt(){var t=h.EAGER;E.useX().mode[0]=t}function qt(t,n){R(t)||Gt("name must be a string"),u(n)||Gt("callback must be a function"),B({type:f.GROUP},(function(){E.run({groupName:t},n)}))}function Bt(t){function n(n){var e=E.useX(),r=e.exclusion;e.inclusion[t]=function(){return Object.prototype.hasOwnProperty.call(r.tests,t)?o(r.tests[t],!0):R(n)?!!r.tests[n]:i(n,i(Et))}}var e=E.useX();return t?(e.inclusion[t]=o(e.exclusion.tests[t],!0),{when:n}):{when:n}}function Vt(t,n){B({type:f.OMIT_WHEN},(function(){E.run({omitted:!!E.useX().omitted||i(t,i(Et))},(function(){return n()}))}))}function Yt(t){(0,A().optionalFields()[1])((function(n){if(Array.isArray(t)||R(t))[].concat(t).forEach((function(t){n[t]=!0}));else for(var e in t)n[e]=t[e];return n}))}function zt(t,n){B({type:f.SKIP_WHEN},(function(){E.run({skipped:!!E.useX().skipped||i(t,i(Et))},(function(){return n()}))}))}function Jt(){var t=E.useX("warn hook called outside of a running suite.");t.currentTest||s("warn called outside of a test."),t.currentTest.warn()}export{Ht as VERSION,E as context,Kt as create,jt as each,Mt as eager,qt as group,Bt as include,Vt as omitWhen,Ot as only,Yt as optional,_t as skip,zt as skipWhen,Ut as test,Jt as warn};
|
|
@@ -511,7 +511,7 @@
|
|
|
511
511
|
return ruleReturn(result);
|
|
512
512
|
}
|
|
513
513
|
else {
|
|
514
|
-
return ruleReturn(result.pass, optionalFunctionValue.apply(void 0, __spreadArray([result.message, ruleName, value], args)));
|
|
514
|
+
return ruleReturn(result.pass, optionalFunctionValue.apply(void 0, __spreadArray([result.message, ruleName, value], args, false)));
|
|
515
515
|
}
|
|
516
516
|
}
|
|
517
517
|
function validateResult(result) {
|
|
@@ -545,12 +545,12 @@
|
|
|
545
545
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
546
546
|
args[_i] = arguments[_i];
|
|
547
547
|
}
|
|
548
|
-
var transformedResult = transformResult.apply(void 0, __spreadArray([ctx.run({ value: value }, function () { return rule.apply(void 0, __spreadArray([value], args)); }),
|
|
548
|
+
var transformedResult = transformResult.apply(void 0, __spreadArray([ctx.run({ value: value }, function () { return rule.apply(void 0, __spreadArray([value], args, false)); }),
|
|
549
549
|
ruleName,
|
|
550
|
-
value], args));
|
|
550
|
+
value], args, false));
|
|
551
551
|
if (!transformedResult.pass) {
|
|
552
552
|
if (isEmpty(transformedResult.message)) {
|
|
553
|
-
throwError("enforce/"
|
|
553
|
+
throwError("enforce/".concat(ruleName, " failed with ").concat(JSON.stringify(value)));
|
|
554
554
|
}
|
|
555
555
|
else {
|
|
556
556
|
// Explicitly throw a string so that vest.test can pick it up as the validation error message
|
|
@@ -577,7 +577,7 @@
|
|
|
577
577
|
}
|
|
578
578
|
var rule = getRule(ruleName);
|
|
579
579
|
registeredRules.push(function (value) {
|
|
580
|
-
return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args)), ruleName, value], args));
|
|
580
|
+
return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args, false)), ruleName, value], args, false));
|
|
581
581
|
});
|
|
582
582
|
var proxy = {
|
|
583
583
|
run: function (value) {
|