vest 5.2.9 → 5.2.10
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/SuiteSerializer.development.js.map +1 -1
- package/dist/cjs/SuiteSerializer.production.js.map +1 -1
- package/dist/cjs/vest.development.js +1041 -1055
- package/dist/cjs/vest.development.js.map +1 -1
- package/dist/cjs/vest.production.js +1 -1
- package/dist/cjs/vest.production.js.map +1 -1
- package/dist/es/SuiteSerializer.development.js.map +1 -1
- package/dist/es/SuiteSerializer.production.js.map +1 -1
- package/dist/es/vest.development.js +1042 -1056
- package/dist/es/vest.development.js.map +1 -1
- package/dist/es/vest.production.js +1 -1
- package/dist/es/vest.production.js.map +1 -1
- package/dist/umd/SuiteSerializer.development.js.map +1 -1
- package/dist/umd/SuiteSerializer.production.js.map +1 -1
- package/dist/umd/vest.development.js +1041 -1055
- package/dist/umd/vest.development.js.map +1 -1
- package/dist/umd/vest.production.js +1 -1
- package/dist/umd/vest.production.js.map +1 -1
- package/package.json +6 -6
- package/types/SuiteSerializer.d.ts +12 -5
- package/types/SuiteSerializer.d.ts.map +1 -1
- package/types/vest.d.ts +28 -25
- package/types/vest.d.ts.map +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { enforce } from 'n4s';
|
|
2
2
|
export { enforce } from 'n4s';
|
|
3
|
-
import { assign, tinyState, cache, isArray, isStringValue, asArray, hasOwnProperty, seq, StateMachine, invariant, isPromise, optionalFunctionValue, Predicates, isNullish,
|
|
3
|
+
import { assign, tinyState, cache, isArray, isStringValue, asArray, hasOwnProperty, noop, isNotEmpty, seq, isPositive, greaterThan, StateMachine, invariant, isPromise, optionalFunctionValue, Predicates, isNullish, bindNot, either, defaultTo, isNotNullish, isUndefined, deferThrow, text, isNull, isFunction, isEmpty, callEach, numberEquals } from 'vest-utils';
|
|
4
4
|
import { Isolate, VestRuntime, IsolateSelectors, IsolateMutator, Walker, Bus, RuntimeEvents, IsolateInspector, Reconciler } from 'vestjs-runtime';
|
|
5
5
|
import { createCascade } from 'context';
|
|
6
6
|
|
|
@@ -139,18 +139,85 @@ function useIsOptionalFieldApplied(fieldName) {
|
|
|
139
139
|
return ((_b = (_a = SuiteOptionalFields.getOptionalField(root, fieldName)) === null || _a === void 0 ? void 0 : _a.applied) !== null && _b !== void 0 ? _b : false);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
var
|
|
143
|
-
(function (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
})
|
|
142
|
+
var FocusModes;
|
|
143
|
+
(function (FocusModes) {
|
|
144
|
+
FocusModes[FocusModes["ONLY"] = 0] = "ONLY";
|
|
145
|
+
FocusModes[FocusModes["SKIP"] = 1] = "SKIP";
|
|
146
|
+
})(FocusModes || (FocusModes = {}));
|
|
147
|
+
|
|
148
|
+
function IsolateFocused(focusMode, match) {
|
|
149
|
+
return Isolate.create(VestIsolateType.Focused, noop, {
|
|
150
|
+
focusMode,
|
|
151
|
+
match: asArray(match).filter(isStringValue),
|
|
152
|
+
matchAll: match === true,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
class FocusSelectors {
|
|
156
|
+
static isSkipFocused(focus, fieldName) {
|
|
157
|
+
return ((focus === null || focus === void 0 ? void 0 : focus.data.focusMode) === FocusModes.SKIP &&
|
|
158
|
+
(hasFocus(focus, fieldName) || focus.data.matchAll === true));
|
|
159
|
+
}
|
|
160
|
+
static isOnlyFocused(focus, fieldName) {
|
|
161
|
+
return ((focus === null || focus === void 0 ? void 0 : focus.data.focusMode) === FocusModes.ONLY && hasFocus(focus, fieldName));
|
|
162
|
+
}
|
|
163
|
+
static isIsolateFocused(isolate) {
|
|
164
|
+
return IsolateSelectors.isIsolateType(isolate, VestIsolateType.Focused);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Adds a field or a list of fields into the inclusion list
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
*
|
|
172
|
+
* only('username');
|
|
173
|
+
*/
|
|
174
|
+
// @vx-allow use-use
|
|
175
|
+
function only(match) {
|
|
176
|
+
return IsolateFocused(FocusModes.ONLY, defaultMatch(match));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Adds a field or a list of fields into the exclusion list
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
*
|
|
183
|
+
* skip('username');
|
|
184
|
+
*/
|
|
185
|
+
// @vx-allow use-use
|
|
186
|
+
function skip(match) {
|
|
187
|
+
return IsolateFocused(FocusModes.SKIP, defaultMatch(match));
|
|
188
|
+
}
|
|
189
|
+
function defaultMatch(match) {
|
|
190
|
+
return match === false ? [] : match;
|
|
191
|
+
}
|
|
192
|
+
function hasFocus(focus, fieldName) {
|
|
193
|
+
var _a, _b;
|
|
194
|
+
return (isNotEmpty(focus === null || focus === void 0 ? void 0 : focus.data.match) &&
|
|
195
|
+
(fieldName ? (_b = (_a = focus === null || focus === void 0 ? void 0 : focus.data.match) === null || _a === void 0 ? void 0 : _a.includes(fieldName)) !== null && _b !== void 0 ? _b : true : true));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function group(...args) {
|
|
199
|
+
const [callback, groupName] = args.reverse();
|
|
200
|
+
return Isolate.create(VestIsolateType.Group, () => {
|
|
201
|
+
return SuiteContext.run(Object.assign({}, (groupName && { groupName })), callback);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
var ErrorStrings;
|
|
206
|
+
(function (ErrorStrings) {
|
|
207
|
+
ErrorStrings["HOOK_CALLED_OUTSIDE"] = "hook called outside of a running suite.";
|
|
208
|
+
ErrorStrings["EXPECTED_VEST_TEST"] = "Expected value to be an instance of IsolateTest";
|
|
209
|
+
ErrorStrings["FIELD_NAME_REQUIRED"] = "Field name must be passed";
|
|
210
|
+
ErrorStrings["SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION"] = "Suite must be initialized with a function";
|
|
211
|
+
ErrorStrings["PROMISIFY_REQUIRE_FUNCTION"] = "Vest.Promisify must be called with a function";
|
|
212
|
+
ErrorStrings["PARSER_EXPECT_RESULT_OBJECT"] = "Vest parser: expected argument at position 0 to be Vest's result object.";
|
|
213
|
+
ErrorStrings["WARN_MUST_BE_CALLED_FROM_TEST"] = "Warn must be called from within the body of a test function";
|
|
214
|
+
ErrorStrings["EACH_CALLBACK_MUST_BE_A_FUNCTION"] = "Each must be called with a function";
|
|
215
|
+
ErrorStrings["INVALID_PARAM_PASSED_TO_FUNCTION"] = "Incompatible params passed to {fn_name} function. \"{param}\" must be of type {expected}";
|
|
216
|
+
ErrorStrings["TESTS_CALLED_IN_DIFFERENT_ORDER"] = "Vest Critical Error: Tests called in different order than previous run.\n expected: {fieldName}\n received: {prevName}\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.";
|
|
217
|
+
ErrorStrings["UNEXPECTED_TEST_REGISTRATION_ERROR"] = "Unexpected error encountered during test registration.\n Please report this issue to Vest's Github repository.\n Test Object: {testObject}.\n Error: {error}.";
|
|
218
|
+
ErrorStrings["UNEXPECTED_TEST_RUN_ERROR"] = "Unexpected error encountered during test run. Please report this issue to Vest's Github repository.\n Test Object: {testObject}.";
|
|
219
|
+
ErrorStrings["INCLUDE_SELF"] = "Trying to call include.when on the same field.";
|
|
220
|
+
})(ErrorStrings || (ErrorStrings = {}));
|
|
154
221
|
|
|
155
222
|
const suiteResultCache = cache();
|
|
156
223
|
function useCreateVestState({ suiteName, VestReconciler, }) {
|
|
@@ -201,124 +268,6 @@ function useLoadSuite(rootNode) {
|
|
|
201
268
|
useExpireSuiteResultCache();
|
|
202
269
|
}
|
|
203
270
|
|
|
204
|
-
const CommonStates = {
|
|
205
|
-
PENDING: 'PENDING',
|
|
206
|
-
INITIAL: 'INITIAL',
|
|
207
|
-
};
|
|
208
|
-
const State = {
|
|
209
|
-
[CommonStates.PENDING]: CommonStates.PENDING,
|
|
210
|
-
[CommonStates.INITIAL]: CommonStates.INITIAL,
|
|
211
|
-
DONE: 'DONE',
|
|
212
|
-
};
|
|
213
|
-
const machine$1 = {
|
|
214
|
-
initial: State.INITIAL,
|
|
215
|
-
states: {
|
|
216
|
-
[State.DONE]: {},
|
|
217
|
-
[State.INITIAL]: {
|
|
218
|
-
[State.PENDING]: State.PENDING,
|
|
219
|
-
[State.DONE]: State.DONE,
|
|
220
|
-
},
|
|
221
|
-
[State.PENDING]: {
|
|
222
|
-
[State.DONE]: State.DONE,
|
|
223
|
-
},
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
function transition(from, to) {
|
|
227
|
-
return CommonStateMachine.staticTransition(from !== null && from !== void 0 ? from : State.INITIAL, to);
|
|
228
|
-
}
|
|
229
|
-
function setDone(isolate) {
|
|
230
|
-
isolate.status = transition(isolate.status, State.DONE);
|
|
231
|
-
}
|
|
232
|
-
function setPending(isolate) {
|
|
233
|
-
isolate.status = transition(isolate.status, State.PENDING);
|
|
234
|
-
}
|
|
235
|
-
const CommonStateMachine = StateMachine(machine$1);
|
|
236
|
-
|
|
237
|
-
class VestIsolate {
|
|
238
|
-
static getStatus(isolate) {
|
|
239
|
-
var _a;
|
|
240
|
-
return (_a = isolate.status) !== null && _a !== void 0 ? _a : CommonStates.INITIAL;
|
|
241
|
-
}
|
|
242
|
-
static setStatus(isolate, status, payload) {
|
|
243
|
-
isolate.status = this.stateMachine.staticTransition(VestIsolate.getStatus(isolate), status, payload);
|
|
244
|
-
}
|
|
245
|
-
static statusEquals(isolate, status) {
|
|
246
|
-
return VestIsolate.getStatus(isolate) === status;
|
|
247
|
-
}
|
|
248
|
-
static setPending(isolate) {
|
|
249
|
-
this.setStatus(isolate, CommonStates.PENDING);
|
|
250
|
-
}
|
|
251
|
-
static isPending(isolate) {
|
|
252
|
-
return VestIsolate.statusEquals(isolate, CommonStates.PENDING);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
VestIsolate.stateMachine = CommonStateMachine;
|
|
256
|
-
|
|
257
|
-
var ErrorStrings;
|
|
258
|
-
(function (ErrorStrings) {
|
|
259
|
-
ErrorStrings["HOOK_CALLED_OUTSIDE"] = "hook called outside of a running suite.";
|
|
260
|
-
ErrorStrings["EXPECTED_VEST_TEST"] = "Expected value to be an instance of IsolateTest";
|
|
261
|
-
ErrorStrings["FIELD_NAME_REQUIRED"] = "Field name must be passed";
|
|
262
|
-
ErrorStrings["SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION"] = "Suite must be initialized with a function";
|
|
263
|
-
ErrorStrings["PROMISIFY_REQUIRE_FUNCTION"] = "Vest.Promisify must be called with a function";
|
|
264
|
-
ErrorStrings["PARSER_EXPECT_RESULT_OBJECT"] = "Vest parser: expected argument at position 0 to be Vest's result object.";
|
|
265
|
-
ErrorStrings["WARN_MUST_BE_CALLED_FROM_TEST"] = "Warn must be called from within the body of a test function";
|
|
266
|
-
ErrorStrings["EACH_CALLBACK_MUST_BE_A_FUNCTION"] = "Each must be called with a function";
|
|
267
|
-
ErrorStrings["INVALID_PARAM_PASSED_TO_FUNCTION"] = "Incompatible params passed to {fn_name} function. \"{param}\" must be of type {expected}";
|
|
268
|
-
ErrorStrings["TESTS_CALLED_IN_DIFFERENT_ORDER"] = "Vest Critical Error: Tests called in different order than previous run.\n expected: {fieldName}\n received: {prevName}\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.";
|
|
269
|
-
ErrorStrings["UNEXPECTED_TEST_REGISTRATION_ERROR"] = "Unexpected error encountered during test registration.\n Please report this issue to Vest's Github repository.\n Test Object: {testObject}.\n Error: {error}.";
|
|
270
|
-
ErrorStrings["UNEXPECTED_TEST_RUN_ERROR"] = "Unexpected error encountered during test run. Please report this issue to Vest's Github repository.\n Test Object: {testObject}.";
|
|
271
|
-
ErrorStrings["INCLUDE_SELF"] = "Trying to call include.when on the same field.";
|
|
272
|
-
})(ErrorStrings || (ErrorStrings = {}));
|
|
273
|
-
|
|
274
|
-
const TestStatus = {
|
|
275
|
-
[CommonStates.PENDING]: CommonStates.PENDING,
|
|
276
|
-
CANCELED: 'CANCELED',
|
|
277
|
-
FAILED: 'FAILED',
|
|
278
|
-
OMITTED: 'OMITTED',
|
|
279
|
-
PASSING: 'PASSING',
|
|
280
|
-
SKIPPED: 'SKIPPED',
|
|
281
|
-
UNTESTED: 'UNTESTED',
|
|
282
|
-
WARNING: 'WARNING',
|
|
283
|
-
};
|
|
284
|
-
const TestAction = {
|
|
285
|
-
RESET: 'RESET',
|
|
286
|
-
};
|
|
287
|
-
const machine = {
|
|
288
|
-
initial: TestStatus.UNTESTED,
|
|
289
|
-
states: {
|
|
290
|
-
'*': {
|
|
291
|
-
[TestStatus.OMITTED]: TestStatus.OMITTED,
|
|
292
|
-
[TestAction.RESET]: TestStatus.UNTESTED,
|
|
293
|
-
},
|
|
294
|
-
[TestStatus.UNTESTED]: {
|
|
295
|
-
[TestStatus.CANCELED]: TestStatus.CANCELED,
|
|
296
|
-
[TestStatus.FAILED]: TestStatus.FAILED,
|
|
297
|
-
[TestStatus.PASSING]: TestStatus.PASSING,
|
|
298
|
-
[TestStatus.PENDING]: TestStatus.PENDING,
|
|
299
|
-
[TestStatus.SKIPPED]: TestStatus.SKIPPED,
|
|
300
|
-
[TestStatus.WARNING]: TestStatus.WARNING,
|
|
301
|
-
},
|
|
302
|
-
[TestStatus.PENDING]: {
|
|
303
|
-
[TestStatus.CANCELED]: TestStatus.CANCELED,
|
|
304
|
-
[TestStatus.FAILED]: TestStatus.FAILED,
|
|
305
|
-
[TestStatus.PASSING]: TestStatus.PASSING,
|
|
306
|
-
[TestStatus.SKIPPED]: [
|
|
307
|
-
TestStatus.SKIPPED,
|
|
308
|
-
(force) => force === true,
|
|
309
|
-
],
|
|
310
|
-
[TestStatus.WARNING]: TestStatus.WARNING,
|
|
311
|
-
},
|
|
312
|
-
[TestStatus.SKIPPED]: {},
|
|
313
|
-
[TestStatus.FAILED]: {},
|
|
314
|
-
[TestStatus.WARNING]: {},
|
|
315
|
-
[TestStatus.PASSING]: {},
|
|
316
|
-
[TestStatus.CANCELED]: {},
|
|
317
|
-
[TestStatus.OMITTED]: {},
|
|
318
|
-
},
|
|
319
|
-
};
|
|
320
|
-
const IsolateTestStateMachine = StateMachine(machine);
|
|
321
|
-
|
|
322
271
|
var Severity;
|
|
323
272
|
(function (Severity) {
|
|
324
273
|
Severity["WARNINGS"] = "warnings";
|
|
@@ -340,161 +289,449 @@ var TestSeverity;
|
|
|
340
289
|
TestSeverity["Warning"] = "warning";
|
|
341
290
|
})(TestSeverity || (TestSeverity = {}));
|
|
342
291
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
292
|
+
// calls collectAll or getByFieldName depending on whether fieldName is provided
|
|
293
|
+
function gatherFailures(testGroup, severityKey, fieldName) {
|
|
294
|
+
return fieldName
|
|
295
|
+
? getByFieldName(testGroup, severityKey, fieldName)
|
|
296
|
+
: collectAll(testGroup, severityKey);
|
|
297
|
+
}
|
|
298
|
+
function getByFieldName(testGroup, severityKey, fieldName) {
|
|
299
|
+
var _a;
|
|
300
|
+
return ((_a = testGroup === null || testGroup === void 0 ? void 0 : testGroup[fieldName]) === null || _a === void 0 ? void 0 : _a[severityKey]) || [];
|
|
301
|
+
}
|
|
302
|
+
function collectAll(testGroup, severityKey) {
|
|
303
|
+
const output = {};
|
|
304
|
+
const countKey = countKeyBySeverity(severityKey);
|
|
305
|
+
for (const field in testGroup) {
|
|
306
|
+
if (isPositive(testGroup[field][countKey])) {
|
|
307
|
+
// We will probably never get to the fallback array
|
|
308
|
+
// leaving it just in case the implementation changes
|
|
309
|
+
output[field] = testGroup[field][severityKey] || [];
|
|
310
|
+
}
|
|
354
311
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
312
|
+
return output;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function nonMatchingFieldName(WithFieldName, fieldName) {
|
|
316
|
+
return !!fieldName && !matchingFieldName(WithFieldName, fieldName);
|
|
317
|
+
}
|
|
318
|
+
function matchingFieldName(WithFieldName, fieldName) {
|
|
319
|
+
return !!(fieldName && WithFieldName.fieldName === fieldName);
|
|
320
|
+
}
|
|
321
|
+
function matchesOrHasNoFieldName(WithFieldName, fieldName) {
|
|
322
|
+
if (fieldName) {
|
|
323
|
+
return matchingFieldName(WithFieldName, fieldName);
|
|
358
324
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
325
|
+
return true;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function bindSuiteSelectors(get) {
|
|
329
|
+
return {
|
|
330
|
+
getError: (...args) => get().getError(...args),
|
|
331
|
+
getErrors: (...args) => get().getErrors(...args),
|
|
332
|
+
getErrorsByGroup: (...args) => get().getErrorsByGroup(...args),
|
|
333
|
+
getWarning: (...args) => get().getWarning(...args),
|
|
334
|
+
getWarnings: (...args) => get().getWarnings(...args),
|
|
335
|
+
getWarningsByGroup: (...args) => get().getWarningsByGroup(...args),
|
|
336
|
+
hasErrors: (...args) => get().hasErrors(...args),
|
|
337
|
+
hasErrorsByGroup: (...args) => get().hasErrorsByGroup(...args),
|
|
338
|
+
hasWarnings: (...args) => get().hasWarnings(...args),
|
|
339
|
+
hasWarningsByGroup: (...args) => get().hasWarningsByGroup(...args),
|
|
340
|
+
isPending: (...args) => {
|
|
341
|
+
return get().isPending(...args);
|
|
342
|
+
},
|
|
343
|
+
isTested: (...args) => get().isTested(...args),
|
|
344
|
+
isValid: (...args) => get().isValid(...args),
|
|
345
|
+
isValidByGroup: (...args) => get().isValidByGroup(...args),
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
// eslint-disable-next-line max-lines-per-function, max-statements
|
|
349
|
+
function suiteSelectors(summary) {
|
|
350
|
+
const selectors = {
|
|
351
|
+
getError,
|
|
352
|
+
getErrors,
|
|
353
|
+
getErrorsByGroup,
|
|
354
|
+
getWarning,
|
|
355
|
+
getWarnings,
|
|
356
|
+
getWarningsByGroup,
|
|
357
|
+
hasErrors,
|
|
358
|
+
hasErrorsByGroup,
|
|
359
|
+
hasWarnings,
|
|
360
|
+
hasWarningsByGroup,
|
|
361
|
+
isPending,
|
|
362
|
+
isTested,
|
|
363
|
+
isValid,
|
|
364
|
+
isValidByGroup,
|
|
365
|
+
};
|
|
366
|
+
return selectors;
|
|
367
|
+
// Booleans
|
|
368
|
+
function isValid(fieldName) {
|
|
369
|
+
var _a;
|
|
370
|
+
return fieldName ? Boolean((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.valid) : summary.valid;
|
|
382
371
|
}
|
|
383
|
-
|
|
384
|
-
|
|
372
|
+
function isValidByGroup(groupName, fieldName) {
|
|
373
|
+
const group = summary.groups[groupName];
|
|
374
|
+
if (!group) {
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
if (fieldName) {
|
|
378
|
+
return isFieldValid(group, fieldName);
|
|
379
|
+
}
|
|
380
|
+
for (const fieldName in group) {
|
|
381
|
+
if (!isFieldValid(group, fieldName)) {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return true;
|
|
385
386
|
}
|
|
386
|
-
|
|
387
|
-
return (
|
|
388
|
-
VestTest.isOmitted(test) ||
|
|
389
|
-
VestTest.isCanceled(test));
|
|
387
|
+
function hasWarnings(fieldName) {
|
|
388
|
+
return hasFailures(summary, SeverityCount.WARN_COUNT, fieldName);
|
|
390
389
|
}
|
|
391
|
-
|
|
392
|
-
return
|
|
390
|
+
function hasErrors(fieldName) {
|
|
391
|
+
return hasFailures(summary, SeverityCount.ERROR_COUNT, fieldName);
|
|
393
392
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
return (VestTest.isSkipped(test) ||
|
|
398
|
-
VestTest.isUntested(test) ||
|
|
399
|
-
VestTest.isPending(test));
|
|
393
|
+
function isTested(fieldName) {
|
|
394
|
+
var _a;
|
|
395
|
+
return isPositive((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.testCount);
|
|
400
396
|
}
|
|
401
|
-
|
|
402
|
-
return
|
|
397
|
+
function hasWarningsByGroup(groupName, fieldName) {
|
|
398
|
+
return hasFailuresByGroup(summary, SeverityCount.WARN_COUNT, groupName, fieldName);
|
|
403
399
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
// this.setStatus(test, TestStatus.PENDING);
|
|
407
|
-
// }
|
|
408
|
-
static fail(test) {
|
|
409
|
-
VestTest.setStatus(test, VestTest.warns(test) ? TestStatus.WARNING : TestStatus.FAILED);
|
|
400
|
+
function hasErrorsByGroup(groupName, fieldName) {
|
|
401
|
+
return hasFailuresByGroup(summary, SeverityCount.ERROR_COUNT, groupName, fieldName);
|
|
410
402
|
}
|
|
411
|
-
|
|
412
|
-
|
|
403
|
+
function getWarnings(fieldName) {
|
|
404
|
+
return getFailures(summary, Severity.WARNINGS, fieldName);
|
|
413
405
|
}
|
|
414
|
-
|
|
415
|
-
|
|
406
|
+
function getWarning(fieldName) {
|
|
407
|
+
return getFailure(Severity.WARNINGS, summary, fieldName);
|
|
416
408
|
}
|
|
417
|
-
|
|
418
|
-
|
|
409
|
+
function getErrors(fieldName) {
|
|
410
|
+
return getFailures(summary, Severity.ERRORS, fieldName);
|
|
419
411
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
// This means that it will not be counted in "allIncomplete" and its done callbacks
|
|
423
|
-
// will not be called, or will be called prematurely.
|
|
424
|
-
// What this mostly say is that when we have a pending test for one field, and we then
|
|
425
|
-
// start typing in a different field - the pending test will be canceled, which
|
|
426
|
-
// is usually an unwanted behavior.
|
|
427
|
-
// The only scenario in which we DO want to cancel the async test regardless
|
|
428
|
-
// is when we specifically skip a test with `skipWhen`, which is handled by the
|
|
429
|
-
// "force" boolean flag.
|
|
430
|
-
// I am not a fan of this flag, but it gets the job done.
|
|
431
|
-
VestTest.setStatus(test, TestStatus.SKIPPED, force);
|
|
412
|
+
function getError(fieldName) {
|
|
413
|
+
return getFailure(Severity.ERRORS, summary, fieldName);
|
|
432
414
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
IsolateMutator.abort(test, TestStatus.CANCELED);
|
|
415
|
+
function getErrorsByGroup(groupName, fieldName) {
|
|
416
|
+
return getFailuresByGroup(summary, Severity.ERRORS, groupName, fieldName);
|
|
436
417
|
}
|
|
437
|
-
|
|
438
|
-
|
|
418
|
+
function getWarningsByGroup(groupName, fieldName) {
|
|
419
|
+
return getFailuresByGroup(summary, Severity.WARNINGS, groupName, fieldName);
|
|
439
420
|
}
|
|
440
|
-
|
|
441
|
-
|
|
421
|
+
function isPending(fieldName) {
|
|
422
|
+
var _a;
|
|
423
|
+
return fieldName
|
|
424
|
+
? greaterThan((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.pendingCount, 0)
|
|
425
|
+
: greaterThan(summary.pendingCount, 0);
|
|
442
426
|
}
|
|
443
427
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
function nonMatchingFieldName(WithFieldName, fieldName) {
|
|
447
|
-
return !!fieldName && !matchingFieldName(WithFieldName, fieldName);
|
|
428
|
+
function getFailures(summary, severityKey, fieldName) {
|
|
429
|
+
return gatherFailures(summary.tests, severityKey, fieldName);
|
|
448
430
|
}
|
|
449
|
-
|
|
450
|
-
|
|
431
|
+
// Gathers all failures of a given severity within a group
|
|
432
|
+
// With a fieldName, it will only gather failures for that field
|
|
433
|
+
function getFailuresByGroup(summary, severityKey, groupName, fieldName) {
|
|
434
|
+
return gatherFailures(summary.groups[groupName], severityKey, fieldName);
|
|
451
435
|
}
|
|
452
|
-
|
|
436
|
+
// Checks if a field is valid within a container object - can be within a group or top level
|
|
437
|
+
function isFieldValid(testContainer, fieldName) {
|
|
438
|
+
var _a;
|
|
439
|
+
return !!((_a = testContainer[fieldName]) === null || _a === void 0 ? void 0 : _a.valid);
|
|
440
|
+
}
|
|
441
|
+
// Checks if a there are any failures of a given severity within a group
|
|
442
|
+
// If a fieldName is provided, it will only check for failures within that field
|
|
443
|
+
function hasFailuresByGroup(summary, severityCount, groupName, fieldName) {
|
|
444
|
+
var _a, _b;
|
|
445
|
+
const group = summary.groups[groupName];
|
|
446
|
+
if (!group) {
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
453
449
|
if (fieldName) {
|
|
454
|
-
return
|
|
450
|
+
return isPositive((_a = group[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
455
451
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
class SuiteWalker {
|
|
460
|
-
static hasPending(predicate) {
|
|
461
|
-
const root = SuiteWalker.defaultRoot();
|
|
462
|
-
if (!root) {
|
|
463
|
-
return false;
|
|
452
|
+
for (const field in group) {
|
|
453
|
+
if (isPositive((_b = group[field]) === null || _b === void 0 ? void 0 : _b[severityCount])) {
|
|
454
|
+
return true;
|
|
464
455
|
}
|
|
465
|
-
return Walker.some(root, Predicates.all(VestIsolate.isPending, predicate !== null && predicate !== void 0 ? predicate : true));
|
|
466
456
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
// Checks if there are any failures of a given severity
|
|
460
|
+
// If a fieldName is provided, it will only check for failures within that field
|
|
461
|
+
function hasFailures(summary, countKey, fieldName) {
|
|
462
|
+
var _a;
|
|
463
|
+
const failureCount = fieldName
|
|
464
|
+
? (_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[countKey]
|
|
465
|
+
: summary[countKey] || 0;
|
|
466
|
+
return isPositive(failureCount);
|
|
467
|
+
}
|
|
468
|
+
function getFailure(severity, summary, fieldName) {
|
|
469
|
+
var _a;
|
|
470
|
+
const summaryKey = summary[severity];
|
|
471
|
+
if (!fieldName) {
|
|
472
|
+
return summaryKey[0];
|
|
473
473
|
}
|
|
474
|
+
return (_a = summaryKey.find((summaryFailure) => matchingFieldName(summaryFailure, fieldName))) === null || _a === void 0 ? void 0 : _a.message;
|
|
474
475
|
}
|
|
475
|
-
SuiteWalker.defaultRoot = VestRuntime.useAvailableRoot;
|
|
476
476
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
if (!root)
|
|
485
|
-
return false;
|
|
486
|
-
return Walker.some(root, isolate => {
|
|
487
|
-
VestTest.isX(isolate);
|
|
488
|
-
return predicate(isolate);
|
|
489
|
-
}, VestTest.is);
|
|
477
|
+
var _a, _b;
|
|
478
|
+
class SummaryBase {
|
|
479
|
+
constructor() {
|
|
480
|
+
this.errorCount = 0;
|
|
481
|
+
this.warnCount = 0;
|
|
482
|
+
this.testCount = 0;
|
|
483
|
+
this.pendingCount = 0;
|
|
490
484
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
485
|
+
}
|
|
486
|
+
class SuiteSummary extends SummaryBase {
|
|
487
|
+
constructor() {
|
|
488
|
+
super(...arguments);
|
|
489
|
+
this[_a] = [];
|
|
490
|
+
this[_b] = [];
|
|
491
|
+
this.groups = {};
|
|
492
|
+
this.tests = {};
|
|
493
|
+
this.valid = false;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
_a = Severity.ERRORS, _b = Severity.WARNINGS;
|
|
497
|
+
|
|
498
|
+
const CommonStates = {
|
|
499
|
+
PENDING: 'PENDING',
|
|
500
|
+
INITIAL: 'INITIAL',
|
|
501
|
+
};
|
|
502
|
+
const State = {
|
|
503
|
+
[CommonStates.PENDING]: CommonStates.PENDING,
|
|
504
|
+
[CommonStates.INITIAL]: CommonStates.INITIAL,
|
|
505
|
+
DONE: 'DONE',
|
|
506
|
+
};
|
|
507
|
+
const machine$1 = {
|
|
508
|
+
initial: State.INITIAL,
|
|
509
|
+
states: {
|
|
510
|
+
[State.DONE]: {},
|
|
511
|
+
[State.INITIAL]: {
|
|
512
|
+
[State.PENDING]: State.PENDING,
|
|
513
|
+
[State.DONE]: State.DONE,
|
|
514
|
+
},
|
|
515
|
+
[State.PENDING]: {
|
|
516
|
+
[State.DONE]: State.DONE,
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
};
|
|
520
|
+
function transition(from, to) {
|
|
521
|
+
return CommonStateMachine.staticTransition(from !== null && from !== void 0 ? from : State.INITIAL, to);
|
|
522
|
+
}
|
|
523
|
+
function setDone(isolate) {
|
|
524
|
+
isolate.status = transition(isolate.status, State.DONE);
|
|
525
|
+
}
|
|
526
|
+
function setPending(isolate) {
|
|
527
|
+
isolate.status = transition(isolate.status, State.PENDING);
|
|
528
|
+
}
|
|
529
|
+
const CommonStateMachine = StateMachine(machine$1);
|
|
530
|
+
|
|
531
|
+
const TestStatus = {
|
|
532
|
+
[CommonStates.PENDING]: CommonStates.PENDING,
|
|
533
|
+
CANCELED: 'CANCELED',
|
|
534
|
+
FAILED: 'FAILED',
|
|
535
|
+
OMITTED: 'OMITTED',
|
|
536
|
+
PASSING: 'PASSING',
|
|
537
|
+
SKIPPED: 'SKIPPED',
|
|
538
|
+
UNTESTED: 'UNTESTED',
|
|
539
|
+
WARNING: 'WARNING',
|
|
540
|
+
};
|
|
541
|
+
const TestAction = {
|
|
542
|
+
RESET: 'RESET',
|
|
543
|
+
};
|
|
544
|
+
const machine = {
|
|
545
|
+
initial: TestStatus.UNTESTED,
|
|
546
|
+
states: {
|
|
547
|
+
'*': {
|
|
548
|
+
[TestStatus.OMITTED]: TestStatus.OMITTED,
|
|
549
|
+
[TestAction.RESET]: TestStatus.UNTESTED,
|
|
550
|
+
},
|
|
551
|
+
[TestStatus.UNTESTED]: {
|
|
552
|
+
[TestStatus.CANCELED]: TestStatus.CANCELED,
|
|
553
|
+
[TestStatus.FAILED]: TestStatus.FAILED,
|
|
554
|
+
[TestStatus.PASSING]: TestStatus.PASSING,
|
|
555
|
+
[TestStatus.PENDING]: TestStatus.PENDING,
|
|
556
|
+
[TestStatus.SKIPPED]: TestStatus.SKIPPED,
|
|
557
|
+
[TestStatus.WARNING]: TestStatus.WARNING,
|
|
558
|
+
},
|
|
559
|
+
[TestStatus.PENDING]: {
|
|
560
|
+
[TestStatus.CANCELED]: TestStatus.CANCELED,
|
|
561
|
+
[TestStatus.FAILED]: TestStatus.FAILED,
|
|
562
|
+
[TestStatus.PASSING]: TestStatus.PASSING,
|
|
563
|
+
[TestStatus.SKIPPED]: [
|
|
564
|
+
TestStatus.SKIPPED,
|
|
565
|
+
(force) => force === true,
|
|
566
|
+
],
|
|
567
|
+
[TestStatus.WARNING]: TestStatus.WARNING,
|
|
568
|
+
},
|
|
569
|
+
[TestStatus.SKIPPED]: {},
|
|
570
|
+
[TestStatus.FAILED]: {},
|
|
571
|
+
[TestStatus.WARNING]: {},
|
|
572
|
+
[TestStatus.PASSING]: {},
|
|
573
|
+
[TestStatus.CANCELED]: {},
|
|
574
|
+
[TestStatus.OMITTED]: {},
|
|
575
|
+
},
|
|
576
|
+
};
|
|
577
|
+
const IsolateTestStateMachine = StateMachine(machine);
|
|
578
|
+
|
|
579
|
+
class VestIsolate {
|
|
580
|
+
static getStatus(isolate) {
|
|
581
|
+
var _a;
|
|
582
|
+
return (_a = isolate.status) !== null && _a !== void 0 ? _a : CommonStates.INITIAL;
|
|
583
|
+
}
|
|
584
|
+
static setStatus(isolate, status, payload) {
|
|
585
|
+
isolate.status = this.stateMachine.staticTransition(VestIsolate.getStatus(isolate), status, payload);
|
|
586
|
+
}
|
|
587
|
+
static statusEquals(isolate, status) {
|
|
588
|
+
return VestIsolate.getStatus(isolate) === status;
|
|
589
|
+
}
|
|
590
|
+
static setPending(isolate) {
|
|
591
|
+
this.setStatus(isolate, CommonStates.PENDING);
|
|
592
|
+
}
|
|
593
|
+
static isPending(isolate) {
|
|
594
|
+
return VestIsolate.statusEquals(isolate, CommonStates.PENDING);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
VestIsolate.stateMachine = CommonStateMachine;
|
|
598
|
+
|
|
599
|
+
class VestTest extends VestIsolate {
|
|
600
|
+
// Read
|
|
601
|
+
static getData(test) {
|
|
602
|
+
invariant(test.data);
|
|
603
|
+
return test.data;
|
|
604
|
+
}
|
|
605
|
+
static is(isolate) {
|
|
606
|
+
return IsolateSelectors.isIsolateType(isolate, VestIsolateType.Test);
|
|
607
|
+
}
|
|
608
|
+
static isX(isolate) {
|
|
609
|
+
invariant(VestTest.is(isolate), ErrorStrings.EXPECTED_VEST_TEST);
|
|
610
|
+
}
|
|
611
|
+
static cast(isolate) {
|
|
612
|
+
VestTest.isX(isolate);
|
|
613
|
+
return isolate;
|
|
614
|
+
}
|
|
615
|
+
static warns(test) {
|
|
616
|
+
return VestTest.getData(test).severity === TestSeverity.Warning;
|
|
617
|
+
}
|
|
618
|
+
static isOmitted(test) {
|
|
619
|
+
return VestTest.statusEquals(test, TestStatus.OMITTED);
|
|
620
|
+
}
|
|
621
|
+
static isUntested(test) {
|
|
622
|
+
return VestTest.statusEquals(test, TestStatus.UNTESTED);
|
|
623
|
+
}
|
|
624
|
+
static isFailing(test) {
|
|
625
|
+
return VestTest.statusEquals(test, TestStatus.FAILED);
|
|
626
|
+
}
|
|
627
|
+
static isCanceled(test) {
|
|
628
|
+
return VestTest.statusEquals(test, TestStatus.CANCELED);
|
|
629
|
+
}
|
|
630
|
+
static isSkipped(test) {
|
|
631
|
+
return VestTest.statusEquals(test, TestStatus.SKIPPED);
|
|
632
|
+
}
|
|
633
|
+
static isPassing(test) {
|
|
634
|
+
return VestTest.statusEquals(test, TestStatus.PASSING);
|
|
635
|
+
}
|
|
636
|
+
static isWarning(test) {
|
|
637
|
+
return VestTest.statusEquals(test, TestStatus.WARNING);
|
|
638
|
+
}
|
|
639
|
+
static hasFailures(test) {
|
|
640
|
+
return VestTest.isFailing(test) || VestTest.isWarning(test);
|
|
641
|
+
}
|
|
642
|
+
static isNonActionable(test) {
|
|
643
|
+
return (VestTest.isSkipped(test) ||
|
|
644
|
+
VestTest.isOmitted(test) ||
|
|
645
|
+
VestTest.isCanceled(test));
|
|
646
|
+
}
|
|
647
|
+
static isTested(test) {
|
|
648
|
+
return VestTest.hasFailures(test) || VestTest.isPassing(test);
|
|
649
|
+
}
|
|
650
|
+
static awaitsResolution(test) {
|
|
651
|
+
// Is the test in a state where it can still be run, or complete running
|
|
652
|
+
// and its final status is indeterminate?
|
|
653
|
+
return (VestTest.isSkipped(test) ||
|
|
654
|
+
VestTest.isUntested(test) ||
|
|
655
|
+
VestTest.isPending(test));
|
|
656
|
+
}
|
|
657
|
+
static isAsyncTest(test) {
|
|
658
|
+
return isPromise(VestTest.getData(test).asyncTest);
|
|
659
|
+
}
|
|
660
|
+
// Mutate
|
|
661
|
+
// static setPending(test: TIsolateTest) {
|
|
662
|
+
// this.setStatus(test, TestStatus.PENDING);
|
|
663
|
+
// }
|
|
664
|
+
static fail(test) {
|
|
665
|
+
VestTest.setStatus(test, VestTest.warns(test) ? TestStatus.WARNING : TestStatus.FAILED);
|
|
666
|
+
}
|
|
667
|
+
static pass(test) {
|
|
668
|
+
VestTest.setStatus(test, TestStatus.PASSING);
|
|
669
|
+
}
|
|
670
|
+
static warn(test) {
|
|
671
|
+
VestTest.setData(test, current => (Object.assign(Object.assign({}, current), { severity: TestSeverity.Warning })));
|
|
672
|
+
}
|
|
673
|
+
static setData(test, setter) {
|
|
674
|
+
test.data = optionalFunctionValue(setter, VestTest.getData(test));
|
|
675
|
+
}
|
|
676
|
+
static skip(test, force) {
|
|
677
|
+
// Without this force flag, the test will be marked as skipped even if it is pending.
|
|
678
|
+
// This means that it will not be counted in "allIncomplete" and its done callbacks
|
|
679
|
+
// will not be called, or will be called prematurely.
|
|
680
|
+
// What this mostly say is that when we have a pending test for one field, and we then
|
|
681
|
+
// start typing in a different field - the pending test will be canceled, which
|
|
682
|
+
// is usually an unwanted behavior.
|
|
683
|
+
// The only scenario in which we DO want to cancel the async test regardless
|
|
684
|
+
// is when we specifically skip a test with `skipWhen`, which is handled by the
|
|
685
|
+
// "force" boolean flag.
|
|
686
|
+
// I am not a fan of this flag, but it gets the job done.
|
|
687
|
+
VestTest.setStatus(test, TestStatus.SKIPPED, force);
|
|
688
|
+
}
|
|
689
|
+
static cancel(test) {
|
|
690
|
+
VestTest.setStatus(test, TestStatus.CANCELED);
|
|
691
|
+
IsolateMutator.abort(test, TestStatus.CANCELED);
|
|
692
|
+
}
|
|
693
|
+
static omit(test) {
|
|
694
|
+
VestTest.setStatus(test, TestStatus.OMITTED);
|
|
695
|
+
}
|
|
696
|
+
static reset(test) {
|
|
697
|
+
VestTest.setStatus(test, TestAction.RESET);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
VestTest.stateMachine = IsolateTestStateMachine;
|
|
701
|
+
|
|
702
|
+
class SummaryFailure {
|
|
703
|
+
constructor(fieldName, message, groupName) {
|
|
704
|
+
this.fieldName = fieldName;
|
|
705
|
+
this.message = message;
|
|
706
|
+
this.groupName = groupName;
|
|
707
|
+
}
|
|
708
|
+
static fromTestObject(testObject) {
|
|
709
|
+
const { fieldName, message, groupName } = VestTest.getData(testObject);
|
|
710
|
+
return new SummaryFailure(fieldName, message, groupName);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
class TestWalker {
|
|
715
|
+
static hasNoTests(root = TestWalker.defaultRoot()) {
|
|
716
|
+
if (!root)
|
|
717
|
+
return true;
|
|
718
|
+
return !Walker.has(root, VestTest.is);
|
|
719
|
+
}
|
|
720
|
+
static someTests(predicate, root = TestWalker.defaultRoot()) {
|
|
721
|
+
if (!root)
|
|
722
|
+
return false;
|
|
723
|
+
return Walker.some(root, isolate => {
|
|
724
|
+
VestTest.isX(isolate);
|
|
725
|
+
return predicate(isolate);
|
|
726
|
+
}, VestTest.is);
|
|
727
|
+
}
|
|
728
|
+
static everyTest(predicate, root = TestWalker.defaultRoot()) {
|
|
729
|
+
if (!root)
|
|
730
|
+
return false;
|
|
731
|
+
return Walker.every(root, isolate => {
|
|
732
|
+
VestTest.isX(isolate);
|
|
733
|
+
return predicate(isolate);
|
|
734
|
+
}, VestTest.is);
|
|
498
735
|
}
|
|
499
736
|
static walkTests(callback, root = TestWalker.defaultRoot()) {
|
|
500
737
|
if (!root)
|
|
@@ -526,180 +763,23 @@ class TestWalker {
|
|
|
526
763
|
}
|
|
527
764
|
TestWalker.defaultRoot = VestRuntime.useAvailableRoot;
|
|
528
765
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
function useOmitOptionalFields() {
|
|
535
|
-
const root = VestRuntime.useAvailableRoot();
|
|
536
|
-
const optionalFields = SuiteOptionalFields.getOptionalFields(root);
|
|
537
|
-
// If there are no optional fields, we don't need to do anything
|
|
538
|
-
if (isEmpty(optionalFields)) {
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
// Create an object to store the fields that need to be omitted
|
|
542
|
-
const shouldOmit = new Set();
|
|
543
|
-
// iterate over each of the tests in the state
|
|
544
|
-
TestWalker.walkTests(testObject => {
|
|
545
|
-
if (VestTest.isPending(testObject)) {
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
const { fieldName } = VestTest.getData(testObject);
|
|
549
|
-
// If we already added the current field (not this test specifically)
|
|
550
|
-
// no need for further checks, go and omit the test
|
|
551
|
-
if (shouldOmit.has(fieldName)) {
|
|
552
|
-
verifyAndOmit(testObject);
|
|
553
|
-
}
|
|
554
|
-
else {
|
|
555
|
-
// check if the field has an optional function
|
|
556
|
-
// if so, run it and verify/omit the test
|
|
557
|
-
runOptionalConfig(testObject);
|
|
558
|
-
}
|
|
559
|
-
});
|
|
560
|
-
Bus.useEmit(Events.DONE_TEST_OMISSION_PASS);
|
|
561
|
-
function verifyAndOmit(testObject) {
|
|
562
|
-
const { fieldName } = VestTest.getData(testObject);
|
|
563
|
-
if (shouldOmit.has(fieldName)) {
|
|
564
|
-
VestTest.omit(testObject);
|
|
565
|
-
SuiteOptionalFields.setOptionalField(root, fieldName, current => (Object.assign(Object.assign({}, current), { applied: true })));
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
function runOptionalConfig(testObject) {
|
|
569
|
-
const { fieldName } = VestTest.getData(testObject);
|
|
570
|
-
// Ge the optional configuration for the given field
|
|
571
|
-
const optionalConfig = SuiteOptionalFields.getOptionalField(root, fieldName);
|
|
572
|
-
// If the optional was set to a function or a boolean, run it and verify/omit the test
|
|
573
|
-
if (optionalFunctionValue(optionalConfig.rule) === true) {
|
|
574
|
-
shouldOmit.add(fieldName);
|
|
575
|
-
}
|
|
576
|
-
verifyAndOmit(testObject);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
/**
|
|
581
|
-
* Runs done callback per field when async tests are finished running.
|
|
582
|
-
*/
|
|
583
|
-
function useRunFieldCallbacks(fieldName) {
|
|
584
|
-
const [fieldCallbacks] = useFieldCallbacks();
|
|
585
|
-
if (fieldName &&
|
|
586
|
-
!SuiteWalker.hasRemainingWithTestNameMatching(fieldName) &&
|
|
587
|
-
isArray(fieldCallbacks[fieldName])) {
|
|
588
|
-
callEach(fieldCallbacks[fieldName]);
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
/**
|
|
592
|
-
* Runs unlabelled done callback when async tests are finished running.
|
|
593
|
-
*/
|
|
594
|
-
function useRunDoneCallbacks() {
|
|
595
|
-
const [doneCallbacks] = useDoneCallbacks();
|
|
596
|
-
callEach(doneCallbacks);
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
// eslint-disable-next-line max-statements, max-lines-per-function
|
|
600
|
-
function useInitVestBus() {
|
|
601
|
-
const VestBus = Bus.useBus();
|
|
602
|
-
// Report a the completion of a test. There may be other tests with the same
|
|
603
|
-
// name that are still running, or not yet started.
|
|
604
|
-
on(Events.TEST_COMPLETED, (testObject) => {
|
|
605
|
-
if (VestTest.isCanceled(testObject)) {
|
|
606
|
-
return;
|
|
607
|
-
}
|
|
608
|
-
const { fieldName } = VestTest.getData(testObject);
|
|
609
|
-
useRunFieldCallbacks(fieldName);
|
|
610
|
-
});
|
|
611
|
-
on(Events.TEST_RUN_STARTED, () => {
|
|
612
|
-
/* Let's just invalidate the suite cache for now */
|
|
613
|
-
});
|
|
614
|
-
on(RuntimeEvents.ISOLATE_PENDING, (isolate) => {
|
|
615
|
-
if (VestTest.is(isolate)) {
|
|
616
|
-
VestTest.setPending(isolate);
|
|
617
|
-
}
|
|
618
|
-
setPending(isolate);
|
|
619
|
-
});
|
|
620
|
-
on(RuntimeEvents.ISOLATE_DONE, (isolate) => {
|
|
621
|
-
if (VestTest.is(isolate)) {
|
|
622
|
-
VestBus.emit(Events.TEST_COMPLETED, isolate);
|
|
623
|
-
}
|
|
624
|
-
setDone(isolate);
|
|
625
|
-
if (!SuiteWalker.hasPending()) {
|
|
626
|
-
// When no more tests are running, emit the done event
|
|
627
|
-
VestBus.emit(Events.ALL_RUNNING_TESTS_FINISHED);
|
|
628
|
-
}
|
|
629
|
-
});
|
|
630
|
-
on(Events.DONE_TEST_OMISSION_PASS, () => {
|
|
631
|
-
/* We NEED to refresh the cache here. Don't ask */
|
|
632
|
-
});
|
|
633
|
-
// Called when all the tests, including async, are done running
|
|
634
|
-
on(Events.ALL_RUNNING_TESTS_FINISHED, () => {
|
|
635
|
-
// Small optimization. We don't need to run this if there are no async tests
|
|
636
|
-
// The reason is that we run this function immediately after the suite callback
|
|
637
|
-
// is run, so if the suite is only comprised of sync tests, we don't need to
|
|
638
|
-
// run this function twice since we know for a fact the state is up to date
|
|
639
|
-
if (TestWalker.someTests(VestTest.isAsyncTest)) {
|
|
640
|
-
useOmitOptionalFields();
|
|
766
|
+
class SuiteWalker {
|
|
767
|
+
static hasPending(predicate) {
|
|
768
|
+
const root = SuiteWalker.defaultRoot();
|
|
769
|
+
if (!root) {
|
|
770
|
+
return false;
|
|
641
771
|
}
|
|
642
|
-
|
|
643
|
-
});
|
|
644
|
-
on(Events.RESET_FIELD, (fieldName) => {
|
|
645
|
-
TestWalker.resetField(fieldName);
|
|
646
|
-
});
|
|
647
|
-
on(Events.SUITE_RUN_STARTED, () => {
|
|
648
|
-
useResetCallbacks();
|
|
649
|
-
});
|
|
650
|
-
on(Events.SUITE_CALLBACK_RUN_FINISHED, () => {
|
|
651
|
-
useOmitOptionalFields();
|
|
652
|
-
});
|
|
653
|
-
on(Events.REMOVE_FIELD, (fieldName) => {
|
|
654
|
-
TestWalker.removeTestByFieldName(fieldName);
|
|
655
|
-
});
|
|
656
|
-
on(Events.RESET_SUITE, () => {
|
|
657
|
-
useResetSuite();
|
|
658
|
-
});
|
|
659
|
-
return {
|
|
660
|
-
subscribe,
|
|
661
|
-
};
|
|
662
|
-
function subscribe(cb) {
|
|
663
|
-
return VestBus.on('*', () => {
|
|
664
|
-
cb();
|
|
665
|
-
}).off;
|
|
666
|
-
}
|
|
667
|
-
function on(event, cb) {
|
|
668
|
-
VestBus.on(event, (...args) => {
|
|
669
|
-
// This is more concise, but it might be an overkill
|
|
670
|
-
// if we're adding events that don't need to invalidate the cache
|
|
671
|
-
useExpireSuiteResultCache();
|
|
672
|
-
cb(...args);
|
|
673
|
-
});
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
class IsolateReconciler {
|
|
678
|
-
static match(_currentNode, _historyNode) {
|
|
679
|
-
return false;
|
|
680
|
-
}
|
|
681
|
-
static reconcile(currentNode, historyNode) {
|
|
682
|
-
return (currentNode !== null && currentNode !== void 0 ? currentNode : historyNode);
|
|
772
|
+
return Walker.some(root, Predicates.all(VestIsolate.isPending, predicate !== null && predicate !== void 0 ? predicate : true));
|
|
683
773
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
gn1 === gn2 &&
|
|
691
|
-
// Specifically using == here. The reason is that when serializing
|
|
692
|
-
// suite result, empty key gets removed, but it can also be null.
|
|
693
|
-
testObject1.key == testObject2.key);
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
function cancelOverriddenPendingTest(prevRunTestObject, currentRunTestObject) {
|
|
697
|
-
if (currentRunTestObject !== prevRunTestObject &&
|
|
698
|
-
isSameProfileTest(prevRunTestObject, currentRunTestObject) &&
|
|
699
|
-
VestTest.isPending(prevRunTestObject)) {
|
|
700
|
-
VestTest.cancel(prevRunTestObject);
|
|
774
|
+
// Checks whether there are pending isolates in the tree.
|
|
775
|
+
// If a fieldname is provided, will only check tests with a matching fieldname.
|
|
776
|
+
static hasRemainingWithTestNameMatching(fieldName) {
|
|
777
|
+
return SuiteWalker.hasPending(Predicates.any(isNullish(fieldName), Predicates.all(VestTest.is, (testObject) => {
|
|
778
|
+
return matchesOrHasNoFieldName(VestTest.getData(testObject), fieldName);
|
|
779
|
+
})));
|
|
701
780
|
}
|
|
702
781
|
}
|
|
782
|
+
SuiteWalker.defaultRoot = VestRuntime.useAvailableRoot;
|
|
703
783
|
|
|
704
784
|
const nonMatchingGroupName = bindNot(matchingGroupName);
|
|
705
785
|
function matchingGroupName(testObject, groupName) {
|
|
@@ -749,296 +829,46 @@ function hasFailuresByTestObject(testObject, severityKey, fieldName) {
|
|
|
749
829
|
return true;
|
|
750
830
|
}
|
|
751
831
|
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
*/
|
|
772
|
-
// @vx-allow use-use
|
|
773
|
-
function mode(mode) {
|
|
774
|
-
const [, setMode] = useMode();
|
|
775
|
-
setMode(mode);
|
|
776
|
-
}
|
|
777
|
-
function useIsMode(mode) {
|
|
778
|
-
const [currentMode] = useMode();
|
|
779
|
-
return currentMode === mode;
|
|
780
|
-
}
|
|
781
|
-
function useIsEager() {
|
|
782
|
-
return useIsMode(Modes.EAGER);
|
|
783
|
-
}
|
|
784
|
-
function useIsOne() {
|
|
785
|
-
return useIsMode(Modes.ONE);
|
|
832
|
+
function useShouldAddValidProperty(fieldName) {
|
|
833
|
+
// Is the field optional, and the optional condition is applied
|
|
834
|
+
if (useIsOptionalFieldApplied(fieldName)) {
|
|
835
|
+
return true;
|
|
836
|
+
}
|
|
837
|
+
// Are there no tests?
|
|
838
|
+
if (TestWalker.hasNoTests()) {
|
|
839
|
+
return false;
|
|
840
|
+
}
|
|
841
|
+
// // Does the field have any tests with errors?
|
|
842
|
+
if (hasErrorsByTestObjects(fieldName)) {
|
|
843
|
+
return false;
|
|
844
|
+
}
|
|
845
|
+
// Does the given field have any pending tests that are not optional?
|
|
846
|
+
if (useHasNonOptionalIncomplete(fieldName)) {
|
|
847
|
+
return false;
|
|
848
|
+
}
|
|
849
|
+
// Does the field have no missing tests?
|
|
850
|
+
return useNoMissingTests(fieldName);
|
|
786
851
|
}
|
|
787
|
-
function
|
|
788
|
-
if (
|
|
789
|
-
return
|
|
852
|
+
function useShouldAddValidPropertyInGroup(groupName, fieldName) {
|
|
853
|
+
if (useIsOptionalFieldApplied(fieldName)) {
|
|
854
|
+
return true;
|
|
790
855
|
}
|
|
791
|
-
if (
|
|
792
|
-
return
|
|
856
|
+
if (hasGroupFailuresByTestObjects(Severity.ERRORS, groupName, fieldName)) {
|
|
857
|
+
return false;
|
|
793
858
|
}
|
|
794
|
-
|
|
859
|
+
// Do the given group/field have any pending tests that are not optional?
|
|
860
|
+
if (useHasNonOptionalIncompleteByGroup(groupName, fieldName)) {
|
|
861
|
+
return false;
|
|
862
|
+
}
|
|
863
|
+
return useNoMissingTestsByGroup(groupName, fieldName);
|
|
795
864
|
}
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
return fieldName
|
|
800
|
-
? getByFieldName(testGroup, severityKey, fieldName)
|
|
801
|
-
: collectAll(testGroup, severityKey);
|
|
865
|
+
// Does the given field have any pending tests that are not optional?
|
|
866
|
+
function useHasNonOptionalIncomplete(fieldName) {
|
|
867
|
+
return SuiteWalker.hasPending(Predicates.all(VestTest.is, (testObject) => !nonMatchingFieldName(VestTest.getData(testObject), fieldName), () => !useIsOptionalFieldApplied(fieldName)));
|
|
802
868
|
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
return ((
|
|
806
|
-
}
|
|
807
|
-
function collectAll(testGroup, severityKey) {
|
|
808
|
-
const output = {};
|
|
809
|
-
const countKey = countKeyBySeverity(severityKey);
|
|
810
|
-
for (const field in testGroup) {
|
|
811
|
-
if (isPositive(testGroup[field][countKey])) {
|
|
812
|
-
// We will probably never get to the fallback array
|
|
813
|
-
// leaving it just in case the implementation changes
|
|
814
|
-
output[field] = testGroup[field][severityKey] || [];
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
return output;
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
function bindSuiteSelectors(get) {
|
|
821
|
-
return {
|
|
822
|
-
getError: (...args) => get().getError(...args),
|
|
823
|
-
getErrors: (...args) => get().getErrors(...args),
|
|
824
|
-
getErrorsByGroup: (...args) => get().getErrorsByGroup(...args),
|
|
825
|
-
getWarning: (...args) => get().getWarning(...args),
|
|
826
|
-
getWarnings: (...args) => get().getWarnings(...args),
|
|
827
|
-
getWarningsByGroup: (...args) => get().getWarningsByGroup(...args),
|
|
828
|
-
hasErrors: (...args) => get().hasErrors(...args),
|
|
829
|
-
hasErrorsByGroup: (...args) => get().hasErrorsByGroup(...args),
|
|
830
|
-
hasWarnings: (...args) => get().hasWarnings(...args),
|
|
831
|
-
hasWarningsByGroup: (...args) => get().hasWarningsByGroup(...args),
|
|
832
|
-
isPending: (...args) => {
|
|
833
|
-
return get().isPending(...args);
|
|
834
|
-
},
|
|
835
|
-
isTested: (...args) => get().isTested(...args),
|
|
836
|
-
isValid: (...args) => get().isValid(...args),
|
|
837
|
-
isValidByGroup: (...args) => get().isValidByGroup(...args),
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
// eslint-disable-next-line max-lines-per-function, max-statements
|
|
841
|
-
function suiteSelectors(summary) {
|
|
842
|
-
const selectors = {
|
|
843
|
-
getError,
|
|
844
|
-
getErrors,
|
|
845
|
-
getErrorsByGroup,
|
|
846
|
-
getWarning,
|
|
847
|
-
getWarnings,
|
|
848
|
-
getWarningsByGroup,
|
|
849
|
-
hasErrors,
|
|
850
|
-
hasErrorsByGroup,
|
|
851
|
-
hasWarnings,
|
|
852
|
-
hasWarningsByGroup,
|
|
853
|
-
isPending,
|
|
854
|
-
isTested,
|
|
855
|
-
isValid,
|
|
856
|
-
isValidByGroup,
|
|
857
|
-
};
|
|
858
|
-
return selectors;
|
|
859
|
-
// Booleans
|
|
860
|
-
function isValid(fieldName) {
|
|
861
|
-
var _a;
|
|
862
|
-
return fieldName ? Boolean((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.valid) : summary.valid;
|
|
863
|
-
}
|
|
864
|
-
function isValidByGroup(groupName, fieldName) {
|
|
865
|
-
const group = summary.groups[groupName];
|
|
866
|
-
if (!group) {
|
|
867
|
-
return false;
|
|
868
|
-
}
|
|
869
|
-
if (fieldName) {
|
|
870
|
-
return isFieldValid(group, fieldName);
|
|
871
|
-
}
|
|
872
|
-
for (const fieldName in group) {
|
|
873
|
-
if (!isFieldValid(group, fieldName)) {
|
|
874
|
-
return false;
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
return true;
|
|
878
|
-
}
|
|
879
|
-
function hasWarnings(fieldName) {
|
|
880
|
-
return hasFailures(summary, SeverityCount.WARN_COUNT, fieldName);
|
|
881
|
-
}
|
|
882
|
-
function hasErrors(fieldName) {
|
|
883
|
-
return hasFailures(summary, SeverityCount.ERROR_COUNT, fieldName);
|
|
884
|
-
}
|
|
885
|
-
function isTested(fieldName) {
|
|
886
|
-
var _a;
|
|
887
|
-
return isPositive((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.testCount);
|
|
888
|
-
}
|
|
889
|
-
function hasWarningsByGroup(groupName, fieldName) {
|
|
890
|
-
return hasFailuresByGroup(summary, SeverityCount.WARN_COUNT, groupName, fieldName);
|
|
891
|
-
}
|
|
892
|
-
function hasErrorsByGroup(groupName, fieldName) {
|
|
893
|
-
return hasFailuresByGroup(summary, SeverityCount.ERROR_COUNT, groupName, fieldName);
|
|
894
|
-
}
|
|
895
|
-
function getWarnings(fieldName) {
|
|
896
|
-
return getFailures(summary, Severity.WARNINGS, fieldName);
|
|
897
|
-
}
|
|
898
|
-
function getWarning(fieldName) {
|
|
899
|
-
return getFailure(Severity.WARNINGS, summary, fieldName);
|
|
900
|
-
}
|
|
901
|
-
function getErrors(fieldName) {
|
|
902
|
-
return getFailures(summary, Severity.ERRORS, fieldName);
|
|
903
|
-
}
|
|
904
|
-
function getError(fieldName) {
|
|
905
|
-
return getFailure(Severity.ERRORS, summary, fieldName);
|
|
906
|
-
}
|
|
907
|
-
function getErrorsByGroup(groupName, fieldName) {
|
|
908
|
-
return getFailuresByGroup(summary, Severity.ERRORS, groupName, fieldName);
|
|
909
|
-
}
|
|
910
|
-
function getWarningsByGroup(groupName, fieldName) {
|
|
911
|
-
return getFailuresByGroup(summary, Severity.WARNINGS, groupName, fieldName);
|
|
912
|
-
}
|
|
913
|
-
function isPending(fieldName) {
|
|
914
|
-
var _a;
|
|
915
|
-
return fieldName
|
|
916
|
-
? greaterThan((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.pendingCount, 0)
|
|
917
|
-
: greaterThan(summary.pendingCount, 0);
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
function getFailures(summary, severityKey, fieldName) {
|
|
921
|
-
return gatherFailures(summary.tests, severityKey, fieldName);
|
|
922
|
-
}
|
|
923
|
-
// Gathers all failures of a given severity within a group
|
|
924
|
-
// With a fieldName, it will only gather failures for that field
|
|
925
|
-
function getFailuresByGroup(summary, severityKey, groupName, fieldName) {
|
|
926
|
-
return gatherFailures(summary.groups[groupName], severityKey, fieldName);
|
|
927
|
-
}
|
|
928
|
-
// Checks if a field is valid within a container object - can be within a group or top level
|
|
929
|
-
function isFieldValid(testContainer, fieldName) {
|
|
930
|
-
var _a;
|
|
931
|
-
return !!((_a = testContainer[fieldName]) === null || _a === void 0 ? void 0 : _a.valid);
|
|
932
|
-
}
|
|
933
|
-
// Checks if a there are any failures of a given severity within a group
|
|
934
|
-
// If a fieldName is provided, it will only check for failures within that field
|
|
935
|
-
function hasFailuresByGroup(summary, severityCount, groupName, fieldName) {
|
|
936
|
-
var _a, _b;
|
|
937
|
-
const group = summary.groups[groupName];
|
|
938
|
-
if (!group) {
|
|
939
|
-
return false;
|
|
940
|
-
}
|
|
941
|
-
if (fieldName) {
|
|
942
|
-
return isPositive((_a = group[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
|
|
943
|
-
}
|
|
944
|
-
for (const field in group) {
|
|
945
|
-
if (isPositive((_b = group[field]) === null || _b === void 0 ? void 0 : _b[severityCount])) {
|
|
946
|
-
return true;
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
return false;
|
|
950
|
-
}
|
|
951
|
-
// Checks if there are any failures of a given severity
|
|
952
|
-
// If a fieldName is provided, it will only check for failures within that field
|
|
953
|
-
function hasFailures(summary, countKey, fieldName) {
|
|
954
|
-
var _a;
|
|
955
|
-
const failureCount = fieldName
|
|
956
|
-
? (_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[countKey]
|
|
957
|
-
: summary[countKey] || 0;
|
|
958
|
-
return isPositive(failureCount);
|
|
959
|
-
}
|
|
960
|
-
function getFailure(severity, summary, fieldName) {
|
|
961
|
-
var _a;
|
|
962
|
-
const summaryKey = summary[severity];
|
|
963
|
-
if (!fieldName) {
|
|
964
|
-
return summaryKey[0];
|
|
965
|
-
}
|
|
966
|
-
return (_a = summaryKey.find((summaryFailure) => matchingFieldName(summaryFailure, fieldName))) === null || _a === void 0 ? void 0 : _a.message;
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
var _a, _b;
|
|
970
|
-
class SummaryBase {
|
|
971
|
-
constructor() {
|
|
972
|
-
this.errorCount = 0;
|
|
973
|
-
this.warnCount = 0;
|
|
974
|
-
this.testCount = 0;
|
|
975
|
-
this.pendingCount = 0;
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
class SuiteSummary extends SummaryBase {
|
|
979
|
-
constructor() {
|
|
980
|
-
super(...arguments);
|
|
981
|
-
this[_a] = [];
|
|
982
|
-
this[_b] = [];
|
|
983
|
-
this.groups = {};
|
|
984
|
-
this.tests = {};
|
|
985
|
-
this.valid = false;
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
_a = Severity.ERRORS, _b = Severity.WARNINGS;
|
|
989
|
-
|
|
990
|
-
class SummaryFailure {
|
|
991
|
-
constructor(fieldName, message, groupName) {
|
|
992
|
-
this.fieldName = fieldName;
|
|
993
|
-
this.message = message;
|
|
994
|
-
this.groupName = groupName;
|
|
995
|
-
}
|
|
996
|
-
static fromTestObject(testObject) {
|
|
997
|
-
const { fieldName, message, groupName } = VestTest.getData(testObject);
|
|
998
|
-
return new SummaryFailure(fieldName, message, groupName);
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
function useShouldAddValidProperty(fieldName) {
|
|
1003
|
-
// Is the field optional, and the optional condition is applied
|
|
1004
|
-
if (useIsOptionalFieldApplied(fieldName)) {
|
|
1005
|
-
return true;
|
|
1006
|
-
}
|
|
1007
|
-
// Are there no tests?
|
|
1008
|
-
if (TestWalker.hasNoTests()) {
|
|
1009
|
-
return false;
|
|
1010
|
-
}
|
|
1011
|
-
// // Does the field have any tests with errors?
|
|
1012
|
-
if (hasErrorsByTestObjects(fieldName)) {
|
|
1013
|
-
return false;
|
|
1014
|
-
}
|
|
1015
|
-
// Does the given field have any pending tests that are not optional?
|
|
1016
|
-
if (useHasNonOptionalIncomplete(fieldName)) {
|
|
1017
|
-
return false;
|
|
1018
|
-
}
|
|
1019
|
-
// Does the field have no missing tests?
|
|
1020
|
-
return useNoMissingTests(fieldName);
|
|
1021
|
-
}
|
|
1022
|
-
function useShouldAddValidPropertyInGroup(groupName, fieldName) {
|
|
1023
|
-
if (useIsOptionalFieldApplied(fieldName)) {
|
|
1024
|
-
return true;
|
|
1025
|
-
}
|
|
1026
|
-
if (hasGroupFailuresByTestObjects(Severity.ERRORS, groupName, fieldName)) {
|
|
1027
|
-
return false;
|
|
1028
|
-
}
|
|
1029
|
-
// Do the given group/field have any pending tests that are not optional?
|
|
1030
|
-
if (useHasNonOptionalIncompleteByGroup(groupName, fieldName)) {
|
|
1031
|
-
return false;
|
|
1032
|
-
}
|
|
1033
|
-
return useNoMissingTestsByGroup(groupName, fieldName);
|
|
1034
|
-
}
|
|
1035
|
-
// Does the given field have any pending tests that are not optional?
|
|
1036
|
-
function useHasNonOptionalIncomplete(fieldName) {
|
|
1037
|
-
return SuiteWalker.hasPending(Predicates.all(VestTest.is, (testObject) => !nonMatchingFieldName(VestTest.getData(testObject), fieldName), () => !useIsOptionalFieldApplied(fieldName)));
|
|
1038
|
-
}
|
|
1039
|
-
// Do the given group/field have any pending tests that are not optional?
|
|
1040
|
-
function useHasNonOptionalIncompleteByGroup(groupName, fieldName) {
|
|
1041
|
-
return SuiteWalker.hasPending(Predicates.all(VestTest.is, (testObject) => !nonMatchingGroupName(testObject, groupName), (testObject) => !nonMatchingFieldName(VestTest.getData(testObject), fieldName), () => !useIsOptionalFieldApplied(fieldName)));
|
|
869
|
+
// Do the given group/field have any pending tests that are not optional?
|
|
870
|
+
function useHasNonOptionalIncompleteByGroup(groupName, fieldName) {
|
|
871
|
+
return SuiteWalker.hasPending(Predicates.all(VestTest.is, (testObject) => !nonMatchingGroupName(testObject, groupName), (testObject) => !nonMatchingFieldName(VestTest.getData(testObject), fieldName), () => !useIsOptionalFieldApplied(fieldName)));
|
|
1042
872
|
}
|
|
1043
873
|
// Did all of the tests for the provided field run/omit?
|
|
1044
874
|
// This makes sure that the fields are not skipped or pending.
|
|
@@ -1201,17 +1031,68 @@ function useCreateSuiteResult() {
|
|
|
1201
1031
|
}
|
|
1202
1032
|
|
|
1203
1033
|
/**
|
|
1204
|
-
*
|
|
1034
|
+
* Checks if context has included tests
|
|
1035
|
+
*/
|
|
1036
|
+
function useHasOnliedTests(testObject, fieldName) {
|
|
1037
|
+
return isNotNullish(Walker.findClosest(testObject, (child) => {
|
|
1038
|
+
if (!FocusSelectors.isIsolateFocused(child))
|
|
1039
|
+
return false;
|
|
1040
|
+
return FocusSelectors.isOnlyFocused(child, fieldName);
|
|
1041
|
+
}));
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* Conditionally includes a field for testing, based on specified criteria.
|
|
1046
|
+
*
|
|
1047
|
+
* @param {string} fieldName - The name of the field to include for testing.
|
|
1205
1048
|
*
|
|
1206
1049
|
* @example
|
|
1050
|
+
* include('confirm').when('password');
|
|
1051
|
+
* // Includes the "confirm" field for testing when the "password" field is included
|
|
1207
1052
|
*
|
|
1208
|
-
*
|
|
1209
|
-
*
|
|
1210
|
-
*
|
|
1211
|
-
|
|
1212
|
-
//
|
|
1213
|
-
|
|
1214
|
-
|
|
1053
|
+
* include('confirm').when(someValue);
|
|
1054
|
+
* // Includes the "confirm" field for testing when the value of `someValue` is true
|
|
1055
|
+
*
|
|
1056
|
+
* include('confirm').when(() => someValue);
|
|
1057
|
+
* // Includes the "confirm" field for testing when the callback function returns true
|
|
1058
|
+
*
|
|
1059
|
+
* include('username').when(result => result.hasErrors('username'));
|
|
1060
|
+
* // Includes the "username" field for testing when there are errors associated with it in the current suite result
|
|
1061
|
+
*/
|
|
1062
|
+
// @vx-allow use-use
|
|
1063
|
+
function include(fieldName) {
|
|
1064
|
+
invariant(isStringValue(fieldName));
|
|
1065
|
+
const inclusion = useInclusion();
|
|
1066
|
+
inclusion[fieldName] = true;
|
|
1067
|
+
return { when };
|
|
1068
|
+
/**
|
|
1069
|
+
* Specifies the inclusion criteria for the field in `include` function.
|
|
1070
|
+
*/
|
|
1071
|
+
function when(condition) {
|
|
1072
|
+
invariant(condition !== fieldName, ErrorStrings.INCLUDE_SELF);
|
|
1073
|
+
const inclusion = useInclusion();
|
|
1074
|
+
// This callback will run as part of the "isExcluded" series of checks
|
|
1075
|
+
inclusion[fieldName] = function isIncluded(currentNode) {
|
|
1076
|
+
if (isStringValue(condition)) {
|
|
1077
|
+
return useHasOnliedTests(currentNode, condition);
|
|
1078
|
+
}
|
|
1079
|
+
return optionalFunctionValue(condition, optionalFunctionValue(useCreateSuiteResult));
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
/**
|
|
1085
|
+
* Conditionally omits tests from the suite.
|
|
1086
|
+
*
|
|
1087
|
+
* @example
|
|
1088
|
+
*
|
|
1089
|
+
* omitWhen(res => res.hasErrors('username'), () => {
|
|
1090
|
+
* test('username', 'User already taken', async () => await doesUserExist(username)
|
|
1091
|
+
* });
|
|
1092
|
+
*/
|
|
1093
|
+
// @vx-allow use-use
|
|
1094
|
+
function omitWhen(conditional, callback) {
|
|
1095
|
+
Isolate.create(VestIsolateType.OmitWhen, () => {
|
|
1215
1096
|
SuiteContext.run({
|
|
1216
1097
|
omitted: useWithinActiveOmitWhen() ||
|
|
1217
1098
|
optionalFunctionValue(conditional, optionalFunctionValue(useCreateSuiteResult)),
|
|
@@ -1249,71 +1130,85 @@ function useIsExcludedIndividually() {
|
|
|
1249
1130
|
return useSkipped();
|
|
1250
1131
|
}
|
|
1251
1132
|
|
|
1252
|
-
var
|
|
1253
|
-
(function (
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1133
|
+
var Events;
|
|
1134
|
+
(function (Events) {
|
|
1135
|
+
Events["TEST_RUN_STARTED"] = "test_run_started";
|
|
1136
|
+
Events["TEST_COMPLETED"] = "test_completed";
|
|
1137
|
+
Events["ALL_RUNNING_TESTS_FINISHED"] = "all_running_tests_finished";
|
|
1138
|
+
Events["REMOVE_FIELD"] = "remove_field";
|
|
1139
|
+
Events["RESET_FIELD"] = "reset_field";
|
|
1140
|
+
Events["RESET_SUITE"] = "reset_suite";
|
|
1141
|
+
Events["SUITE_RUN_STARTED"] = "suite_run_started";
|
|
1142
|
+
Events["SUITE_CALLBACK_RUN_FINISHED"] = "SUITE_CALLBACK_RUN_FINISHED";
|
|
1143
|
+
Events["DONE_TEST_OMISSION_PASS"] = "DONE_TEST_OMISSION_PASS";
|
|
1144
|
+
})(Events || (Events = {}));
|
|
1257
1145
|
|
|
1258
|
-
function
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
matchAll: match === true,
|
|
1263
|
-
});
|
|
1264
|
-
}
|
|
1265
|
-
class FocusSelectors {
|
|
1266
|
-
static isSkipFocused(focus, fieldName) {
|
|
1267
|
-
return ((focus === null || focus === void 0 ? void 0 : focus.data.focusMode) === FocusModes.SKIP &&
|
|
1268
|
-
(hasFocus(focus, fieldName) || focus.data.matchAll === true));
|
|
1269
|
-
}
|
|
1270
|
-
static isOnlyFocused(focus, fieldName) {
|
|
1271
|
-
return ((focus === null || focus === void 0 ? void 0 : focus.data.focusMode) === FocusModes.ONLY && hasFocus(focus, fieldName));
|
|
1146
|
+
function IsolateTest(callback, input, key) {
|
|
1147
|
+
const payload = Object.assign(Object.assign({}, IsolateTestBase()), { fieldName: input.fieldName, testFn: input.testFn });
|
|
1148
|
+
if (input.groupName) {
|
|
1149
|
+
payload.groupName = input.groupName;
|
|
1272
1150
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1151
|
+
if (input.message) {
|
|
1152
|
+
payload.message = input.message;
|
|
1275
1153
|
}
|
|
1154
|
+
const isolate = Isolate.create(VestIsolateType.Test, callback, payload, key !== null && key !== void 0 ? key : null);
|
|
1155
|
+
return isolate;
|
|
1276
1156
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
return
|
|
1157
|
+
function IsolateTestBase() {
|
|
1158
|
+
return {
|
|
1159
|
+
severity: TestSeverity.Error,
|
|
1160
|
+
status: IsolateTestStateMachine.initial(),
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
function shouldUseErrorAsMessage(message, error) {
|
|
1165
|
+
// kind of cheating with this safe guard, but it does the job
|
|
1166
|
+
return isUndefined(message) && isStringValue(error);
|
|
1287
1167
|
}
|
|
1168
|
+
|
|
1288
1169
|
/**
|
|
1289
|
-
*
|
|
1170
|
+
* Sets the current execution mode for the current suite.
|
|
1171
|
+
*
|
|
1172
|
+
* Supported modes:
|
|
1173
|
+
* - `EAGER` - (default) Runs all tests, but stops on first failure for each given field.
|
|
1174
|
+
* - `ALL` - Runs all tests, regardless of failures.
|
|
1175
|
+
* - `ONE` - Stops suite execution on first failure of any field.
|
|
1290
1176
|
*
|
|
1291
1177
|
* @example
|
|
1178
|
+
* ```js
|
|
1179
|
+
* import {Modes, create} from 'vest';
|
|
1292
1180
|
*
|
|
1293
|
-
*
|
|
1181
|
+
* const suite = create('suite_name', () => {
|
|
1182
|
+
* vest.mode(Modes.ALL);
|
|
1183
|
+
*
|
|
1184
|
+
* // ...
|
|
1185
|
+
* });
|
|
1186
|
+
* ```
|
|
1187
|
+
* @param 'ALL' | 'EAGER' | 'ONE' mode - The mode to set.
|
|
1294
1188
|
*/
|
|
1295
1189
|
// @vx-allow use-use
|
|
1296
|
-
function
|
|
1297
|
-
|
|
1190
|
+
function mode(mode) {
|
|
1191
|
+
const [, setMode] = useMode();
|
|
1192
|
+
setMode(mode);
|
|
1298
1193
|
}
|
|
1299
|
-
function
|
|
1300
|
-
|
|
1194
|
+
function useIsMode(mode) {
|
|
1195
|
+
const [currentMode] = useMode();
|
|
1196
|
+
return currentMode === mode;
|
|
1301
1197
|
}
|
|
1302
|
-
function
|
|
1303
|
-
|
|
1304
|
-
return (isNotEmpty(focus === null || focus === void 0 ? void 0 : focus.data.match) &&
|
|
1305
|
-
(fieldName ? (_b = (_a = focus === null || focus === void 0 ? void 0 : focus.data.match) === null || _a === void 0 ? void 0 : _a.includes(fieldName)) !== null && _b !== void 0 ? _b : true : true));
|
|
1198
|
+
function useIsEager() {
|
|
1199
|
+
return useIsMode(Modes.EAGER);
|
|
1306
1200
|
}
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
return
|
|
1316
|
-
}
|
|
1201
|
+
function useIsOne() {
|
|
1202
|
+
return useIsMode(Modes.ONE);
|
|
1203
|
+
}
|
|
1204
|
+
function useShouldSkipBasedOnMode(testData) {
|
|
1205
|
+
if (useIsOne()) {
|
|
1206
|
+
return hasErrorsByTestObjects();
|
|
1207
|
+
}
|
|
1208
|
+
if (useIsEager()) {
|
|
1209
|
+
return hasErrorsByTestObjects(testData.fieldName);
|
|
1210
|
+
}
|
|
1211
|
+
return false;
|
|
1317
1212
|
}
|
|
1318
1213
|
|
|
1319
1214
|
//Checks whether a certain test profile excluded by any of the exclusion groups.
|
|
@@ -1382,304 +1277,409 @@ function useForceSkipIfInSkipWhen(testNode) {
|
|
|
1382
1277
|
return testNode;
|
|
1383
1278
|
}
|
|
1384
1279
|
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1280
|
+
// eslint-disable-next-line max-statements
|
|
1281
|
+
function useAttemptRunTest(testObject) {
|
|
1282
|
+
useVerifyTestRun(testObject);
|
|
1283
|
+
if (VestTest.isUntested(testObject)) {
|
|
1284
|
+
return useRunTest(testObject);
|
|
1388
1285
|
}
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1286
|
+
if (!VestTest.isNonActionable(testObject)) {
|
|
1287
|
+
// Probably unreachable. If we get here, it means that
|
|
1288
|
+
// something was really wrong and should be reported.
|
|
1289
|
+
/* istanbul ignore next */
|
|
1290
|
+
deferThrow(text(ErrorStrings.UNEXPECTED_TEST_REGISTRATION_ERROR, {
|
|
1291
|
+
testObject: JSON.stringify(testObject),
|
|
1292
|
+
}));
|
|
1393
1293
|
}
|
|
1394
1294
|
}
|
|
1395
|
-
function
|
|
1396
|
-
|
|
1397
|
-
|
|
1295
|
+
function runSyncTest(testObject) {
|
|
1296
|
+
return SuiteContext.run({ currentTest: testObject }, () => {
|
|
1297
|
+
let result;
|
|
1298
|
+
const { message, testFn } = VestTest.getData(testObject);
|
|
1299
|
+
try {
|
|
1300
|
+
result = testFn({ signal: testObject.abortController.signal });
|
|
1301
|
+
}
|
|
1302
|
+
catch (error) {
|
|
1303
|
+
if (shouldUseErrorAsMessage(message, error)) {
|
|
1304
|
+
VestTest.getData(testObject).message = error;
|
|
1305
|
+
}
|
|
1306
|
+
result = false;
|
|
1307
|
+
}
|
|
1308
|
+
if (result === false) {
|
|
1309
|
+
VestTest.fail(testObject);
|
|
1310
|
+
}
|
|
1311
|
+
return result;
|
|
1312
|
+
});
|
|
1398
1313
|
}
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1314
|
+
/**
|
|
1315
|
+
* runs test, if async - adds to pending array
|
|
1316
|
+
*/
|
|
1317
|
+
function useRunTest(testObject) {
|
|
1318
|
+
// Run test callback.
|
|
1319
|
+
// If a promise is returned, set as async and
|
|
1320
|
+
// Move to pending list.
|
|
1321
|
+
const result = runSyncTest(testObject);
|
|
1322
|
+
try {
|
|
1323
|
+
// try catch for safe property access
|
|
1324
|
+
// in case object is an enforce chain
|
|
1325
|
+
if (isPromise(result)) {
|
|
1326
|
+
VestTest.getData(testObject).asyncTest = result;
|
|
1327
|
+
return useRunAsyncTest(testObject);
|
|
1328
|
+
}
|
|
1329
|
+
onTestCompleted(testObject);
|
|
1406
1330
|
}
|
|
1407
|
-
|
|
1408
|
-
//
|
|
1409
|
-
//
|
|
1331
|
+
catch (e) {
|
|
1332
|
+
// Probably unreachable. If we get here, it means that
|
|
1333
|
+
// something was really wrong and should be reported.
|
|
1410
1334
|
/* istanbul ignore next */
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
// In short: if the node was omitted in the previous run,
|
|
1416
|
-
// we want to re-evaluate it. The reason is that we may incorrectly
|
|
1417
|
-
// identify it is "optional" because it was omitted in the previous run.
|
|
1418
|
-
// There may be a better way to handle this. Need to revisit this.
|
|
1419
|
-
if (VestTest.isOmitted(prevNode)) {
|
|
1420
|
-
return newNode;
|
|
1421
|
-
}
|
|
1422
|
-
return prevNode;
|
|
1423
|
-
}
|
|
1424
|
-
function cancelOverriddenPendingTestOnTestReRun(nextNode, currentNode, prevTestObject) {
|
|
1425
|
-
if (nextNode === currentNode && VestTest.is(currentNode)) {
|
|
1426
|
-
cancelOverriddenPendingTest(prevTestObject, currentNode);
|
|
1335
|
+
throw new Error(text(ErrorStrings.UNEXPECTED_TEST_REGISTRATION_ERROR, {
|
|
1336
|
+
testObject: JSON.stringify(testObject),
|
|
1337
|
+
error: e,
|
|
1338
|
+
}));
|
|
1427
1339
|
}
|
|
1428
1340
|
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
function
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1341
|
+
/**
|
|
1342
|
+
* Runs async test.
|
|
1343
|
+
*/
|
|
1344
|
+
function useRunAsyncTest(testObject) {
|
|
1345
|
+
const { asyncTest, message } = VestTest.getData(testObject);
|
|
1346
|
+
if (!isPromise(asyncTest))
|
|
1347
|
+
return;
|
|
1348
|
+
// VestTest.setPending(testObject);
|
|
1349
|
+
const done = VestRuntime.persist(() => {
|
|
1350
|
+
onTestCompleted(testObject);
|
|
1351
|
+
});
|
|
1352
|
+
const fail = VestRuntime.persist((rejectionMessage) => {
|
|
1353
|
+
if (VestTest.isCanceled(testObject)) {
|
|
1354
|
+
return;
|
|
1355
|
+
}
|
|
1356
|
+
VestTest.getData(testObject).message = isStringValue(rejectionMessage)
|
|
1357
|
+
? rejectionMessage
|
|
1358
|
+
: message;
|
|
1359
|
+
VestTest.fail(testObject);
|
|
1360
|
+
done();
|
|
1361
|
+
});
|
|
1362
|
+
return asyncTest.then(done, fail);
|
|
1363
|
+
}
|
|
1364
|
+
function onTestCompleted(testObject) {
|
|
1365
|
+
// Attempts passing if the test is not already failed.
|
|
1366
|
+
// or is not canceled/omitted.
|
|
1367
|
+
VestTest.pass(testObject);
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
// @vx-allow use-use
|
|
1371
|
+
function wrapTestMemo(test) {
|
|
1372
|
+
function memo(fieldName, ...args) {
|
|
1373
|
+
const [deps, testFn, msg] = args.reverse();
|
|
1374
|
+
// Implicit dependency for better specificity
|
|
1375
|
+
const dependencies = [
|
|
1376
|
+
useSuiteId(),
|
|
1377
|
+
fieldName,
|
|
1378
|
+
VestRuntime.useCurrentCursor(),
|
|
1379
|
+
].concat(deps);
|
|
1380
|
+
return useGetTestFromCache(dependencies, cacheAction);
|
|
1381
|
+
function cacheAction() {
|
|
1382
|
+
return test(fieldName, msg, testFn);
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
return memo;
|
|
1386
|
+
}
|
|
1387
|
+
function useGetTestFromCache(dependencies, cacheAction) {
|
|
1388
|
+
const cache = useTestMemoCache();
|
|
1389
|
+
const cached = cache.get(dependencies);
|
|
1390
|
+
if (isNull(cached)) {
|
|
1391
|
+
// cache miss
|
|
1392
|
+
return cache(dependencies, cacheAction);
|
|
1393
|
+
}
|
|
1394
|
+
const [, cachedValue] = cached;
|
|
1395
|
+
if (VestTest.isCanceled(cachedValue)) {
|
|
1396
|
+
// cache hit, but test is canceled
|
|
1397
|
+
cache.invalidate(dependencies);
|
|
1398
|
+
return cache(dependencies, cacheAction);
|
|
1399
|
+
}
|
|
1400
|
+
VestRuntime.addNodeToHistory(cachedValue);
|
|
1401
|
+
return cachedValue;
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
// @vx-allow use-use
|
|
1405
|
+
function vestTest(fieldName, ...args) {
|
|
1406
|
+
const [message, testFn, key] = (isFunction(args[1]) ? args : [undefined, ...args]);
|
|
1407
|
+
validateTestParams(fieldName, testFn);
|
|
1408
|
+
const groupName = useGroupName();
|
|
1409
|
+
const testObjectInput = { fieldName, groupName, message, testFn };
|
|
1410
|
+
// This invalidates the suite cache.
|
|
1411
|
+
Bus.useEmit(Events.TEST_RUN_STARTED);
|
|
1412
|
+
return IsolateTest(useAttemptRunTest, testObjectInput, key);
|
|
1413
|
+
}
|
|
1414
|
+
const test = assign(vestTest, {
|
|
1415
|
+
memo: wrapTestMemo(vestTest),
|
|
1416
|
+
});
|
|
1417
|
+
function validateTestParams(fieldName, testFn) {
|
|
1418
|
+
const fnName = 'test';
|
|
1419
|
+
invariant(isStringValue(fieldName), text(ErrorStrings.INVALID_PARAM_PASSED_TO_FUNCTION, {
|
|
1420
|
+
fn_name: fnName,
|
|
1421
|
+
param: 'fieldName',
|
|
1422
|
+
expected: 'string',
|
|
1423
|
+
}));
|
|
1424
|
+
invariant(isFunction(testFn), text(ErrorStrings.INVALID_PARAM_PASSED_TO_FUNCTION, {
|
|
1425
|
+
fn_name: fnName,
|
|
1426
|
+
param: 'callback',
|
|
1427
|
+
expected: 'function',
|
|
1441
1428
|
}));
|
|
1442
1429
|
}
|
|
1443
1430
|
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
return
|
|
1447
|
-
|
|
1431
|
+
// import { optional, skipWhen, omitWhen, IsolateTest, group } from 'vest';
|
|
1432
|
+
function getTypedMethods() {
|
|
1433
|
+
return {
|
|
1434
|
+
group,
|
|
1435
|
+
include,
|
|
1436
|
+
omitWhen,
|
|
1437
|
+
only,
|
|
1438
|
+
optional,
|
|
1439
|
+
skip,
|
|
1440
|
+
skipWhen,
|
|
1441
|
+
test,
|
|
1442
|
+
};
|
|
1448
1443
|
}
|
|
1449
1444
|
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1445
|
+
/**
|
|
1446
|
+
* This module gets triggered once the suite is done running its sync tests.
|
|
1447
|
+
*
|
|
1448
|
+
* It goes over all the tests in the state, and checks if they need to be omitted.
|
|
1449
|
+
*/
|
|
1450
|
+
function useOmitOptionalFields() {
|
|
1451
|
+
const root = VestRuntime.useAvailableRoot();
|
|
1452
|
+
const optionalFields = SuiteOptionalFields.getOptionalFields(root);
|
|
1453
|
+
// If there are no optional fields, we don't need to do anything
|
|
1454
|
+
if (isEmpty(optionalFields)) {
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
// Create an object to store the fields that need to be omitted
|
|
1458
|
+
const shouldOmit = new Set();
|
|
1459
|
+
// iterate over each of the tests in the state
|
|
1460
|
+
TestWalker.walkTests(testObject => {
|
|
1461
|
+
if (VestTest.isPending(testObject)) {
|
|
1462
|
+
return;
|
|
1463
|
+
}
|
|
1464
|
+
const { fieldName } = VestTest.getData(testObject);
|
|
1465
|
+
// If we already added the current field (not this test specifically)
|
|
1466
|
+
// no need for further checks, go and omit the test
|
|
1467
|
+
if (shouldOmit.has(fieldName)) {
|
|
1468
|
+
verifyAndOmit(testObject);
|
|
1469
|
+
}
|
|
1470
|
+
else {
|
|
1471
|
+
// check if the field has an optional function
|
|
1472
|
+
// if so, run it and verify/omit the test
|
|
1473
|
+
runOptionalConfig(testObject);
|
|
1474
|
+
}
|
|
1454
1475
|
});
|
|
1476
|
+
Bus.useEmit(Events.DONE_TEST_OMISSION_PASS);
|
|
1477
|
+
function verifyAndOmit(testObject) {
|
|
1478
|
+
const { fieldName } = VestTest.getData(testObject);
|
|
1479
|
+
if (shouldOmit.has(fieldName)) {
|
|
1480
|
+
VestTest.omit(testObject);
|
|
1481
|
+
SuiteOptionalFields.setOptionalField(root, fieldName, current => (Object.assign(Object.assign({}, current), { applied: true })));
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
function runOptionalConfig(testObject) {
|
|
1485
|
+
const { fieldName } = VestTest.getData(testObject);
|
|
1486
|
+
// Ge the optional configuration for the given field
|
|
1487
|
+
const optionalConfig = SuiteOptionalFields.getOptionalField(root, fieldName);
|
|
1488
|
+
// If the optional was set to a function or a boolean, run it and verify/omit the test
|
|
1489
|
+
if (optionalFunctionValue(optionalConfig.rule) === true) {
|
|
1490
|
+
shouldOmit.add(fieldName);
|
|
1491
|
+
}
|
|
1492
|
+
verifyAndOmit(testObject);
|
|
1493
|
+
}
|
|
1455
1494
|
}
|
|
1456
1495
|
|
|
1457
1496
|
/**
|
|
1458
|
-
*
|
|
1459
|
-
*
|
|
1460
|
-
* @param {string} fieldName - The name of the field to include for testing.
|
|
1461
|
-
*
|
|
1462
|
-
* @example
|
|
1463
|
-
* include('confirm').when('password');
|
|
1464
|
-
* // Includes the "confirm" field for testing when the "password" field is included
|
|
1465
|
-
*
|
|
1466
|
-
* include('confirm').when(someValue);
|
|
1467
|
-
* // Includes the "confirm" field for testing when the value of `someValue` is true
|
|
1468
|
-
*
|
|
1469
|
-
* include('confirm').when(() => someValue);
|
|
1470
|
-
* // Includes the "confirm" field for testing when the callback function returns true
|
|
1471
|
-
*
|
|
1472
|
-
* include('username').when(result => result.hasErrors('username'));
|
|
1473
|
-
* // Includes the "username" field for testing when there are errors associated with it in the current suite result
|
|
1497
|
+
* Runs done callback per field when async tests are finished running.
|
|
1474
1498
|
*/
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1499
|
+
function useRunFieldCallbacks(fieldName) {
|
|
1500
|
+
const [fieldCallbacks] = useFieldCallbacks();
|
|
1501
|
+
if (fieldName &&
|
|
1502
|
+
!SuiteWalker.hasRemainingWithTestNameMatching(fieldName) &&
|
|
1503
|
+
isArray(fieldCallbacks[fieldName])) {
|
|
1504
|
+
callEach(fieldCallbacks[fieldName]);
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
/**
|
|
1508
|
+
* Runs unlabelled done callback when async tests are finished running.
|
|
1509
|
+
*/
|
|
1510
|
+
function useRunDoneCallbacks() {
|
|
1511
|
+
const [doneCallbacks] = useDoneCallbacks();
|
|
1512
|
+
callEach(doneCallbacks);
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
// eslint-disable-next-line max-statements, max-lines-per-function
|
|
1516
|
+
function useInitVestBus() {
|
|
1517
|
+
const VestBus = Bus.useBus();
|
|
1518
|
+
// Report a the completion of a test. There may be other tests with the same
|
|
1519
|
+
// name that are still running, or not yet started.
|
|
1520
|
+
on(Events.TEST_COMPLETED, (testObject) => {
|
|
1521
|
+
if (VestTest.isCanceled(testObject)) {
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
const { fieldName } = VestTest.getData(testObject);
|
|
1525
|
+
useRunFieldCallbacks(fieldName);
|
|
1526
|
+
});
|
|
1527
|
+
on(Events.TEST_RUN_STARTED, () => {
|
|
1528
|
+
/* Let's just invalidate the suite cache for now */
|
|
1529
|
+
});
|
|
1530
|
+
on(RuntimeEvents.ISOLATE_PENDING, (isolate) => {
|
|
1531
|
+
if (VestTest.is(isolate)) {
|
|
1532
|
+
VestTest.setPending(isolate);
|
|
1533
|
+
}
|
|
1534
|
+
setPending(isolate);
|
|
1535
|
+
});
|
|
1536
|
+
on(RuntimeEvents.ISOLATE_DONE, (isolate) => {
|
|
1537
|
+
if (VestTest.is(isolate)) {
|
|
1538
|
+
VestBus.emit(Events.TEST_COMPLETED, isolate);
|
|
1539
|
+
}
|
|
1540
|
+
setDone(isolate);
|
|
1541
|
+
if (!SuiteWalker.hasPending()) {
|
|
1542
|
+
// When no more tests are running, emit the done event
|
|
1543
|
+
VestBus.emit(Events.ALL_RUNNING_TESTS_FINISHED);
|
|
1544
|
+
}
|
|
1545
|
+
});
|
|
1546
|
+
on(Events.DONE_TEST_OMISSION_PASS, () => {
|
|
1547
|
+
/* We NEED to refresh the cache here. Don't ask */
|
|
1548
|
+
});
|
|
1549
|
+
// Called when all the tests, including async, are done running
|
|
1550
|
+
on(Events.ALL_RUNNING_TESTS_FINISHED, () => {
|
|
1551
|
+
// Small optimization. We don't need to run this if there are no async tests
|
|
1552
|
+
// The reason is that we run this function immediately after the suite callback
|
|
1553
|
+
// is run, so if the suite is only comprised of sync tests, we don't need to
|
|
1554
|
+
// run this function twice since we know for a fact the state is up to date
|
|
1555
|
+
if (TestWalker.someTests(VestTest.isAsyncTest)) {
|
|
1556
|
+
useOmitOptionalFields();
|
|
1557
|
+
}
|
|
1558
|
+
useRunDoneCallbacks();
|
|
1559
|
+
});
|
|
1560
|
+
on(Events.RESET_FIELD, (fieldName) => {
|
|
1561
|
+
TestWalker.resetField(fieldName);
|
|
1562
|
+
});
|
|
1563
|
+
on(Events.SUITE_RUN_STARTED, () => {
|
|
1564
|
+
useResetCallbacks();
|
|
1565
|
+
});
|
|
1566
|
+
on(Events.SUITE_CALLBACK_RUN_FINISHED, () => {
|
|
1567
|
+
useOmitOptionalFields();
|
|
1568
|
+
});
|
|
1569
|
+
on(Events.REMOVE_FIELD, (fieldName) => {
|
|
1570
|
+
TestWalker.removeTestByFieldName(fieldName);
|
|
1571
|
+
});
|
|
1572
|
+
on(Events.RESET_SUITE, () => {
|
|
1573
|
+
useResetSuite();
|
|
1574
|
+
});
|
|
1575
|
+
return {
|
|
1576
|
+
subscribe,
|
|
1577
|
+
};
|
|
1578
|
+
function subscribe(cb) {
|
|
1579
|
+
return VestBus.on('*', () => {
|
|
1580
|
+
cb();
|
|
1581
|
+
}).off;
|
|
1582
|
+
}
|
|
1583
|
+
function on(event, cb) {
|
|
1584
|
+
VestBus.on(event, (...args) => {
|
|
1585
|
+
// This is more concise, but it might be an overkill
|
|
1586
|
+
// if we're adding events that don't need to invalidate the cache
|
|
1587
|
+
useExpireSuiteResultCache();
|
|
1588
|
+
cb(...args);
|
|
1589
|
+
});
|
|
1494
1590
|
}
|
|
1495
1591
|
}
|
|
1496
1592
|
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
payload.groupName = input.groupName;
|
|
1593
|
+
class IsolateReconciler {
|
|
1594
|
+
static match(_currentNode, _historyNode) {
|
|
1595
|
+
return false;
|
|
1501
1596
|
}
|
|
1502
|
-
|
|
1503
|
-
|
|
1597
|
+
static reconcile(currentNode, historyNode) {
|
|
1598
|
+
return (currentNode !== null && currentNode !== void 0 ? currentNode : historyNode);
|
|
1504
1599
|
}
|
|
1505
|
-
const isolate = Isolate.create(VestIsolateType.Test, callback, payload, key !== null && key !== void 0 ? key : null);
|
|
1506
|
-
return isolate;
|
|
1507
1600
|
}
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1601
|
+
|
|
1602
|
+
function isSameProfileTest(testObject1, testObject2) {
|
|
1603
|
+
const { groupName: gn1 } = VestTest.getData(testObject1);
|
|
1604
|
+
const { groupName: gn2, fieldName: fn2 } = VestTest.getData(testObject2);
|
|
1605
|
+
return (matchingFieldName(VestTest.getData(testObject1), fn2) &&
|
|
1606
|
+
gn1 === gn2 &&
|
|
1607
|
+
// Specifically using == here. The reason is that when serializing
|
|
1608
|
+
// suite result, empty key gets removed, but it can also be null.
|
|
1609
|
+
testObject1.key == testObject2.key);
|
|
1513
1610
|
}
|
|
1514
1611
|
|
|
1515
|
-
function
|
|
1516
|
-
|
|
1517
|
-
|
|
1612
|
+
function cancelOverriddenPendingTest(prevRunTestObject, currentRunTestObject) {
|
|
1613
|
+
if (currentRunTestObject !== prevRunTestObject &&
|
|
1614
|
+
isSameProfileTest(prevRunTestObject, currentRunTestObject) &&
|
|
1615
|
+
VestTest.isPending(prevRunTestObject)) {
|
|
1616
|
+
VestTest.cancel(prevRunTestObject);
|
|
1617
|
+
}
|
|
1518
1618
|
}
|
|
1519
1619
|
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
if (VestTest.isUntested(testObject)) {
|
|
1524
|
-
return useRunTest(testObject);
|
|
1620
|
+
class IsolateTestReconciler extends IsolateReconciler {
|
|
1621
|
+
static match(currentNode, historyNode) {
|
|
1622
|
+
return VestTest.is(currentNode) && VestTest.is(historyNode);
|
|
1525
1623
|
}
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
deferThrow(text(ErrorStrings.UNEXPECTED_TEST_REGISTRATION_ERROR, {
|
|
1531
|
-
testObject: JSON.stringify(testObject),
|
|
1532
|
-
}));
|
|
1624
|
+
static reconcile(currentNode, historyNode) {
|
|
1625
|
+
const reconcilerOutput = usePickNode(historyNode, currentNode);
|
|
1626
|
+
cancelOverriddenPendingTestOnTestReRun(reconcilerOutput, currentNode, historyNode);
|
|
1627
|
+
return reconcilerOutput;
|
|
1533
1628
|
}
|
|
1534
1629
|
}
|
|
1535
|
-
function
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
const { message, testFn } = VestTest.getData(testObject);
|
|
1539
|
-
try {
|
|
1540
|
-
result = testFn({ signal: testObject.abortController.signal });
|
|
1541
|
-
}
|
|
1542
|
-
catch (error) {
|
|
1543
|
-
if (shouldUseErrorAsMessage(message, error)) {
|
|
1544
|
-
VestTest.getData(testObject).message = error;
|
|
1545
|
-
}
|
|
1546
|
-
result = false;
|
|
1547
|
-
}
|
|
1548
|
-
if (result === false) {
|
|
1549
|
-
VestTest.fail(testObject);
|
|
1550
|
-
}
|
|
1551
|
-
return result;
|
|
1552
|
-
});
|
|
1630
|
+
function usePickNode(historyNode, currentNode) {
|
|
1631
|
+
const collisionResult = handleCollision(currentNode, historyNode);
|
|
1632
|
+
return useVerifyTestRun(currentNode, collisionResult);
|
|
1553
1633
|
}
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
function useRunTest(testObject) {
|
|
1558
|
-
// Run test callback.
|
|
1559
|
-
// If a promise is returned, set as async and
|
|
1560
|
-
// Move to pending list.
|
|
1561
|
-
const result = runSyncTest(testObject);
|
|
1562
|
-
try {
|
|
1563
|
-
// try catch for safe property access
|
|
1564
|
-
// in case object is an enforce chain
|
|
1565
|
-
if (isPromise(result)) {
|
|
1566
|
-
VestTest.getData(testObject).asyncTest = result;
|
|
1567
|
-
return useRunAsyncTest(testObject);
|
|
1568
|
-
}
|
|
1569
|
-
onTestCompleted(testObject);
|
|
1634
|
+
function handleCollision(newNode, prevNode) {
|
|
1635
|
+
if (IsolateInspector.usesKey(newNode)) {
|
|
1636
|
+
return VestTest.cast(Reconciler.handleIsolateNodeWithKey(newNode, VestTest.isNonActionable));
|
|
1570
1637
|
}
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1638
|
+
if (Reconciler.dropNextNodesOnReorder(nodeReorderDetected, newNode, prevNode)) {
|
|
1639
|
+
throwTestOrderError(newNode, prevNode);
|
|
1640
|
+
return newNode;
|
|
1641
|
+
}
|
|
1642
|
+
if (!VestTest.is(prevNode)) {
|
|
1643
|
+
// I believe we cannot actually reach this point.
|
|
1644
|
+
// Because it should already be handled by nodeReorderDetected.
|
|
1574
1645
|
/* istanbul ignore next */
|
|
1575
|
-
|
|
1576
|
-
testObject: JSON.stringify(testObject),
|
|
1577
|
-
error: e,
|
|
1578
|
-
}));
|
|
1646
|
+
return newNode;
|
|
1579
1647
|
}
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
if (
|
|
1587
|
-
return;
|
|
1588
|
-
// VestTest.setPending(testObject);
|
|
1589
|
-
const done = VestRuntime.persist(() => {
|
|
1590
|
-
onTestCompleted(testObject);
|
|
1591
|
-
});
|
|
1592
|
-
const fail = VestRuntime.persist((rejectionMessage) => {
|
|
1593
|
-
if (VestTest.isCanceled(testObject)) {
|
|
1594
|
-
return;
|
|
1595
|
-
}
|
|
1596
|
-
VestTest.getData(testObject).message = isStringValue(rejectionMessage)
|
|
1597
|
-
? rejectionMessage
|
|
1598
|
-
: message;
|
|
1599
|
-
VestTest.fail(testObject);
|
|
1600
|
-
done();
|
|
1601
|
-
});
|
|
1602
|
-
return asyncTest.then(done, fail);
|
|
1603
|
-
}
|
|
1604
|
-
function onTestCompleted(testObject) {
|
|
1605
|
-
// Attempts passing if the test is not already failed.
|
|
1606
|
-
// or is not canceled/omitted.
|
|
1607
|
-
VestTest.pass(testObject);
|
|
1608
|
-
}
|
|
1609
|
-
|
|
1610
|
-
// @vx-allow use-use
|
|
1611
|
-
function wrapTestMemo(test) {
|
|
1612
|
-
function memo(fieldName, ...args) {
|
|
1613
|
-
const [deps, testFn, msg] = args.reverse();
|
|
1614
|
-
// Implicit dependency for better specificity
|
|
1615
|
-
const dependencies = [
|
|
1616
|
-
useSuiteId(),
|
|
1617
|
-
fieldName,
|
|
1618
|
-
VestRuntime.useCurrentCursor(),
|
|
1619
|
-
].concat(deps);
|
|
1620
|
-
return useGetTestFromCache(dependencies, cacheAction);
|
|
1621
|
-
function cacheAction() {
|
|
1622
|
-
return test(fieldName, msg, testFn);
|
|
1623
|
-
}
|
|
1648
|
+
// FIXME: May-13-2023
|
|
1649
|
+
// This may not be the most ideal solution.
|
|
1650
|
+
// In short: if the node was omitted in the previous run,
|
|
1651
|
+
// we want to re-evaluate it. The reason is that we may incorrectly
|
|
1652
|
+
// identify it is "optional" because it was omitted in the previous run.
|
|
1653
|
+
// There may be a better way to handle this. Need to revisit this.
|
|
1654
|
+
if (VestTest.isOmitted(prevNode)) {
|
|
1655
|
+
return newNode;
|
|
1624
1656
|
}
|
|
1625
|
-
return
|
|
1657
|
+
return prevNode;
|
|
1626
1658
|
}
|
|
1627
|
-
function
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
if (isNull(cached)) {
|
|
1631
|
-
// cache miss
|
|
1632
|
-
return cache(dependencies, cacheAction);
|
|
1633
|
-
}
|
|
1634
|
-
const [, cachedValue] = cached;
|
|
1635
|
-
if (VestTest.isCanceled(cachedValue)) {
|
|
1636
|
-
// cache hit, but test is canceled
|
|
1637
|
-
cache.invalidate(dependencies);
|
|
1638
|
-
return cache(dependencies, cacheAction);
|
|
1659
|
+
function cancelOverriddenPendingTestOnTestReRun(nextNode, currentNode, prevTestObject) {
|
|
1660
|
+
if (nextNode === currentNode && VestTest.is(currentNode)) {
|
|
1661
|
+
cancelOverriddenPendingTest(prevTestObject, currentNode);
|
|
1639
1662
|
}
|
|
1640
|
-
VestRuntime.addNodeToHistory(cachedValue);
|
|
1641
|
-
return cachedValue;
|
|
1642
1663
|
}
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
function vestTest(fieldName, ...args) {
|
|
1646
|
-
const [message, testFn, key] = (isFunction(args[1]) ? args : [undefined, ...args]);
|
|
1647
|
-
validateTestParams(fieldName, testFn);
|
|
1648
|
-
const groupName = useGroupName();
|
|
1649
|
-
const testObjectInput = { fieldName, groupName, message, testFn };
|
|
1650
|
-
// This invalidates the suite cache.
|
|
1651
|
-
Bus.useEmit(Events.TEST_RUN_STARTED);
|
|
1652
|
-
return IsolateTest(useAttemptRunTest, testObjectInput, key);
|
|
1664
|
+
function nodeReorderDetected(newNode, prevNode) {
|
|
1665
|
+
return VestTest.is(prevNode) && !isSameProfileTest(prevNode, newNode);
|
|
1653
1666
|
}
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
}));
|
|
1664
|
-
invariant(isFunction(testFn), text(ErrorStrings.INVALID_PARAM_PASSED_TO_FUNCTION, {
|
|
1665
|
-
fn_name: fnName,
|
|
1666
|
-
param: 'callback',
|
|
1667
|
-
expected: 'function',
|
|
1667
|
+
function throwTestOrderError(newNode, prevNode) {
|
|
1668
|
+
if (IsolateInspector.canReorder(newNode)) {
|
|
1669
|
+
return;
|
|
1670
|
+
}
|
|
1671
|
+
deferThrow(text(ErrorStrings.TESTS_CALLED_IN_DIFFERENT_ORDER, {
|
|
1672
|
+
fieldName: VestTest.getData(newNode).fieldName,
|
|
1673
|
+
prevName: VestTest.is(prevNode)
|
|
1674
|
+
? VestTest.getData(prevNode).fieldName
|
|
1675
|
+
: undefined,
|
|
1668
1676
|
}));
|
|
1669
1677
|
}
|
|
1670
1678
|
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
return
|
|
1674
|
-
|
|
1675
|
-
include,
|
|
1676
|
-
omitWhen,
|
|
1677
|
-
only,
|
|
1678
|
-
optional,
|
|
1679
|
-
skip,
|
|
1680
|
-
skipWhen,
|
|
1681
|
-
test,
|
|
1682
|
-
};
|
|
1679
|
+
function VestReconciler(currentNode, historyNode) {
|
|
1680
|
+
var _a, _b;
|
|
1681
|
+
return ((_b = (_a = [IsolateTestReconciler]
|
|
1682
|
+
.find(reconciler => reconciler.match(currentNode, historyNode))) === null || _a === void 0 ? void 0 : _a.reconcile(currentNode, historyNode)) !== null && _b !== void 0 ? _b : null);
|
|
1683
1683
|
}
|
|
1684
1684
|
|
|
1685
1685
|
function useDeferDoneCallback(doneCallback, fieldName) {
|
|
@@ -1734,6 +1734,7 @@ function validateSuiteCallback(suiteCallback) {
|
|
|
1734
1734
|
}
|
|
1735
1735
|
|
|
1736
1736
|
// @vx-allow use-use
|
|
1737
|
+
// eslint-disable-next-line max-lines-per-function
|
|
1737
1738
|
function createSuite(...args) {
|
|
1738
1739
|
const [suiteCallback, suiteName] = args.reverse();
|
|
1739
1740
|
validateSuiteCallback(suiteCallback);
|
|
@@ -1748,6 +1749,7 @@ function createSuite(...args) {
|
|
|
1748
1749
|
return IsolateSuite(useRunSuiteCallback(suiteCallback, ...args));
|
|
1749
1750
|
}).output;
|
|
1750
1751
|
}
|
|
1752
|
+
const mountedStatic = staticSuite(...args);
|
|
1751
1753
|
// Assign methods to the suite
|
|
1752
1754
|
// We do this within the VestRuntime so that the suite methods
|
|
1753
1755
|
// will be bound to the suite's stateRef and be able to access it.
|
|
@@ -1757,7 +1759,7 @@ function createSuite(...args) {
|
|
|
1757
1759
|
return assign(
|
|
1758
1760
|
// We're also binding the suite to the stateRef, so that the suite
|
|
1759
1761
|
// can access the stateRef when it's called.
|
|
1760
|
-
VestRuntime.persist(suite), Object.assign(Object.assign({ dump: VestRuntime.persist(() => VestRuntime.useAvailableRoot()), get: VestRuntime.persist(useCreateSuiteResult), remove: Bus.usePrepareEmitter(Events.REMOVE_FIELD), reset: Bus.usePrepareEmitter(Events.RESET_SUITE), resetField: Bus.usePrepareEmitter(Events.RESET_FIELD), resume: VestRuntime.persist(useLoadSuite), subscribe: VestBus.subscribe }, bindSuiteSelectors(VestRuntime.persist(useCreateSuiteResult))), getTypedMethods()));
|
|
1762
|
+
VestRuntime.persist(suite), Object.assign(Object.assign({ dump: VestRuntime.persist(() => VestRuntime.useAvailableRoot()), get: VestRuntime.persist(useCreateSuiteResult), remove: Bus.usePrepareEmitter(Events.REMOVE_FIELD), reset: Bus.usePrepareEmitter(Events.RESET_SUITE), resetField: Bus.usePrepareEmitter(Events.RESET_FIELD), resume: VestRuntime.persist(useLoadSuite), runStatic: (...args) => mountedStatic(...args), subscribe: VestBus.subscribe }, bindSuiteSelectors(VestRuntime.persist(useCreateSuiteResult))), getTypedMethods()));
|
|
1761
1763
|
});
|
|
1762
1764
|
}
|
|
1763
1765
|
function useRunSuiteCallback(suiteCallback, ...args) {
|
|
@@ -1768,6 +1770,17 @@ function useRunSuiteCallback(suiteCallback, ...args) {
|
|
|
1768
1770
|
return useSuiteRunResult();
|
|
1769
1771
|
};
|
|
1770
1772
|
}
|
|
1773
|
+
// @vx-allow use-use
|
|
1774
|
+
// eslint-disable-next-line max-lines-per-function
|
|
1775
|
+
function staticSuite(...createArgs) {
|
|
1776
|
+
return assign((...args) => {
|
|
1777
|
+
const suite = createSuite(...createArgs);
|
|
1778
|
+
const result = suite(...args);
|
|
1779
|
+
return Object.freeze(assign({
|
|
1780
|
+
dump: suite.dump,
|
|
1781
|
+
}, result));
|
|
1782
|
+
}, Object.assign({}, getTypedMethods()));
|
|
1783
|
+
}
|
|
1771
1784
|
|
|
1772
1785
|
function IsolateEach(callback) {
|
|
1773
1786
|
return Isolate.create(VestIsolateType.Each, callback, {
|
|
@@ -1797,33 +1810,6 @@ function each(list, callback) {
|
|
|
1797
1810
|
});
|
|
1798
1811
|
}
|
|
1799
1812
|
|
|
1800
|
-
/**
|
|
1801
|
-
* Creates a static suite for server-side validation.
|
|
1802
|
-
*
|
|
1803
|
-
* @param {Function} validationFn - The validation function that defines the suite's tests.
|
|
1804
|
-
* @returns {Function} - A function that runs the validations defined in the suite.
|
|
1805
|
-
*
|
|
1806
|
-
* @example
|
|
1807
|
-
* import { staticSuite, test, enforce } from 'vest';
|
|
1808
|
-
*
|
|
1809
|
-
* const suite = staticSuite(data => {
|
|
1810
|
-
* test('username', 'username is required', () => {
|
|
1811
|
-
* enforce(data.username).isNotEmpty();
|
|
1812
|
-
* });
|
|
1813
|
-
* });
|
|
1814
|
-
*
|
|
1815
|
-
* suite(data);
|
|
1816
|
-
*/
|
|
1817
|
-
function staticSuite(suiteCallback) {
|
|
1818
|
-
return assign((...args) => {
|
|
1819
|
-
const suite = createSuite(suiteCallback);
|
|
1820
|
-
const result = suite(...args);
|
|
1821
|
-
return Object.freeze(assign({
|
|
1822
|
-
dump: suite.dump,
|
|
1823
|
-
}, result));
|
|
1824
|
-
}, Object.assign({}, getTypedMethods()));
|
|
1825
|
-
}
|
|
1826
|
-
|
|
1827
1813
|
const ERROR_OUTSIDE_OF_TEST = ErrorStrings.WARN_MUST_BE_CALLED_FROM_TEST;
|
|
1828
1814
|
/**
|
|
1829
1815
|
* Sets the severity level of a test to `warn`, allowing it to fail without marking the suite as invalid.
|