vest 4.2.3-dev-87ebfa → 4.3.2-dev-2805e3

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.
Files changed (41) hide show
  1. package/dist/cjs/classnames.development.js +61 -23
  2. package/dist/cjs/classnames.production.js +1 -1
  3. package/dist/cjs/enforce/compose.development.js +1 -1
  4. package/dist/cjs/enforce/compounds.development.js +20 -5
  5. package/dist/cjs/enforce/compounds.production.js +1 -1
  6. package/dist/cjs/enforce/schema.development.js +1 -1
  7. package/dist/cjs/parser.development.js +87 -22
  8. package/dist/cjs/parser.production.js +1 -1
  9. package/dist/cjs/vest.development.js +548 -566
  10. package/dist/cjs/vest.production.js +1 -1
  11. package/dist/es/classnames.development.js +61 -23
  12. package/dist/es/classnames.production.js +1 -1
  13. package/dist/es/enforce/compose.development.js +1 -1
  14. package/dist/es/enforce/compounds.development.js +20 -5
  15. package/dist/es/enforce/compounds.production.js +1 -1
  16. package/dist/es/enforce/schema.development.js +1 -1
  17. package/dist/es/parser.development.js +87 -22
  18. package/dist/es/parser.production.js +1 -1
  19. package/dist/es/vest.development.js +548 -566
  20. package/dist/es/vest.production.js +1 -1
  21. package/dist/umd/classnames.development.js +61 -23
  22. package/dist/umd/classnames.production.js +1 -1
  23. package/dist/umd/enforce/compose.development.js +34 -30
  24. package/dist/umd/enforce/compose.production.js +1 -1
  25. package/dist/umd/enforce/compounds.development.js +36 -32
  26. package/dist/umd/enforce/compounds.production.js +1 -1
  27. package/dist/umd/enforce/schema.development.js +34 -30
  28. package/dist/umd/enforce/schema.production.js +1 -1
  29. package/dist/umd/parser.development.js +87 -22
  30. package/dist/umd/parser.production.js +1 -1
  31. package/dist/umd/vest.development.js +482 -515
  32. package/dist/umd/vest.production.js +1 -1
  33. package/package.json +1 -1
  34. package/testUtils/suiteDummy.ts +5 -1
  35. package/types/classnames.d.ts +17 -55
  36. package/types/enforce/compose.d.ts +22 -21
  37. package/types/enforce/compounds.d.ts +24 -23
  38. package/types/enforce/schema.d.ts +26 -25
  39. package/types/parser.d.ts +16 -54
  40. package/types/promisify.d.ts +23 -16
  41. package/types/vest.d.ts +109 -101
@@ -5,8 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var n4s = require('n4s');
6
6
  var context$1 = require('context');
7
7
 
8
- var assign = Object.assign;
9
-
10
8
  /**
11
9
  * @returns a unique numeric id.
12
10
  */
@@ -14,203 +12,91 @@ var genId = (function (n) { return function () {
14
12
  return "".concat(n++);
15
13
  }; })(0);
16
14
 
17
- function isFunction(value) {
18
- return typeof value === 'function';
19
- }
20
-
21
- function optionalFunctionValue(value) {
22
- var args = [];
23
- for (var _i = 1; _i < arguments.length; _i++) {
24
- args[_i - 1] = arguments[_i];
25
- }
26
- return isFunction(value) ? value.apply(void 0, args) : value;
27
- }
28
-
29
- function invariant(condition,
30
- // eslint-disable-next-line @typescript-eslint/ban-types
31
- message) {
32
- if (condition) {
33
- return;
34
- }
35
- // If message is a string object (rather than string literal)
36
- // Throw the value directly as a string
37
- // Alternatively, throw an error with the message
38
- throw message instanceof String
39
- ? message.valueOf()
40
- : new Error(message ? optionalFunctionValue(message) : message);
15
+ function isStringValue(v) {
16
+ return String(v) === v;
41
17
  }
42
18
 
43
- // eslint-disable-next-line max-lines-per-function
44
- function createState(onStateChange) {
45
- var state = {
46
- references: []
47
- };
48
- var registrations = [];
49
- return {
50
- registerStateKey: registerStateKey,
51
- reset: reset
52
- };
53
- /**
54
- * Registers a new key in the state, takes the initial value (may be a function that returns the initial value), returns a function.
55
- *
56
- * @example
57
- *
58
- * const useColor = state.registerStateKey("blue");
59
- *
60
- * let [color, setColor] = useColor(); // -> ["blue", Function]
61
- *
62
- * setColor("green");
63
- *
64
- * useColor()[0]; -> "green"
65
- */
66
- function registerStateKey(initialState, onUpdate) {
67
- var key = registrations.length;
68
- registrations.push([initialState, onUpdate]);
69
- return initKey(key, initialState);
70
- }
71
- function reset() {
72
- var prev = current();
73
- state.references = [];
74
- registrations.forEach(function (_a, index) {
75
- var initialValue = _a[0];
76
- return initKey(index, initialValue, prev[index]);
77
- });
78
- }
79
- function initKey(key, initialState, prevState) {
80
- current().push();
81
- set(key, optionalFunctionValue(initialState, prevState));
82
- return function useStateKey() {
83
- return [
84
- current()[key],
85
- function (nextState) {
86
- return set(key, optionalFunctionValue(nextState, current()[key]));
87
- },
88
- ];
89
- };
90
- }
91
- function current() {
92
- return state.references;
93
- }
94
- function set(index, value) {
95
- var prevValue = state.references[index];
96
- state.references[index] = value;
97
- var _a = registrations[index], onUpdate = _a[1];
98
- if (isFunction(onUpdate)) {
99
- onUpdate(value, prevValue);
100
- }
101
- if (isFunction(onStateChange)) {
102
- onStateChange();
19
+ function bindNot(fn) {
20
+ return function () {
21
+ var args = [];
22
+ for (var _i = 0; _i < arguments.length; _i++) {
23
+ args[_i] = arguments[_i];
103
24
  }
104
- }
25
+ return !fn.apply(void 0, args);
26
+ };
105
27
  }
106
28
 
107
- var IsolateTypes;
108
- (function (IsolateTypes) {
109
- IsolateTypes[IsolateTypes["DEFAULT"] = 0] = "DEFAULT";
110
- IsolateTypes[IsolateTypes["SUITE"] = 1] = "SUITE";
111
- IsolateTypes[IsolateTypes["EACH"] = 2] = "EACH";
112
- IsolateTypes[IsolateTypes["SKIP_WHEN"] = 3] = "SKIP_WHEN";
113
- IsolateTypes[IsolateTypes["OMIT_WHEN"] = 4] = "OMIT_WHEN";
114
- IsolateTypes[IsolateTypes["GROUP"] = 5] = "GROUP";
115
- })(IsolateTypes || (IsolateTypes = {}));
29
+ function isUndefined(value) {
30
+ return value === undefined;
31
+ }
116
32
 
117
- function createStateRef(state, _a) {
118
- var suiteId = _a.suiteId, suiteName = _a.suiteName;
119
- return {
120
- optionalFields: state.registerStateKey(function () { return ({}); }),
121
- suiteId: state.registerStateKey(suiteId),
122
- suiteName: state.registerStateKey(suiteName),
123
- testCallbacks: state.registerStateKey(function () { return ({
124
- fieldCallbacks: {},
125
- doneCallbacks: []
126
- }); }),
127
- testObjects: state.registerStateKey(function (prev) {
128
- return {
129
- prev: prev ? prev.current : [],
130
- current: []
131
- };
132
- })
133
- };
33
+ function shouldUseErrorAsMessage(message, error) {
34
+ // kind of cheating with this safe guard, but it does the job
35
+ return isUndefined(message) && isStringValue(error);
134
36
  }
135
37
 
136
38
  function asArray(possibleArg) {
137
39
  return [].concat(possibleArg);
138
40
  }
139
41
 
140
- function last(values) {
141
- var valuesArray = asArray(values);
142
- return valuesArray[valuesArray.length - 1];
42
+ function isNumeric(value) {
43
+ var str = String(value);
44
+ var num = Number(value);
45
+ var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
46
+ return Boolean(result);
143
47
  }
144
48
 
145
- function createCursor() {
146
- var storage = {
147
- cursor: []
148
- };
149
- function addLevel() {
150
- storage.cursor.push(0);
151
- }
152
- function removeLevel() {
153
- storage.cursor.pop();
154
- }
155
- function cursorAt() {
156
- return last(storage.cursor);
157
- }
158
- function getCursor() {
159
- return asArray(storage.cursor);
160
- }
161
- function next() {
162
- storage.cursor[storage.cursor.length - 1]++;
163
- return last(storage.cursor);
164
- }
165
- function reset() {
166
- storage.cursor = [0];
167
- }
168
- reset();
169
- return {
170
- addLevel: addLevel,
171
- cursorAt: cursorAt,
172
- getCursor: getCursor,
173
- next: next,
174
- removeLevel: removeLevel,
175
- reset: reset
176
- };
49
+ function numberEquals(value, eq) {
50
+ return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
177
51
  }
178
52
 
179
- var Modes;
180
- (function (Modes) {
181
- Modes[Modes["ALL"] = 0] = "ALL";
182
- Modes[Modes["EAGER"] = 1] = "EAGER";
183
- })(Modes || (Modes = {}));
53
+ function lengthEquals(value, arg1) {
54
+ return numberEquals(value.length, arg1);
55
+ }
184
56
 
185
- var context = context$1.createContext(function (ctxRef, parentContext) {
186
- return parentContext
187
- ? null
188
- : assign({}, {
189
- exclusion: {
190
- tests: {},
191
- groups: {}
192
- },
193
- inclusion: {},
194
- isolate: {
195
- type: IsolateTypes.DEFAULT,
196
- keys: {
197
- current: {},
198
- prev: {}
199
- }
200
- },
201
- mode: [Modes.ALL],
202
- testCursor: createCursor()
203
- }, ctxRef);
204
- });
57
+ function greaterThan(value, gt) {
58
+ return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
59
+ }
205
60
 
206
- function bindNot(fn) {
207
- return function () {
208
- var args = [];
209
- for (var _i = 0; _i < arguments.length; _i++) {
210
- args[_i] = arguments[_i];
211
- }
212
- return !fn.apply(void 0, args);
61
+ function longerThan(value, arg1) {
62
+ return greaterThan(value.length, arg1);
63
+ }
64
+
65
+ /**
66
+ * Creates a cache function
67
+ */
68
+ function createCache(maxSize) {
69
+ if (maxSize === void 0) { maxSize = 1; }
70
+ var cacheStorage = [];
71
+ var cache = function (deps, cacheAction) {
72
+ var cacheHit = cache.get(deps);
73
+ // cache hit is not null
74
+ if (cacheHit)
75
+ return cacheHit[1];
76
+ var result = cacheAction();
77
+ cacheStorage.unshift([deps.concat(), result]);
78
+ if (longerThan(cacheStorage, maxSize))
79
+ cacheStorage.length = maxSize;
80
+ return result;
81
+ };
82
+ // invalidate an item in the cache by its dependencies
83
+ cache.invalidate = function (deps) {
84
+ var index = findIndex(deps);
85
+ if (index > -1)
86
+ cacheStorage.splice(index, 1);
213
87
  };
88
+ // Retrieves an item from the cache.
89
+ cache.get = function (deps) {
90
+ return cacheStorage[findIndex(deps)] || null;
91
+ };
92
+ return cache;
93
+ function findIndex(deps) {
94
+ return cacheStorage.findIndex(function (_a) {
95
+ var cachedDeps = _a[0];
96
+ return lengthEquals(deps, cachedDeps.length) &&
97
+ deps.every(function (dep, i) { return dep === cachedDeps[i]; });
98
+ });
99
+ }
214
100
  }
215
101
 
216
102
  // The module is named "isArrayValue" since it
@@ -225,11 +111,28 @@ function isNull(value) {
225
111
  }
226
112
  var isNotNull = bindNot(isNull);
227
113
 
114
+ function isFunction(value) {
115
+ return typeof value === 'function';
116
+ }
117
+
118
+ function optionalFunctionValue(value) {
119
+ var args = [];
120
+ for (var _i = 1; _i < arguments.length; _i++) {
121
+ args[_i - 1] = arguments[_i];
122
+ }
123
+ return isFunction(value) ? value.apply(void 0, args) : value;
124
+ }
125
+
228
126
  function defaultTo(callback, defaultValue) {
229
127
  var _a;
230
128
  return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
231
129
  }
232
130
 
131
+ function last(values) {
132
+ var valuesArray = asArray(values);
133
+ return valuesArray[valuesArray.length - 1];
134
+ }
135
+
233
136
  // This is kind of a map/filter in one function.
234
137
  // Normally, behaves like a nested-array map,
235
138
  // but returning `null` will drop the element from the array
@@ -275,74 +178,79 @@ function getCurrent(array, path) {
275
178
  return current;
276
179
  }
277
180
 
278
- function isUndefined(value) {
279
- return value === undefined;
280
- }
281
-
282
- function isNullish(value) {
283
- return isNull(value) || isUndefined(value);
284
- }
285
-
286
- function deferThrow(message) {
287
- setTimeout(function () {
288
- throw new Error(message);
289
- }, 0);
290
- }
291
-
292
- function isStringValue(v) {
293
- return String(v) === v;
294
- }
295
-
296
- function shouldUseErrorAsMessage(message, error) {
297
- // kind of cheating with this safe guard, but it does the job
298
- return isUndefined(message) && isStringValue(error);
299
- }
300
-
301
- function lengthEquals(value, arg1) {
302
- return value.length === Number(arg1);
303
- }
304
-
305
- function longerThan(value, arg1) {
306
- return value.length > Number(arg1);
307
- }
181
+ var assign = Object.assign;
308
182
 
309
- /**
310
- * Creates a cache function
311
- */
312
- function createCache(maxSize) {
313
- if (maxSize === void 0) { maxSize = 1; }
314
- var cacheStorage = [];
315
- var cache = function (deps, cacheAction) {
316
- var cacheHit = cache.get(deps);
317
- // cache hit is not null
318
- if (cacheHit)
319
- return cacheHit[1];
320
- var result = cacheAction();
321
- cacheStorage.unshift([deps.concat(), result]);
322
- if (longerThan(cacheStorage, maxSize))
323
- cacheStorage.length = maxSize;
324
- return result;
325
- };
326
- // invalidate an item in the cache by its dependencies
327
- cache.invalidate = function (deps) {
328
- var index = findIndex(deps);
329
- if (index > -1)
330
- cacheStorage.splice(index, 1);
331
- };
332
- // Retrieves an item from the cache.
333
- cache.get = function (deps) {
334
- return cacheStorage[findIndex(deps)] || null;
183
+ function createCursor() {
184
+ var storage = {
185
+ cursor: []
335
186
  };
336
- return cache;
337
- function findIndex(deps) {
338
- return cacheStorage.findIndex(function (_a) {
339
- var cachedDeps = _a[0];
340
- return lengthEquals(deps, cachedDeps.length) &&
341
- deps.every(function (dep, i) { return dep === cachedDeps[i]; });
342
- });
187
+ function addLevel() {
188
+ storage.cursor.push(0);
189
+ }
190
+ function removeLevel() {
191
+ storage.cursor.pop();
192
+ }
193
+ function cursorAt() {
194
+ return last(storage.cursor);
195
+ }
196
+ function getCursor() {
197
+ return asArray(storage.cursor);
198
+ }
199
+ function next() {
200
+ storage.cursor[storage.cursor.length - 1]++;
201
+ return last(storage.cursor);
202
+ }
203
+ function reset() {
204
+ storage.cursor = [0];
343
205
  }
206
+ reset();
207
+ return {
208
+ addLevel: addLevel,
209
+ cursorAt: cursorAt,
210
+ getCursor: getCursor,
211
+ next: next,
212
+ removeLevel: removeLevel,
213
+ reset: reset
214
+ };
344
215
  }
345
216
 
217
+ var IsolateTypes;
218
+ (function (IsolateTypes) {
219
+ IsolateTypes[IsolateTypes["DEFAULT"] = 0] = "DEFAULT";
220
+ IsolateTypes[IsolateTypes["SUITE"] = 1] = "SUITE";
221
+ IsolateTypes[IsolateTypes["EACH"] = 2] = "EACH";
222
+ IsolateTypes[IsolateTypes["SKIP_WHEN"] = 3] = "SKIP_WHEN";
223
+ IsolateTypes[IsolateTypes["OMIT_WHEN"] = 4] = "OMIT_WHEN";
224
+ IsolateTypes[IsolateTypes["GROUP"] = 5] = "GROUP";
225
+ })(IsolateTypes || (IsolateTypes = {}));
226
+
227
+ var Modes;
228
+ (function (Modes) {
229
+ Modes[Modes["ALL"] = 0] = "ALL";
230
+ Modes[Modes["EAGER"] = 1] = "EAGER";
231
+ })(Modes || (Modes = {}));
232
+
233
+ var context = context$1.createContext(function (ctxRef, parentContext) {
234
+ return parentContext
235
+ ? null
236
+ : assign({}, {
237
+ exclusion: {
238
+ tests: {},
239
+ groups: {}
240
+ },
241
+ inclusion: {},
242
+ isolate: {
243
+ type: IsolateTypes.DEFAULT,
244
+ keys: {
245
+ current: {},
246
+ prev: {}
247
+ }
248
+ },
249
+ mode: [Modes.ALL],
250
+ testCursor: createCursor()
251
+ }, ctxRef);
252
+ });
253
+
346
254
  // STATE REF
347
255
  function useStateRef() {
348
256
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -392,18 +300,6 @@ function useAllIncomplete() {
392
300
  return testObject.isPending() ? testObject : null;
393
301
  }));
394
302
  }
395
- function useOmittedFields() {
396
- var testObjects = useTestsFlat();
397
- return testObjects.reduce(function (omittedFields, testObject) {
398
- if (omittedFields[testObject.fieldName]) {
399
- return omittedFields;
400
- }
401
- if (testObject.isOmitted()) {
402
- omittedFields[testObject.fieldName] = true;
403
- }
404
- return omittedFields;
405
- }, {});
406
- }
407
303
  var flatCache = createCache();
408
304
  function useTestsFlat() {
409
305
  var current = useTestObjects()[0].current;
@@ -558,6 +454,113 @@ var STATUS_PENDING = 'PENDING';
558
454
  var STATUS_CANCELED = 'CANCELED';
559
455
  var STATUS_OMITTED = 'OMITTED';
560
456
 
457
+ function invariant(condition,
458
+ // eslint-disable-next-line @typescript-eslint/ban-types
459
+ message) {
460
+ if (condition) {
461
+ return;
462
+ }
463
+ // If message is a string object (rather than string literal)
464
+ // Throw the value directly as a string
465
+ // Alternatively, throw an error with the message
466
+ throw message instanceof String
467
+ ? message.valueOf()
468
+ : new Error(message ? optionalFunctionValue(message) : message);
469
+ }
470
+
471
+ // eslint-disable-next-line max-lines-per-function
472
+ function createState(onStateChange) {
473
+ var state = {
474
+ references: []
475
+ };
476
+ var registrations = [];
477
+ return {
478
+ registerStateKey: registerStateKey,
479
+ reset: reset
480
+ };
481
+ /**
482
+ * Registers a new key in the state, takes the initial value (may be a function that returns the initial value), returns a function.
483
+ *
484
+ * @example
485
+ *
486
+ * const useColor = state.registerStateKey("blue");
487
+ *
488
+ * let [color, setColor] = useColor(); // -> ["blue", Function]
489
+ *
490
+ * setColor("green");
491
+ *
492
+ * useColor()[0]; -> "green"
493
+ */
494
+ function registerStateKey(initialState, onUpdate) {
495
+ var key = registrations.length;
496
+ registrations.push([initialState, onUpdate]);
497
+ return initKey(key, initialState);
498
+ }
499
+ function reset() {
500
+ var prev = current();
501
+ state.references = [];
502
+ registrations.forEach(function (_a, index) {
503
+ var initialValue = _a[0];
504
+ return initKey(index, initialValue, prev[index]);
505
+ });
506
+ }
507
+ function initKey(key, initialState, prevState) {
508
+ current().push();
509
+ set(key, optionalFunctionValue(initialState, prevState));
510
+ return function useStateKey() {
511
+ return [
512
+ current()[key],
513
+ function (nextState) {
514
+ return set(key, optionalFunctionValue(nextState, current()[key]));
515
+ },
516
+ ];
517
+ };
518
+ }
519
+ function current() {
520
+ return state.references;
521
+ }
522
+ function set(index, value) {
523
+ var prevValue = state.references[index];
524
+ state.references[index] = value;
525
+ var _a = registrations[index], onUpdate = _a[1];
526
+ if (isFunction(onUpdate)) {
527
+ onUpdate(value, prevValue);
528
+ }
529
+ if (isFunction(onStateChange)) {
530
+ onStateChange();
531
+ }
532
+ }
533
+ }
534
+
535
+ function createStateRef(state, _a) {
536
+ var suiteId = _a.suiteId, suiteName = _a.suiteName;
537
+ return {
538
+ optionalFields: state.registerStateKey(function () { return ({}); }),
539
+ suiteId: state.registerStateKey(suiteId),
540
+ suiteName: state.registerStateKey(suiteName),
541
+ testCallbacks: state.registerStateKey(function () { return ({
542
+ fieldCallbacks: {},
543
+ doneCallbacks: []
544
+ }); }),
545
+ testObjects: state.registerStateKey(function (prev) {
546
+ return {
547
+ prev: prev ? prev.current : [],
548
+ current: []
549
+ };
550
+ })
551
+ };
552
+ }
553
+
554
+ function isNullish(value) {
555
+ return isNull(value) || isUndefined(value);
556
+ }
557
+
558
+ function deferThrow(message) {
559
+ setTimeout(function () {
560
+ throw new Error(message);
561
+ }, 0);
562
+ }
563
+
561
564
  function usePath() {
562
565
  var context$1 = context.useX();
563
566
  return context$1.testCursor.getCursor();
@@ -609,9 +612,7 @@ function useRetainTestKey(key, testObject) {
609
612
 
610
613
  function isolate(_a, callback) {
611
614
  var _b = _a.type, type = _b === void 0 ? IsolateTypes.DEFAULT : _b;
612
- if (!isFunction(callback)) {
613
- return;
614
- }
615
+ invariant(isFunction(callback));
615
616
  var keys = {
616
617
  current: {},
617
618
  prev: {}
@@ -641,7 +642,138 @@ var SeverityCount;
641
642
  SeverityCount["ERROR_COUNT"] = "errorCount";
642
643
  SeverityCount["WARN_COUNT"] = "warnCount";
643
644
  })(SeverityCount || (SeverityCount = {}));
645
+ function countKeyBySeverity(severity) {
646
+ return severity === Severity.ERRORS
647
+ ? SeverityCount.ERROR_COUNT
648
+ : SeverityCount.WARN_COUNT;
649
+ }
650
+
651
+ /**
652
+ * A safe hasOwnProperty access
653
+ */
654
+ function hasOwnProperty(obj, key) {
655
+ return Object.prototype.hasOwnProperty.call(obj, key);
656
+ }
657
+
658
+ function isNumber(value) {
659
+ return Boolean(typeof value === 'number');
660
+ }
661
+
662
+ function isEmpty(value) {
663
+ if (!value) {
664
+ return true;
665
+ }
666
+ else if (isNumber(value)) {
667
+ return value === 0;
668
+ }
669
+ else if (hasOwnProperty(value, 'length')) {
670
+ return lengthEquals(value, 0);
671
+ }
672
+ else if (typeof value === 'object') {
673
+ return lengthEquals(Object.keys(value), 0);
674
+ }
675
+ return false;
676
+ }
677
+ var isNotEmpty = bindNot(isEmpty);
678
+
679
+ function nonMatchingFieldName(testObject, fieldName) {
680
+ return !!fieldName && !matchingFieldName(testObject, fieldName);
681
+ }
682
+ function matchingFieldName(testObject, fieldName) {
683
+ return !!(fieldName && testObject.fieldName === fieldName);
684
+ }
685
+
686
+ function either(a, b) {
687
+ return !!a !== !!b;
688
+ }
689
+
690
+ /**
691
+ * Checks that a given test object matches the currently specified severity level
692
+ */
693
+ function nonMatchingSeverityProfile(severity, testObject) {
694
+ return either(severity === Severity.WARNINGS, testObject.warns());
695
+ }
696
+
697
+ /**
698
+ * The difference between this file and hasFailures is that hasFailures uses the static
699
+ * summary object, while this one uses the actual validation state
700
+ */
701
+ function hasErrorsByTestObjects(fieldName) {
702
+ return hasFailuresByTestObjects(Severity.ERRORS, fieldName);
703
+ }
704
+ function hasFailuresByTestObjects(severityKey, fieldName) {
705
+ var testObjects = useTestsFlat();
706
+ return testObjects.some(function (testObject) {
707
+ return hasFailuresByTestObject(testObject, severityKey, fieldName);
708
+ });
709
+ }
710
+ /**
711
+ * Determines whether a certain test profile has failures.
712
+ */
713
+ function hasFailuresByTestObject(testObject, severityKey, fieldName) {
714
+ if (!testObject.hasFailures()) {
715
+ return false;
716
+ }
717
+ if (nonMatchingFieldName(testObject, fieldName)) {
718
+ return false;
719
+ }
720
+ if (nonMatchingSeverityProfile(severityKey, testObject)) {
721
+ return false;
722
+ }
723
+ return true;
724
+ }
725
+
726
+ // eslint-disable-next-line max-statements, complexity
727
+ function shouldAddValidProp(fieldName) {
728
+ if (fieldIsOmitted(fieldName)) {
729
+ return true;
730
+ }
731
+ if (hasErrorsByTestObjects(fieldName)) {
732
+ return false;
733
+ }
734
+ var testObjects = useTestsFlat();
735
+ if (isEmpty(testObjects)) {
736
+ return false;
737
+ }
738
+ if (hasNonOptionalIncomplete(fieldName)) {
739
+ return false;
740
+ }
741
+ return noMissingTests(fieldName);
742
+ }
743
+ function fieldIsOmitted(fieldName) {
744
+ if (!fieldName) {
745
+ return false;
746
+ }
747
+ var flatTests = useTestsFlat();
748
+ return flatTests.some(function (testObject) { return testObject.fieldName === fieldName && testObject.isOmitted(); });
749
+ }
750
+ function hasNonOptionalIncomplete(fieldName) {
751
+ var optionalFields = useOptionalFields()[0];
752
+ return isNotEmpty(useAllIncomplete().filter(function (testObject) {
753
+ if (nonMatchingFieldName(testObject, fieldName)) {
754
+ return false;
755
+ }
756
+ return optionalFields[testObject.fieldName] !== true;
757
+ }));
758
+ }
759
+ function noMissingTests(fieldName) {
760
+ var testObjects = useTestsFlat();
761
+ var optionalFields = useOptionalFields()[0];
762
+ return testObjects.every(function (testObject) {
763
+ if (nonMatchingFieldName(testObject, fieldName)) {
764
+ return true;
765
+ }
766
+ return (optionalFields[testObject.fieldName] === true ||
767
+ testObject.isTested() ||
768
+ testObject.isOmitted());
769
+ });
770
+ }
644
771
 
772
+ function useSummary() {
773
+ var summary = context.useX().summary;
774
+ invariant(summary);
775
+ return summary;
776
+ }
645
777
  /**
646
778
  * Reads the testObjects list and gets full validation result from it.
647
779
  */
@@ -649,17 +781,24 @@ function genTestsSummary() {
649
781
  var testObjects = useTestsFlat();
650
782
  var summary = assign(baseStats(), {
651
783
  groups: {},
652
- tests: {}
784
+ tests: {},
785
+ valid: false
653
786
  });
654
787
  testObjects.reduce(function (summary, testObject) {
655
788
  appendToTest(summary.tests, testObject);
656
789
  appendToGroup(summary.groups, testObject);
657
790
  return summary;
658
791
  }, summary);
792
+ summary.valid = shouldAddValidProp();
659
793
  return countFailures(summary);
660
794
  }
661
795
  function appendToTest(tests, testObject) {
662
796
  tests[testObject.fieldName] = appendTestObject(tests, testObject);
797
+ // If `valid` is false to begin with, keep it that way. Otherwise, assess.
798
+ tests[testObject.fieldName].valid =
799
+ tests[testObject.fieldName].valid === false
800
+ ? false
801
+ : shouldAddValidProp(testObject.fieldName);
663
802
  }
664
803
  /**
665
804
  * Appends to a group object if within a group
@@ -683,13 +822,9 @@ function countFailures(summary) {
683
822
  }
684
823
  return summary;
685
824
  }
686
- /**
687
- * Appends the test to a results object
688
- */
689
- // eslint-disable-next-line max-statements
690
825
  function appendTestObject(summaryKey, testObject) {
691
826
  var fieldName = testObject.fieldName, message = testObject.message;
692
- summaryKey[fieldName] = summaryKey[fieldName] || baseStats();
827
+ summaryKey[fieldName] = summaryKey[fieldName] || baseTestStats();
693
828
  var testKey = summaryKey[fieldName];
694
829
  if (testObject.isNonActionable())
695
830
  return testKey;
@@ -702,18 +837,13 @@ function appendTestObject(summaryKey, testObject) {
702
837
  }
703
838
  return testKey;
704
839
  function incrementFailures(severity) {
705
- var countKey = getCountKey(severity);
840
+ var countKey = countKeyBySeverity(severity);
706
841
  testKey[countKey]++;
707
842
  if (message) {
708
843
  testKey[severity] = (testKey[severity] || []).concat(message);
709
844
  }
710
845
  }
711
846
  }
712
- function getCountKey(severity) {
713
- return severity === Severity.ERRORS
714
- ? SeverityCount.ERROR_COUNT
715
- : SeverityCount.WARN_COUNT;
716
- }
717
847
  function baseStats() {
718
848
  return {
719
849
  errorCount: 0,
@@ -721,97 +851,31 @@ function baseStats() {
721
851
  testCount: 0
722
852
  };
723
853
  }
724
-
725
- /*! *****************************************************************************
726
- Copyright (c) Microsoft Corporation.
727
-
728
- Permission to use, copy, modify, and/or distribute this software for any
729
- purpose with or without fee is hereby granted.
730
-
731
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
732
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
733
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
734
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
735
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
736
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
737
- PERFORMANCE OF THIS SOFTWARE.
738
- ***************************************************************************** */
739
-
740
- var __assign = function() {
741
- __assign = Object.assign || function __assign(t) {
742
- for (var s, i = 1, n = arguments.length; i < n; i++) {
743
- s = arguments[i];
744
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
745
- }
746
- return t;
747
- };
748
- return __assign.apply(this, arguments);
749
- };
750
-
751
- function __spreadArray(to, from, pack) {
752
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
753
- if (ar || !(i in from)) {
754
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
755
- ar[i] = from[i];
756
- }
757
- }
758
- return to.concat(ar || Array.prototype.slice.call(from));
759
- }
760
-
761
- function nonMatchingFieldName(testObject, fieldName) {
762
- return !!fieldName && !matchingFieldName(testObject, fieldName);
763
- }
764
- function matchingFieldName(testObject, fieldName) {
765
- return !!(fieldName && testObject.fieldName === fieldName);
766
- }
767
-
768
- function either(a, b) {
769
- return !!a !== !!b;
854
+ function baseTestStats() {
855
+ return assign(baseStats(), {
856
+ errors: [],
857
+ warnings: []
858
+ });
770
859
  }
771
860
 
772
- /**
773
- * Checks that a given test object matches the currently specified severity level
774
- */
775
- function nonMatchingSeverityProfile(severity, testObject) {
776
- return either(severity === Severity.WARNINGS, testObject.warns());
861
+ // calls collectAll or getByFieldName depending on whether fieldName is provided
862
+ function gatherFailures(testGroup, severityKey, fieldName) {
863
+ return fieldName
864
+ ? getByFieldName(testGroup, severityKey, fieldName)
865
+ : collectAll(testGroup, severityKey);
777
866
  }
778
-
779
- function collectFailureMessages(severity, testObjects, options) {
867
+ function getByFieldName(testGroup, severityKey, fieldName) {
780
868
  var _a;
781
- if (options === void 0) { options = {}; }
782
- var _b = options || {}, group = _b.group, fieldName = _b.fieldName;
783
- return testObjects.reduce(function (collector, testObject) {
784
- if (noMatch(testObject, severity, group, fieldName)) {
785
- return collector;
786
- }
787
- if (!testObject.hasFailures()) {
788
- return collector;
789
- }
790
- collector[testObject.fieldName] = (collector[testObject.fieldName] || []).concat(testObject.message || []);
791
- return collector;
792
- }, __assign({}, (fieldName && (_a = {}, _a[fieldName] = [], _a))));
793
- }
794
- function noGroupMatch(testObject, groupName) {
795
- return !!(groupName && testObject.groupName !== groupName);
796
- }
797
- function noMatch(testObject, severity, group, fieldName) {
798
- if (noGroupMatch(testObject, group)) {
799
- return true;
800
- }
801
- if (nonMatchingFieldName(testObject, fieldName)) {
802
- return true;
803
- }
804
- if (nonMatchingSeverityProfile(severity, testObject)) {
805
- return true;
806
- }
807
- return false;
869
+ return ((_a = testGroup === null || testGroup === void 0 ? void 0 : testGroup[fieldName]) === null || _a === void 0 ? void 0 : _a[severityKey]) || [];
808
870
  }
809
-
810
- function getFailuresArrayOrObject(group, fieldName) {
811
- if (fieldName) {
812
- return group[fieldName];
871
+ function collectAll(testGroup, severityKey) {
872
+ var output = {};
873
+ for (var field in testGroup) {
874
+ // We will probably never get to the fallback array
875
+ // leaving it just in case the implementation changes
876
+ output[field] = testGroup[field][severityKey] || [];
813
877
  }
814
- return group;
878
+ return output;
815
879
  }
816
880
 
817
881
  function getErrors(fieldName) {
@@ -824,178 +888,90 @@ function getWarnings(fieldName) {
824
888
  * @returns suite or field's errors or warnings.
825
889
  */
826
890
  function getFailures(severityKey, fieldName) {
827
- var testObjects = useTestsFlat();
828
- var failureMessages = collectFailureMessages(severityKey, testObjects, {
829
- fieldName: fieldName
830
- });
831
- return getFailuresArrayOrObject(failureMessages, fieldName);
891
+ var summary = useSummary();
892
+ return gatherFailures(summary.tests, severityKey, fieldName);
832
893
  }
833
894
 
834
895
  function getErrorsByGroup(groupName, fieldName) {
835
- var errors = getByGroup(Severity.ERRORS, groupName, fieldName);
836
- return getFailuresArrayOrObject(errors, fieldName);
896
+ return getFailuresByGroup(groupName, Severity.ERRORS, fieldName);
837
897
  }
838
898
  function getWarningsByGroup(groupName, fieldName) {
839
- var warnings = getByGroup(Severity.WARNINGS, groupName, fieldName);
840
- return getFailuresArrayOrObject(warnings, fieldName);
899
+ return getFailuresByGroup(groupName, Severity.WARNINGS, fieldName);
841
900
  }
842
- /**
843
- * Gets failure messages by group.
844
- */
845
- function getByGroup(severityKey, group, fieldName) {
846
- invariant(group, "get".concat(severityKey[0].toUpperCase()).concat(severityKey.slice(1), "ByGroup requires a group name. Received `").concat(group, "` instead."));
847
- var testObjects = useTestsFlat();
848
- return collectFailureMessages(severityKey, testObjects, {
849
- group: group,
850
- fieldName: fieldName
851
- });
901
+ function getFailuresByGroup(groupName, severityKey, fieldName) {
902
+ var summary = useSummary();
903
+ return gatherFailures(summary.groups[groupName], severityKey, fieldName);
852
904
  }
853
905
 
854
- /**
855
- * Determines whether a certain test profile has failures.
856
- */
857
- function hasFailuresLogic(testObject, severityKey, fieldName) {
858
- if (!testObject.hasFailures()) {
859
- return false;
860
- }
861
- if (nonMatchingFieldName(testObject, fieldName)) {
862
- return false;
863
- }
864
- if (nonMatchingSeverityProfile(severityKey, testObject)) {
865
- return false;
866
- }
867
- return true;
906
+ function isPositive(value) {
907
+ return greaterThan(value, 0);
868
908
  }
869
909
 
870
910
  function hasErrors(fieldName) {
871
- return has(Severity.ERRORS, fieldName);
911
+ return hasFailures(SeverityCount.ERROR_COUNT, fieldName);
872
912
  }
873
913
  function hasWarnings(fieldName) {
874
- return has(Severity.WARNINGS, fieldName);
914
+ return hasFailures(SeverityCount.WARN_COUNT, fieldName);
875
915
  }
876
- function has(severityKey, fieldName) {
877
- var testObjects = useTestsFlat();
878
- return testObjects.some(function (testObject) {
879
- return hasFailuresLogic(testObject, severityKey, fieldName);
880
- });
916
+ function hasFailures(severityCount, fieldName) {
917
+ var _a;
918
+ var summary = useSummary();
919
+ if (fieldName) {
920
+ return isPositive((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
921
+ }
922
+ return isPositive(summary[severityCount]);
881
923
  }
882
924
 
883
925
  function hasErrorsByGroup(groupName, fieldName) {
884
- return hasByGroup(Severity.ERRORS, groupName, fieldName);
926
+ return hasFailuresByGroup(Severity.ERRORS, groupName, fieldName);
885
927
  }
886
928
  function hasWarningsByGroup(groupName, fieldName) {
887
- return hasByGroup(Severity.WARNINGS, groupName, fieldName);
888
- }
889
- /**
890
- * Checks whether there are failures in a given group.
891
- */
892
- function hasByGroup(severityKey, group, fieldName) {
893
- var testObjects = useTestsFlat();
894
- return testObjects.some(function (testObject) {
895
- return group === testObject.groupName
896
- ? hasFailuresLogic(testObject, severityKey, fieldName)
897
- : false;
898
- });
899
- }
900
-
901
- /**
902
- * A safe hasOwnProperty access
903
- */
904
- function hasOwnProperty(obj, key) {
905
- return Object.prototype.hasOwnProperty.call(obj, key);
929
+ return hasFailuresByGroup(Severity.WARNINGS, groupName, fieldName);
906
930
  }
907
-
908
- function isNumber(value) {
909
- return Boolean(typeof value === 'number');
910
- }
911
-
912
- function isEmpty(value) {
913
- if (!value) {
914
- return true;
915
- }
916
- else if (isNumber(value)) {
917
- return value === 0;
931
+ // eslint-disable-next-line max-statements
932
+ function hasFailuresByGroup(severityKey, groupName, fieldName) {
933
+ var _a, _b;
934
+ var summary = useSummary();
935
+ var severityCount = countKeyBySeverity(severityKey);
936
+ var group = summary.groups[groupName];
937
+ if (!group) {
938
+ return false;
918
939
  }
919
- else if (hasOwnProperty(value, 'length')) {
920
- return lengthEquals(value, 0);
940
+ if (fieldName) {
941
+ return isPositive((_a = group[fieldName]) === null || _a === void 0 ? void 0 : _a[severityCount]);
921
942
  }
922
- else if (typeof value === 'object') {
923
- return lengthEquals(Object.keys(value), 0);
943
+ for (var field in group) {
944
+ if (isPositive((_b = group[field]) === null || _b === void 0 ? void 0 : _b[severityCount])) {
945
+ return true;
946
+ }
924
947
  }
925
- return true;
948
+ return false;
926
949
  }
927
- var isNotEmpty = bindNot(isEmpty);
928
950
 
929
- // eslint-disable-next-line max-statements, complexity
930
951
  function isValid(fieldName) {
931
- if (fieldIsOmitted(fieldName)) {
932
- return true;
933
- }
934
- if (hasErrors(fieldName)) {
935
- return false;
936
- }
937
- var testObjects = useTestsFlat();
938
- if (isEmpty(testObjects)) {
939
- return false;
940
- }
941
- if (fieldDoesNotExist(fieldName)) {
942
- return false;
943
- }
944
- if (hasNonOptionalIncomplete(fieldName)) {
945
- return false;
946
- }
947
- return noMissingTests(fieldName);
948
- }
949
- function fieldIsOmitted(fieldName) {
950
- var omittedFields = useOmittedFields();
951
- if (!fieldName) {
952
- return false;
953
- }
954
- return !!omittedFields[fieldName];
955
- }
956
- function hasNonOptionalIncomplete(fieldName) {
957
- var optionalFields = useOptionalFields()[0];
958
- return isNotEmpty(useAllIncomplete().filter(function (testObject) {
959
- if (nonMatchingFieldName(testObject, fieldName)) {
960
- return false;
961
- }
962
- return optionalFields[testObject.fieldName] !== true;
963
- }));
964
- }
965
- function fieldDoesNotExist(fieldName) {
966
- var testObjects = useTestsFlat();
967
- return (!!fieldName &&
968
- !testObjects.find(function (testObject) { return testObject.fieldName === fieldName; }));
969
- }
970
- function noMissingTests(fieldName) {
971
- var testObjects = useTestsFlat();
972
- var optionalFields = useOptionalFields()[0];
973
- return testObjects.every(function (testObject) {
974
- if (nonMatchingFieldName(testObject, fieldName)) {
975
- return true;
976
- }
977
- return (optionalFields[testObject.fieldName] === true ||
978
- testObject.isTested() ||
979
- testObject.isOmitted());
980
- });
952
+ var _a;
953
+ var summary = useSummary();
954
+ return fieldName ? Boolean((_a = summary.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.valid) : summary.valid;
981
955
  }
982
956
 
983
- var cache$1 = createCache(20);
957
+ var cache$1 = createCache(1);
984
958
  function produceSuiteResult() {
985
959
  var testObjects = useTestsFlat();
986
960
  var ctxRef = { stateRef: useStateRef() };
987
961
  return cache$1([testObjects], context.bind(ctxRef, function () {
962
+ var summary = genTestsSummary();
988
963
  var suiteName = useSuiteName();
989
- return assign(genTestsSummary(), {
990
- getErrors: context.bind(ctxRef, getErrors),
991
- getErrorsByGroup: context.bind(ctxRef, getErrorsByGroup),
992
- getWarnings: context.bind(ctxRef, getWarnings),
993
- getWarningsByGroup: context.bind(ctxRef, getWarningsByGroup),
994
- hasErrors: context.bind(ctxRef, hasErrors),
995
- hasErrorsByGroup: context.bind(ctxRef, hasErrorsByGroup),
996
- hasWarnings: context.bind(ctxRef, hasWarnings),
997
- hasWarningsByGroup: context.bind(ctxRef, hasWarningsByGroup),
998
- isValid: context.bind(ctxRef, isValid),
964
+ var ref = { summary: summary };
965
+ return assign(summary, {
966
+ getErrors: context.bind(ref, getErrors),
967
+ getErrorsByGroup: context.bind(ref, getErrorsByGroup),
968
+ getWarnings: context.bind(ref, getWarnings),
969
+ getWarningsByGroup: context.bind(ref, getWarningsByGroup),
970
+ hasErrors: context.bind(ref, hasErrors),
971
+ hasErrorsByGroup: context.bind(ref, hasErrorsByGroup),
972
+ hasWarnings: context.bind(ref, hasWarnings),
973
+ hasWarningsByGroup: context.bind(ref, hasWarningsByGroup),
974
+ isValid: context.bind(ref, isValid),
999
975
  suiteName: suiteName
1000
976
  });
1001
977
  }));
@@ -1064,14 +1040,13 @@ var done = function done() {
1064
1040
  return output;
1065
1041
  };
1066
1042
  function deferDoneCallback(doneCallback, fieldName) {
1067
- var deferredCallback = context.bind({}, doneCallback);
1068
1043
  var _a = useTestCallbacks(), setTestCallbacks = _a[1];
1069
1044
  setTestCallbacks(function (current) {
1070
1045
  if (fieldName) {
1071
- current.fieldCallbacks[fieldName] = (current.fieldCallbacks[fieldName] || []).concat(deferredCallback);
1046
+ current.fieldCallbacks[fieldName] = (current.fieldCallbacks[fieldName] || []).concat(doneCallback);
1072
1047
  }
1073
1048
  else {
1074
- current.doneCallbacks.push(deferredCallback);
1049
+ current.doneCallbacks.push(doneCallback);
1075
1050
  }
1076
1051
  return current;
1077
1052
  });
@@ -1081,19 +1056,22 @@ function createBus() {
1081
1056
  var listeners = {};
1082
1057
  return {
1083
1058
  emit: function (event, data) {
1084
- (listeners[event] || []).forEach(function (handler) {
1059
+ listener(event).forEach(function (handler) {
1085
1060
  handler(data);
1086
1061
  });
1087
1062
  },
1088
1063
  on: function (event, handler) {
1089
- listeners[event] = (listeners[event] || []).concat(handler);
1064
+ listeners[event] = listener(event).concat(handler);
1090
1065
  return {
1091
1066
  off: function () {
1092
- listeners[event] = listeners[event].filter(function (h) { return h !== handler; });
1067
+ listeners[event] = listener(event).filter(function (h) { return h !== handler; });
1093
1068
  }
1094
1069
  };
1095
1070
  }
1096
1071
  };
1072
+ function listener(event) {
1073
+ return listeners[event] || [];
1074
+ }
1097
1075
  }
1098
1076
 
1099
1077
  function omitOptionalTests() {
@@ -1105,24 +1083,27 @@ function omitOptionalTests() {
1105
1083
  useSetTests(function (tests) {
1106
1084
  return transform(tests, function (testObject) {
1107
1085
  var fieldName = testObject.fieldName;
1108
- if (shouldOmit.hasOwnProperty(fieldName)) {
1109
- omit(testObject);
1086
+ if (hasOwnProperty(shouldOmit, fieldName)) {
1087
+ verifyAndOmit(testObject);
1110
1088
  }
1111
1089
  else {
1112
- var optionalConfig = optionalFields[fieldName];
1113
- if (isFunction(optionalConfig)) {
1114
- shouldOmit[fieldName] = optionalConfig();
1115
- omit(testObject);
1116
- }
1090
+ runOptionalConfig(testObject);
1117
1091
  }
1118
1092
  return testObject;
1119
1093
  });
1120
1094
  });
1121
- function omit(testObject) {
1095
+ function verifyAndOmit(testObject) {
1122
1096
  if (shouldOmit[testObject.fieldName]) {
1123
1097
  testObject.omit();
1124
1098
  }
1125
1099
  }
1100
+ function runOptionalConfig(testObject) {
1101
+ var optionalConfig = optionalFields[testObject.fieldName];
1102
+ if (isFunction(optionalConfig)) {
1103
+ shouldOmit[testObject.fieldName] = optionalConfig();
1104
+ verifyAndOmit(testObject);
1105
+ }
1106
+ }
1126
1107
  }
1127
1108
 
1128
1109
  /**
@@ -1373,7 +1354,7 @@ function isExcluded(testObject) {
1373
1354
  return keyTests[fieldName] === false;
1374
1355
  }
1375
1356
  }
1376
- if (isMissingFromIncludedGroup(groupName)) {
1357
+ if (isTopLevelWhenThereIsAnIncludedGroup(groupName)) {
1377
1358
  return true;
1378
1359
  }
1379
1360
  // if field is only'ed
@@ -1382,39 +1363,13 @@ function isExcluded(testObject) {
1382
1363
  // If there is _ANY_ `only`ed test (and we already know this one isn't) return true
1383
1364
  if (hasIncludedTests(keyTests)) {
1384
1365
  // Check if inclusion rules for this field (`include` hook)
1366
+ // TODO: Check if this may need to be moved outside of the condition.
1367
+ // What if there are no included tests? This shouldn't run then?
1385
1368
  return !optionalFunctionValue(inclusion[fieldName]);
1386
1369
  }
1387
1370
  // We're done here. This field is not excluded
1388
1371
  return false;
1389
1372
  }
1390
- // eslint-disable-next-line max-statements
1391
- function isMissingFromIncludedGroup(groupName) {
1392
- var context$1 = context.useX();
1393
- var exclusion = context$1.exclusion;
1394
- if (!hasIncludedGroups()) {
1395
- return false;
1396
- }
1397
- if (!groupName) {
1398
- return true;
1399
- }
1400
- if (groupName in exclusion.groups) {
1401
- if (exclusion.groups[groupName]) {
1402
- return false;
1403
- }
1404
- return true;
1405
- }
1406
- return true;
1407
- }
1408
- function hasIncludedGroups() {
1409
- var context$1 = context.useX();
1410
- var exclusion = context$1.exclusion;
1411
- for (var group in exclusion.groups) {
1412
- if (exclusion.groups[group]) {
1413
- return true;
1414
- }
1415
- }
1416
- return false;
1417
- }
1418
1373
  /**
1419
1374
  * Checks whether a given group is excluded from running.
1420
1375
  */
@@ -1429,13 +1384,8 @@ function isGroupExcluded(groupName) {
1429
1384
  return keyGroups[groupName] === false;
1430
1385
  }
1431
1386
  // Group is not present
1432
- for (var group in keyGroups) {
1433
- // If any other group is only'ed
1434
- if (keyGroups[group] === true) {
1435
- return true;
1436
- }
1437
- }
1438
- return false;
1387
+ // Return whether other groups are included
1388
+ return hasIncludedGroups();
1439
1389
  }
1440
1390
  /**
1441
1391
  * Adds fields to a specified exclusion group.
@@ -1464,6 +1414,24 @@ function hasIncludedTests(keyTests) {
1464
1414
  }
1465
1415
  return false;
1466
1416
  }
1417
+ // are we not in a group and there is an included group?
1418
+ function isTopLevelWhenThereIsAnIncludedGroup(groupName) {
1419
+ if (!hasIncludedGroups()) {
1420
+ return false;
1421
+ }
1422
+ // Return whether there's an included group, and we're not inside a group
1423
+ return !groupName;
1424
+ }
1425
+ function hasIncludedGroups() {
1426
+ var context$1 = context.useX();
1427
+ var exclusion = context$1.exclusion;
1428
+ for (var group in exclusion.groups) {
1429
+ if (exclusion.groups[group]) {
1430
+ return true;
1431
+ }
1432
+ }
1433
+ return false;
1434
+ }
1467
1435
 
1468
1436
  /**
1469
1437
  * Runs tests within a group so that they can be controlled or queried separately.
@@ -1489,16 +1457,18 @@ function groupErrorMsg(error) {
1489
1457
  function include(fieldName) {
1490
1458
  var context$1 = context.useX();
1491
1459
  var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
1492
- if (!fieldName) {
1493
- return { when: when };
1494
- }
1460
+ invariant(isStringValue(fieldName));
1495
1461
  inclusion[fieldName] = defaultTo(exclusion.tests[fieldName], true);
1496
1462
  return { when: when };
1497
1463
  function when(condition) {
1498
1464
  var context$1 = context.useX();
1499
1465
  var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
1466
+ // This callback will run as part of the "isExcluded" series of checks
1500
1467
  inclusion[fieldName] = function () {
1501
1468
  if (hasOwnProperty(exclusion.tests, fieldName)) {
1469
+ // I suspect this code is technically unreachable because
1470
+ // if there are any skip/only rules applied to the current
1471
+ // field, the "isExcluded" function will have already bailed
1502
1472
  return defaultTo(exclusion.tests[fieldName], true);
1503
1473
  }
1504
1474
  if (isStringValue(condition)) {
@@ -1532,7 +1502,7 @@ function eager() {
1532
1502
  setMode(Modes.EAGER);
1533
1503
  }
1534
1504
  function shouldSkipBasedOnMode(testObject) {
1535
- if (isEager() && hasErrors(testObject.fieldName))
1505
+ if (isEager() && hasErrorsByTestObjects(testObject.fieldName))
1536
1506
  return true;
1537
1507
  return false;
1538
1508
  }
@@ -1599,6 +1569,31 @@ function optional(optionals) {
1599
1569
  });
1600
1570
  }
1601
1571
 
1572
+ /*! *****************************************************************************
1573
+ Copyright (c) Microsoft Corporation.
1574
+
1575
+ Permission to use, copy, modify, and/or distribute this software for any
1576
+ purpose with or without fee is hereby granted.
1577
+
1578
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1579
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1580
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1581
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1582
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1583
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1584
+ PERFORMANCE OF THIS SOFTWARE.
1585
+ ***************************************************************************** */
1586
+
1587
+ function __spreadArray(to, from, pack) {
1588
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
1589
+ if (ar || !(i in from)) {
1590
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
1591
+ ar[i] = from[i];
1592
+ }
1593
+ }
1594
+ return to.concat(ar || Array.prototype.slice.call(from));
1595
+ }
1596
+
1602
1597
  function isPromise(value) {
1603
1598
  return value && isFunction(value.then);
1604
1599
  }
@@ -1644,6 +1639,8 @@ function runAsyncTest(testObject) {
1644
1639
  asyncTest.then(done, fail);
1645
1640
  }
1646
1641
  catch (e) {
1642
+ // We will probably never get here, unless the consumer uses a buggy custom Promise
1643
+ // implementation that behaves differently than the native one, or if they for some
1647
1644
  fail();
1648
1645
  }
1649
1646
  }
@@ -1652,22 +1649,7 @@ function runAsyncTest(testObject) {
1652
1649
  * Runs sync tests - or extracts promise.
1653
1650
  */
1654
1651
  function runSyncTest(testObject) {
1655
- return context.run({ currentTest: testObject }, function () {
1656
- var result;
1657
- try {
1658
- result = testObject.testFn();
1659
- }
1660
- catch (e) {
1661
- if (shouldUseErrorAsMessage(testObject.message, e)) {
1662
- testObject.message = e;
1663
- }
1664
- result = false;
1665
- }
1666
- if (result === false) {
1667
- testObject.fail();
1668
- }
1669
- return result;
1670
- });
1652
+ return context.run({ currentTest: testObject }, function () { return testObject.run(); });
1671
1653
  }
1672
1654
 
1673
1655
  /**
@@ -1817,7 +1799,7 @@ function registerTestObjectByTier(testObject) {
1817
1799
  /* eslint-disable jest/valid-title */
1818
1800
  // eslint-disable-next-line max-lines-per-function
1819
1801
  function bindTestMemo(test) {
1820
- var cache = createCache(100); // arbitrary cache size
1802
+ var cache = createCache(10); // arbitrary cache size
1821
1803
  // eslint-disable-next-line max-statements
1822
1804
  function memo(fieldName) {
1823
1805
  var args = [];
@@ -1886,7 +1868,7 @@ function warn() {
1886
1868
  ctx.currentTest.warn();
1887
1869
  }
1888
1870
 
1889
- var VERSION = "4.2.3-dev-87ebfa";
1871
+ var VERSION = "4.3.2-dev-2805e3";
1890
1872
 
1891
1873
  Object.defineProperty(exports, 'enforce', {
1892
1874
  enumerable: true,