vest 4.2.1-dev-ee64be → 4.2.3-dev-87ebfa
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/classnames.development.js +21 -8
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/enforce/compose.development.js +27 -59
- package/dist/cjs/enforce/compose.production.js +1 -1
- package/dist/cjs/promisify.development.js +21 -8
- package/dist/cjs/promisify.production.js +1 -1
- package/dist/cjs/vest.development.js +322 -313
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +21 -8
- package/dist/es/classnames.production.js +1 -1
- package/dist/es/enforce/compose.development.js +27 -59
- package/dist/es/enforce/compose.production.js +1 -1
- package/dist/es/promisify.development.js +21 -8
- package/dist/es/promisify.production.js +1 -1
- package/dist/es/vest.development.js +322 -313
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +21 -8
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +73 -83
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +18 -20
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +18 -20
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/promisify.development.js +21 -8
- package/dist/umd/promisify.production.js +1 -1
- package/dist/umd/vest.development.js +279 -277
- package/dist/umd/vest.production.js +1 -1
- package/package.json +1 -1
- package/testUtils/mockThrowError.ts +3 -6
- package/testUtils/suiteDummy.ts +5 -5
- package/types/classnames.d.ts +9 -8
- package/types/parser.d.ts +9 -8
- package/types/promisify.d.ts +9 -8
- package/types/vest.d.ts +69 -68
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var n4s = require('n4s');
|
|
6
6
|
var context$1 = require('context');
|
|
7
7
|
|
|
8
|
+
var assign = Object.assign;
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* @returns a unique numeric id.
|
|
10
12
|
*/
|
|
@@ -12,76 +14,203 @@ var genId = (function (n) { return function () {
|
|
|
12
14
|
return "".concat(n++);
|
|
13
15
|
}; })(0);
|
|
14
16
|
|
|
15
|
-
function
|
|
16
|
-
return
|
|
17
|
+
function isFunction(value) {
|
|
18
|
+
return typeof value === 'function';
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return !fn.apply(void 0, args);
|
|
26
|
-
};
|
|
21
|
+
function optionalFunctionValue(value) {
|
|
22
|
+
var args = [];
|
|
23
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
24
|
+
args[_i - 1] = arguments[_i];
|
|
25
|
+
}
|
|
26
|
+
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
function
|
|
30
|
-
|
|
29
|
+
function invariant(condition,
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
31
|
+
message) {
|
|
32
|
+
if (condition) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
// If message is a string object (rather than string literal)
|
|
36
|
+
// Throw the value directly as a string
|
|
37
|
+
// Alternatively, throw an error with the message
|
|
38
|
+
throw message instanceof String
|
|
39
|
+
? message.valueOf()
|
|
40
|
+
: new Error(message ? optionalFunctionValue(message) : message);
|
|
31
41
|
}
|
|
32
42
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
43
|
+
// eslint-disable-next-line max-lines-per-function
|
|
44
|
+
function createState(onStateChange) {
|
|
45
|
+
var state = {
|
|
46
|
+
references: []
|
|
47
|
+
};
|
|
48
|
+
var registrations = [];
|
|
49
|
+
return {
|
|
50
|
+
registerStateKey: registerStateKey,
|
|
51
|
+
reset: reset
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Registers a new key in the state, takes the initial value (may be a function that returns the initial value), returns a function.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
*
|
|
58
|
+
* const useColor = state.registerStateKey("blue");
|
|
59
|
+
*
|
|
60
|
+
* let [color, setColor] = useColor(); // -> ["blue", Function]
|
|
61
|
+
*
|
|
62
|
+
* setColor("green");
|
|
63
|
+
*
|
|
64
|
+
* useColor()[0]; -> "green"
|
|
65
|
+
*/
|
|
66
|
+
function registerStateKey(initialState, onUpdate) {
|
|
67
|
+
var key = registrations.length;
|
|
68
|
+
registrations.push([initialState, onUpdate]);
|
|
69
|
+
return initKey(key, initialState);
|
|
70
|
+
}
|
|
71
|
+
function reset() {
|
|
72
|
+
var prev = current();
|
|
73
|
+
state.references = [];
|
|
74
|
+
registrations.forEach(function (_a, index) {
|
|
75
|
+
var initialValue = _a[0];
|
|
76
|
+
return initKey(index, initialValue, prev[index]);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function initKey(key, initialState, prevState) {
|
|
80
|
+
current().push();
|
|
81
|
+
set(key, optionalFunctionValue(initialState, prevState));
|
|
82
|
+
return function useStateKey() {
|
|
83
|
+
return [
|
|
84
|
+
current()[key],
|
|
85
|
+
function (nextState) {
|
|
86
|
+
return set(key, optionalFunctionValue(nextState, current()[key]));
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function current() {
|
|
92
|
+
return state.references;
|
|
93
|
+
}
|
|
94
|
+
function set(index, value) {
|
|
95
|
+
var prevValue = state.references[index];
|
|
96
|
+
state.references[index] = value;
|
|
97
|
+
var _a = registrations[index], onUpdate = _a[1];
|
|
98
|
+
if (isFunction(onUpdate)) {
|
|
99
|
+
onUpdate(value, prevValue);
|
|
100
|
+
}
|
|
101
|
+
if (isFunction(onStateChange)) {
|
|
102
|
+
onStateChange();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
36
105
|
}
|
|
37
106
|
|
|
38
|
-
|
|
39
|
-
|
|
107
|
+
var IsolateTypes;
|
|
108
|
+
(function (IsolateTypes) {
|
|
109
|
+
IsolateTypes[IsolateTypes["DEFAULT"] = 0] = "DEFAULT";
|
|
110
|
+
IsolateTypes[IsolateTypes["SUITE"] = 1] = "SUITE";
|
|
111
|
+
IsolateTypes[IsolateTypes["EACH"] = 2] = "EACH";
|
|
112
|
+
IsolateTypes[IsolateTypes["SKIP_WHEN"] = 3] = "SKIP_WHEN";
|
|
113
|
+
IsolateTypes[IsolateTypes["OMIT_WHEN"] = 4] = "OMIT_WHEN";
|
|
114
|
+
IsolateTypes[IsolateTypes["GROUP"] = 5] = "GROUP";
|
|
115
|
+
})(IsolateTypes || (IsolateTypes = {}));
|
|
116
|
+
|
|
117
|
+
function createStateRef(state, _a) {
|
|
118
|
+
var suiteId = _a.suiteId, suiteName = _a.suiteName;
|
|
119
|
+
return {
|
|
120
|
+
optionalFields: state.registerStateKey(function () { return ({}); }),
|
|
121
|
+
suiteId: state.registerStateKey(suiteId),
|
|
122
|
+
suiteName: state.registerStateKey(suiteName),
|
|
123
|
+
testCallbacks: state.registerStateKey(function () { return ({
|
|
124
|
+
fieldCallbacks: {},
|
|
125
|
+
doneCallbacks: []
|
|
126
|
+
}); }),
|
|
127
|
+
testObjects: state.registerStateKey(function (prev) {
|
|
128
|
+
return {
|
|
129
|
+
prev: prev ? prev.current : [],
|
|
130
|
+
current: []
|
|
131
|
+
};
|
|
132
|
+
})
|
|
133
|
+
};
|
|
40
134
|
}
|
|
41
135
|
|
|
42
|
-
function
|
|
43
|
-
return
|
|
136
|
+
function asArray(possibleArg) {
|
|
137
|
+
return [].concat(possibleArg);
|
|
44
138
|
}
|
|
45
139
|
|
|
46
|
-
function
|
|
47
|
-
|
|
140
|
+
function last(values) {
|
|
141
|
+
var valuesArray = asArray(values);
|
|
142
|
+
return valuesArray[valuesArray.length - 1];
|
|
48
143
|
}
|
|
49
144
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
function createCache(maxSize) {
|
|
54
|
-
if (maxSize === void 0) { maxSize = 1; }
|
|
55
|
-
var cacheStorage = [];
|
|
56
|
-
var cache = function (deps, cacheAction) {
|
|
57
|
-
var cacheHit = cache.get(deps);
|
|
58
|
-
// cache hit is not null
|
|
59
|
-
if (cacheHit)
|
|
60
|
-
return cacheHit[1];
|
|
61
|
-
var result = cacheAction();
|
|
62
|
-
cacheStorage.unshift([deps.concat(), result]);
|
|
63
|
-
if (longerThan(cacheStorage, maxSize))
|
|
64
|
-
cacheStorage.length = maxSize;
|
|
65
|
-
return result;
|
|
145
|
+
function createCursor() {
|
|
146
|
+
var storage = {
|
|
147
|
+
cursor: []
|
|
66
148
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
149
|
+
function addLevel() {
|
|
150
|
+
storage.cursor.push(0);
|
|
151
|
+
}
|
|
152
|
+
function removeLevel() {
|
|
153
|
+
storage.cursor.pop();
|
|
154
|
+
}
|
|
155
|
+
function cursorAt() {
|
|
156
|
+
return last(storage.cursor);
|
|
157
|
+
}
|
|
158
|
+
function getCursor() {
|
|
159
|
+
return asArray(storage.cursor);
|
|
160
|
+
}
|
|
161
|
+
function next() {
|
|
162
|
+
storage.cursor[storage.cursor.length - 1]++;
|
|
163
|
+
return last(storage.cursor);
|
|
164
|
+
}
|
|
165
|
+
function reset() {
|
|
166
|
+
storage.cursor = [0];
|
|
167
|
+
}
|
|
168
|
+
reset();
|
|
169
|
+
return {
|
|
170
|
+
addLevel: addLevel,
|
|
171
|
+
cursorAt: cursorAt,
|
|
172
|
+
getCursor: getCursor,
|
|
173
|
+
next: next,
|
|
174
|
+
removeLevel: removeLevel,
|
|
175
|
+
reset: reset
|
|
72
176
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
var Modes;
|
|
180
|
+
(function (Modes) {
|
|
181
|
+
Modes[Modes["ALL"] = 0] = "ALL";
|
|
182
|
+
Modes[Modes["EAGER"] = 1] = "EAGER";
|
|
183
|
+
})(Modes || (Modes = {}));
|
|
184
|
+
|
|
185
|
+
var context = context$1.createContext(function (ctxRef, parentContext) {
|
|
186
|
+
return parentContext
|
|
187
|
+
? null
|
|
188
|
+
: assign({}, {
|
|
189
|
+
exclusion: {
|
|
190
|
+
tests: {},
|
|
191
|
+
groups: {}
|
|
192
|
+
},
|
|
193
|
+
inclusion: {},
|
|
194
|
+
isolate: {
|
|
195
|
+
type: IsolateTypes.DEFAULT,
|
|
196
|
+
keys: {
|
|
197
|
+
current: {},
|
|
198
|
+
prev: {}
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
mode: [Modes.ALL],
|
|
202
|
+
testCursor: createCursor()
|
|
203
|
+
}, ctxRef);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
function bindNot(fn) {
|
|
207
|
+
return function () {
|
|
208
|
+
var args = [];
|
|
209
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
210
|
+
args[_i] = arguments[_i];
|
|
211
|
+
}
|
|
212
|
+
return !fn.apply(void 0, args);
|
|
76
213
|
};
|
|
77
|
-
return cache;
|
|
78
|
-
function findIndex(deps) {
|
|
79
|
-
return cacheStorage.findIndex(function (_a) {
|
|
80
|
-
var cachedDeps = _a[0];
|
|
81
|
-
return lengthEquals(deps, cachedDeps.length) &&
|
|
82
|
-
deps.every(function (dep, i) { return dep === cachedDeps[i]; });
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
214
|
}
|
|
86
215
|
|
|
87
216
|
// The module is named "isArrayValue" since it
|
|
@@ -96,28 +225,11 @@ function isNull(value) {
|
|
|
96
225
|
}
|
|
97
226
|
var isNotNull = bindNot(isNull);
|
|
98
227
|
|
|
99
|
-
function isFunction(value) {
|
|
100
|
-
return typeof value === 'function';
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function optionalFunctionValue(value) {
|
|
104
|
-
var args = [];
|
|
105
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
106
|
-
args[_i - 1] = arguments[_i];
|
|
107
|
-
}
|
|
108
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
228
|
function defaultTo(callback, defaultValue) {
|
|
112
229
|
var _a;
|
|
113
230
|
return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
|
|
114
231
|
}
|
|
115
232
|
|
|
116
|
-
function last(values) {
|
|
117
|
-
var valuesArray = asArray(values);
|
|
118
|
-
return valuesArray[valuesArray.length - 1];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
233
|
// This is kind of a map/filter in one function.
|
|
122
234
|
// Normally, behaves like a nested-array map,
|
|
123
235
|
// but returning `null` will drop the element from the array
|
|
@@ -163,78 +275,73 @@ function getCurrent(array, path) {
|
|
|
163
275
|
return current;
|
|
164
276
|
}
|
|
165
277
|
|
|
166
|
-
|
|
278
|
+
function isUndefined(value) {
|
|
279
|
+
return value === undefined;
|
|
280
|
+
}
|
|
167
281
|
|
|
168
|
-
function
|
|
169
|
-
|
|
170
|
-
cursor: []
|
|
171
|
-
};
|
|
172
|
-
function addLevel() {
|
|
173
|
-
storage.cursor.push(0);
|
|
174
|
-
}
|
|
175
|
-
function removeLevel() {
|
|
176
|
-
storage.cursor.pop();
|
|
177
|
-
}
|
|
178
|
-
function cursorAt() {
|
|
179
|
-
return last(storage.cursor);
|
|
180
|
-
}
|
|
181
|
-
function getCursor() {
|
|
182
|
-
return asArray(storage.cursor);
|
|
183
|
-
}
|
|
184
|
-
function next() {
|
|
185
|
-
storage.cursor[storage.cursor.length - 1]++;
|
|
186
|
-
return last(storage.cursor);
|
|
187
|
-
}
|
|
188
|
-
function reset() {
|
|
189
|
-
storage.cursor = [0];
|
|
190
|
-
}
|
|
191
|
-
reset();
|
|
192
|
-
return {
|
|
193
|
-
addLevel: addLevel,
|
|
194
|
-
cursorAt: cursorAt,
|
|
195
|
-
getCursor: getCursor,
|
|
196
|
-
next: next,
|
|
197
|
-
removeLevel: removeLevel,
|
|
198
|
-
reset: reset
|
|
199
|
-
};
|
|
282
|
+
function isNullish(value) {
|
|
283
|
+
return isNull(value) || isUndefined(value);
|
|
200
284
|
}
|
|
201
285
|
|
|
202
|
-
|
|
203
|
-
(function (
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
IsolateTypes[IsolateTypes["SKIP_WHEN"] = 3] = "SKIP_WHEN";
|
|
208
|
-
IsolateTypes[IsolateTypes["OMIT_WHEN"] = 4] = "OMIT_WHEN";
|
|
209
|
-
IsolateTypes[IsolateTypes["GROUP"] = 5] = "GROUP";
|
|
210
|
-
})(IsolateTypes || (IsolateTypes = {}));
|
|
286
|
+
function deferThrow(message) {
|
|
287
|
+
setTimeout(function () {
|
|
288
|
+
throw new Error(message);
|
|
289
|
+
}, 0);
|
|
290
|
+
}
|
|
211
291
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
Modes[Modes["EAGER"] = 1] = "EAGER";
|
|
216
|
-
})(Modes || (Modes = {}));
|
|
292
|
+
function isStringValue(v) {
|
|
293
|
+
return String(v) === v;
|
|
294
|
+
}
|
|
217
295
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
296
|
+
function shouldUseErrorAsMessage(message, error) {
|
|
297
|
+
// kind of cheating with this safe guard, but it does the job
|
|
298
|
+
return isUndefined(message) && isStringValue(error);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function lengthEquals(value, arg1) {
|
|
302
|
+
return value.length === Number(arg1);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function longerThan(value, arg1) {
|
|
306
|
+
return value.length > Number(arg1);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Creates a cache function
|
|
311
|
+
*/
|
|
312
|
+
function createCache(maxSize) {
|
|
313
|
+
if (maxSize === void 0) { maxSize = 1; }
|
|
314
|
+
var cacheStorage = [];
|
|
315
|
+
var cache = function (deps, cacheAction) {
|
|
316
|
+
var cacheHit = cache.get(deps);
|
|
317
|
+
// cache hit is not null
|
|
318
|
+
if (cacheHit)
|
|
319
|
+
return cacheHit[1];
|
|
320
|
+
var result = cacheAction();
|
|
321
|
+
cacheStorage.unshift([deps.concat(), result]);
|
|
322
|
+
if (longerThan(cacheStorage, maxSize))
|
|
323
|
+
cacheStorage.length = maxSize;
|
|
324
|
+
return result;
|
|
325
|
+
};
|
|
326
|
+
// invalidate an item in the cache by its dependencies
|
|
327
|
+
cache.invalidate = function (deps) {
|
|
328
|
+
var index = findIndex(deps);
|
|
329
|
+
if (index > -1)
|
|
330
|
+
cacheStorage.splice(index, 1);
|
|
331
|
+
};
|
|
332
|
+
// Retrieves an item from the cache.
|
|
333
|
+
cache.get = function (deps) {
|
|
334
|
+
return cacheStorage[findIndex(deps)] || null;
|
|
335
|
+
};
|
|
336
|
+
return cache;
|
|
337
|
+
function findIndex(deps) {
|
|
338
|
+
return cacheStorage.findIndex(function (_a) {
|
|
339
|
+
var cachedDeps = _a[0];
|
|
340
|
+
return lengthEquals(deps, cachedDeps.length) &&
|
|
341
|
+
deps.every(function (dep, i) { return dep === cachedDeps[i]; });
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
}
|
|
238
345
|
|
|
239
346
|
// STATE REF
|
|
240
347
|
function useStateRef() {
|
|
@@ -451,105 +558,6 @@ var STATUS_PENDING = 'PENDING';
|
|
|
451
558
|
var STATUS_CANCELED = 'CANCELED';
|
|
452
559
|
var STATUS_OMITTED = 'OMITTED';
|
|
453
560
|
|
|
454
|
-
/**
|
|
455
|
-
* Throws a timed out error.
|
|
456
|
-
*/
|
|
457
|
-
function throwError(devMessage, productionMessage) {
|
|
458
|
-
throw new Error(devMessage );
|
|
459
|
-
}
|
|
460
|
-
function throwErrorDeferred(devMessage, productionMessage) {
|
|
461
|
-
setTimeout(function () {
|
|
462
|
-
throwError(devMessage);
|
|
463
|
-
}, 0);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
// eslint-disable-next-line max-lines-per-function
|
|
467
|
-
function createState(onStateChange) {
|
|
468
|
-
var state = {
|
|
469
|
-
references: []
|
|
470
|
-
};
|
|
471
|
-
var registrations = [];
|
|
472
|
-
return {
|
|
473
|
-
registerStateKey: registerStateKey,
|
|
474
|
-
reset: reset
|
|
475
|
-
};
|
|
476
|
-
/**
|
|
477
|
-
* Registers a new key in the state, takes the initial value (may be a function that returns the initial value), returns a function.
|
|
478
|
-
*
|
|
479
|
-
* @example
|
|
480
|
-
*
|
|
481
|
-
* const useColor = state.registerStateKey("blue");
|
|
482
|
-
*
|
|
483
|
-
* let [color, setColor] = useColor(); // -> ["blue", Function]
|
|
484
|
-
*
|
|
485
|
-
* setColor("green");
|
|
486
|
-
*
|
|
487
|
-
* useColor()[0]; -> "green"
|
|
488
|
-
*/
|
|
489
|
-
function registerStateKey(initialState, onUpdate) {
|
|
490
|
-
var key = registrations.length;
|
|
491
|
-
registrations.push([initialState, onUpdate]);
|
|
492
|
-
return initKey(key, initialState);
|
|
493
|
-
}
|
|
494
|
-
function reset() {
|
|
495
|
-
var prev = current();
|
|
496
|
-
state.references = [];
|
|
497
|
-
registrations.forEach(function (_a, index) {
|
|
498
|
-
var initialValue = _a[0];
|
|
499
|
-
return initKey(index, initialValue, prev[index]);
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
function initKey(key, initialState, prevState) {
|
|
503
|
-
current().push();
|
|
504
|
-
set(key, optionalFunctionValue(initialState, prevState));
|
|
505
|
-
return function useStateKey() {
|
|
506
|
-
return [
|
|
507
|
-
current()[key],
|
|
508
|
-
function (nextState) {
|
|
509
|
-
return set(key, optionalFunctionValue(nextState, current()[key]));
|
|
510
|
-
},
|
|
511
|
-
];
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
function current() {
|
|
515
|
-
return state.references;
|
|
516
|
-
}
|
|
517
|
-
function set(index, value) {
|
|
518
|
-
var prevValue = state.references[index];
|
|
519
|
-
state.references[index] = value;
|
|
520
|
-
var _a = registrations[index], onUpdate = _a[1];
|
|
521
|
-
if (isFunction(onUpdate)) {
|
|
522
|
-
onUpdate(value, prevValue);
|
|
523
|
-
}
|
|
524
|
-
if (isFunction(onStateChange)) {
|
|
525
|
-
onStateChange();
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
function createStateRef(state, _a) {
|
|
531
|
-
var suiteId = _a.suiteId, suiteName = _a.suiteName;
|
|
532
|
-
return {
|
|
533
|
-
optionalFields: state.registerStateKey(function () { return ({}); }),
|
|
534
|
-
suiteId: state.registerStateKey(suiteId),
|
|
535
|
-
suiteName: state.registerStateKey(suiteName),
|
|
536
|
-
testCallbacks: state.registerStateKey(function () { return ({
|
|
537
|
-
fieldCallbacks: {},
|
|
538
|
-
doneCallbacks: []
|
|
539
|
-
}); }),
|
|
540
|
-
testObjects: state.registerStateKey(function (prev) {
|
|
541
|
-
return {
|
|
542
|
-
prev: prev ? prev.current : [],
|
|
543
|
-
current: []
|
|
544
|
-
};
|
|
545
|
-
})
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
function isNullish(value) {
|
|
550
|
-
return isNull(value) || isUndefined(value);
|
|
551
|
-
}
|
|
552
|
-
|
|
553
561
|
function usePath() {
|
|
554
562
|
var context$1 = context.useX();
|
|
555
563
|
return context$1.testCursor.getCursor();
|
|
@@ -595,7 +603,7 @@ function useRetainTestKey(key, testObject) {
|
|
|
595
603
|
current[key] = testObject;
|
|
596
604
|
}
|
|
597
605
|
else {
|
|
598
|
-
|
|
606
|
+
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."));
|
|
599
607
|
}
|
|
600
608
|
}
|
|
601
609
|
|
|
@@ -628,6 +636,11 @@ var Severity;
|
|
|
628
636
|
Severity["WARNINGS"] = "warnings";
|
|
629
637
|
Severity["ERRORS"] = "errors";
|
|
630
638
|
})(Severity || (Severity = {}));
|
|
639
|
+
var SeverityCount;
|
|
640
|
+
(function (SeverityCount) {
|
|
641
|
+
SeverityCount["ERROR_COUNT"] = "errorCount";
|
|
642
|
+
SeverityCount["WARN_COUNT"] = "warnCount";
|
|
643
|
+
})(SeverityCount || (SeverityCount = {}));
|
|
631
644
|
|
|
632
645
|
/**
|
|
633
646
|
* Reads the testObjects list and gets full validation result from it.
|
|
@@ -638,18 +651,26 @@ function genTestsSummary() {
|
|
|
638
651
|
groups: {},
|
|
639
652
|
tests: {}
|
|
640
653
|
});
|
|
641
|
-
|
|
654
|
+
testObjects.reduce(function (summary, testObject) {
|
|
655
|
+
appendToTest(summary.tests, testObject);
|
|
656
|
+
appendToGroup(summary.groups, testObject);
|
|
657
|
+
return summary;
|
|
658
|
+
}, summary);
|
|
642
659
|
return countFailures(summary);
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
660
|
+
}
|
|
661
|
+
function appendToTest(tests, testObject) {
|
|
662
|
+
tests[testObject.fieldName] = appendTestObject(tests, testObject);
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Appends to a group object if within a group
|
|
666
|
+
*/
|
|
667
|
+
function appendToGroup(groups, testObject) {
|
|
668
|
+
var groupName = testObject.groupName;
|
|
669
|
+
if (!groupName) {
|
|
670
|
+
return;
|
|
652
671
|
}
|
|
672
|
+
groups[groupName] = groups[groupName] || {};
|
|
673
|
+
groups[groupName][testObject.fieldName] = appendTestObject(groups[groupName], testObject);
|
|
653
674
|
}
|
|
654
675
|
/**
|
|
655
676
|
* Counts the failed tests and adds global counters
|
|
@@ -662,29 +683,36 @@ function countFailures(summary) {
|
|
|
662
683
|
}
|
|
663
684
|
return summary;
|
|
664
685
|
}
|
|
686
|
+
/**
|
|
687
|
+
* Appends the test to a results object
|
|
688
|
+
*/
|
|
665
689
|
// eslint-disable-next-line max-statements
|
|
666
|
-
function
|
|
690
|
+
function appendTestObject(summaryKey, testObject) {
|
|
667
691
|
var fieldName = testObject.fieldName, message = testObject.message;
|
|
668
692
|
summaryKey[fieldName] = summaryKey[fieldName] || baseStats();
|
|
669
693
|
var testKey = summaryKey[fieldName];
|
|
670
694
|
if (testObject.isNonActionable())
|
|
671
695
|
return testKey;
|
|
672
696
|
summaryKey[fieldName].testCount++;
|
|
673
|
-
// Adds to severity group
|
|
674
|
-
function addTo(severity) {
|
|
675
|
-
var countKey = severity === Severity.ERRORS ? 'errorCount' : 'warnCount';
|
|
676
|
-
testKey[countKey]++;
|
|
677
|
-
if (message) {
|
|
678
|
-
testKey[severity] = (testKey[severity] || []).concat(message);
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
697
|
if (testObject.isFailing()) {
|
|
682
|
-
|
|
698
|
+
incrementFailures(Severity.ERRORS);
|
|
683
699
|
}
|
|
684
700
|
else if (testObject.isWarning()) {
|
|
685
|
-
|
|
701
|
+
incrementFailures(Severity.WARNINGS);
|
|
686
702
|
}
|
|
687
703
|
return testKey;
|
|
704
|
+
function incrementFailures(severity) {
|
|
705
|
+
var countKey = getCountKey(severity);
|
|
706
|
+
testKey[countKey]++;
|
|
707
|
+
if (message) {
|
|
708
|
+
testKey[severity] = (testKey[severity] || []).concat(message);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
function getCountKey(severity) {
|
|
713
|
+
return severity === Severity.ERRORS
|
|
714
|
+
? SeverityCount.ERROR_COUNT
|
|
715
|
+
: SeverityCount.WARN_COUNT;
|
|
688
716
|
}
|
|
689
717
|
function baseStats() {
|
|
690
718
|
return {
|
|
@@ -815,9 +843,7 @@ function getWarningsByGroup(groupName, fieldName) {
|
|
|
815
843
|
* Gets failure messages by group.
|
|
816
844
|
*/
|
|
817
845
|
function getByGroup(severityKey, group, fieldName) {
|
|
818
|
-
|
|
819
|
-
throwError("get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
|
|
820
|
-
}
|
|
846
|
+
invariant(group, "get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
|
|
821
847
|
var testObjects = useTestsFlat();
|
|
822
848
|
return collectFailureMessages(severityKey, testObjects, {
|
|
823
849
|
group: group,
|
|
@@ -901,18 +927,18 @@ function isEmpty(value) {
|
|
|
901
927
|
var isNotEmpty = bindNot(isEmpty);
|
|
902
928
|
|
|
903
929
|
// eslint-disable-next-line max-statements, complexity
|
|
904
|
-
function isValid(
|
|
930
|
+
function isValid(fieldName) {
|
|
905
931
|
if (fieldIsOmitted(fieldName)) {
|
|
906
932
|
return true;
|
|
907
933
|
}
|
|
908
|
-
if (
|
|
934
|
+
if (hasErrors(fieldName)) {
|
|
909
935
|
return false;
|
|
910
936
|
}
|
|
911
937
|
var testObjects = useTestsFlat();
|
|
912
938
|
if (isEmpty(testObjects)) {
|
|
913
939
|
return false;
|
|
914
940
|
}
|
|
915
|
-
if (fieldDoesNotExist(
|
|
941
|
+
if (fieldDoesNotExist(fieldName)) {
|
|
916
942
|
return false;
|
|
917
943
|
}
|
|
918
944
|
if (hasNonOptionalIncomplete(fieldName)) {
|
|
@@ -936,8 +962,10 @@ function hasNonOptionalIncomplete(fieldName) {
|
|
|
936
962
|
return optionalFields[testObject.fieldName] !== true;
|
|
937
963
|
}));
|
|
938
964
|
}
|
|
939
|
-
function fieldDoesNotExist(
|
|
940
|
-
|
|
965
|
+
function fieldDoesNotExist(fieldName) {
|
|
966
|
+
var testObjects = useTestsFlat();
|
|
967
|
+
return (!!fieldName &&
|
|
968
|
+
!testObjects.find(function (testObject) { return testObject.fieldName === fieldName; }));
|
|
941
969
|
}
|
|
942
970
|
function noMissingTests(fieldName) {
|
|
943
971
|
var testObjects = useTestsFlat();
|
|
@@ -953,7 +981,7 @@ function noMissingTests(fieldName) {
|
|
|
953
981
|
}
|
|
954
982
|
|
|
955
983
|
var cache$1 = createCache(20);
|
|
956
|
-
function
|
|
984
|
+
function produceSuiteResult() {
|
|
957
985
|
var testObjects = useTestsFlat();
|
|
958
986
|
var ctxRef = { stateRef: useStateRef() };
|
|
959
987
|
return cache$1([testObjects], context.bind(ctxRef, function () {
|
|
@@ -967,9 +995,7 @@ function produceBase() {
|
|
|
967
995
|
hasErrorsByGroup: context.bind(ctxRef, hasErrorsByGroup),
|
|
968
996
|
hasWarnings: context.bind(ctxRef, hasWarnings),
|
|
969
997
|
hasWarningsByGroup: context.bind(ctxRef, hasWarningsByGroup),
|
|
970
|
-
isValid: context.bind(ctxRef,
|
|
971
|
-
return isValid(produceBase(), fieldName);
|
|
972
|
-
}),
|
|
998
|
+
isValid: context.bind(ctxRef, isValid),
|
|
973
999
|
suiteName: suiteName
|
|
974
1000
|
});
|
|
975
1001
|
}));
|
|
@@ -996,7 +1022,7 @@ function produceFullResult() {
|
|
|
996
1022
|
var testObjects = useTestsFlat();
|
|
997
1023
|
var ctxRef = { stateRef: useStateRef() };
|
|
998
1024
|
return cache([testObjects], context.bind(ctxRef, function () {
|
|
999
|
-
return assign({},
|
|
1025
|
+
return assign({}, produceSuiteResult(), {
|
|
1000
1026
|
done: context.bind(ctxRef, done)
|
|
1001
1027
|
});
|
|
1002
1028
|
}));
|
|
@@ -1029,7 +1055,7 @@ var done = function done() {
|
|
|
1029
1055
|
if (shouldSkipDoneRegistration(callback, fieldName, output)) {
|
|
1030
1056
|
return output;
|
|
1031
1057
|
}
|
|
1032
|
-
var doneCallback = function () { return callback(
|
|
1058
|
+
var doneCallback = function () { return callback(produceSuiteResult()); };
|
|
1033
1059
|
if (shouldRunDoneCallback(fieldName)) {
|
|
1034
1060
|
doneCallback();
|
|
1035
1061
|
return output;
|
|
@@ -1178,9 +1204,7 @@ function initBus() {
|
|
|
1178
1204
|
}
|
|
1179
1205
|
function useBus() {
|
|
1180
1206
|
var context$1 = context.useX();
|
|
1181
|
-
|
|
1182
|
-
throwError();
|
|
1183
|
-
}
|
|
1207
|
+
invariant(context$1.bus);
|
|
1184
1208
|
return context$1.bus;
|
|
1185
1209
|
}
|
|
1186
1210
|
var Events;
|
|
@@ -1199,9 +1223,7 @@ function create() {
|
|
|
1199
1223
|
args[_i] = arguments[_i];
|
|
1200
1224
|
}
|
|
1201
1225
|
var _a = args.reverse(), suiteCallback = _a[0], suiteName = _a[1];
|
|
1202
|
-
|
|
1203
|
-
throwError('vest.create: Expected callback to be a function.');
|
|
1204
|
-
}
|
|
1226
|
+
invariant(isFunction(suiteCallback), 'vest.create: Expected callback to be a function.');
|
|
1205
1227
|
// Event bus initialization
|
|
1206
1228
|
var bus = initBus();
|
|
1207
1229
|
// State initialization
|
|
@@ -1230,7 +1252,7 @@ function create() {
|
|
|
1230
1252
|
// Return the result
|
|
1231
1253
|
return produceFullResult();
|
|
1232
1254
|
}), {
|
|
1233
|
-
get: context.bind(ctxRef,
|
|
1255
|
+
get: context.bind(ctxRef, produceSuiteResult),
|
|
1234
1256
|
remove: context.bind(ctxRef, function (fieldName) {
|
|
1235
1257
|
bus.emit(Events.REMOVE_FIELD, fieldName);
|
|
1236
1258
|
}),
|
|
@@ -1256,9 +1278,7 @@ function create() {
|
|
|
1256
1278
|
* })
|
|
1257
1279
|
*/
|
|
1258
1280
|
function each(list, callback) {
|
|
1259
|
-
|
|
1260
|
-
throwError('each callback must be a function');
|
|
1261
|
-
}
|
|
1281
|
+
invariant(isFunction(callback), 'each callback must be a function');
|
|
1262
1282
|
isolate({ type: IsolateTypes.EACH }, function () {
|
|
1263
1283
|
list.forEach(function (arg, index) {
|
|
1264
1284
|
callback(arg, index);
|
|
@@ -1288,7 +1308,7 @@ function skipWhen(conditional, callback) {
|
|
|
1288
1308
|
// we should skip the test if the parent conditional is true.
|
|
1289
1309
|
isExcludedIndividually() ||
|
|
1290
1310
|
// Otherwise, we should skip the test if the conditional is true.
|
|
1291
|
-
optionalFunctionValue(conditional, optionalFunctionValue(
|
|
1311
|
+
optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
|
|
1292
1312
|
}, function () { return callback(); });
|
|
1293
1313
|
});
|
|
1294
1314
|
}
|
|
@@ -1455,19 +1475,15 @@ function hasIncludedTests(keyTests) {
|
|
|
1455
1475
|
* });
|
|
1456
1476
|
*/
|
|
1457
1477
|
function group(groupName, tests) {
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
}
|
|
1461
|
-
if (!isFunction(tests)) {
|
|
1462
|
-
throwGroupError('callback must be a function');
|
|
1463
|
-
}
|
|
1478
|
+
invariant(isStringValue(groupName), groupErrorMsg('name must be a string'));
|
|
1479
|
+
invariant(isFunction(tests), groupErrorMsg('callback must be a function'));
|
|
1464
1480
|
// Running with the context applied
|
|
1465
1481
|
isolate({ type: IsolateTypes.GROUP }, function () {
|
|
1466
1482
|
context.run({ groupName: groupName }, tests);
|
|
1467
1483
|
});
|
|
1468
1484
|
}
|
|
1469
|
-
function
|
|
1470
|
-
|
|
1485
|
+
function groupErrorMsg(error) {
|
|
1486
|
+
return "Wrong arguments passed to group. Group ".concat(error, ".");
|
|
1471
1487
|
}
|
|
1472
1488
|
|
|
1473
1489
|
function include(fieldName) {
|
|
@@ -1488,7 +1504,7 @@ function include(fieldName) {
|
|
|
1488
1504
|
if (isStringValue(condition)) {
|
|
1489
1505
|
return Boolean(exclusion.tests[condition]);
|
|
1490
1506
|
}
|
|
1491
|
-
return optionalFunctionValue(condition, optionalFunctionValue(
|
|
1507
|
+
return optionalFunctionValue(condition, optionalFunctionValue(produceSuiteResult));
|
|
1492
1508
|
};
|
|
1493
1509
|
}
|
|
1494
1510
|
}
|
|
@@ -1545,7 +1561,7 @@ function omitWhen(conditional, callback) {
|
|
|
1545
1561
|
isolate({ type: IsolateTypes.OMIT_WHEN }, function () {
|
|
1546
1562
|
context.run({
|
|
1547
1563
|
omitted: isOmitted() ||
|
|
1548
|
-
optionalFunctionValue(conditional, optionalFunctionValue(
|
|
1564
|
+
optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
|
|
1549
1565
|
}, function () { return callback(); });
|
|
1550
1566
|
});
|
|
1551
1567
|
}
|
|
@@ -1583,8 +1599,6 @@ function optional(optionals) {
|
|
|
1583
1599
|
});
|
|
1584
1600
|
}
|
|
1585
1601
|
|
|
1586
|
-
var isNotString = bindNot(isStringValue);
|
|
1587
|
-
|
|
1588
1602
|
function isPromise(value) {
|
|
1589
1603
|
return value && isFunction(value.then);
|
|
1590
1604
|
}
|
|
@@ -1678,7 +1692,7 @@ function registerTest(testObject) {
|
|
|
1678
1692
|
}
|
|
1679
1693
|
}
|
|
1680
1694
|
catch (e) {
|
|
1681
|
-
|
|
1695
|
+
throw new Error("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(testObject), ".\n Error: ").concat(e, "."));
|
|
1682
1696
|
}
|
|
1683
1697
|
}
|
|
1684
1698
|
|
|
@@ -1705,7 +1719,7 @@ function useTestAtCursor(newTestObject) {
|
|
|
1705
1719
|
useSetTestAtCursor(nextTest_1);
|
|
1706
1720
|
return nextTest_1;
|
|
1707
1721
|
}
|
|
1708
|
-
if (
|
|
1722
|
+
if (testReorderDetected(prevTest, newTestObject)) {
|
|
1709
1723
|
throwTestOrderError(prevTest, newTestObject);
|
|
1710
1724
|
removeAllNextTestsInIsolate();
|
|
1711
1725
|
// Need to see if this has any effect at all.
|
|
@@ -1742,14 +1756,14 @@ function useGetTestAtCursor(tests) {
|
|
|
1742
1756
|
var cursorPath = usePath();
|
|
1743
1757
|
return valueAtPath(tests, cursorPath);
|
|
1744
1758
|
}
|
|
1745
|
-
function
|
|
1759
|
+
function testReorderDetected(prevTest, newTest) {
|
|
1746
1760
|
return isNotEmpty(prevTest) && !isSameProfileTest(prevTest, newTest);
|
|
1747
1761
|
}
|
|
1748
1762
|
function throwTestOrderError(prevTest, newTestObject) {
|
|
1749
1763
|
if (shouldAllowReorder()) {
|
|
1750
1764
|
return;
|
|
1751
1765
|
}
|
|
1752
|
-
|
|
1766
|
+
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."));
|
|
1753
1767
|
}
|
|
1754
1768
|
function handleKeyTest(key, newTestObject) {
|
|
1755
1769
|
var prevTestByKey = usePrevTestByKey(key);
|
|
@@ -1763,12 +1777,13 @@ function handleKeyTest(key, newTestObject) {
|
|
|
1763
1777
|
|
|
1764
1778
|
// eslint-disable-next-line max-statements
|
|
1765
1779
|
function registerPrevRunTest(testObject) {
|
|
1766
|
-
var prevRunTest = useTestAtCursor(testObject);
|
|
1767
1780
|
if (shouldSkipBasedOnMode(testObject)) {
|
|
1768
|
-
moveForward();
|
|
1769
1781
|
testObject.skip();
|
|
1782
|
+
useTestAtCursor(testObject);
|
|
1783
|
+
moveForward();
|
|
1770
1784
|
return testObject;
|
|
1771
1785
|
}
|
|
1786
|
+
var prevRunTest = useTestAtCursor(testObject);
|
|
1772
1787
|
if (isOmitted()) {
|
|
1773
1788
|
prevRunTest.omit();
|
|
1774
1789
|
moveForward();
|
|
@@ -1834,12 +1849,8 @@ function testBase(fieldName) {
|
|
|
1834
1849
|
args[_i - 1] = arguments[_i];
|
|
1835
1850
|
}
|
|
1836
1851
|
var _a = (isFunction(args[1]) ? args : __spreadArray([undefined], args, true)), message = _a[0], testFn = _a[1], key = _a[2];
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
}
|
|
1840
|
-
if (!isFunction(testFn)) {
|
|
1841
|
-
throwIncompatibleParamsError('Test callback', 'function');
|
|
1842
|
-
}
|
|
1852
|
+
invariant(isStringValue(fieldName), incompatibleParamsError('fieldName', 'string'));
|
|
1853
|
+
invariant(isFunction(testFn), incompatibleParamsError('Test callback', 'function'));
|
|
1843
1854
|
var context$1 = context.useX();
|
|
1844
1855
|
var testObject = new VestTest(fieldName, testFn, {
|
|
1845
1856
|
message: message,
|
|
@@ -1860,8 +1871,8 @@ function testBase(fieldName) {
|
|
|
1860
1871
|
var test = assign(testBase, {
|
|
1861
1872
|
memo: bindTestMemo(testBase)
|
|
1862
1873
|
});
|
|
1863
|
-
function
|
|
1864
|
-
|
|
1874
|
+
function incompatibleParamsError(name, expected) {
|
|
1875
|
+
return "Incompatible params passed to test function. ".concat(name, " must be a ").concat(expected);
|
|
1865
1876
|
}
|
|
1866
1877
|
|
|
1867
1878
|
var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won't have an effect."
|
|
@@ -1871,13 +1882,11 @@ var ERROR_OUTSIDE_OF_TEST = "warn hook called outside of a test callback. It won
|
|
|
1871
1882
|
*/
|
|
1872
1883
|
function warn() {
|
|
1873
1884
|
var ctx = context.useX('warn ' + ERROR_HOOK_CALLED_OUTSIDE);
|
|
1874
|
-
|
|
1875
|
-
throwError(ERROR_OUTSIDE_OF_TEST);
|
|
1876
|
-
}
|
|
1885
|
+
invariant(ctx.currentTest, ERROR_OUTSIDE_OF_TEST);
|
|
1877
1886
|
ctx.currentTest.warn();
|
|
1878
1887
|
}
|
|
1879
1888
|
|
|
1880
|
-
var VERSION = "4.2.
|
|
1889
|
+
var VERSION = "4.2.3-dev-87ebfa";
|
|
1881
1890
|
|
|
1882
1891
|
Object.defineProperty(exports, 'enforce', {
|
|
1883
1892
|
enumerable: true,
|