vest 4.0.0-dev-31f012 → 4.0.0-dev-e266d9
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 +70 -52
- package/README.md +2 -112
- package/dist/cjs/compose.js +7 -0
- package/dist/cjs/compounds.js +7 -0
- package/dist/cjs/enforce/compose.development.js +139 -0
- package/dist/cjs/enforce/compose.production.js +1 -0
- package/dist/cjs/enforce/compounds.development.js +132 -0
- package/dist/cjs/enforce/compounds.production.js +1 -0
- package/dist/cjs/enforce/package.json +1 -0
- package/dist/cjs/enforce/schema.development.js +144 -0
- package/dist/cjs/enforce/schema.production.js +1 -0
- package/dist/cjs/schema.js +7 -0
- package/dist/cjs/vest.development.js +504 -1034
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/enforce/compose.development.js +137 -0
- package/dist/es/enforce/compose.production.js +1 -0
- package/dist/es/enforce/compounds.development.js +130 -0
- package/dist/es/enforce/compounds.production.js +1 -0
- package/dist/es/enforce/package.json +1 -0
- package/dist/es/enforce/schema.development.js +140 -0
- package/dist/es/enforce/schema.production.js +1 -0
- package/dist/es/vest.development.js +497 -1033
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +143 -0
- package/dist/umd/enforce/compose.production.js +1 -0
- package/dist/umd/enforce/compounds.development.js +136 -0
- package/dist/umd/enforce/compounds.production.js +1 -0
- package/dist/umd/enforce/schema.development.js +148 -0
- package/dist/umd/enforce/schema.production.js +1 -0
- package/dist/umd/vest.development.js +1693 -2226
- package/dist/umd/vest.production.js +1 -1
- package/enforce/compose/package.json +7 -0
- package/enforce/compounds/package.json +7 -0
- package/enforce/schema/package.json +7 -0
- package/package.json +107 -13
- package/testUtils/mockThrowError.ts +16 -0
- package/types/enforce/compose.d.ts +134 -0
- package/types/enforce/compounds.d.ts +146 -0
- package/types/enforce/schema.d.ts +151 -0
- package/types/vest.d.ts +31 -203
|
@@ -2,804 +2,46 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
purpose with or without fee is hereby granted.
|
|
10
|
-
|
|
11
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
-
***************************************************************************** */
|
|
19
|
-
|
|
20
|
-
var __assign = function() {
|
|
21
|
-
__assign = Object.assign || function __assign(t) {
|
|
22
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
23
|
-
s = arguments[i];
|
|
24
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
25
|
-
}
|
|
26
|
-
return t;
|
|
27
|
-
};
|
|
28
|
-
return __assign.apply(this, arguments);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
function __spreadArray(to, from, pack) {
|
|
32
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
33
|
-
if (ar || !(i in from)) {
|
|
34
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
35
|
-
ar[i] = from[i];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return to.concat(ar || from);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
var assign = Object.assign;
|
|
42
|
-
|
|
43
|
-
function isFunction(value) {
|
|
44
|
-
return typeof value === 'function';
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function mapFirst(array, callback) {
|
|
48
|
-
var broke = false;
|
|
49
|
-
var breakoutValue = null;
|
|
50
|
-
for (var i = 0; i < array.length; i++) {
|
|
51
|
-
callback(array[i], breakout, i);
|
|
52
|
-
if (broke) {
|
|
53
|
-
return breakoutValue;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function breakout(value) {
|
|
57
|
-
broke = true;
|
|
58
|
-
breakoutValue = value;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function optionalFunctionValue(value) {
|
|
63
|
-
var args = [];
|
|
64
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
65
|
-
args[_i - 1] = arguments[_i];
|
|
66
|
-
}
|
|
67
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function defaultTo(callback, defaultValue) {
|
|
71
|
-
var _a;
|
|
72
|
-
return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function ruleReturn(pass, message) {
|
|
76
|
-
var output = { pass: pass };
|
|
77
|
-
if (message) {
|
|
78
|
-
output.message = message;
|
|
79
|
-
}
|
|
80
|
-
return output;
|
|
81
|
-
}
|
|
82
|
-
function failing() {
|
|
83
|
-
return ruleReturn(false);
|
|
84
|
-
}
|
|
85
|
-
function passing() {
|
|
86
|
-
return ruleReturn(true);
|
|
87
|
-
}
|
|
88
|
-
function defaultToFailing(callback) {
|
|
89
|
-
return defaultTo(callback, failing());
|
|
90
|
-
}
|
|
91
|
-
function defaultToPassing(callback) {
|
|
92
|
-
return defaultTo(callback, passing());
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function runLazyRule(lazyRule, currentValue) {
|
|
96
|
-
try {
|
|
97
|
-
return lazyRule.run(currentValue);
|
|
98
|
-
}
|
|
99
|
-
catch (_a) {
|
|
100
|
-
return failing();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function allOf(value) {
|
|
105
|
-
var rules = [];
|
|
106
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
107
|
-
rules[_i - 1] = arguments[_i];
|
|
108
|
-
}
|
|
109
|
-
return defaultToPassing(mapFirst(rules, function (rule, breakout) {
|
|
110
|
-
var res = runLazyRule(rule, value);
|
|
111
|
-
if (!res.pass) {
|
|
112
|
-
breakout(res);
|
|
113
|
-
}
|
|
114
|
-
}));
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function anyOf(value) {
|
|
118
|
-
var rules = [];
|
|
119
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
120
|
-
rules[_i - 1] = arguments[_i];
|
|
121
|
-
}
|
|
122
|
-
return defaultToFailing(mapFirst(rules, function (rule, breakout) {
|
|
123
|
-
var res = runLazyRule(rule, value);
|
|
124
|
-
if (res.pass) {
|
|
125
|
-
breakout(res);
|
|
126
|
-
}
|
|
127
|
-
}));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function noneOf(value) {
|
|
131
|
-
var rules = [];
|
|
132
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
133
|
-
rules[_i - 1] = arguments[_i];
|
|
134
|
-
}
|
|
135
|
-
return defaultToPassing(mapFirst(rules, function (rule, breakout) {
|
|
136
|
-
var res = runLazyRule(rule, value);
|
|
137
|
-
if (res.pass) {
|
|
138
|
-
breakout(failing());
|
|
139
|
-
}
|
|
140
|
-
}));
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function bindNot(fn) {
|
|
144
|
-
return function () {
|
|
145
|
-
var args = [];
|
|
146
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
147
|
-
args[_i] = arguments[_i];
|
|
148
|
-
}
|
|
149
|
-
return !fn.apply(void 0, args);
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function lengthEquals(value, arg1) {
|
|
154
|
-
return value.length === Number(arg1);
|
|
155
|
-
}
|
|
156
|
-
var lengthNotEquals = bindNot(lengthEquals);
|
|
157
|
-
|
|
158
|
-
function longerThan(value, arg1) {
|
|
159
|
-
return value.length > Number(arg1);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function oneOf(value) {
|
|
163
|
-
var rules = [];
|
|
164
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
165
|
-
rules[_i - 1] = arguments[_i];
|
|
166
|
-
}
|
|
167
|
-
var passing = [];
|
|
168
|
-
rules.some(function (rule) {
|
|
169
|
-
if (longerThan(passing, 1)) {
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
var res = runLazyRule(rule, value);
|
|
173
|
-
if (res.pass) {
|
|
174
|
-
passing.push(res);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
return ruleReturn(lengthEquals(passing, 1));
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function isNull(value) {
|
|
181
|
-
return value === null;
|
|
182
|
-
}
|
|
183
|
-
var isNotNull = bindNot(isNull);
|
|
184
|
-
|
|
185
|
-
function isUndefined(value) {
|
|
186
|
-
return value === undefined;
|
|
187
|
-
}
|
|
188
|
-
var isNotUndefined = bindNot(isUndefined);
|
|
189
|
-
|
|
190
|
-
function optional$1(value, ruleChain) {
|
|
191
|
-
if (isUndefined(value) || isNull(value)) {
|
|
192
|
-
return passing();
|
|
193
|
-
}
|
|
194
|
-
return runLazyRule(ruleChain, value);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function compounds() {
|
|
198
|
-
return { allOf: allOf, anyOf: anyOf, noneOf: noneOf, oneOf: oneOf, optional: optional$1 };
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function isStringValue(v) {
|
|
202
|
-
return String(v) === v;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function endsWith(value, arg1) {
|
|
206
|
-
return isStringValue(value) && isStringValue(arg1) && value.endsWith(arg1);
|
|
207
|
-
}
|
|
208
|
-
var doesNotEndWith = bindNot(endsWith);
|
|
209
|
-
|
|
210
|
-
function equals(value, arg1) {
|
|
211
|
-
return value === arg1;
|
|
212
|
-
}
|
|
213
|
-
var notEquals = bindNot(equals);
|
|
214
|
-
|
|
215
|
-
function isNumeric(value) {
|
|
216
|
-
var str = String(value);
|
|
217
|
-
var num = Number(value);
|
|
218
|
-
var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
|
|
219
|
-
return Boolean(result);
|
|
220
|
-
}
|
|
221
|
-
var isNotNumeric = bindNot(isNumeric);
|
|
222
|
-
|
|
223
|
-
function greaterThan(value, gt) {
|
|
224
|
-
return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function greaterThanOrEquals(value, gte) {
|
|
228
|
-
return isNumeric(value) && isNumeric(gte) && Number(value) >= Number(gte);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// The module is named "isArrayValue" since it
|
|
232
|
-
// is conflicting with a nested npm dependency.
|
|
233
|
-
// We may need to revisit this in the future.
|
|
234
|
-
function isArray(value) {
|
|
235
|
-
return Boolean(Array.isArray(value));
|
|
236
|
-
}
|
|
237
|
-
var isNotArray = bindNot(isArray);
|
|
238
|
-
|
|
239
|
-
function inside(value, arg1) {
|
|
240
|
-
if (isArray(arg1)) {
|
|
241
|
-
return arg1.indexOf(value) !== -1;
|
|
242
|
-
}
|
|
243
|
-
// both value and arg1 are strings
|
|
244
|
-
if (isStringValue(arg1) && isStringValue(value)) {
|
|
245
|
-
return arg1.indexOf(value) !== -1;
|
|
246
|
-
}
|
|
247
|
-
return false;
|
|
248
|
-
}
|
|
249
|
-
var notInside = bindNot(inside);
|
|
250
|
-
|
|
251
|
-
function lessThanOrEquals(value, lte) {
|
|
252
|
-
return isNumeric(value) && isNumeric(lte) && Number(value) <= Number(lte);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function isBetween(value, min, max) {
|
|
256
|
-
return greaterThanOrEquals(value, min) && lessThanOrEquals(value, max);
|
|
257
|
-
}
|
|
258
|
-
var isNotBetween = bindNot(isBetween);
|
|
259
|
-
|
|
260
|
-
function isBlank(value) {
|
|
261
|
-
return isStringValue(value) && !value.trim();
|
|
262
|
-
}
|
|
263
|
-
var isNotBlank = bindNot(isBlank);
|
|
264
|
-
|
|
265
|
-
function isBoolean(value) {
|
|
266
|
-
return !!value === value;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
var isNotBoolean = bindNot(isBoolean);
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* A safe hasOwnProperty access
|
|
273
|
-
*/
|
|
274
|
-
function hasOwnProperty(obj, key) {
|
|
275
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
function isNumber(value) {
|
|
279
|
-
return Boolean(typeof value === 'number');
|
|
280
|
-
}
|
|
281
|
-
var isNotNumber = bindNot(isNumber);
|
|
282
|
-
|
|
283
|
-
function isEmpty(value) {
|
|
284
|
-
if (!value) {
|
|
285
|
-
return true;
|
|
286
|
-
}
|
|
287
|
-
else if (isNumber(value)) {
|
|
288
|
-
return value === 0;
|
|
289
|
-
}
|
|
290
|
-
else if (hasOwnProperty(value, 'length')) {
|
|
291
|
-
return lengthEquals(value, 0);
|
|
292
|
-
}
|
|
293
|
-
else if (typeof value === 'object') {
|
|
294
|
-
return lengthEquals(Object.keys(value), 0);
|
|
295
|
-
}
|
|
296
|
-
return true;
|
|
297
|
-
}
|
|
298
|
-
var isNotEmpty = bindNot(isEmpty);
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Validates that a given value is an even number
|
|
302
|
-
*/
|
|
303
|
-
var isEven = function (value) {
|
|
304
|
-
if (isNumeric(value)) {
|
|
305
|
-
return value % 2 === 0;
|
|
306
|
-
}
|
|
307
|
-
return false;
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
function isNaN$1(value) {
|
|
311
|
-
return Number.isNaN(value);
|
|
312
|
-
}
|
|
313
|
-
var isNotNaN = bindNot(isNaN$1);
|
|
314
|
-
|
|
315
|
-
function isNegative(value) {
|
|
316
|
-
if (isNumeric(value)) {
|
|
317
|
-
return Number(value) < 0;
|
|
318
|
-
}
|
|
319
|
-
return false;
|
|
320
|
-
}
|
|
321
|
-
var isPositive = bindNot(isNegative);
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Validates that a given value is an odd number
|
|
325
|
-
*/
|
|
326
|
-
var isOdd = function (value) {
|
|
327
|
-
if (isNumeric(value)) {
|
|
328
|
-
return value % 2 !== 0;
|
|
329
|
-
}
|
|
330
|
-
return false;
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
var isNotString = bindNot(isStringValue);
|
|
334
|
-
|
|
335
|
-
function isTruthy(value) {
|
|
336
|
-
return !!value;
|
|
337
|
-
}
|
|
338
|
-
var isFalsy = bindNot(isTruthy);
|
|
339
|
-
|
|
340
|
-
function lessThan(value, lt) {
|
|
341
|
-
return isNumeric(value) && isNumeric(lt) && Number(value) < Number(lt);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
function longerThanOrEquals(value, arg1) {
|
|
345
|
-
return value.length >= Number(arg1);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
function matches(value, regex) {
|
|
349
|
-
if (regex instanceof RegExp) {
|
|
350
|
-
return regex.test(value);
|
|
351
|
-
}
|
|
352
|
-
else if (isStringValue(regex)) {
|
|
353
|
-
return new RegExp(regex).test(value);
|
|
354
|
-
}
|
|
355
|
-
else {
|
|
356
|
-
return false;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
var notMatches = bindNot(matches);
|
|
360
|
-
|
|
361
|
-
function numberEquals(value, eq) {
|
|
362
|
-
return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
|
|
363
|
-
}
|
|
364
|
-
var numberNotEquals = bindNot(numberEquals);
|
|
365
|
-
|
|
366
|
-
function condition(value, callback) {
|
|
367
|
-
try {
|
|
368
|
-
return callback(value);
|
|
369
|
-
}
|
|
370
|
-
catch (_a) {
|
|
371
|
-
return false;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
function shorterThan(value, arg1) {
|
|
376
|
-
return value.length < Number(arg1);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function shorterThanOrEquals(value, arg1) {
|
|
380
|
-
return value.length <= Number(arg1);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
function startsWith(value, arg1) {
|
|
384
|
-
return isStringValue(value) && isStringValue(arg1) && value.startsWith(arg1);
|
|
385
|
-
}
|
|
386
|
-
var doesNotStartWith = bindNot(startsWith);
|
|
387
|
-
|
|
388
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, max-lines-per-function
|
|
389
|
-
function rules() {
|
|
390
|
-
return {
|
|
391
|
-
condition: condition,
|
|
392
|
-
doesNotEndWith: doesNotEndWith,
|
|
393
|
-
doesNotStartWith: doesNotStartWith,
|
|
394
|
-
endsWith: endsWith,
|
|
395
|
-
equals: equals,
|
|
396
|
-
greaterThan: greaterThan,
|
|
397
|
-
greaterThanOrEquals: greaterThanOrEquals,
|
|
398
|
-
gt: greaterThan,
|
|
399
|
-
gte: greaterThanOrEquals,
|
|
400
|
-
inside: inside,
|
|
401
|
-
isArray: isArray,
|
|
402
|
-
isBetween: isBetween,
|
|
403
|
-
isBlank: isBlank,
|
|
404
|
-
isBoolean: isBoolean,
|
|
405
|
-
isEmpty: isEmpty,
|
|
406
|
-
isEven: isEven,
|
|
407
|
-
isFalsy: isFalsy,
|
|
408
|
-
isNaN: isNaN$1,
|
|
409
|
-
isNegative: isNegative,
|
|
410
|
-
isNotArray: isNotArray,
|
|
411
|
-
isNotBetween: isNotBetween,
|
|
412
|
-
isNotBlank: isNotBlank,
|
|
413
|
-
isNotBoolean: isNotBoolean,
|
|
414
|
-
isNotEmpty: isNotEmpty,
|
|
415
|
-
isNotNaN: isNotNaN,
|
|
416
|
-
isNotNull: isNotNull,
|
|
417
|
-
isNotNumber: isNotNumber,
|
|
418
|
-
isNotNumeric: isNotNumeric,
|
|
419
|
-
isNotString: isNotString,
|
|
420
|
-
isNotUndefined: isNotUndefined,
|
|
421
|
-
isNull: isNull,
|
|
422
|
-
isNumber: isNumber,
|
|
423
|
-
isNumeric: isNumeric,
|
|
424
|
-
isOdd: isOdd,
|
|
425
|
-
isPositive: isPositive,
|
|
426
|
-
isString: isStringValue,
|
|
427
|
-
isTruthy: isTruthy,
|
|
428
|
-
isUndefined: isUndefined,
|
|
429
|
-
lengthEquals: lengthEquals,
|
|
430
|
-
lengthNotEquals: lengthNotEquals,
|
|
431
|
-
lessThan: lessThan,
|
|
432
|
-
lessThanOrEquals: lessThanOrEquals,
|
|
433
|
-
longerThan: longerThan,
|
|
434
|
-
longerThanOrEquals: longerThanOrEquals,
|
|
435
|
-
lt: lessThan,
|
|
436
|
-
lte: lessThanOrEquals,
|
|
437
|
-
matches: matches,
|
|
438
|
-
notEquals: notEquals,
|
|
439
|
-
notInside: notInside,
|
|
440
|
-
notMatches: notMatches,
|
|
441
|
-
numberEquals: numberEquals,
|
|
442
|
-
numberNotEquals: numberNotEquals,
|
|
443
|
-
shorterThan: shorterThan,
|
|
444
|
-
shorterThanOrEquals: shorterThanOrEquals,
|
|
445
|
-
startsWith: startsWith
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* Throws a timed out error.
|
|
451
|
-
*/
|
|
452
|
-
function throwError(devMessage, productionMessage) {
|
|
453
|
-
throw new Error(devMessage );
|
|
454
|
-
}
|
|
455
|
-
function throwErrorDeferred(devMessage, productionMessage) {
|
|
456
|
-
setTimeout(function () {
|
|
457
|
-
throwError(devMessage);
|
|
458
|
-
}, 0);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
// eslint-disable-next-line max-lines-per-function
|
|
462
|
-
function createContext(init) {
|
|
463
|
-
var storage = { ancestry: [] };
|
|
464
|
-
return {
|
|
465
|
-
bind: bind,
|
|
466
|
-
run: run,
|
|
467
|
-
use: use,
|
|
468
|
-
useX: useX
|
|
469
|
-
};
|
|
470
|
-
function useX(errorMessage) {
|
|
471
|
-
var _a;
|
|
472
|
-
return ((_a = storage.ctx) !== null && _a !== void 0 ? _a : throwError(defaultTo(errorMessage, 'Context was used after it was closed')));
|
|
473
|
-
}
|
|
474
|
-
function run(ctxRef, fn) {
|
|
475
|
-
var _a;
|
|
476
|
-
var parentContext = use();
|
|
477
|
-
var out = assign({}, parentContext ? parentContext : {}, (_a = init === null || init === void 0 ? void 0 : init(ctxRef, parentContext)) !== null && _a !== void 0 ? _a : ctxRef);
|
|
478
|
-
var ctx = set(Object.freeze(out));
|
|
479
|
-
storage.ancestry.unshift(ctx);
|
|
480
|
-
var res = fn(ctx);
|
|
481
|
-
clear();
|
|
482
|
-
return res;
|
|
483
|
-
}
|
|
484
|
-
function bind(ctxRef, fn) {
|
|
485
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
486
|
-
// @ts-ignore - this one's pretty hard to get right
|
|
487
|
-
var returnedFn = function () {
|
|
488
|
-
var runTimeArgs = [];
|
|
489
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
490
|
-
runTimeArgs[_i] = arguments[_i];
|
|
491
|
-
}
|
|
492
|
-
return run(ctxRef, function () {
|
|
493
|
-
return fn.apply(void 0, runTimeArgs);
|
|
494
|
-
});
|
|
495
|
-
};
|
|
496
|
-
return returnedFn;
|
|
497
|
-
}
|
|
498
|
-
function use() {
|
|
499
|
-
return storage.ctx;
|
|
500
|
-
}
|
|
501
|
-
function set(value) {
|
|
502
|
-
return (storage.ctx = value);
|
|
503
|
-
}
|
|
504
|
-
function clear() {
|
|
505
|
-
var _a;
|
|
506
|
-
storage.ancestry.shift();
|
|
507
|
-
set((_a = storage.ancestry[0]) !== null && _a !== void 0 ? _a : null);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
var ctx$1 = createContext(function (ctxRef, parentContext) {
|
|
512
|
-
var base = {
|
|
513
|
-
value: ctxRef.value,
|
|
514
|
-
meta: ctxRef.meta || {}
|
|
515
|
-
};
|
|
516
|
-
if (!parentContext) {
|
|
517
|
-
return assign(base, {
|
|
518
|
-
parent: emptyParent
|
|
519
|
-
});
|
|
520
|
-
}
|
|
521
|
-
else if (ctxRef.set) {
|
|
522
|
-
return assign(base, {
|
|
523
|
-
parent: function () { return stripContext(parentContext); }
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
return parentContext;
|
|
527
|
-
});
|
|
528
|
-
function stripContext(ctx) {
|
|
529
|
-
if (!ctx) {
|
|
530
|
-
return ctx;
|
|
531
|
-
}
|
|
532
|
-
return {
|
|
533
|
-
value: ctx.value,
|
|
534
|
-
meta: ctx.meta,
|
|
535
|
-
parent: ctx.parent
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
function emptyParent() {
|
|
539
|
-
return null;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
function isArrayOf(inputArray, currentRule) {
|
|
543
|
-
return defaultToPassing(mapFirst(inputArray, function (currentValue, breakout, index) {
|
|
544
|
-
var res = ctx$1.run({ value: currentValue, set: true, meta: { index: index } }, function () { return runLazyRule(currentRule, currentValue); });
|
|
545
|
-
if (!res.pass) {
|
|
546
|
-
breakout(res);
|
|
547
|
-
}
|
|
548
|
-
}));
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
function loose(inputObject, shapeObject) {
|
|
552
|
-
var _loop_1 = function (key) {
|
|
553
|
-
var currentValue = inputObject[key];
|
|
554
|
-
var currentRule = shapeObject[key];
|
|
555
|
-
var res = ctx$1.run({ value: currentValue, set: true, meta: { key: key } }, function () {
|
|
556
|
-
return runLazyRule(currentRule, currentValue);
|
|
557
|
-
});
|
|
558
|
-
if (!res.pass) {
|
|
559
|
-
return { value: res };
|
|
560
|
-
}
|
|
561
|
-
};
|
|
562
|
-
for (var key in shapeObject) {
|
|
563
|
-
var state_1 = _loop_1(key);
|
|
564
|
-
if (typeof state_1 === "object")
|
|
565
|
-
return state_1.value;
|
|
566
|
-
}
|
|
567
|
-
return passing();
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
function shape(inputObject, shapeObject) {
|
|
571
|
-
var baseRes = loose(inputObject, shapeObject);
|
|
572
|
-
if (!baseRes.pass) {
|
|
573
|
-
return baseRes;
|
|
574
|
-
}
|
|
575
|
-
for (var key in inputObject) {
|
|
576
|
-
if (!hasOwnProperty(shapeObject, key)) {
|
|
577
|
-
return failing();
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
return passing();
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
function schema() {
|
|
584
|
-
return { shape: shape, loose: loose, isArrayOf: isArrayOf };
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
var baseRules = assign(rules(), compounds(), schema());
|
|
588
|
-
function getRule(ruleName) {
|
|
589
|
-
return baseRules[ruleName];
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
function eachEnforceRule(action) {
|
|
593
|
-
for (var ruleName in baseRules) {
|
|
594
|
-
var ruleFn = getRule(ruleName);
|
|
595
|
-
if (isFunction(ruleFn)) {
|
|
596
|
-
action(ruleName, ruleFn);
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
function isProxySupported() {
|
|
602
|
-
try {
|
|
603
|
-
return isFunction(Proxy);
|
|
604
|
-
}
|
|
605
|
-
catch (_a) {
|
|
606
|
-
return false;
|
|
607
|
-
}
|
|
608
|
-
}
|
|
5
|
+
var n4s = require('n4s');
|
|
6
|
+
var context$1 = require('context');
|
|
7
|
+
|
|
8
|
+
var assign = Object.assign;
|
|
609
9
|
|
|
610
10
|
/**
|
|
611
|
-
*
|
|
11
|
+
* @returns a unique numeric id.
|
|
612
12
|
*/
|
|
613
|
-
function
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
args[_i - 3] = arguments[_i];
|
|
617
|
-
}
|
|
618
|
-
validateResult(result);
|
|
619
|
-
// if result is boolean
|
|
620
|
-
if (isBoolean(result)) {
|
|
621
|
-
return ruleReturn(result);
|
|
622
|
-
}
|
|
623
|
-
else {
|
|
624
|
-
return ruleReturn(result.pass, optionalFunctionValue.apply(void 0, __spreadArray([result.message, ruleName, value], args)));
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
function validateResult(result) {
|
|
628
|
-
// if result is boolean, or if result.pass is boolean
|
|
629
|
-
if (isBoolean(result) || (result && isBoolean(result.pass))) {
|
|
630
|
-
return;
|
|
631
|
-
}
|
|
632
|
-
throwError('Incorrect return value for rule: ' + JSON.stringify(result));
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
function enforceEager(value) {
|
|
636
|
-
var target = {};
|
|
637
|
-
if (!isProxySupported()) {
|
|
638
|
-
eachEnforceRule(function (ruleName, ruleFn) {
|
|
639
|
-
target[ruleName] = genRuleCall(target, ruleFn, ruleName);
|
|
640
|
-
});
|
|
641
|
-
return target;
|
|
642
|
-
}
|
|
643
|
-
var proxy = new Proxy(target, {
|
|
644
|
-
get: function (_, ruleName) {
|
|
645
|
-
var rule = getRule(ruleName);
|
|
646
|
-
if (rule) {
|
|
647
|
-
return genRuleCall(proxy, rule, ruleName);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
});
|
|
651
|
-
return proxy;
|
|
652
|
-
function genRuleCall(target, rule, ruleName) {
|
|
653
|
-
return function ruleCall() {
|
|
654
|
-
var args = [];
|
|
655
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
656
|
-
args[_i] = arguments[_i];
|
|
657
|
-
}
|
|
658
|
-
var transformedResult = transformResult.apply(void 0, __spreadArray([ctx$1.run({ value: value }, function () { return rule.apply(void 0, __spreadArray([value], args)); }),
|
|
659
|
-
ruleName,
|
|
660
|
-
value], args));
|
|
661
|
-
if (!transformedResult.pass) {
|
|
662
|
-
if (isEmpty(transformedResult.message)) {
|
|
663
|
-
throwError("enforce/" + ruleName + " failed with " + JSON.stringify(value));
|
|
664
|
-
}
|
|
665
|
-
else {
|
|
666
|
-
// Explicitly throw a string so that vest.test can pick it up as the validation error message
|
|
667
|
-
throw transformedResult.message;
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
return target;
|
|
671
|
-
};
|
|
672
|
-
}
|
|
673
|
-
}
|
|
13
|
+
var genId = (function (n) { return function () {
|
|
14
|
+
return "" + n++;
|
|
15
|
+
}; })(0);
|
|
674
16
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
var registeredRules = [];
|
|
678
|
-
var lazyMessage;
|
|
679
|
-
return addLazyRule(key);
|
|
680
|
-
// eslint-disable-next-line max-lines-per-function
|
|
681
|
-
function addLazyRule(ruleName) {
|
|
682
|
-
// eslint-disable-next-line max-lines-per-function
|
|
683
|
-
return function () {
|
|
684
|
-
var args = [];
|
|
685
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
686
|
-
args[_i] = arguments[_i];
|
|
687
|
-
}
|
|
688
|
-
var rule = getRule(ruleName);
|
|
689
|
-
registeredRules.push(function (value) {
|
|
690
|
-
return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args)), ruleName, value], args));
|
|
691
|
-
});
|
|
692
|
-
var proxy = {
|
|
693
|
-
run: function (value) {
|
|
694
|
-
return defaultToPassing(mapFirst(registeredRules, function (rule, breakout) {
|
|
695
|
-
var _a;
|
|
696
|
-
var res = ctx$1.run({ value: value }, function () { return rule(value); });
|
|
697
|
-
if (!res.pass) {
|
|
698
|
-
breakout(ruleReturn(!!res.pass, (_a = optionalFunctionValue(lazyMessage, value, res.message)) !== null && _a !== void 0 ? _a : res.message));
|
|
699
|
-
}
|
|
700
|
-
}));
|
|
701
|
-
},
|
|
702
|
-
test: function (value) { return proxy.run(value).pass; },
|
|
703
|
-
message: function (message) {
|
|
704
|
-
if (message) {
|
|
705
|
-
lazyMessage = message;
|
|
706
|
-
}
|
|
707
|
-
return proxy;
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
if (!isProxySupported()) {
|
|
711
|
-
eachEnforceRule(function (ruleName) {
|
|
712
|
-
proxy[ruleName] = addLazyRule(ruleName);
|
|
713
|
-
});
|
|
714
|
-
return proxy;
|
|
715
|
-
}
|
|
716
|
-
// reassigning the proxy here is not pretty
|
|
717
|
-
// but it's a cleaner way of getting `run` and `test` for free
|
|
718
|
-
proxy = new Proxy(proxy, {
|
|
719
|
-
get: function (target, key) {
|
|
720
|
-
if (getRule(key)) {
|
|
721
|
-
return addLazyRule(key);
|
|
722
|
-
}
|
|
723
|
-
return target[key]; // already has `run` and `test` on it
|
|
724
|
-
}
|
|
725
|
-
});
|
|
726
|
-
return proxy;
|
|
727
|
-
};
|
|
728
|
-
}
|
|
17
|
+
function isFunction(value) {
|
|
18
|
+
return typeof value === 'function';
|
|
729
19
|
}
|
|
730
20
|
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
for (var key in shapeObject) {
|
|
736
|
-
output[key] = enforce.optional(shapeObject[key]);
|
|
21
|
+
function optionalFunctionValue(value) {
|
|
22
|
+
var args = [];
|
|
23
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
24
|
+
args[_i - 1] = arguments[_i];
|
|
737
25
|
}
|
|
738
|
-
return
|
|
26
|
+
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
739
27
|
}
|
|
740
28
|
|
|
741
|
-
function
|
|
742
|
-
|
|
29
|
+
function defaultTo(callback, defaultValue) {
|
|
30
|
+
var _a;
|
|
31
|
+
return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
|
|
743
32
|
}
|
|
744
33
|
|
|
745
34
|
/**
|
|
746
|
-
*
|
|
747
|
-
* It is dynamic in nature, so a lot of proxy objects are involved.
|
|
748
|
-
*
|
|
749
|
-
* Enforce has two main interfaces
|
|
750
|
-
* 1. eager
|
|
751
|
-
* 2. lazy
|
|
752
|
-
*
|
|
753
|
-
* The eager interface is the most commonly used, and the easier to understand.
|
|
754
|
-
* It throws an error when a rule is not satisfied.
|
|
755
|
-
* The eager interface is declared in enforceEager.ts and it is quite simple to understand.
|
|
756
|
-
* enforce is called with a value, and the return value is a proxy object that points back to all the rules.
|
|
757
|
-
* When a rule is called, the value is mapped as its first argument, and if the rule passes, the same
|
|
758
|
-
* proxy object is returned. Otherwise, an error is thrown.
|
|
759
|
-
*
|
|
760
|
-
* The lazy interface works quite differently. It is declared in genEnforceLazy.ts.
|
|
761
|
-
* Rather than calling enforce directly, the lazy interface has all the rules as "methods" (only by proxy).
|
|
762
|
-
* Calling the first function in the chain will initialize an array of calls. It stores the different rule calls
|
|
763
|
-
* and the parameters passed to them. None of the rules are called yet.
|
|
764
|
-
* The rules are only invoked in sequence once either of these chained functions are called:
|
|
765
|
-
* 1. test(value)
|
|
766
|
-
* 2. run(value)
|
|
767
|
-
*
|
|
768
|
-
* Calling run or test will call all the rules in sequence, with the difference that test will only return a boolean value,
|
|
769
|
-
* while run will return an object with the validation result and an optional message created by the rule.
|
|
35
|
+
* Throws a timed out error.
|
|
770
36
|
*/
|
|
771
|
-
function
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
target[ruleName] = genEnforceLazy(ruleName);
|
|
779
|
-
});
|
|
780
|
-
return target;
|
|
781
|
-
}
|
|
782
|
-
return new Proxy(assign(enforceEager, target), {
|
|
783
|
-
get: function (target, key) {
|
|
784
|
-
if (key in target) {
|
|
785
|
-
return target[key];
|
|
786
|
-
}
|
|
787
|
-
if (!getRule(key)) {
|
|
788
|
-
return;
|
|
789
|
-
}
|
|
790
|
-
// Only on the first rule access - start the chain of calls
|
|
791
|
-
return genEnforceLazy(key);
|
|
792
|
-
}
|
|
793
|
-
});
|
|
37
|
+
function throwError(devMessage, productionMessage) {
|
|
38
|
+
throw new Error(devMessage );
|
|
39
|
+
}
|
|
40
|
+
function throwErrorDeferred(devMessage, productionMessage) {
|
|
41
|
+
setTimeout(function () {
|
|
42
|
+
throwError(devMessage);
|
|
43
|
+
}, 0);
|
|
794
44
|
}
|
|
795
|
-
var enforce = genEnforce();
|
|
796
|
-
|
|
797
|
-
/**
|
|
798
|
-
* @returns a unique numeric id.
|
|
799
|
-
*/
|
|
800
|
-
var genId = (function (n) { return function () {
|
|
801
|
-
return "" + n++;
|
|
802
|
-
}; })(0);
|
|
803
45
|
|
|
804
46
|
// eslint-disable-next-line max-lines-per-function
|
|
805
47
|
function createState(onStateChange) {
|
|
@@ -875,17 +117,18 @@ var IsolateTypes;
|
|
|
875
117
|
})(IsolateTypes || (IsolateTypes = {}));
|
|
876
118
|
|
|
877
119
|
function createStateRef(state, _a) {
|
|
878
|
-
var suiteId = _a.suiteId;
|
|
120
|
+
var suiteId = _a.suiteId, suiteName = _a.suiteName;
|
|
879
121
|
return {
|
|
880
122
|
optionalFields: state.registerStateKey(function () { return ({}); }),
|
|
881
123
|
suiteId: state.registerStateKey(suiteId),
|
|
124
|
+
suiteName: state.registerStateKey(suiteName),
|
|
882
125
|
testCallbacks: state.registerStateKey(function () { return ({
|
|
883
126
|
fieldCallbacks: {},
|
|
884
127
|
doneCallbacks: []
|
|
885
128
|
}); }),
|
|
886
129
|
testObjects: state.registerStateKey(function (prev) {
|
|
887
130
|
return {
|
|
888
|
-
prev:
|
|
131
|
+
prev: prev ? prev.current : [],
|
|
889
132
|
current: []
|
|
890
133
|
};
|
|
891
134
|
})
|
|
@@ -898,8 +141,7 @@ function asArray(possibleArg) {
|
|
|
898
141
|
|
|
899
142
|
function last(values) {
|
|
900
143
|
var valuesArray = asArray(values);
|
|
901
|
-
|
|
902
|
-
return lastValue;
|
|
144
|
+
return valuesArray[valuesArray.length - 1];
|
|
903
145
|
}
|
|
904
146
|
|
|
905
147
|
function createCursor() {
|
|
@@ -936,19 +178,47 @@ function createCursor() {
|
|
|
936
178
|
};
|
|
937
179
|
}
|
|
938
180
|
|
|
939
|
-
var
|
|
181
|
+
var context = context$1.createContext(function (ctxRef, parentContext) {
|
|
940
182
|
return parentContext
|
|
941
183
|
? null
|
|
942
184
|
: assign({}, {
|
|
943
|
-
isolate: { type: IsolateTypes.DEFAULT },
|
|
944
|
-
testCursor: createCursor(),
|
|
945
185
|
exclusion: {
|
|
946
186
|
tests: {},
|
|
947
187
|
groups: {}
|
|
948
|
-
}
|
|
188
|
+
},
|
|
189
|
+
isolate: {
|
|
190
|
+
type: IsolateTypes.DEFAULT,
|
|
191
|
+
keys: {
|
|
192
|
+
current: {},
|
|
193
|
+
prev: {}
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
testCursor: createCursor()
|
|
949
197
|
}, ctxRef);
|
|
950
198
|
});
|
|
951
199
|
|
|
200
|
+
function bindNot(fn) {
|
|
201
|
+
return function () {
|
|
202
|
+
var args = [];
|
|
203
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
204
|
+
args[_i] = arguments[_i];
|
|
205
|
+
}
|
|
206
|
+
return !fn.apply(void 0, args);
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// The module is named "isArrayValue" since it
|
|
211
|
+
// is conflicting with a nested npm dependency.
|
|
212
|
+
// We may need to revisit this in the future.
|
|
213
|
+
function isArray(value) {
|
|
214
|
+
return Boolean(Array.isArray(value));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function isNull(value) {
|
|
218
|
+
return value === null;
|
|
219
|
+
}
|
|
220
|
+
var isNotNull = bindNot(isNull);
|
|
221
|
+
|
|
952
222
|
// This is sort of a map/filter in one function.
|
|
953
223
|
// Normally, behaves like a nested-array map
|
|
954
224
|
// Returning `null` will drop the element from the array
|
|
@@ -994,6 +264,31 @@ function getCurrent(array, path) {
|
|
|
994
264
|
return current;
|
|
995
265
|
}
|
|
996
266
|
|
|
267
|
+
function isUndefined(value) {
|
|
268
|
+
return value === undefined;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function isNullish(value) {
|
|
272
|
+
return isNull(value) || isUndefined(value);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function isStringValue(v) {
|
|
276
|
+
return String(v) === v;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function shouldUseErrorAsMessage(message, error) {
|
|
280
|
+
// kind of cheating with this safe guard, but it does the job
|
|
281
|
+
return isUndefined(message) && isStringValue(error);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function lengthEquals(value, arg1) {
|
|
285
|
+
return value.length === Number(arg1);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function longerThan(value, arg1) {
|
|
289
|
+
return value.length > Number(arg1);
|
|
290
|
+
}
|
|
291
|
+
|
|
997
292
|
/**
|
|
998
293
|
* Creates a cache function
|
|
999
294
|
*/
|
|
@@ -1035,11 +330,14 @@ function createCache(maxSize) {
|
|
|
1035
330
|
// STATE REF
|
|
1036
331
|
function useStateRef() {
|
|
1037
332
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1038
|
-
return
|
|
333
|
+
return context.useX().stateRef; // I should revisit this
|
|
1039
334
|
}
|
|
1040
335
|
// STATE KEYS
|
|
1041
336
|
function useSuiteId() {
|
|
1042
|
-
return useStateRef().suiteId();
|
|
337
|
+
return useStateRef().suiteId()[0];
|
|
338
|
+
}
|
|
339
|
+
function useSuiteName() {
|
|
340
|
+
return useStateRef().suiteName()[0];
|
|
1043
341
|
}
|
|
1044
342
|
function useTestCallbacks() {
|
|
1045
343
|
return useStateRef().testCallbacks();
|
|
@@ -1096,25 +394,187 @@ function useTestsFlat() {
|
|
|
1096
394
|
return flatCache([current], function () { return flatten(current); });
|
|
1097
395
|
}
|
|
1098
396
|
|
|
397
|
+
var TestSeverity;
|
|
398
|
+
(function (TestSeverity) {
|
|
399
|
+
TestSeverity["Error"] = "error";
|
|
400
|
+
TestSeverity["Warning"] = "warning";
|
|
401
|
+
})(TestSeverity || (TestSeverity = {}));
|
|
402
|
+
var VestTest = /** @class */ (function () {
|
|
403
|
+
function VestTest(fieldName, testFn, _a) {
|
|
404
|
+
var _b = _a === void 0 ? {} : _a, message = _b.message, groupName = _b.groupName, key = _b.key;
|
|
405
|
+
this.key = null;
|
|
406
|
+
this.id = genId();
|
|
407
|
+
this.severity = TestSeverity.Error;
|
|
408
|
+
this.status = STATUS_UNTESTED;
|
|
409
|
+
this.fieldName = fieldName;
|
|
410
|
+
this.testFn = testFn;
|
|
411
|
+
if (groupName) {
|
|
412
|
+
this.groupName = groupName;
|
|
413
|
+
}
|
|
414
|
+
if (message) {
|
|
415
|
+
this.message = message;
|
|
416
|
+
}
|
|
417
|
+
if (key) {
|
|
418
|
+
this.key = key;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
VestTest.prototype.run = function () {
|
|
422
|
+
var result;
|
|
423
|
+
try {
|
|
424
|
+
result = this.testFn();
|
|
425
|
+
}
|
|
426
|
+
catch (error) {
|
|
427
|
+
if (shouldUseErrorAsMessage(this.message, error)) {
|
|
428
|
+
this.message = error;
|
|
429
|
+
}
|
|
430
|
+
result = false;
|
|
431
|
+
}
|
|
432
|
+
if (result === false) {
|
|
433
|
+
this.fail();
|
|
434
|
+
}
|
|
435
|
+
return result;
|
|
436
|
+
};
|
|
437
|
+
VestTest.prototype.setStatus = function (status) {
|
|
438
|
+
if (this.isFinalStatus() && status !== STATUS_OMITTED) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
this.status = status;
|
|
442
|
+
};
|
|
443
|
+
VestTest.prototype.warns = function () {
|
|
444
|
+
return this.severity === TestSeverity.Warning;
|
|
445
|
+
};
|
|
446
|
+
VestTest.prototype.setPending = function () {
|
|
447
|
+
this.setStatus(STATUS_PENDING);
|
|
448
|
+
};
|
|
449
|
+
VestTest.prototype.fail = function () {
|
|
450
|
+
this.setStatus(this.warns() ? STATUS_WARNING : STATUS_FAILED);
|
|
451
|
+
};
|
|
452
|
+
VestTest.prototype.done = function () {
|
|
453
|
+
if (this.isFinalStatus()) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
this.setStatus(STATUS_PASSING);
|
|
457
|
+
};
|
|
458
|
+
VestTest.prototype.warn = function () {
|
|
459
|
+
this.severity = TestSeverity.Warning;
|
|
460
|
+
};
|
|
461
|
+
VestTest.prototype.isFinalStatus = function () {
|
|
462
|
+
return this.hasFailures() || this.isCanceled() || this.isPassing();
|
|
463
|
+
};
|
|
464
|
+
VestTest.prototype.skip = function (force) {
|
|
465
|
+
if (this.isPending() && !force) {
|
|
466
|
+
// Without this condition, the test will be marked as skipped even if it is pending.
|
|
467
|
+
// This means that it will not be counted in "allIncomplete" and its done callbacks
|
|
468
|
+
// will not be called, or will be called prematurely.
|
|
469
|
+
// What this mostly say is that when we have a pending test for one field, and we then
|
|
470
|
+
// start typing in a different field - the pending test will be canceled, which
|
|
471
|
+
// is usually an unwanted behavior.
|
|
472
|
+
// The only scenario in which we DO want to cancel the async test regardless
|
|
473
|
+
// is when we specifically skip a test with `skipWhen`, which is handled by the
|
|
474
|
+
// "force" boolean flag.
|
|
475
|
+
// I am not a fan of this flag, but it gets the job done.
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
this.setStatus(STATUS_SKIPPED);
|
|
479
|
+
};
|
|
480
|
+
VestTest.prototype.cancel = function () {
|
|
481
|
+
this.setStatus(STATUS_CANCELED);
|
|
482
|
+
useRefreshTestObjects();
|
|
483
|
+
};
|
|
484
|
+
VestTest.prototype.omit = function () {
|
|
485
|
+
this.setStatus(STATUS_OMITTED);
|
|
486
|
+
};
|
|
487
|
+
VestTest.prototype.valueOf = function () {
|
|
488
|
+
return !this.isFailing();
|
|
489
|
+
};
|
|
490
|
+
VestTest.prototype.hasFailures = function () {
|
|
491
|
+
return this.isFailing() || this.isWarning();
|
|
492
|
+
};
|
|
493
|
+
VestTest.prototype.isPending = function () {
|
|
494
|
+
return this.status === STATUS_PENDING;
|
|
495
|
+
};
|
|
496
|
+
VestTest.prototype.isTested = function () {
|
|
497
|
+
return this.hasFailures() || this.isPassing();
|
|
498
|
+
};
|
|
499
|
+
VestTest.prototype.isOmitted = function () {
|
|
500
|
+
return this.status === STATUS_OMITTED;
|
|
501
|
+
};
|
|
502
|
+
VestTest.prototype.isUntested = function () {
|
|
503
|
+
return this.status === STATUS_UNTESTED;
|
|
504
|
+
};
|
|
505
|
+
VestTest.prototype.isFailing = function () {
|
|
506
|
+
return this.status === STATUS_FAILED;
|
|
507
|
+
};
|
|
508
|
+
VestTest.prototype.isCanceled = function () {
|
|
509
|
+
return this.status === STATUS_CANCELED;
|
|
510
|
+
};
|
|
511
|
+
VestTest.prototype.isSkipped = function () {
|
|
512
|
+
return this.status === STATUS_SKIPPED;
|
|
513
|
+
};
|
|
514
|
+
VestTest.prototype.isPassing = function () {
|
|
515
|
+
return this.status === STATUS_PASSING;
|
|
516
|
+
};
|
|
517
|
+
VestTest.prototype.isWarning = function () {
|
|
518
|
+
return this.status === STATUS_WARNING;
|
|
519
|
+
};
|
|
520
|
+
return VestTest;
|
|
521
|
+
}());
|
|
522
|
+
var STATUS_UNTESTED = 'UNTESTED';
|
|
523
|
+
var STATUS_SKIPPED = 'SKIPPED';
|
|
524
|
+
var STATUS_FAILED = 'FAILED';
|
|
525
|
+
var STATUS_WARNING = 'WARNING';
|
|
526
|
+
var STATUS_PASSING = 'PASSING';
|
|
527
|
+
var STATUS_PENDING = 'PENDING';
|
|
528
|
+
var STATUS_CANCELED = 'CANCELED';
|
|
529
|
+
var STATUS_OMITTED = 'OMITTED';
|
|
530
|
+
|
|
1099
531
|
function usePath() {
|
|
1100
|
-
var context =
|
|
1101
|
-
return context.testCursor.getCursor();
|
|
532
|
+
var context$1 = context.useX();
|
|
533
|
+
return context$1.testCursor.getCursor();
|
|
1102
534
|
}
|
|
1103
535
|
function useCursorAt() {
|
|
1104
|
-
var context =
|
|
1105
|
-
return context.testCursor.cursorAt();
|
|
536
|
+
var context$1 = context.useX();
|
|
537
|
+
return context$1.testCursor.cursorAt();
|
|
1106
538
|
}
|
|
1107
539
|
function moveForward() {
|
|
1108
|
-
var context =
|
|
1109
|
-
return context.testCursor.next();
|
|
540
|
+
var context$1 = context.useX();
|
|
541
|
+
return context$1.testCursor.next();
|
|
1110
542
|
}
|
|
1111
543
|
function addLevel() {
|
|
1112
|
-
var context =
|
|
1113
|
-
context.testCursor.addLevel();
|
|
544
|
+
var context$1 = context.useX();
|
|
545
|
+
context$1.testCursor.addLevel();
|
|
1114
546
|
}
|
|
1115
547
|
function removeLevel() {
|
|
1116
|
-
var context =
|
|
1117
|
-
context.testCursor.removeLevel();
|
|
548
|
+
var context$1 = context.useX();
|
|
549
|
+
context$1.testCursor.removeLevel();
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function usePrevKeys() {
|
|
553
|
+
var prev = useTestObjects()[0].prev;
|
|
554
|
+
return asArray(getCurrent(prev, usePath())).reduce(function (prevKeys, testObject) {
|
|
555
|
+
if (!(testObject instanceof VestTest)) {
|
|
556
|
+
return prevKeys;
|
|
557
|
+
}
|
|
558
|
+
if (isNullish(testObject.key)) {
|
|
559
|
+
return prevKeys;
|
|
560
|
+
}
|
|
561
|
+
prevKeys[testObject.key] = testObject;
|
|
562
|
+
return prevKeys;
|
|
563
|
+
}, {});
|
|
564
|
+
}
|
|
565
|
+
function usePrevTestByKey(key) {
|
|
566
|
+
var prev = context.useX().isolate.keys.prev;
|
|
567
|
+
return prev[key];
|
|
568
|
+
}
|
|
569
|
+
function useRetainTestKey(key, testObject) {
|
|
570
|
+
var context$1 = context.useX();
|
|
571
|
+
var current = context$1.isolate.keys.current;
|
|
572
|
+
if (isNullish(current[key])) {
|
|
573
|
+
current[key] = testObject;
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
throwErrorDeferred("Encountered the same test key \"" + key + "\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.");
|
|
577
|
+
}
|
|
1118
578
|
}
|
|
1119
579
|
|
|
1120
580
|
function isolate(_a, callback) {
|
|
@@ -1122,9 +582,14 @@ function isolate(_a, callback) {
|
|
|
1122
582
|
if (!isFunction(callback)) {
|
|
1123
583
|
return;
|
|
1124
584
|
}
|
|
585
|
+
var keys = {
|
|
586
|
+
current: {},
|
|
587
|
+
prev: {}
|
|
588
|
+
};
|
|
1125
589
|
var path = usePath();
|
|
1126
|
-
return
|
|
590
|
+
return context.run({ isolate: { type: type, keys: keys } }, function () {
|
|
1127
591
|
addLevel();
|
|
592
|
+
keys.prev = usePrevKeys();
|
|
1128
593
|
useSetTests(function (tests) { return setValueAtPath(tests, path, []); });
|
|
1129
594
|
var res = callback();
|
|
1130
595
|
removeLevel();
|
|
@@ -1132,9 +597,37 @@ function isolate(_a, callback) {
|
|
|
1132
597
|
return res;
|
|
1133
598
|
});
|
|
1134
599
|
}
|
|
1135
|
-
function shouldAllowReorder() {
|
|
1136
|
-
return
|
|
600
|
+
function shouldAllowReorder() {
|
|
601
|
+
return context.useX().isolate.type === IsolateTypes.EACH;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* A safe hasOwnProperty access
|
|
606
|
+
*/
|
|
607
|
+
function hasOwnProperty(obj, key) {
|
|
608
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
function isNumber(value) {
|
|
612
|
+
return Boolean(typeof value === 'number');
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function isEmpty(value) {
|
|
616
|
+
if (!value) {
|
|
617
|
+
return true;
|
|
618
|
+
}
|
|
619
|
+
else if (isNumber(value)) {
|
|
620
|
+
return value === 0;
|
|
621
|
+
}
|
|
622
|
+
else if (hasOwnProperty(value, 'length')) {
|
|
623
|
+
return lengthEquals(value, 0);
|
|
624
|
+
}
|
|
625
|
+
else if (typeof value === 'object') {
|
|
626
|
+
return lengthEquals(Object.keys(value), 0);
|
|
627
|
+
}
|
|
628
|
+
return true;
|
|
1137
629
|
}
|
|
630
|
+
var isNotEmpty = bindNot(isEmpty);
|
|
1138
631
|
|
|
1139
632
|
function nonMatchingFieldName(testObject, fieldName) {
|
|
1140
633
|
return !!fieldName && !matchingFieldName(testObject, fieldName);
|
|
@@ -1223,6 +716,42 @@ function genTestObject(summaryKey, testObject) {
|
|
|
1223
716
|
return testKey;
|
|
1224
717
|
}
|
|
1225
718
|
|
|
719
|
+
/*! *****************************************************************************
|
|
720
|
+
Copyright (c) Microsoft Corporation.
|
|
721
|
+
|
|
722
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
723
|
+
purpose with or without fee is hereby granted.
|
|
724
|
+
|
|
725
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
726
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
727
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
728
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
729
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
730
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
731
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
732
|
+
***************************************************************************** */
|
|
733
|
+
|
|
734
|
+
var __assign = function() {
|
|
735
|
+
__assign = Object.assign || function __assign(t) {
|
|
736
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
737
|
+
s = arguments[i];
|
|
738
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
739
|
+
}
|
|
740
|
+
return t;
|
|
741
|
+
};
|
|
742
|
+
return __assign.apply(this, arguments);
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
function __spreadArray(to, from, pack) {
|
|
746
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
747
|
+
if (ar || !(i in from)) {
|
|
748
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
749
|
+
ar[i] = from[i];
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return to.concat(ar || from);
|
|
753
|
+
}
|
|
754
|
+
|
|
1226
755
|
function either(a, b) {
|
|
1227
756
|
return !!a !== !!b;
|
|
1228
757
|
}
|
|
@@ -1231,7 +760,7 @@ function either(a, b) {
|
|
|
1231
760
|
* Checks that a given test object matches the currently specified severity level
|
|
1232
761
|
*/
|
|
1233
762
|
function nonMatchingSeverityProfile(severity, testObject) {
|
|
1234
|
-
return either(severity === 'warnings', testObject.warns);
|
|
763
|
+
return either(severity === 'warnings', testObject.warns());
|
|
1235
764
|
}
|
|
1236
765
|
|
|
1237
766
|
function collectFailureMessages(severity, testObjects, options) {
|
|
@@ -1416,19 +945,21 @@ var cache$1 = createCache(20);
|
|
|
1416
945
|
function produceDraft() {
|
|
1417
946
|
var testObjects = useTestsFlat();
|
|
1418
947
|
var ctxRef = { stateRef: useStateRef() };
|
|
1419
|
-
return cache$1([testObjects],
|
|
948
|
+
return cache$1([testObjects], context.bind(ctxRef, function () {
|
|
949
|
+
var suiteName = useSuiteName();
|
|
1420
950
|
return assign(genTestsSummary(), {
|
|
1421
|
-
getErrors:
|
|
1422
|
-
getErrorsByGroup:
|
|
1423
|
-
getWarnings:
|
|
1424
|
-
getWarningsByGroup:
|
|
1425
|
-
hasErrors:
|
|
1426
|
-
hasErrorsByGroup:
|
|
1427
|
-
hasWarnings:
|
|
1428
|
-
hasWarningsByGroup:
|
|
1429
|
-
isValid:
|
|
951
|
+
getErrors: context.bind(ctxRef, getErrors),
|
|
952
|
+
getErrorsByGroup: context.bind(ctxRef, getErrorsByGroup),
|
|
953
|
+
getWarnings: context.bind(ctxRef, getWarnings),
|
|
954
|
+
getWarningsByGroup: context.bind(ctxRef, getWarningsByGroup),
|
|
955
|
+
hasErrors: context.bind(ctxRef, hasErrors),
|
|
956
|
+
hasErrorsByGroup: context.bind(ctxRef, hasErrorsByGroup),
|
|
957
|
+
hasWarnings: context.bind(ctxRef, hasWarnings),
|
|
958
|
+
hasWarningsByGroup: context.bind(ctxRef, hasWarningsByGroup),
|
|
959
|
+
isValid: context.bind(ctxRef, function (fieldName) {
|
|
1430
960
|
return isValid(produceDraft(), fieldName);
|
|
1431
|
-
})
|
|
961
|
+
}),
|
|
962
|
+
suiteName: suiteName
|
|
1432
963
|
});
|
|
1433
964
|
}));
|
|
1434
965
|
}
|
|
@@ -1437,9 +968,9 @@ var cache = createCache(20);
|
|
|
1437
968
|
function produceFullResult() {
|
|
1438
969
|
var testObjects = useTestsFlat();
|
|
1439
970
|
var ctxRef = { stateRef: useStateRef() };
|
|
1440
|
-
return cache([testObjects],
|
|
971
|
+
return cache([testObjects], context.bind(ctxRef, function () {
|
|
1441
972
|
return assign({}, produceDraft(), {
|
|
1442
|
-
done:
|
|
973
|
+
done: context.bind(ctxRef, done)
|
|
1443
974
|
});
|
|
1444
975
|
}));
|
|
1445
976
|
}
|
|
@@ -1450,7 +981,7 @@ function shouldSkipDoneRegistration(callback, fieldName, output) {
|
|
|
1450
981
|
// If we do not have any test runs for the current field
|
|
1451
982
|
return !!(!isFunction(callback) ||
|
|
1452
983
|
(fieldName &&
|
|
1453
|
-
(!output.tests[fieldName] || output.tests[fieldName].testCount
|
|
984
|
+
(!output.tests[fieldName] || isEmpty(output.tests[fieldName].testCount))));
|
|
1454
985
|
}
|
|
1455
986
|
function shouldRunDoneCallback(fieldName) {
|
|
1456
987
|
// is suite finished || field name exists, and test is finished;
|
|
@@ -1480,7 +1011,7 @@ var done = function done() {
|
|
|
1480
1011
|
return output;
|
|
1481
1012
|
};
|
|
1482
1013
|
function deferDoneCallback(doneCallback, fieldName) {
|
|
1483
|
-
var deferredCallback =
|
|
1014
|
+
var deferredCallback = context.bind({}, doneCallback);
|
|
1484
1015
|
var _a = useTestCallbacks(), setTestCallbacks = _a[1];
|
|
1485
1016
|
setTestCallbacks(function (current) {
|
|
1486
1017
|
if (fieldName) {
|
|
@@ -1612,11 +1143,11 @@ function initBus() {
|
|
|
1612
1143
|
return bus;
|
|
1613
1144
|
}
|
|
1614
1145
|
function useBus() {
|
|
1615
|
-
var context =
|
|
1616
|
-
if (!context.bus) {
|
|
1146
|
+
var context$1 = context.useX();
|
|
1147
|
+
if (!context$1.bus) {
|
|
1617
1148
|
throwError();
|
|
1618
1149
|
}
|
|
1619
|
-
return context.bus;
|
|
1150
|
+
return context$1.bus;
|
|
1620
1151
|
}
|
|
1621
1152
|
var Events;
|
|
1622
1153
|
(function (Events) {
|
|
@@ -1626,7 +1157,12 @@ var Events;
|
|
|
1626
1157
|
})(Events || (Events = {}));
|
|
1627
1158
|
|
|
1628
1159
|
// eslint-disable-next-line max-lines-per-function
|
|
1629
|
-
function create(
|
|
1160
|
+
function create() {
|
|
1161
|
+
var args = [];
|
|
1162
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1163
|
+
args[_i] = arguments[_i];
|
|
1164
|
+
}
|
|
1165
|
+
var _a = args.reverse(), suiteCallback = _a[0], suiteName = _a[1];
|
|
1630
1166
|
if (!isFunction(suiteCallback)) {
|
|
1631
1167
|
throwError('vest.create: Expected callback to be a function.');
|
|
1632
1168
|
}
|
|
@@ -1635,12 +1171,12 @@ function create(suiteCallback) {
|
|
|
1635
1171
|
// State initialization
|
|
1636
1172
|
var state = createState();
|
|
1637
1173
|
// State reference - this holds the actual state values
|
|
1638
|
-
var stateRef = createStateRef(state, { suiteId: genId() });
|
|
1174
|
+
var stateRef = createStateRef(state, { suiteId: genId(), suiteName: suiteName });
|
|
1639
1175
|
// Create base context reference. All hooks will derive their data from this
|
|
1640
1176
|
var ctxRef = { stateRef: stateRef, bus: bus };
|
|
1641
1177
|
var suite = assign(
|
|
1642
1178
|
// Bind the suite body to the context
|
|
1643
|
-
|
|
1179
|
+
context.bind(ctxRef, function () {
|
|
1644
1180
|
var args = [];
|
|
1645
1181
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1646
1182
|
args[_i] = arguments[_i];
|
|
@@ -1658,15 +1194,26 @@ function create(suiteCallback) {
|
|
|
1658
1194
|
// Return the result
|
|
1659
1195
|
return produceFullResult();
|
|
1660
1196
|
}), {
|
|
1661
|
-
get:
|
|
1197
|
+
get: context.bind(ctxRef, produceDraft),
|
|
1662
1198
|
reset: state.reset,
|
|
1663
|
-
remove:
|
|
1199
|
+
remove: context.bind(ctxRef, function (fieldName) {
|
|
1664
1200
|
bus.emit(Events.REMOVE_FIELD, fieldName);
|
|
1665
1201
|
})
|
|
1666
1202
|
});
|
|
1667
1203
|
return suite;
|
|
1668
1204
|
}
|
|
1669
1205
|
|
|
1206
|
+
function each(list, callback) {
|
|
1207
|
+
if (!isFunction(callback)) {
|
|
1208
|
+
throwError('callback must be a function');
|
|
1209
|
+
}
|
|
1210
|
+
isolate({ type: IsolateTypes.EACH }, function () {
|
|
1211
|
+
list.forEach(function (arg, index) {
|
|
1212
|
+
callback(arg, index);
|
|
1213
|
+
});
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1670
1217
|
/**
|
|
1671
1218
|
* Error message to display when a hook was called outside of context.
|
|
1672
1219
|
*/
|
|
@@ -1690,14 +1237,17 @@ function skip(item) {
|
|
|
1690
1237
|
skip.group = function (item) {
|
|
1691
1238
|
return addTo(1 /* SKIP */, 'groups', item);
|
|
1692
1239
|
};
|
|
1240
|
+
function isExcludedIndividually() {
|
|
1241
|
+
return !!context.useX().skipped;
|
|
1242
|
+
}
|
|
1693
1243
|
//Checks whether a certain test profile excluded by any of the exclusion groups.
|
|
1694
1244
|
// eslint-disable-next-line complexity, max-statements
|
|
1695
1245
|
function isExcluded(testObject) {
|
|
1696
1246
|
var fieldName = testObject.fieldName, groupName = testObject.groupName;
|
|
1697
|
-
|
|
1698
|
-
if (context.skipped)
|
|
1247
|
+
if (isExcludedIndividually())
|
|
1699
1248
|
return true;
|
|
1700
|
-
var
|
|
1249
|
+
var context$1 = context.useX();
|
|
1250
|
+
var exclusion = context$1.exclusion;
|
|
1701
1251
|
var keyTests = exclusion.tests;
|
|
1702
1252
|
var testValue = keyTests[fieldName];
|
|
1703
1253
|
// if test is skipped
|
|
@@ -1720,6 +1270,9 @@ function isExcluded(testObject) {
|
|
|
1720
1270
|
return keyTests[fieldName] === false;
|
|
1721
1271
|
}
|
|
1722
1272
|
}
|
|
1273
|
+
if (isMissingFromIncludedGroup(groupName)) {
|
|
1274
|
+
return true;
|
|
1275
|
+
}
|
|
1723
1276
|
// if field is only'ed
|
|
1724
1277
|
if (isTestIncluded)
|
|
1725
1278
|
return false;
|
|
@@ -1727,12 +1280,40 @@ function isExcluded(testObject) {
|
|
|
1727
1280
|
// Otherwise return false
|
|
1728
1281
|
return hasIncludedTests(keyTests);
|
|
1729
1282
|
}
|
|
1283
|
+
// eslint-disable-next-line max-statements
|
|
1284
|
+
function isMissingFromIncludedGroup(groupName) {
|
|
1285
|
+
var context$1 = context.useX();
|
|
1286
|
+
var exclusion = context$1.exclusion;
|
|
1287
|
+
if (!hasIncludedGroups()) {
|
|
1288
|
+
return false;
|
|
1289
|
+
}
|
|
1290
|
+
if (!groupName) {
|
|
1291
|
+
return true;
|
|
1292
|
+
}
|
|
1293
|
+
if (groupName in exclusion.groups) {
|
|
1294
|
+
if (exclusion.groups[groupName]) {
|
|
1295
|
+
return false;
|
|
1296
|
+
}
|
|
1297
|
+
return true;
|
|
1298
|
+
}
|
|
1299
|
+
return true;
|
|
1300
|
+
}
|
|
1301
|
+
function hasIncludedGroups() {
|
|
1302
|
+
var context$1 = context.useX();
|
|
1303
|
+
var exclusion = context$1.exclusion;
|
|
1304
|
+
for (var group in exclusion.groups) {
|
|
1305
|
+
if (exclusion.groups[group]) {
|
|
1306
|
+
return true;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
return false;
|
|
1310
|
+
}
|
|
1730
1311
|
/**
|
|
1731
1312
|
* Checks whether a given group is excluded from running.
|
|
1732
1313
|
*/
|
|
1733
1314
|
function isGroupExcluded(groupName) {
|
|
1734
|
-
var context =
|
|
1735
|
-
var exclusion = context.exclusion;
|
|
1315
|
+
var context$1 = context.useX();
|
|
1316
|
+
var exclusion = context$1.exclusion;
|
|
1736
1317
|
var keyGroups = exclusion.groups;
|
|
1737
1318
|
var groupPresent = hasOwnProperty(keyGroups, groupName);
|
|
1738
1319
|
// When group is either only'ed or skipped
|
|
@@ -1753,7 +1334,7 @@ function isGroupExcluded(groupName) {
|
|
|
1753
1334
|
* Adds fields to a specified exclusion group.
|
|
1754
1335
|
*/
|
|
1755
1336
|
function addTo(exclusionGroup, itemType, item) {
|
|
1756
|
-
var context =
|
|
1337
|
+
var context$1 = context.useX(ERROR_HOOK_CALLED_OUTSIDE);
|
|
1757
1338
|
if (!item) {
|
|
1758
1339
|
return;
|
|
1759
1340
|
}
|
|
@@ -1761,7 +1342,7 @@ function addTo(exclusionGroup, itemType, item) {
|
|
|
1761
1342
|
if (!isStringValue(itemName)) {
|
|
1762
1343
|
return;
|
|
1763
1344
|
}
|
|
1764
|
-
context.exclusion[itemType][itemName] =
|
|
1345
|
+
context$1.exclusion[itemType][itemName] =
|
|
1765
1346
|
exclusionGroup === 0 /* ONLY */;
|
|
1766
1347
|
});
|
|
1767
1348
|
}
|
|
@@ -1777,25 +1358,6 @@ function hasIncludedTests(keyTests) {
|
|
|
1777
1358
|
return false;
|
|
1778
1359
|
}
|
|
1779
1360
|
|
|
1780
|
-
function skipWhen(conditional, callback) {
|
|
1781
|
-
isolate({ type: IsolateTypes.SKIP_WHEN }, function () {
|
|
1782
|
-
ctx.run({ skipped: optionalFunctionValue(conditional) }, function () { return callback(); });
|
|
1783
|
-
});
|
|
1784
|
-
}
|
|
1785
|
-
|
|
1786
|
-
var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won't have an effect."
|
|
1787
|
-
;
|
|
1788
|
-
/**
|
|
1789
|
-
* Sets a running test to warn only mode.
|
|
1790
|
-
*/
|
|
1791
|
-
function warn() {
|
|
1792
|
-
var ctx$1 = ctx.useX('warn ' + ERROR_HOOK_CALLED_OUTSIDE);
|
|
1793
|
-
if (!ctx$1.currentTest) {
|
|
1794
|
-
throwError(ERROR_OUTSIDE_OF_TEST);
|
|
1795
|
-
}
|
|
1796
|
-
ctx$1.currentTest.warn();
|
|
1797
|
-
}
|
|
1798
|
-
|
|
1799
1361
|
/**
|
|
1800
1362
|
* Runs a group callback.
|
|
1801
1363
|
*/
|
|
@@ -1808,7 +1370,7 @@ function group(groupName, tests) {
|
|
|
1808
1370
|
}
|
|
1809
1371
|
// Running with the context applied
|
|
1810
1372
|
isolate({ type: IsolateTypes.GROUP }, function () {
|
|
1811
|
-
|
|
1373
|
+
context.run({ groupName: groupName }, tests);
|
|
1812
1374
|
});
|
|
1813
1375
|
}
|
|
1814
1376
|
function throwGroupError(error) {
|
|
@@ -1834,125 +1396,15 @@ function optional(optionals) {
|
|
|
1834
1396
|
});
|
|
1835
1397
|
}
|
|
1836
1398
|
|
|
1837
|
-
function
|
|
1838
|
-
|
|
1839
|
-
|
|
1399
|
+
function skipWhen(conditional, callback) {
|
|
1400
|
+
isolate({ type: IsolateTypes.SKIP_WHEN }, function () {
|
|
1401
|
+
context.run({
|
|
1402
|
+
skipped: optionalFunctionValue(conditional, optionalFunctionValue(produceDraft))
|
|
1403
|
+
}, function () { return callback(); });
|
|
1404
|
+
});
|
|
1840
1405
|
}
|
|
1841
1406
|
|
|
1842
|
-
var
|
|
1843
|
-
function VestTest(fieldName, testFn, _a) {
|
|
1844
|
-
var _b = _a === void 0 ? {} : _a, message = _b.message, groupName = _b.groupName;
|
|
1845
|
-
this.id = genId();
|
|
1846
|
-
this.warns = false;
|
|
1847
|
-
this.status = STATUS_UNTESTED;
|
|
1848
|
-
this.fieldName = fieldName;
|
|
1849
|
-
this.testFn = testFn;
|
|
1850
|
-
if (groupName) {
|
|
1851
|
-
this.groupName = groupName;
|
|
1852
|
-
}
|
|
1853
|
-
if (message) {
|
|
1854
|
-
this.message = message;
|
|
1855
|
-
}
|
|
1856
|
-
}
|
|
1857
|
-
VestTest.prototype.run = function () {
|
|
1858
|
-
var result;
|
|
1859
|
-
try {
|
|
1860
|
-
result = this.testFn();
|
|
1861
|
-
}
|
|
1862
|
-
catch (error) {
|
|
1863
|
-
if (shouldUseErrorAsMessage(this.message, error)) {
|
|
1864
|
-
this.message = error;
|
|
1865
|
-
}
|
|
1866
|
-
result = false;
|
|
1867
|
-
}
|
|
1868
|
-
if (result === false) {
|
|
1869
|
-
this.fail();
|
|
1870
|
-
}
|
|
1871
|
-
return result;
|
|
1872
|
-
};
|
|
1873
|
-
VestTest.prototype.setStatus = function (status) {
|
|
1874
|
-
if (this.isFinalStatus() && status !== STATUS_OMITTED) {
|
|
1875
|
-
return;
|
|
1876
|
-
}
|
|
1877
|
-
this.status = status;
|
|
1878
|
-
};
|
|
1879
|
-
VestTest.prototype.setPending = function () {
|
|
1880
|
-
this.setStatus(STATUS_PENDING);
|
|
1881
|
-
};
|
|
1882
|
-
VestTest.prototype.fail = function () {
|
|
1883
|
-
this.setStatus(this.warns ? STATUS_WARNING : STATUS_FAILED);
|
|
1884
|
-
};
|
|
1885
|
-
VestTest.prototype.done = function () {
|
|
1886
|
-
if (this.isFinalStatus()) {
|
|
1887
|
-
return;
|
|
1888
|
-
}
|
|
1889
|
-
this.setStatus(STATUS_PASSING);
|
|
1890
|
-
};
|
|
1891
|
-
VestTest.prototype.warn = function () {
|
|
1892
|
-
this.warns = true;
|
|
1893
|
-
};
|
|
1894
|
-
VestTest.prototype.isFinalStatus = function () {
|
|
1895
|
-
return this.hasFailures() || this.isCanceled() || this.isPassing();
|
|
1896
|
-
};
|
|
1897
|
-
VestTest.prototype.skip = function () {
|
|
1898
|
-
if (this.isPending()) {
|
|
1899
|
-
// Without this condition, the test will be marked as skipped even if it is pending.
|
|
1900
|
-
// This means that it will not be counted in "allIncomplete" and its done callbacks
|
|
1901
|
-
// will not be called, or will be called prematurely.
|
|
1902
|
-
return;
|
|
1903
|
-
}
|
|
1904
|
-
this.setStatus(STATUS_SKIPPED);
|
|
1905
|
-
};
|
|
1906
|
-
VestTest.prototype.cancel = function () {
|
|
1907
|
-
this.setStatus(STATUS_CANCELED);
|
|
1908
|
-
useRefreshTestObjects();
|
|
1909
|
-
};
|
|
1910
|
-
VestTest.prototype.omit = function () {
|
|
1911
|
-
this.setStatus(STATUS_OMITTED);
|
|
1912
|
-
};
|
|
1913
|
-
VestTest.prototype.valueOf = function () {
|
|
1914
|
-
return !this.isFailing();
|
|
1915
|
-
};
|
|
1916
|
-
VestTest.prototype.hasFailures = function () {
|
|
1917
|
-
return this.isFailing() || this.isWarning();
|
|
1918
|
-
};
|
|
1919
|
-
VestTest.prototype.isPending = function () {
|
|
1920
|
-
return this.status === STATUS_PENDING;
|
|
1921
|
-
};
|
|
1922
|
-
VestTest.prototype.isTested = function () {
|
|
1923
|
-
return this.hasFailures() || this.isPassing();
|
|
1924
|
-
};
|
|
1925
|
-
VestTest.prototype.isOmitted = function () {
|
|
1926
|
-
return this.status === STATUS_OMITTED;
|
|
1927
|
-
};
|
|
1928
|
-
VestTest.prototype.isUntested = function () {
|
|
1929
|
-
return this.status === STATUS_UNTESTED;
|
|
1930
|
-
};
|
|
1931
|
-
VestTest.prototype.isFailing = function () {
|
|
1932
|
-
return this.status === STATUS_FAILED;
|
|
1933
|
-
};
|
|
1934
|
-
VestTest.prototype.isCanceled = function () {
|
|
1935
|
-
return this.status === STATUS_CANCELED;
|
|
1936
|
-
};
|
|
1937
|
-
VestTest.prototype.isSkipped = function () {
|
|
1938
|
-
return this.status === STATUS_SKIPPED;
|
|
1939
|
-
};
|
|
1940
|
-
VestTest.prototype.isPassing = function () {
|
|
1941
|
-
return this.status === STATUS_PASSING;
|
|
1942
|
-
};
|
|
1943
|
-
VestTest.prototype.isWarning = function () {
|
|
1944
|
-
return this.status === STATUS_WARNING;
|
|
1945
|
-
};
|
|
1946
|
-
return VestTest;
|
|
1947
|
-
}());
|
|
1948
|
-
var STATUS_UNTESTED = 'UNTESTED';
|
|
1949
|
-
var STATUS_SKIPPED = 'SKIPPED';
|
|
1950
|
-
var STATUS_FAILED = 'FAILED';
|
|
1951
|
-
var STATUS_WARNING = 'WARNING';
|
|
1952
|
-
var STATUS_PASSING = 'PASSING';
|
|
1953
|
-
var STATUS_PENDING = 'PENDING';
|
|
1954
|
-
var STATUS_CANCELED = 'CANCELED';
|
|
1955
|
-
var STATUS_OMITTED = 'OMITTED';
|
|
1407
|
+
var isNotString = bindNot(isStringValue);
|
|
1956
1408
|
|
|
1957
1409
|
function isPromise(value) {
|
|
1958
1410
|
return value && isFunction(value.then);
|
|
@@ -1980,12 +1432,12 @@ function runAsyncTest(testObject) {
|
|
|
1980
1432
|
return;
|
|
1981
1433
|
var emit = useBus().emit;
|
|
1982
1434
|
var stateRef = useStateRef();
|
|
1983
|
-
var done =
|
|
1435
|
+
var done = context.bind({ stateRef: stateRef }, function () {
|
|
1984
1436
|
// invalidating the "produce" cache
|
|
1985
1437
|
useRefreshTestObjects();
|
|
1986
1438
|
emit(Events.TEST_COMPLETED, testObject);
|
|
1987
1439
|
});
|
|
1988
|
-
var fail =
|
|
1440
|
+
var fail = context.bind({ stateRef: stateRef }, function (rejectionMessage) {
|
|
1989
1441
|
if (testObject.isCanceled()) {
|
|
1990
1442
|
return;
|
|
1991
1443
|
}
|
|
@@ -2007,7 +1459,7 @@ function runAsyncTest(testObject) {
|
|
|
2007
1459
|
* Runs sync tests - or extracts promise.
|
|
2008
1460
|
*/
|
|
2009
1461
|
function runSyncTest(testObject) {
|
|
2010
|
-
return
|
|
1462
|
+
return context.run({ currentTest: testObject }, function () {
|
|
2011
1463
|
var result;
|
|
2012
1464
|
try {
|
|
2013
1465
|
result = testObject.testFn();
|
|
@@ -2062,33 +1514,21 @@ function registerTest(testObject) {
|
|
|
2062
1514
|
*/
|
|
2063
1515
|
// eslint-disable-next-line max-statements, max-lines-per-function
|
|
2064
1516
|
function useTestAtCursor(newTestObject) {
|
|
2065
|
-
var
|
|
1517
|
+
var testObjects = useTestObjects()[0];
|
|
2066
1518
|
var prevTests = testObjects.prev;
|
|
2067
1519
|
if (isEmpty(prevTests)) {
|
|
2068
1520
|
useSetTestAtCursor(newTestObject);
|
|
2069
1521
|
return newTestObject;
|
|
2070
1522
|
}
|
|
2071
1523
|
var prevTest = useGetTestAtCursor(prevTests);
|
|
1524
|
+
if (!isNullish(newTestObject.key)) {
|
|
1525
|
+
var nextTest_1 = handleKeyTest(newTestObject.key, newTestObject);
|
|
1526
|
+
useSetTestAtCursor(nextTest_1);
|
|
1527
|
+
return nextTest_1;
|
|
1528
|
+
}
|
|
2072
1529
|
if (shouldPurgePrevTest(prevTest, newTestObject)) {
|
|
2073
1530
|
throwTestOrderError(prevTest, newTestObject);
|
|
2074
|
-
|
|
2075
|
-
// We need to also handle a case in which tests are added in between other tests.
|
|
2076
|
-
// At the moment all we can do is just splice the tests out of the array when this happens.
|
|
2077
|
-
// A viable solution would be to use something like React's key prop to identify tests regardless
|
|
2078
|
-
// of their position in the suite. https://reactjs.org/docs/lists-and-keys.html#keys
|
|
2079
|
-
var current = getCurrent(prevTests, usePath());
|
|
2080
|
-
var cursorAt = useCursorAt();
|
|
2081
|
-
current.splice(cursorAt);
|
|
2082
|
-
// We actually don't mind mutating the state directly (as can be seen above). There is no harm in it
|
|
2083
|
-
// since we're only touching the "prev" state. The reason we still use the setter function is
|
|
2084
|
-
// to prevent future headaches if we ever do need to rely on prev-state immutability.
|
|
2085
|
-
setTestObjects(function (_a) {
|
|
2086
|
-
var current = _a.current;
|
|
2087
|
-
return ({
|
|
2088
|
-
prev: prevTests,
|
|
2089
|
-
current: current
|
|
2090
|
-
});
|
|
2091
|
-
});
|
|
1531
|
+
removeAllNextTestsInIsolate();
|
|
2092
1532
|
// Need to see if this has any effect at all.
|
|
2093
1533
|
prevTest = null;
|
|
2094
1534
|
}
|
|
@@ -2096,6 +1536,23 @@ function useTestAtCursor(newTestObject) {
|
|
|
2096
1536
|
useSetTestAtCursor(nextTest);
|
|
2097
1537
|
return nextTest;
|
|
2098
1538
|
}
|
|
1539
|
+
function removeAllNextTestsInIsolate() {
|
|
1540
|
+
var _a = useTestObjects(), testObjects = _a[0], setTestObjects = _a[1];
|
|
1541
|
+
var prevTests = testObjects.prev;
|
|
1542
|
+
var current = getCurrent(prevTests, usePath());
|
|
1543
|
+
var cursorAt = useCursorAt();
|
|
1544
|
+
current.splice(cursorAt);
|
|
1545
|
+
// We actually don't mind mutating the state directly (as can be seen above). There is no harm in it
|
|
1546
|
+
// since we're only touching the "prev" state. The reason we still use the setter function is
|
|
1547
|
+
// to prevent future headaches if we ever do need to rely on prev-state immutability.
|
|
1548
|
+
setTestObjects(function (_a) {
|
|
1549
|
+
var current = _a.current;
|
|
1550
|
+
return ({
|
|
1551
|
+
prev: prevTests,
|
|
1552
|
+
current: current
|
|
1553
|
+
});
|
|
1554
|
+
});
|
|
1555
|
+
}
|
|
2099
1556
|
function useSetTestAtCursor(testObject) {
|
|
2100
1557
|
var cursorPath = usePath();
|
|
2101
1558
|
useSetTests(function (tests) {
|
|
@@ -2113,13 +1570,26 @@ function throwTestOrderError(prevTest, newTestObject) {
|
|
|
2113
1570
|
if (shouldAllowReorder()) {
|
|
2114
1571
|
return;
|
|
2115
1572
|
}
|
|
2116
|
-
throwErrorDeferred("Vest Critical Error: Tests called in different order than previous run.\n expected: " + prevTest.fieldName + "\n received: " + newTestObject.fieldName + "\n This
|
|
1573
|
+
throwErrorDeferred("Vest Critical Error: Tests called in different order than previous run.\n expected: " + prevTest.fieldName + "\n received: " + 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.");
|
|
1574
|
+
}
|
|
1575
|
+
function handleKeyTest(key, newTestObject) {
|
|
1576
|
+
var prevTestByKey = usePrevTestByKey(key);
|
|
1577
|
+
var nextTest = newTestObject;
|
|
1578
|
+
if (prevTestByKey) {
|
|
1579
|
+
nextTest = prevTestByKey;
|
|
1580
|
+
}
|
|
1581
|
+
useRetainTestKey(key, nextTest);
|
|
1582
|
+
return nextTest;
|
|
2117
1583
|
}
|
|
2118
1584
|
|
|
2119
1585
|
function registerPrevRunTest(testObject) {
|
|
2120
1586
|
var prevRunTest = useTestAtCursor(testObject);
|
|
2121
1587
|
if (isExcluded(testObject)) {
|
|
2122
|
-
|
|
1588
|
+
// We're forcing skipping the pending test
|
|
1589
|
+
// if we're directly within a skipWhen block
|
|
1590
|
+
// This mostly means that we're probably giving
|
|
1591
|
+
// up on this async test intentionally.
|
|
1592
|
+
prevRunTest.skip(isExcludedIndividually());
|
|
2123
1593
|
moveForward();
|
|
2124
1594
|
return prevRunTest;
|
|
2125
1595
|
}
|
|
@@ -2139,33 +1609,6 @@ function registerTestObjectByTier(testObject) {
|
|
|
2139
1609
|
}
|
|
2140
1610
|
}
|
|
2141
1611
|
|
|
2142
|
-
function bindTestEach(test) {
|
|
2143
|
-
/**
|
|
2144
|
-
* Run multiple tests using a parameter table
|
|
2145
|
-
*/
|
|
2146
|
-
function each(table) {
|
|
2147
|
-
if (!isArray(table)) {
|
|
2148
|
-
throwError('test.each: Expected table to be an array.');
|
|
2149
|
-
}
|
|
2150
|
-
function eachReturn(fieldName) {
|
|
2151
|
-
var args = [];
|
|
2152
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
2153
|
-
args[_i - 1] = arguments[_i];
|
|
2154
|
-
}
|
|
2155
|
-
var _a = args.reverse(), testFn = _a[0], message = _a[1];
|
|
2156
|
-
return isolate({ type: IsolateTypes.EACH }, function () {
|
|
2157
|
-
return table.map(function (item) {
|
|
2158
|
-
item = asArray(item);
|
|
2159
|
-
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
|
|
2160
|
-
);
|
|
2161
|
-
});
|
|
2162
|
-
});
|
|
2163
|
-
}
|
|
2164
|
-
return eachReturn;
|
|
2165
|
-
}
|
|
2166
|
-
return each;
|
|
2167
|
-
}
|
|
2168
|
-
|
|
2169
1612
|
// eslint-disable-next-line max-lines-per-function
|
|
2170
1613
|
function bindTestMemo(test) {
|
|
2171
1614
|
var cache = createCache(100); // arbitrary cache size
|
|
@@ -2175,11 +1618,10 @@ function bindTestMemo(test) {
|
|
|
2175
1618
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
2176
1619
|
args[_i - 1] = arguments[_i];
|
|
2177
1620
|
}
|
|
2178
|
-
var suiteId = useSuiteId()[0];
|
|
2179
1621
|
var cursorAt = useCursorAt();
|
|
2180
1622
|
var _a = args.reverse(), deps = _a[0], testFn = _a[1], msg = _a[2];
|
|
2181
1623
|
// Implicit dependency for more specificity
|
|
2182
|
-
var dependencies = [
|
|
1624
|
+
var dependencies = [useSuiteId(), fieldName, cursorAt].concat(deps);
|
|
2183
1625
|
var cached = cache.get(dependencies);
|
|
2184
1626
|
if (isNull(cached)) {
|
|
2185
1627
|
// cache miss
|
|
@@ -2200,24 +1642,52 @@ function testBase(fieldName) {
|
|
|
2200
1642
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
2201
1643
|
args[_i - 1] = arguments[_i];
|
|
2202
1644
|
}
|
|
2203
|
-
var _a = args
|
|
2204
|
-
|
|
1645
|
+
var _a = (isFunction(args[1]) ? args : __spreadArray([undefined], args)), message = _a[0], testFn = _a[1], key = _a[2];
|
|
1646
|
+
if (isNotString(fieldName)) {
|
|
1647
|
+
throwIncompatibleParamsError('fieldName', 'string');
|
|
1648
|
+
}
|
|
1649
|
+
if (!isFunction(testFn)) {
|
|
1650
|
+
throwIncompatibleParamsError('Test callback', 'function');
|
|
1651
|
+
}
|
|
1652
|
+
var context$1 = context.useX();
|
|
2205
1653
|
var testObject = new VestTest(fieldName, testFn, {
|
|
2206
1654
|
message: message,
|
|
2207
|
-
groupName: context
|
|
1655
|
+
groupName: context$1.groupName,
|
|
1656
|
+
key: key
|
|
2208
1657
|
});
|
|
2209
1658
|
return registerPrevRunTest(testObject);
|
|
2210
1659
|
}
|
|
2211
1660
|
var test = assign(testBase, {
|
|
2212
|
-
each: bindTestEach(testBase),
|
|
2213
1661
|
memo: bindTestMemo(testBase)
|
|
2214
1662
|
});
|
|
1663
|
+
function throwIncompatibleParamsError(name, expected) {
|
|
1664
|
+
throwError("Incompatible params passed to test function. " + name + " must be a " + expected);
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won't have an effect."
|
|
1668
|
+
;
|
|
1669
|
+
/**
|
|
1670
|
+
* Sets a running test to warn only mode.
|
|
1671
|
+
*/
|
|
1672
|
+
function warn() {
|
|
1673
|
+
var ctx = context.useX('warn ' + ERROR_HOOK_CALLED_OUTSIDE);
|
|
1674
|
+
if (!ctx.currentTest) {
|
|
1675
|
+
throwError(ERROR_OUTSIDE_OF_TEST);
|
|
1676
|
+
}
|
|
1677
|
+
ctx.currentTest.warn();
|
|
1678
|
+
}
|
|
2215
1679
|
|
|
2216
|
-
var VERSION = "4.0.0-dev-
|
|
1680
|
+
var VERSION = "4.0.0-dev-e266d9";
|
|
2217
1681
|
|
|
1682
|
+
Object.defineProperty(exports, 'enforce', {
|
|
1683
|
+
enumerable: true,
|
|
1684
|
+
get: function () {
|
|
1685
|
+
return n4s.enforce;
|
|
1686
|
+
}
|
|
1687
|
+
});
|
|
2218
1688
|
exports.VERSION = VERSION;
|
|
2219
1689
|
exports.create = create;
|
|
2220
|
-
exports.
|
|
1690
|
+
exports.each = each;
|
|
2221
1691
|
exports.group = group;
|
|
2222
1692
|
exports.only = only;
|
|
2223
1693
|
exports.optional = optional;
|