vest 4.4.1 → 4.4.2-dev-ae93bf

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