vest 4.4.0 → 4.4.2-dev-d13b14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/classnames.development.js +9 -60
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/enforce/compose.development.js +6 -53
- package/dist/cjs/enforce/compose.production.js +1 -1
- package/dist/cjs/enforce/compounds.development.js +16 -71
- package/dist/cjs/enforce/compounds.production.js +1 -1
- package/dist/cjs/enforce/schema.development.js +6 -58
- package/dist/cjs/enforce/schema.production.js +1 -1
- package/dist/cjs/parser.development.js +8 -59
- package/dist/cjs/parser.production.js +1 -1
- package/dist/cjs/promisify.development.js +2 -26
- package/dist/cjs/promisify.production.js +1 -1
- package/dist/cjs/vest.development.js +163 -429
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +1 -52
- package/dist/es/classnames.production.js +1 -1
- package/dist/es/enforce/compose.development.js +4 -51
- package/dist/es/enforce/compose.production.js +1 -1
- package/dist/es/enforce/compounds.development.js +11 -66
- package/dist/es/enforce/compounds.production.js +1 -1
- package/dist/es/enforce/schema.development.js +2 -54
- package/dist/es/enforce/schema.production.js +1 -1
- package/dist/es/parser.development.js +1 -52
- package/dist/es/parser.production.js +1 -1
- package/dist/es/promisify.development.js +1 -25
- package/dist/es/promisify.production.js +1 -1
- package/dist/es/vest.development.js +92 -358
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +13 -13
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +121 -121
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +180 -184
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +132 -132
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/parser.development.js +13 -13
- package/dist/umd/parser.production.js +1 -1
- package/dist/umd/vest.development.js +399 -406
- package/dist/umd/vest.production.js +1 -1
- package/package.json +4 -3
- package/testUtils/mockThrowError.ts +2 -1
- package/testUtils/suiteDummy.ts +1 -1
- package/testUtils/testObjects.ts +2 -17
- package/types/enforce/compose.d.ts +14 -30
- package/types/enforce/compounds.d.ts +14 -30
- package/types/enforce/schema.d.ts +14 -30
- package/types/vest.d.ts +4 -3
- package/testUtils/itWithContext.ts +0 -23
|
@@ -3,181 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var n4s = require('n4s');
|
|
6
|
+
var vestUtils = require('vest-utils');
|
|
6
7
|
var context$1 = require('context');
|
|
7
8
|
|
|
8
|
-
/**
|
|
9
|
-
* @returns a unique numeric id.
|
|
10
|
-
*/
|
|
11
|
-
var genId = (function (n) { return function () {
|
|
12
|
-
return "".concat(n++);
|
|
13
|
-
}; })(0);
|
|
14
|
-
|
|
15
|
-
function isStringValue(v) {
|
|
16
|
-
return String(v) === v;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function bindNot(fn) {
|
|
20
|
-
return function () {
|
|
21
|
-
var args = [];
|
|
22
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
23
|
-
args[_i] = arguments[_i];
|
|
24
|
-
}
|
|
25
|
-
return !fn.apply(void 0, args);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function isUndefined(value) {
|
|
30
|
-
return value === undefined;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
9
|
function shouldUseErrorAsMessage(message, error) {
|
|
34
10
|
// kind of cheating with this safe guard, but it does the job
|
|
35
|
-
return isUndefined(message) && isStringValue(error);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function asArray(possibleArg) {
|
|
39
|
-
return [].concat(possibleArg);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
var assign = Object.assign;
|
|
43
|
-
|
|
44
|
-
function isNumeric(value) {
|
|
45
|
-
var str = String(value);
|
|
46
|
-
var num = Number(value);
|
|
47
|
-
var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
|
|
48
|
-
return Boolean(result);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function numberEquals(value, eq) {
|
|
52
|
-
return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function lengthEquals(value, arg1) {
|
|
56
|
-
return numberEquals(value.length, arg1);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function greaterThan(value, gt) {
|
|
60
|
-
return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function longerThan(value, arg1) {
|
|
64
|
-
return greaterThan(value.length, arg1);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Creates a cache function
|
|
69
|
-
*/
|
|
70
|
-
function createCache(maxSize) {
|
|
71
|
-
if (maxSize === void 0) { maxSize = 1; }
|
|
72
|
-
var cacheStorage = [];
|
|
73
|
-
var cache = function (deps, cacheAction) {
|
|
74
|
-
var cacheHit = cache.get(deps);
|
|
75
|
-
// cache hit is not null
|
|
76
|
-
if (cacheHit)
|
|
77
|
-
return cacheHit[1];
|
|
78
|
-
var result = cacheAction();
|
|
79
|
-
cacheStorage.unshift([deps.concat(), result]);
|
|
80
|
-
if (longerThan(cacheStorage, maxSize))
|
|
81
|
-
cacheStorage.length = maxSize;
|
|
82
|
-
return result;
|
|
83
|
-
};
|
|
84
|
-
// invalidate an item in the cache by its dependencies
|
|
85
|
-
cache.invalidate = function (deps) {
|
|
86
|
-
var index = findIndex(deps);
|
|
87
|
-
if (index > -1)
|
|
88
|
-
cacheStorage.splice(index, 1);
|
|
89
|
-
};
|
|
90
|
-
// Retrieves an item from the cache.
|
|
91
|
-
cache.get = function (deps) {
|
|
92
|
-
return cacheStorage[findIndex(deps)] || null;
|
|
93
|
-
};
|
|
94
|
-
return cache;
|
|
95
|
-
function findIndex(deps) {
|
|
96
|
-
return cacheStorage.findIndex(function (_a) {
|
|
97
|
-
var cachedDeps = _a[0];
|
|
98
|
-
return lengthEquals(deps, cachedDeps.length) &&
|
|
99
|
-
deps.every(function (dep, i) { return dep === cachedDeps[i]; });
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// The module is named "isArrayValue" since it
|
|
105
|
-
// is conflicting with a nested npm dependency.
|
|
106
|
-
// We may need to revisit this in the future.
|
|
107
|
-
function isArray(value) {
|
|
108
|
-
return Boolean(Array.isArray(value));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function isNull(value) {
|
|
112
|
-
return value === null;
|
|
113
|
-
}
|
|
114
|
-
var isNotNull = bindNot(isNull);
|
|
115
|
-
|
|
116
|
-
function isFunction(value) {
|
|
117
|
-
return typeof value === 'function';
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function optionalFunctionValue(value) {
|
|
121
|
-
var args = [];
|
|
122
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
123
|
-
args[_i - 1] = arguments[_i];
|
|
124
|
-
}
|
|
125
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function defaultTo(callback, defaultValue) {
|
|
129
|
-
var _a;
|
|
130
|
-
return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function last(values) {
|
|
134
|
-
var valuesArray = asArray(values);
|
|
135
|
-
return valuesArray[valuesArray.length - 1];
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// This is kind of a map/filter in one function.
|
|
139
|
-
// Normally, behaves like a nested-array map,
|
|
140
|
-
// but returning `null` will drop the element from the array
|
|
141
|
-
function transform(array, cb) {
|
|
142
|
-
var res = [];
|
|
143
|
-
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
|
|
144
|
-
var v = array_1[_i];
|
|
145
|
-
if (isArray(v)) {
|
|
146
|
-
res.push(transform(v, cb));
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
var output = cb(v);
|
|
150
|
-
if (isNotNull(output)) {
|
|
151
|
-
res.push(output);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return res;
|
|
156
|
-
}
|
|
157
|
-
function valueAtPath(array, path) {
|
|
158
|
-
return getCurrent(array, path)[last(path)];
|
|
159
|
-
}
|
|
160
|
-
function setValueAtPath(array, path, value) {
|
|
161
|
-
var current = getCurrent(array, path);
|
|
162
|
-
current[last(path)] = value;
|
|
163
|
-
return array;
|
|
164
|
-
}
|
|
165
|
-
function flatten(values) {
|
|
166
|
-
return asArray(values).reduce(function (acc, value) {
|
|
167
|
-
if (isArray(value)) {
|
|
168
|
-
return acc.concat(flatten(value));
|
|
169
|
-
}
|
|
170
|
-
return asArray(acc).concat(value);
|
|
171
|
-
}, []);
|
|
172
|
-
}
|
|
173
|
-
function getCurrent(array, path) {
|
|
174
|
-
var current = array;
|
|
175
|
-
for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) {
|
|
176
|
-
var p = _a[_i];
|
|
177
|
-
current[p] = defaultTo(current[p], []);
|
|
178
|
-
current = current[p];
|
|
179
|
-
}
|
|
180
|
-
return current;
|
|
11
|
+
return vestUtils.isUndefined(message) && vestUtils.isStringValue(error);
|
|
181
12
|
}
|
|
182
13
|
|
|
183
14
|
var IsolateTypes;
|
|
@@ -196,20 +27,6 @@ var Modes;
|
|
|
196
27
|
Modes[Modes["EAGER"] = 1] = "EAGER";
|
|
197
28
|
})(Modes || (Modes = {}));
|
|
198
29
|
|
|
199
|
-
function invariant(condition,
|
|
200
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
201
|
-
message) {
|
|
202
|
-
if (condition) {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
// If message is a string object (rather than string literal)
|
|
206
|
-
// Throw the value directly as a string
|
|
207
|
-
// Alternatively, throw an error with the message
|
|
208
|
-
throw message instanceof String
|
|
209
|
-
? message.valueOf()
|
|
210
|
-
: new Error(message ? optionalFunctionValue(message) : message);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
30
|
function createIsolateCursor() {
|
|
214
31
|
var cursor = {
|
|
215
32
|
value: 0
|
|
@@ -232,84 +49,6 @@ function createIsolateCursor() {
|
|
|
232
49
|
}
|
|
233
50
|
}
|
|
234
51
|
|
|
235
|
-
function isNullish(value) {
|
|
236
|
-
return isNull(value) || isUndefined(value);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function deferThrow(message) {
|
|
240
|
-
setTimeout(function () {
|
|
241
|
-
throw new Error(message);
|
|
242
|
-
}, 0);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function usePrevKeys() {
|
|
246
|
-
var prev = useTestObjects()[0].prev;
|
|
247
|
-
return asArray(getCurrent(prev, useCurrentPath())).reduce(function (prevKeys, testObject) {
|
|
248
|
-
if (!(testObject instanceof VestTest)) {
|
|
249
|
-
return prevKeys;
|
|
250
|
-
}
|
|
251
|
-
if (isNullish(testObject.key)) {
|
|
252
|
-
return prevKeys;
|
|
253
|
-
}
|
|
254
|
-
prevKeys[testObject.key] = testObject;
|
|
255
|
-
return prevKeys;
|
|
256
|
-
}, {});
|
|
257
|
-
}
|
|
258
|
-
function usePrevTestByKey(key) {
|
|
259
|
-
var prev = context.useX().isolate.keys.prev;
|
|
260
|
-
return prev[key];
|
|
261
|
-
}
|
|
262
|
-
function useRetainTestKey(key, testObject) {
|
|
263
|
-
var context$1 = context.useX();
|
|
264
|
-
var current = context$1.isolate.keys.current;
|
|
265
|
-
if (isNullish(current[key])) {
|
|
266
|
-
current[key] = testObject;
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
deferThrow("Encountered the same test key \"".concat(key, "\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."));
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function isolate(_a, callback) {
|
|
274
|
-
var _b = _a.type, type = _b === void 0 ? IsolateTypes.DEFAULT : _b;
|
|
275
|
-
invariant(isFunction(callback));
|
|
276
|
-
// Generate a new Isolate layer, with its own cursor
|
|
277
|
-
var isolate = generateIsolate(type, useCurrentPath());
|
|
278
|
-
var output = context.run({ isolate: isolate }, function () {
|
|
279
|
-
isolate.keys.prev = usePrevKeys();
|
|
280
|
-
useSetTests(function (tests) { return setValueAtPath(tests, isolate.path, []); });
|
|
281
|
-
var res = callback();
|
|
282
|
-
return res;
|
|
283
|
-
});
|
|
284
|
-
// Move the parent cursor forward once we're done
|
|
285
|
-
useCursor().next();
|
|
286
|
-
return output;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* @returns {Isolate} The current isolate layer
|
|
290
|
-
*/
|
|
291
|
-
function useIsolate() {
|
|
292
|
-
return context.useX().isolate;
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* @returns {boolean} Whether or not the current isolate allows tests to be reordered
|
|
296
|
-
*/
|
|
297
|
-
function shouldAllowReorder() {
|
|
298
|
-
return context.useX().isolate.type === IsolateTypes.EACH;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* @returns {number[]} The current cursor path of the isolate tree
|
|
302
|
-
*/
|
|
303
|
-
function useCurrentPath() {
|
|
304
|
-
var isolate = useIsolate();
|
|
305
|
-
return isolate.path.concat(isolate.cursor.current());
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* @returns {IsolateCursor} The cursor object for the current isolate
|
|
309
|
-
*/
|
|
310
|
-
function useCursor() {
|
|
311
|
-
return useIsolate().cursor;
|
|
312
|
-
}
|
|
313
52
|
function generateIsolate(type, path) {
|
|
314
53
|
if (path === void 0) { path = []; }
|
|
315
54
|
return {
|
|
@@ -326,7 +65,7 @@ function generateIsolate(type, path) {
|
|
|
326
65
|
var context = context$1.createContext(function (ctxRef, parentContext) {
|
|
327
66
|
return parentContext
|
|
328
67
|
? null
|
|
329
|
-
: assign({}, {
|
|
68
|
+
: vestUtils.assign({}, {
|
|
330
69
|
exclusion: {
|
|
331
70
|
tests: {},
|
|
332
71
|
groups: {}
|
|
@@ -364,8 +103,8 @@ function useSetOptionalField(fieldName, setter) {
|
|
|
364
103
|
var _a = useOptionalFields(), setOptionalFields = _a[1];
|
|
365
104
|
setOptionalFields(function (optionalFields) {
|
|
366
105
|
var _a;
|
|
367
|
-
return assign(optionalFields, (_a = {},
|
|
368
|
-
_a[fieldName] = optionalFunctionValue(setter, optionalFields[fieldName]),
|
|
106
|
+
return vestUtils.assign(optionalFields, (_a = {},
|
|
107
|
+
_a[fieldName] = vestUtils.optionalFunctionValue(setter, optionalFields[fieldName]),
|
|
369
108
|
_a));
|
|
370
109
|
});
|
|
371
110
|
}
|
|
@@ -390,7 +129,7 @@ function useSetTests(handler) {
|
|
|
390
129
|
var current = _a.current, prev = _a.prev;
|
|
391
130
|
return ({
|
|
392
131
|
prev: prev,
|
|
393
|
-
current: asArray(handler(current))
|
|
132
|
+
current: vestUtils.asArray(handler(current))
|
|
394
133
|
});
|
|
395
134
|
});
|
|
396
135
|
}
|
|
@@ -398,10 +137,10 @@ function useSetTests(handler) {
|
|
|
398
137
|
function useAllIncomplete() {
|
|
399
138
|
return useTestsFlat().filter(function (test) { return test.isPending(); });
|
|
400
139
|
}
|
|
401
|
-
var flatCache =
|
|
140
|
+
var flatCache = vestUtils.cache();
|
|
402
141
|
function useTestsFlat() {
|
|
403
142
|
var current = useTestObjects()[0].current;
|
|
404
|
-
return flatCache([current], function () { return flatten(current); });
|
|
143
|
+
return flatCache([current], function () { return vestUtils.nestedArray.flatten(current); });
|
|
405
144
|
}
|
|
406
145
|
function useEachTestObject(handler) {
|
|
407
146
|
var testObjects = useTestsFlat();
|
|
@@ -417,7 +156,7 @@ var VestTest = /** @class */ (function () {
|
|
|
417
156
|
function VestTest(fieldName, testFn, _a) {
|
|
418
157
|
var _b = _a === void 0 ? {} : _a, message = _b.message, groupName = _b.groupName, key = _b.key;
|
|
419
158
|
this.key = null;
|
|
420
|
-
this.id = genId();
|
|
159
|
+
this.id = vestUtils.genId();
|
|
421
160
|
this.severity = TestSeverity.Error;
|
|
422
161
|
this.status = STATUS_UNTESTED;
|
|
423
162
|
this.fieldName = fieldName;
|
|
@@ -590,12 +329,12 @@ function createState(onStateChange) {
|
|
|
590
329
|
}
|
|
591
330
|
function initKey(key, initialState, prevState) {
|
|
592
331
|
current().push();
|
|
593
|
-
set(key, optionalFunctionValue(initialState, prevState));
|
|
332
|
+
set(key, vestUtils.optionalFunctionValue(initialState, prevState));
|
|
594
333
|
return function useStateKey() {
|
|
595
334
|
return [
|
|
596
335
|
current()[key],
|
|
597
336
|
function (nextState) {
|
|
598
|
-
return set(key, optionalFunctionValue(nextState, current()[key]));
|
|
337
|
+
return set(key, vestUtils.optionalFunctionValue(nextState, current()[key]));
|
|
599
338
|
},
|
|
600
339
|
];
|
|
601
340
|
};
|
|
@@ -607,10 +346,10 @@ function createState(onStateChange) {
|
|
|
607
346
|
var prevValue = state.references[index];
|
|
608
347
|
state.references[index] = value;
|
|
609
348
|
var _a = registrations[index], onUpdate = _a[1];
|
|
610
|
-
if (isFunction(onUpdate)) {
|
|
349
|
+
if (vestUtils.isFunction(onUpdate)) {
|
|
611
350
|
onUpdate(value, prevValue);
|
|
612
351
|
}
|
|
613
|
-
if (isFunction(onStateChange)) {
|
|
352
|
+
if (vestUtils.isFunction(onStateChange)) {
|
|
614
353
|
onStateChange();
|
|
615
354
|
}
|
|
616
355
|
}
|
|
@@ -635,6 +374,74 @@ function createStateRef(state, _a) {
|
|
|
635
374
|
};
|
|
636
375
|
}
|
|
637
376
|
|
|
377
|
+
function usePrevKeys() {
|
|
378
|
+
var prev = useTestObjects()[0].prev;
|
|
379
|
+
return vestUtils.asArray(vestUtils.nestedArray.getCurrent(prev, useCurrentPath())).reduce(function (prevKeys, testObject) {
|
|
380
|
+
if (!(testObject instanceof VestTest)) {
|
|
381
|
+
return prevKeys;
|
|
382
|
+
}
|
|
383
|
+
if (vestUtils.isNullish(testObject.key)) {
|
|
384
|
+
return prevKeys;
|
|
385
|
+
}
|
|
386
|
+
prevKeys[testObject.key] = testObject;
|
|
387
|
+
return prevKeys;
|
|
388
|
+
}, {});
|
|
389
|
+
}
|
|
390
|
+
function usePrevTestByKey(key) {
|
|
391
|
+
var prev = useIsolate().keys.prev;
|
|
392
|
+
return prev[key];
|
|
393
|
+
}
|
|
394
|
+
function useRetainTestKey(key, testObject) {
|
|
395
|
+
var current = useIsolate().keys.current;
|
|
396
|
+
if (vestUtils.isNullish(current[key])) {
|
|
397
|
+
current[key] = testObject;
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
vestUtils.deferThrow("Encountered the same test key \"".concat(key, "\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."));
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function isolate(_a, callback) {
|
|
405
|
+
var _b = _a.type, type = _b === void 0 ? IsolateTypes.DEFAULT : _b;
|
|
406
|
+
vestUtils.invariant(vestUtils.isFunction(callback));
|
|
407
|
+
// Generate a new Isolate layer, with its own cursor
|
|
408
|
+
var isolate = generateIsolate(type, useCurrentPath());
|
|
409
|
+
var output = context.run({ isolate: isolate }, function () {
|
|
410
|
+
isolate.keys.prev = usePrevKeys();
|
|
411
|
+
useSetTests(function (tests) { return vestUtils.nestedArray.setValueAtPath(tests, isolate.path, []); });
|
|
412
|
+
var res = callback();
|
|
413
|
+
return res;
|
|
414
|
+
});
|
|
415
|
+
// Move the parent cursor forward once we're done
|
|
416
|
+
useCursor().next();
|
|
417
|
+
return output;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* @returns {Isolate} The current isolate layer
|
|
421
|
+
*/
|
|
422
|
+
function useIsolate() {
|
|
423
|
+
return context.useX().isolate;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* @returns {boolean} Whether or not the current isolate allows tests to be reordered
|
|
427
|
+
*/
|
|
428
|
+
function shouldAllowReorder() {
|
|
429
|
+
return useIsolate().type === IsolateTypes.EACH;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* @returns {number[]} The current cursor path of the isolate tree
|
|
433
|
+
*/
|
|
434
|
+
function useCurrentPath() {
|
|
435
|
+
var isolate = useIsolate();
|
|
436
|
+
return isolate.path.concat(isolate.cursor.current());
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* @returns {IsolateCursor} The cursor object for the current isolate
|
|
440
|
+
*/
|
|
441
|
+
function useCursor() {
|
|
442
|
+
return useIsolate().cursor;
|
|
443
|
+
}
|
|
444
|
+
|
|
638
445
|
var Severity;
|
|
639
446
|
(function (Severity) {
|
|
640
447
|
Severity["WARNINGS"] = "warnings";
|
|
@@ -651,34 +458,6 @@ function countKeyBySeverity(severity) {
|
|
|
651
458
|
: SeverityCount.WARN_COUNT;
|
|
652
459
|
}
|
|
653
460
|
|
|
654
|
-
/**
|
|
655
|
-
* A safe hasOwnProperty access
|
|
656
|
-
*/
|
|
657
|
-
function hasOwnProperty(obj, key) {
|
|
658
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
function isNumber(value) {
|
|
662
|
-
return Boolean(typeof value === 'number');
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
function isEmpty(value) {
|
|
666
|
-
if (!value) {
|
|
667
|
-
return true;
|
|
668
|
-
}
|
|
669
|
-
else if (isNumber(value)) {
|
|
670
|
-
return value === 0;
|
|
671
|
-
}
|
|
672
|
-
else if (hasOwnProperty(value, 'length')) {
|
|
673
|
-
return lengthEquals(value, 0);
|
|
674
|
-
}
|
|
675
|
-
else if (typeof value === 'object') {
|
|
676
|
-
return lengthEquals(Object.keys(value), 0);
|
|
677
|
-
}
|
|
678
|
-
return false;
|
|
679
|
-
}
|
|
680
|
-
var isNotEmpty = bindNot(isEmpty);
|
|
681
|
-
|
|
682
461
|
function nonMatchingFieldName(testObject, fieldName) {
|
|
683
462
|
return !!fieldName && !matchingFieldName(testObject, fieldName);
|
|
684
463
|
}
|
|
@@ -686,20 +465,16 @@ function matchingFieldName(testObject, fieldName) {
|
|
|
686
465
|
return !!(fieldName && testObject.fieldName === fieldName);
|
|
687
466
|
}
|
|
688
467
|
|
|
689
|
-
var nonMatchingGroupName = bindNot(matchingGroupName);
|
|
468
|
+
var nonMatchingGroupName = vestUtils.bindNot(matchingGroupName);
|
|
690
469
|
function matchingGroupName(testObject, groupName) {
|
|
691
470
|
return testObject.groupName === groupName;
|
|
692
471
|
}
|
|
693
472
|
|
|
694
|
-
function either(a, b) {
|
|
695
|
-
return !!a !== !!b;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
473
|
/**
|
|
699
474
|
* Checks that a given test object matches the currently specified severity level
|
|
700
475
|
*/
|
|
701
476
|
function nonMatchingSeverityProfile(severity, testObject) {
|
|
702
|
-
return either(severity === Severity.WARNINGS, testObject.warns());
|
|
477
|
+
return vestUtils.either(severity === Severity.WARNINGS, testObject.warns());
|
|
703
478
|
}
|
|
704
479
|
|
|
705
480
|
/**
|
|
@@ -749,7 +524,7 @@ function shouldAddValidProperty(fieldName) {
|
|
|
749
524
|
return false;
|
|
750
525
|
}
|
|
751
526
|
var testObjects = useTestsFlat();
|
|
752
|
-
if (isEmpty(testObjects)) {
|
|
527
|
+
if (vestUtils.isEmpty(testObjects)) {
|
|
753
528
|
return false;
|
|
754
529
|
}
|
|
755
530
|
// Does the given field have any pending tests that are not optional?
|
|
@@ -779,13 +554,13 @@ function fieldIsOmitted(fieldName) {
|
|
|
779
554
|
}
|
|
780
555
|
// Does the given field have any pending tests that are not optional?
|
|
781
556
|
function hasNonOptionalIncomplete(fieldName) {
|
|
782
|
-
return isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
557
|
+
return vestUtils.isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
783
558
|
return isOptionalFieldIncomplete(testObject, fieldName);
|
|
784
559
|
}));
|
|
785
560
|
}
|
|
786
561
|
// Do the given group/field have any pending tests that are not optional?
|
|
787
562
|
function hasNonOptionalIncompleteByGroup(groupName, fieldName) {
|
|
788
|
-
return isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
563
|
+
return vestUtils.isNotEmpty(useAllIncomplete().filter(function (testObject) {
|
|
789
564
|
if (nonMatchingGroupName(testObject, groupName)) {
|
|
790
565
|
return false;
|
|
791
566
|
}
|
|
@@ -827,7 +602,7 @@ function missingTestsLogic(testObject, fieldName) {
|
|
|
827
602
|
|
|
828
603
|
function useSummary() {
|
|
829
604
|
var summary = context.useX().summary;
|
|
830
|
-
invariant(summary);
|
|
605
|
+
vestUtils.invariant(summary);
|
|
831
606
|
return summary;
|
|
832
607
|
}
|
|
833
608
|
/**
|
|
@@ -835,7 +610,7 @@ function useSummary() {
|
|
|
835
610
|
*/
|
|
836
611
|
function genTestsSummary() {
|
|
837
612
|
var testObjects = useTestsFlat();
|
|
838
|
-
var summary = assign(baseStats(), {
|
|
613
|
+
var summary = vestUtils.assign(baseStats(), {
|
|
839
614
|
groups: {},
|
|
840
615
|
tests: {},
|
|
841
616
|
valid: false
|
|
@@ -912,16 +687,12 @@ function baseStats() {
|
|
|
912
687
|
};
|
|
913
688
|
}
|
|
914
689
|
function baseTestStats() {
|
|
915
|
-
return assign(baseStats(), {
|
|
690
|
+
return vestUtils.assign(baseStats(), {
|
|
916
691
|
errors: [],
|
|
917
692
|
warnings: []
|
|
918
693
|
});
|
|
919
694
|
}
|
|
920
695
|
|
|
921
|
-
function isPositive(value) {
|
|
922
|
-
return greaterThan(value, 0);
|
|
923
|
-
}
|
|
924
|
-
|
|
925
696
|
// calls collectAll or getByFieldName depending on whether fieldName is provided
|
|
926
697
|
function gatherFailures(testGroup, severityKey, fieldName) {
|
|
927
698
|
return fieldName
|
|
@@ -936,7 +707,7 @@ function collectAll(testGroup, severityKey) {
|
|
|
936
707
|
var output = {};
|
|
937
708
|
var countKey = countKeyBySeverity(severityKey);
|
|
938
709
|
for (var field in testGroup) {
|
|
939
|
-
if (isPositive(testGroup[field][countKey])) {
|
|
710
|
+
if (vestUtils.isPositive(testGroup[field][countKey])) {
|
|
940
711
|
// We will probably never get to the fallback array
|
|
941
712
|
// leaving it just in case the implementation changes
|
|
942
713
|
output[field] = testGroup[field][severityKey] || [];
|
|
@@ -980,9 +751,9 @@ function hasFailures(severityCount, fieldName) {
|
|
|
980
751
|
var _a;
|
|
981
752
|
var summary = useSummary();
|
|
982
753
|
if (fieldName) {
|
|
983
|
-
return isPositive((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
754
|
+
return vestUtils.isPositive((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
984
755
|
}
|
|
985
|
-
return isPositive(summary[severityCount]);
|
|
756
|
+
return vestUtils.isPositive(summary[severityCount]);
|
|
986
757
|
}
|
|
987
758
|
|
|
988
759
|
function hasErrorsByGroup(groupName, fieldName) {
|
|
@@ -1001,10 +772,10 @@ function hasFailuresByGroup(severityKey, groupName, fieldName) {
|
|
|
1001
772
|
return false;
|
|
1002
773
|
}
|
|
1003
774
|
if (fieldName) {
|
|
1004
|
-
return isPositive((_a = group[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
775
|
+
return vestUtils.isPositive((_a = group[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
1005
776
|
}
|
|
1006
777
|
for (var field in group) {
|
|
1007
|
-
if (isPositive((_b = group[field]) === null || _b === void 0 ? void 0 : _b[severityCount])) {
|
|
778
|
+
if (vestUtils.isPositive((_b = group[field]) === null || _b === void 0 ? void 0 : _b[severityCount])) {
|
|
1008
779
|
return true;
|
|
1009
780
|
}
|
|
1010
781
|
}
|
|
@@ -1038,7 +809,7 @@ function isFieldValid(testContainer, fieldName) {
|
|
|
1038
809
|
return !!((_a = testContainer[fieldName]) === null || _a === void 0 ? void 0 : _a.valid);
|
|
1039
810
|
}
|
|
1040
811
|
|
|
1041
|
-
var cache$1 =
|
|
812
|
+
var cache$1 = vestUtils.cache(1);
|
|
1042
813
|
function produceSuiteResult() {
|
|
1043
814
|
var testObjects = useTestsFlat();
|
|
1044
815
|
var ctxRef = { stateRef: useStateRef() };
|
|
@@ -1046,7 +817,7 @@ function produceSuiteResult() {
|
|
|
1046
817
|
var summary = genTestsSummary();
|
|
1047
818
|
var suiteName = useSuiteName();
|
|
1048
819
|
var ref = { summary: summary };
|
|
1049
|
-
return assign(summary, {
|
|
820
|
+
return vestUtils.assign(summary, {
|
|
1050
821
|
getErrors: context.bind(ref, getErrors),
|
|
1051
822
|
getErrorsByGroup: context.bind(ref, getErrorsByGroup),
|
|
1052
823
|
getWarnings: context.bind(ref, getWarnings),
|
|
@@ -1067,7 +838,7 @@ function produceSuiteResult() {
|
|
|
1067
838
|
*/
|
|
1068
839
|
function hasRemainingTests(fieldName) {
|
|
1069
840
|
var allIncomplete = useAllIncomplete();
|
|
1070
|
-
if (isEmpty(allIncomplete)) {
|
|
841
|
+
if (vestUtils.isEmpty(allIncomplete)) {
|
|
1071
842
|
return false;
|
|
1072
843
|
}
|
|
1073
844
|
if (fieldName) {
|
|
@@ -1075,15 +846,15 @@ function hasRemainingTests(fieldName) {
|
|
|
1075
846
|
return matchingFieldName(testObject, fieldName);
|
|
1076
847
|
});
|
|
1077
848
|
}
|
|
1078
|
-
return isNotEmpty(allIncomplete);
|
|
849
|
+
return vestUtils.isNotEmpty(allIncomplete);
|
|
1079
850
|
}
|
|
1080
851
|
|
|
1081
|
-
var cache =
|
|
852
|
+
var cache = vestUtils.cache(20);
|
|
1082
853
|
function produceFullResult() {
|
|
1083
854
|
var testObjects = useTestsFlat();
|
|
1084
855
|
var ctxRef = { stateRef: useStateRef() };
|
|
1085
856
|
return cache([testObjects], context.bind(ctxRef, function () {
|
|
1086
|
-
return assign({}, produceSuiteResult(), {
|
|
857
|
+
return vestUtils.assign({}, produceSuiteResult(), {
|
|
1087
858
|
done: context.bind(ctxRef, done)
|
|
1088
859
|
});
|
|
1089
860
|
}));
|
|
@@ -1093,9 +864,9 @@ function produceFullResult() {
|
|
|
1093
864
|
*/
|
|
1094
865
|
function shouldSkipDoneRegistration(callback, fieldName, output) {
|
|
1095
866
|
// If we do not have any test runs for the current field
|
|
1096
|
-
return !!(!isFunction(callback) ||
|
|
867
|
+
return !!(!vestUtils.isFunction(callback) ||
|
|
1097
868
|
(fieldName &&
|
|
1098
|
-
(!output.tests[fieldName] || isEmpty(output.tests[fieldName].testCount))));
|
|
869
|
+
(!output.tests[fieldName] || vestUtils.isEmpty(output.tests[fieldName].testCount))));
|
|
1099
870
|
}
|
|
1100
871
|
function shouldRunDoneCallback(fieldName) {
|
|
1101
872
|
// is suite finished || field name exists, and test is finished;
|
|
@@ -1137,38 +908,16 @@ function deferDoneCallback(doneCallback, fieldName) {
|
|
|
1137
908
|
});
|
|
1138
909
|
}
|
|
1139
910
|
|
|
1140
|
-
function createBus() {
|
|
1141
|
-
var listeners = {};
|
|
1142
|
-
return {
|
|
1143
|
-
emit: function (event, data) {
|
|
1144
|
-
listener(event).forEach(function (handler) {
|
|
1145
|
-
handler(data);
|
|
1146
|
-
});
|
|
1147
|
-
},
|
|
1148
|
-
on: function (event, handler) {
|
|
1149
|
-
listeners[event] = listener(event).concat(handler);
|
|
1150
|
-
return {
|
|
1151
|
-
off: function () {
|
|
1152
|
-
listeners[event] = listener(event).filter(function (h) { return h !== handler; });
|
|
1153
|
-
}
|
|
1154
|
-
};
|
|
1155
|
-
}
|
|
1156
|
-
};
|
|
1157
|
-
function listener(event) {
|
|
1158
|
-
return listeners[event] || [];
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
911
|
function omitOptionalFields() {
|
|
1163
912
|
var optionalFields = useOptionalFields()[0];
|
|
1164
|
-
if (isEmpty(optionalFields)) {
|
|
913
|
+
if (vestUtils.isEmpty(optionalFields)) {
|
|
1165
914
|
return;
|
|
1166
915
|
}
|
|
1167
916
|
var shouldOmit = {};
|
|
1168
917
|
useSetTests(function (tests) {
|
|
1169
|
-
return transform(tests, function (testObject) {
|
|
918
|
+
return vestUtils.nestedArray.transform(tests, function (testObject) {
|
|
1170
919
|
var fieldName = testObject.fieldName;
|
|
1171
|
-
if (hasOwnProperty(shouldOmit, fieldName)) {
|
|
920
|
+
if (vestUtils.hasOwnProperty(shouldOmit, fieldName)) {
|
|
1172
921
|
verifyAndOmit(testObject);
|
|
1173
922
|
}
|
|
1174
923
|
else {
|
|
@@ -1185,7 +934,7 @@ function omitOptionalFields() {
|
|
|
1185
934
|
}
|
|
1186
935
|
function runOptionalConfig(testObject) {
|
|
1187
936
|
var optionalConfig = useOptionalFieldConfig(testObject.fieldName);
|
|
1188
|
-
if (isFunction(optionalConfig)) {
|
|
937
|
+
if (vestUtils.isFunction(optionalConfig)) {
|
|
1189
938
|
shouldOmit[testObject.fieldName] = optionalConfig();
|
|
1190
939
|
verifyAndOmit(testObject);
|
|
1191
940
|
}
|
|
@@ -1197,14 +946,10 @@ function omitOptionalFields() {
|
|
|
1197
946
|
*/
|
|
1198
947
|
function removeTestFromState (testObject) {
|
|
1199
948
|
useSetTests(function (tests) {
|
|
1200
|
-
return transform(tests, function (test) { return (testObject !== test ? test : null); });
|
|
949
|
+
return vestUtils.nestedArray.transform(tests, function (test) { return (testObject !== test ? test : null); });
|
|
1201
950
|
});
|
|
1202
951
|
}
|
|
1203
952
|
|
|
1204
|
-
function callEach(arr) {
|
|
1205
|
-
return arr.forEach(function (fn) { return fn(); });
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
953
|
/**
|
|
1209
954
|
* Runs done callback per field when async tests are finished running.
|
|
1210
955
|
*/
|
|
@@ -1212,8 +957,8 @@ function runFieldCallbacks(fieldName) {
|
|
|
1212
957
|
var fieldCallbacks = useTestCallbacks()[0].fieldCallbacks;
|
|
1213
958
|
if (fieldName &&
|
|
1214
959
|
!hasRemainingTests(fieldName) &&
|
|
1215
|
-
isArray(fieldCallbacks[fieldName])) {
|
|
1216
|
-
callEach(fieldCallbacks[fieldName]);
|
|
960
|
+
vestUtils.isArray(fieldCallbacks[fieldName])) {
|
|
961
|
+
vestUtils.callEach(fieldCallbacks[fieldName]);
|
|
1217
962
|
}
|
|
1218
963
|
}
|
|
1219
964
|
/**
|
|
@@ -1221,15 +966,15 @@ function runFieldCallbacks(fieldName) {
|
|
|
1221
966
|
*/
|
|
1222
967
|
function runDoneCallbacks() {
|
|
1223
968
|
var doneCallbacks = useTestCallbacks()[0].doneCallbacks;
|
|
1224
|
-
callEach(doneCallbacks);
|
|
969
|
+
vestUtils.callEach(doneCallbacks);
|
|
1225
970
|
}
|
|
1226
971
|
|
|
1227
972
|
// eslint-disable-next-line max-lines-per-function
|
|
1228
973
|
function initBus() {
|
|
1229
|
-
var
|
|
974
|
+
var vestBus = vestUtils.bus.createBus();
|
|
1230
975
|
// Report a the completion of a test. There may be other tests with the same
|
|
1231
976
|
// name that are still running, or not yet started.
|
|
1232
|
-
|
|
977
|
+
vestBus.on(Events.TEST_COMPLETED, function (testObject) {
|
|
1233
978
|
if (testObject.isCanceled()) {
|
|
1234
979
|
return;
|
|
1235
980
|
}
|
|
@@ -1237,21 +982,21 @@ function initBus() {
|
|
|
1237
982
|
runFieldCallbacks(testObject.fieldName);
|
|
1238
983
|
if (!hasRemainingTests()) {
|
|
1239
984
|
// When no more tests are running, emit the done event
|
|
1240
|
-
|
|
985
|
+
vestBus.emit(Events.ALL_RUNNING_TESTS_FINISHED);
|
|
1241
986
|
}
|
|
1242
987
|
});
|
|
1243
988
|
// Report that the suite completed its synchronous test run.
|
|
1244
989
|
// Async operations may still be running.
|
|
1245
|
-
|
|
990
|
+
vestBus.on(Events.SUITE_CALLBACK_DONE_RUNNING, function () {
|
|
1246
991
|
// Remove tests that are optional and need to be omitted
|
|
1247
992
|
omitOptionalFields();
|
|
1248
993
|
});
|
|
1249
994
|
// Called when all the tests, including async, are done running
|
|
1250
|
-
|
|
995
|
+
vestBus.on(Events.ALL_RUNNING_TESTS_FINISHED, function () {
|
|
1251
996
|
runDoneCallbacks();
|
|
1252
997
|
});
|
|
1253
998
|
// Removes a certain field from the state.
|
|
1254
|
-
|
|
999
|
+
vestBus.on(Events.REMOVE_FIELD, function (fieldName) {
|
|
1255
1000
|
useEachTestObject(function (testObject) {
|
|
1256
1001
|
if (matchingFieldName(testObject, fieldName)) {
|
|
1257
1002
|
testObject.cancel();
|
|
@@ -1260,18 +1005,18 @@ function initBus() {
|
|
|
1260
1005
|
});
|
|
1261
1006
|
});
|
|
1262
1007
|
// Resets a certain field in the state.
|
|
1263
|
-
|
|
1008
|
+
vestBus.on(Events.RESET_FIELD, function (fieldName) {
|
|
1264
1009
|
useEachTestObject(function (testObject) {
|
|
1265
1010
|
if (matchingFieldName(testObject, fieldName)) {
|
|
1266
1011
|
testObject.reset();
|
|
1267
1012
|
}
|
|
1268
1013
|
});
|
|
1269
1014
|
});
|
|
1270
|
-
return
|
|
1015
|
+
return vestBus;
|
|
1271
1016
|
}
|
|
1272
1017
|
function useBus() {
|
|
1273
1018
|
var context$1 = context.useX();
|
|
1274
|
-
invariant(context$1.bus);
|
|
1019
|
+
vestUtils.invariant(context$1.bus);
|
|
1275
1020
|
return context$1.bus;
|
|
1276
1021
|
}
|
|
1277
1022
|
var Events;
|
|
@@ -1290,16 +1035,16 @@ function create() {
|
|
|
1290
1035
|
args[_i] = arguments[_i];
|
|
1291
1036
|
}
|
|
1292
1037
|
var _a = args.reverse(), suiteCallback = _a[0], suiteName = _a[1];
|
|
1293
|
-
invariant(isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
|
|
1038
|
+
vestUtils.invariant(vestUtils.isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
|
|
1294
1039
|
// Event bus initialization
|
|
1295
1040
|
var bus = initBus();
|
|
1296
1041
|
// State initialization
|
|
1297
1042
|
var state = createState();
|
|
1298
1043
|
// State reference - this holds the actual state values
|
|
1299
|
-
var stateRef = createStateRef(state, { suiteId: genId(), suiteName: suiteName });
|
|
1044
|
+
var stateRef = createStateRef(state, { suiteId: vestUtils.genId(), suiteName: suiteName });
|
|
1300
1045
|
// Create base context reference. All hooks will derive their data from this
|
|
1301
1046
|
var ctxRef = { stateRef: stateRef, bus: bus };
|
|
1302
|
-
var suite = assign(
|
|
1047
|
+
var suite = vestUtils.assign(
|
|
1303
1048
|
// Bind the suite body to the context
|
|
1304
1049
|
context.bind(ctxRef, function () {
|
|
1305
1050
|
var args = [];
|
|
@@ -1345,7 +1090,7 @@ function create() {
|
|
|
1345
1090
|
* })
|
|
1346
1091
|
*/
|
|
1347
1092
|
function each(list, callback) {
|
|
1348
|
-
invariant(isFunction(callback), 'each callback must be a function');
|
|
1093
|
+
vestUtils.invariant(vestUtils.isFunction(callback), 'each callback must be a function');
|
|
1349
1094
|
isolate({ type: IsolateTypes.EACH }, function () {
|
|
1350
1095
|
list.forEach(function (arg, index) {
|
|
1351
1096
|
callback(arg, index);
|
|
@@ -1375,7 +1120,7 @@ function skipWhen(conditional, callback) {
|
|
|
1375
1120
|
// we should skip the test if the parent conditional is true.
|
|
1376
1121
|
isExcludedIndividually() ||
|
|
1377
1122
|
// Otherwise, we should skip the test if the conditional is true.
|
|
1378
|
-
optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
|
|
1123
|
+
vestUtils.optionalFunctionValue(conditional, vestUtils.optionalFunctionValue(produceSuiteResult))
|
|
1379
1124
|
}, function () { return callback(); });
|
|
1380
1125
|
});
|
|
1381
1126
|
}
|
|
@@ -1451,7 +1196,7 @@ function isExcluded(testObject) {
|
|
|
1451
1196
|
// Check if inclusion rules for this field (`include` hook)
|
|
1452
1197
|
// TODO: Check if this may need to be moved outside of the condition.
|
|
1453
1198
|
// What if there are no included tests? This shouldn't run then?
|
|
1454
|
-
return !optionalFunctionValue(inclusion[fieldName]);
|
|
1199
|
+
return !vestUtils.optionalFunctionValue(inclusion[fieldName]);
|
|
1455
1200
|
}
|
|
1456
1201
|
// We're done here. This field is not excluded
|
|
1457
1202
|
return false;
|
|
@@ -1463,7 +1208,7 @@ function isGroupExcluded(groupName) {
|
|
|
1463
1208
|
var context$1 = context.useX();
|
|
1464
1209
|
var exclusion = context$1.exclusion;
|
|
1465
1210
|
var keyGroups = exclusion.groups;
|
|
1466
|
-
var groupPresent = hasOwnProperty(keyGroups, groupName);
|
|
1211
|
+
var groupPresent = vestUtils.hasOwnProperty(keyGroups, groupName);
|
|
1467
1212
|
// When group is either only'ed or skipped
|
|
1468
1213
|
if (groupPresent) {
|
|
1469
1214
|
// Return true if group is skipped and false if only'ed
|
|
@@ -1481,8 +1226,8 @@ function addTo(exclusionGroup, itemType, item) {
|
|
|
1481
1226
|
if (!item) {
|
|
1482
1227
|
return;
|
|
1483
1228
|
}
|
|
1484
|
-
asArray(item).forEach(function (itemName) {
|
|
1485
|
-
if (!isStringValue(itemName)) {
|
|
1229
|
+
vestUtils.asArray(item).forEach(function (itemName) {
|
|
1230
|
+
if (!vestUtils.isStringValue(itemName)) {
|
|
1486
1231
|
return;
|
|
1487
1232
|
}
|
|
1488
1233
|
context$1.exclusion[itemType][itemName] =
|
|
@@ -1529,8 +1274,8 @@ function hasIncludedGroups() {
|
|
|
1529
1274
|
* });
|
|
1530
1275
|
*/
|
|
1531
1276
|
function group(groupName, tests) {
|
|
1532
|
-
invariant(isStringValue(groupName), groupErrorMsg('name must be a string'));
|
|
1533
|
-
invariant(isFunction(tests), groupErrorMsg('callback must be a function'));
|
|
1277
|
+
vestUtils.invariant(vestUtils.isStringValue(groupName), groupErrorMsg('name must be a string'));
|
|
1278
|
+
vestUtils.invariant(vestUtils.isFunction(tests), groupErrorMsg('callback must be a function'));
|
|
1534
1279
|
// Running with the context applied
|
|
1535
1280
|
isolate({ type: IsolateTypes.GROUP }, function () {
|
|
1536
1281
|
context.run({ groupName: groupName }, tests);
|
|
@@ -1543,24 +1288,24 @@ function groupErrorMsg(error) {
|
|
|
1543
1288
|
function include(fieldName) {
|
|
1544
1289
|
var context$1 = context.useX();
|
|
1545
1290
|
var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
|
|
1546
|
-
invariant(isStringValue(fieldName));
|
|
1547
|
-
inclusion[fieldName] = defaultTo(exclusion.tests[fieldName], true);
|
|
1291
|
+
vestUtils.invariant(vestUtils.isStringValue(fieldName));
|
|
1292
|
+
inclusion[fieldName] = vestUtils.defaultTo(exclusion.tests[fieldName], true);
|
|
1548
1293
|
return { when: when };
|
|
1549
1294
|
function when(condition) {
|
|
1550
1295
|
var context$1 = context.useX();
|
|
1551
1296
|
var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
|
|
1552
1297
|
// This callback will run as part of the "isExcluded" series of checks
|
|
1553
1298
|
inclusion[fieldName] = function () {
|
|
1554
|
-
if (hasOwnProperty(exclusion.tests, fieldName)) {
|
|
1299
|
+
if (vestUtils.hasOwnProperty(exclusion.tests, fieldName)) {
|
|
1555
1300
|
// I suspect this code is technically unreachable because
|
|
1556
1301
|
// if there are any skip/only rules applied to the current
|
|
1557
1302
|
// field, the "isExcluded" function will have already bailed
|
|
1558
|
-
return defaultTo(exclusion.tests[fieldName], true);
|
|
1303
|
+
return vestUtils.defaultTo(exclusion.tests[fieldName], true);
|
|
1559
1304
|
}
|
|
1560
|
-
if (isStringValue(condition)) {
|
|
1305
|
+
if (vestUtils.isStringValue(condition)) {
|
|
1561
1306
|
return Boolean(exclusion.tests[condition]);
|
|
1562
1307
|
}
|
|
1563
|
-
return optionalFunctionValue(condition, optionalFunctionValue(produceSuiteResult));
|
|
1308
|
+
return vestUtils.optionalFunctionValue(condition, vestUtils.optionalFunctionValue(produceSuiteResult));
|
|
1564
1309
|
};
|
|
1565
1310
|
}
|
|
1566
1311
|
}
|
|
@@ -1588,9 +1333,7 @@ function eager() {
|
|
|
1588
1333
|
setMode(Modes.EAGER);
|
|
1589
1334
|
}
|
|
1590
1335
|
function shouldSkipBasedOnMode(testObject) {
|
|
1591
|
-
|
|
1592
|
-
return true;
|
|
1593
|
-
return false;
|
|
1336
|
+
return isEager() && hasErrorsByTestObjects(testObject.fieldName);
|
|
1594
1337
|
}
|
|
1595
1338
|
function isEager() {
|
|
1596
1339
|
return isMode(Modes.EAGER);
|
|
@@ -1617,7 +1360,7 @@ function omitWhen(conditional, callback) {
|
|
|
1617
1360
|
isolate({ type: IsolateTypes.OMIT_WHEN }, function () {
|
|
1618
1361
|
context.run({
|
|
1619
1362
|
omitted: isOmitted() ||
|
|
1620
|
-
optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
|
|
1363
|
+
vestUtils.optionalFunctionValue(conditional, vestUtils.optionalFunctionValue(produceSuiteResult))
|
|
1621
1364
|
}, function () { return callback(); });
|
|
1622
1365
|
});
|
|
1623
1366
|
}
|
|
@@ -1639,8 +1382,8 @@ function isOmitted() {
|
|
|
1639
1382
|
function optional(optionals) {
|
|
1640
1383
|
// When the optional is given as a string or a list of strings
|
|
1641
1384
|
// we just add them to the list of optional fields.
|
|
1642
|
-
if (isArray(optionals) || isStringValue(optionals)) {
|
|
1643
|
-
asArray(optionals).forEach(function (optionalField) {
|
|
1385
|
+
if (vestUtils.isArray(optionals) || vestUtils.isStringValue(optionals)) {
|
|
1386
|
+
vestUtils.asArray(optionals).forEach(function (optionalField) {
|
|
1644
1387
|
useSetOptionalField(optionalField, [true, false]);
|
|
1645
1388
|
});
|
|
1646
1389
|
}
|
|
@@ -1679,9 +1422,7 @@ function __spreadArray(to, from, pack) {
|
|
|
1679
1422
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
1680
1423
|
}
|
|
1681
1424
|
|
|
1682
|
-
|
|
1683
|
-
return value && isFunction(value.then);
|
|
1684
|
-
}
|
|
1425
|
+
vestUtils.bindNot(vestUtils.isStringValue);
|
|
1685
1426
|
|
|
1686
1427
|
function isSameProfileTest(testObject1, testObject2) {
|
|
1687
1428
|
return (testObject1.fieldName === testObject2.fieldName &&
|
|
@@ -1701,7 +1442,7 @@ function cancelOverriddenPendingTest(prevRunTestObject, currentRunTestObject) {
|
|
|
1701
1442
|
*/
|
|
1702
1443
|
function runAsyncTest(testObject) {
|
|
1703
1444
|
var asyncTest = testObject.asyncTest, message = testObject.message;
|
|
1704
|
-
if (!isPromise(asyncTest))
|
|
1445
|
+
if (!vestUtils.isPromise(asyncTest))
|
|
1705
1446
|
return;
|
|
1706
1447
|
var emit = useBus().emit;
|
|
1707
1448
|
var stateRef = useStateRef();
|
|
@@ -1714,7 +1455,7 @@ function runAsyncTest(testObject) {
|
|
|
1714
1455
|
if (testObject.isCanceled()) {
|
|
1715
1456
|
return;
|
|
1716
1457
|
}
|
|
1717
|
-
testObject.message = isStringValue(rejectionMessage)
|
|
1458
|
+
testObject.message = vestUtils.isStringValue(rejectionMessage)
|
|
1718
1459
|
? rejectionMessage
|
|
1719
1460
|
: message;
|
|
1720
1461
|
testObject.fail();
|
|
@@ -1749,7 +1490,7 @@ function registerTest(testObject) {
|
|
|
1749
1490
|
try {
|
|
1750
1491
|
// try catch for safe property access
|
|
1751
1492
|
// in case object is an enforce chain
|
|
1752
|
-
if (isPromise(result)) {
|
|
1493
|
+
if (vestUtils.isPromise(result)) {
|
|
1753
1494
|
testObject.asyncTest = result;
|
|
1754
1495
|
testObject.setPending();
|
|
1755
1496
|
runAsyncTest(testObject);
|
|
@@ -1776,12 +1517,12 @@ function registerTest(testObject) {
|
|
|
1776
1517
|
function useTestAtCursor(newTestObject) {
|
|
1777
1518
|
var testObjects = useTestObjects()[0];
|
|
1778
1519
|
var prevTests = testObjects.prev;
|
|
1779
|
-
if (isEmpty(prevTests)) {
|
|
1520
|
+
if (vestUtils.isEmpty(prevTests)) {
|
|
1780
1521
|
useSetTestAtCursor(newTestObject);
|
|
1781
1522
|
return newTestObject;
|
|
1782
1523
|
}
|
|
1783
1524
|
var prevTest = useGetTestAtCursor(prevTests);
|
|
1784
|
-
if (!isNullish(newTestObject.key)) {
|
|
1525
|
+
if (!vestUtils.isNullish(newTestObject.key)) {
|
|
1785
1526
|
var nextTest_1 = handleKeyTest(newTestObject.key, newTestObject);
|
|
1786
1527
|
useSetTestAtCursor(nextTest_1);
|
|
1787
1528
|
return nextTest_1;
|
|
@@ -1792,45 +1533,38 @@ function useTestAtCursor(newTestObject) {
|
|
|
1792
1533
|
// Need to see if this has any effect at all.
|
|
1793
1534
|
prevTest = null;
|
|
1794
1535
|
}
|
|
1795
|
-
var nextTest = defaultTo(prevTest, newTestObject);
|
|
1536
|
+
var nextTest = vestUtils.defaultTo(prevTest, newTestObject);
|
|
1796
1537
|
useSetTestAtCursor(nextTest);
|
|
1797
1538
|
return nextTest;
|
|
1798
1539
|
}
|
|
1799
1540
|
function removeAllNextTestsInIsolate() {
|
|
1800
|
-
var _a = useTestObjects(), testObjects = _a[0], setTestObjects = _a[1];
|
|
1801
|
-
var prevTests = testObjects.prev;
|
|
1802
|
-
var current = getCurrent(prevTests, useCurrentPath());
|
|
1803
1541
|
var cursorAt = useCursor().current();
|
|
1804
|
-
current.splice(cursorAt);
|
|
1805
1542
|
// We actually don't mind mutating the state directly (as can be seen above). There is no harm in it
|
|
1806
1543
|
// since we're only touching the "prev" state. The reason we still use the setter function is
|
|
1807
1544
|
// to prevent future headaches if we ever do need to rely on prev-state immutability.
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
return
|
|
1811
|
-
prev: prevTests,
|
|
1812
|
-
current: current
|
|
1813
|
-
});
|
|
1545
|
+
useSetTests(function (current) {
|
|
1546
|
+
current.splice(cursorAt);
|
|
1547
|
+
return current;
|
|
1814
1548
|
});
|
|
1815
1549
|
}
|
|
1816
1550
|
function useSetTestAtCursor(testObject) {
|
|
1817
1551
|
var cursorPath = useCurrentPath();
|
|
1818
1552
|
useSetTests(function (tests) {
|
|
1819
|
-
return setValueAtPath(tests, cursorPath, testObject);
|
|
1553
|
+
return vestUtils.nestedArray.setValueAtPath(tests, cursorPath, testObject);
|
|
1820
1554
|
});
|
|
1821
1555
|
}
|
|
1822
1556
|
function useGetTestAtCursor(tests) {
|
|
1823
1557
|
var cursorPath = useCurrentPath();
|
|
1824
|
-
return valueAtPath(tests, cursorPath);
|
|
1558
|
+
return vestUtils.nestedArray.valueAtPath(tests, cursorPath);
|
|
1825
1559
|
}
|
|
1826
1560
|
function testReorderDetected(prevTest, newTest) {
|
|
1827
|
-
return isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
|
|
1561
|
+
return vestUtils.isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
|
|
1828
1562
|
}
|
|
1829
1563
|
function throwTestOrderError(prevTest, newTestObject) {
|
|
1830
1564
|
if (shouldAllowReorder()) {
|
|
1831
1565
|
return;
|
|
1832
1566
|
}
|
|
1833
|
-
deferThrow("Vest Critical Error: Tests called in different order than previous run.\n expected: ".concat(prevTest.fieldName, "\n received: ").concat(newTestObject.fieldName, "\n This can happen on one of two reasons:\n 1. You're using if/else statements to conditionally select tests. Instead, use \"skipWhen\".\n 2. You are iterating over a list of tests, and their order changed. Use \"each\" and a custom key prop so that Vest retains their state."));
|
|
1567
|
+
vestUtils.deferThrow("Vest Critical Error: Tests called in different order than previous run.\n expected: ".concat(prevTest.fieldName, "\n received: ").concat(newTestObject.fieldName, "\n This can happen on one of two reasons:\n 1. You're using if/else statements to conditionally select tests. Instead, use \"skipWhen\".\n 2. You are iterating over a list of tests, and their order changed. Use \"each\" and a custom key prop so that Vest retains their state."));
|
|
1834
1568
|
}
|
|
1835
1569
|
function handleKeyTest(key, newTestObject) {
|
|
1836
1570
|
var prevTestByKey = usePrevTestByKey(key);
|
|
@@ -1876,7 +1610,7 @@ function registerTestObjectByTier(testObject) {
|
|
|
1876
1610
|
if (testObject.isUntested()) {
|
|
1877
1611
|
registerTest(testObject);
|
|
1878
1612
|
}
|
|
1879
|
-
else if (isPromise(testObject.asyncTest)) {
|
|
1613
|
+
else if (vestUtils.isPromise(testObject.asyncTest)) {
|
|
1880
1614
|
testObject.setPending();
|
|
1881
1615
|
runAsyncTest(testObject);
|
|
1882
1616
|
}
|
|
@@ -1885,7 +1619,7 @@ function registerTestObjectByTier(testObject) {
|
|
|
1885
1619
|
/* eslint-disable jest/valid-title */
|
|
1886
1620
|
// eslint-disable-next-line max-lines-per-function
|
|
1887
1621
|
function bindTestMemo(test) {
|
|
1888
|
-
var cache =
|
|
1622
|
+
var cache = vestUtils.cache(10); // arbitrary cache size
|
|
1889
1623
|
// eslint-disable-next-line max-statements
|
|
1890
1624
|
function memo(fieldName) {
|
|
1891
1625
|
var args = [];
|
|
@@ -1897,7 +1631,7 @@ function bindTestMemo(test) {
|
|
|
1897
1631
|
// Implicit dependency for more specificity
|
|
1898
1632
|
var dependencies = [useSuiteId(), fieldName, cursorAt].concat(deps);
|
|
1899
1633
|
var cached = cache.get(dependencies);
|
|
1900
|
-
if (isNull(cached)) {
|
|
1634
|
+
if (vestUtils.isNull(cached)) {
|
|
1901
1635
|
// cache miss
|
|
1902
1636
|
return cache(dependencies, function () { return test(fieldName, msg, testFn); });
|
|
1903
1637
|
}
|
|
@@ -1916,9 +1650,9 @@ function testBase(fieldName) {
|
|
|
1916
1650
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1917
1651
|
args[_i - 1] = arguments[_i];
|
|
1918
1652
|
}
|
|
1919
|
-
var _a = (isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
|
|
1920
|
-
invariant(isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
|
|
1921
|
-
invariant(isFunction(testFn), incompatibleParamsError('Test callback', 'function'));
|
|
1653
|
+
var _a = (vestUtils.isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
|
|
1654
|
+
vestUtils.invariant(vestUtils.isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
|
|
1655
|
+
vestUtils.invariant(vestUtils.isFunction(testFn), incompatibleParamsError('Test callback', 'function'));
|
|
1922
1656
|
var context$1 = context.useX();
|
|
1923
1657
|
var testObject = new VestTest(fieldName, testFn, {
|
|
1924
1658
|
message: message,
|
|
@@ -1936,7 +1670,7 @@ function testBase(fieldName) {
|
|
|
1936
1670
|
* enforce(data.username).isNotBlank();
|
|
1937
1671
|
* });
|
|
1938
1672
|
*/
|
|
1939
|
-
var test = assign(testBase, {
|
|
1673
|
+
var test = vestUtils.assign(testBase, {
|
|
1940
1674
|
memo: bindTestMemo(testBase)
|
|
1941
1675
|
});
|
|
1942
1676
|
function incompatibleParamsError(name, expected) {
|
|
@@ -1950,11 +1684,11 @@ var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won
|
|
|
1950
1684
|
*/
|
|
1951
1685
|
function warn() {
|
|
1952
1686
|
var ctx = context.useX('warn ' + ERROR_HOOK_CALLED_OUTSIDE);
|
|
1953
|
-
invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
|
|
1687
|
+
vestUtils.invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
|
|
1954
1688
|
ctx.currentTest.warn();
|
|
1955
1689
|
}
|
|
1956
1690
|
|
|
1957
|
-
var VERSION = "4.4.
|
|
1691
|
+
var VERSION = "4.4.2-dev-d13b14";
|
|
1958
1692
|
|
|
1959
1693
|
Object.defineProperty(exports, 'enforce', {
|
|
1960
1694
|
enumerable: true,
|