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