vest 4.5.0 → 5.0.0-dev-781e21

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 (34) hide show
  1. package/dist/cjs/enforce/compose.development.js +1 -1
  2. package/dist/cjs/enforce/compose.production.js +1 -1
  3. package/dist/cjs/enforce/compounds.development.js +1 -1
  4. package/dist/cjs/enforce/compounds.production.js +1 -1
  5. package/dist/cjs/enforce/schema.development.js +1 -1
  6. package/dist/cjs/enforce/schema.production.js +1 -1
  7. package/dist/cjs/vest.development.js +146 -95
  8. package/dist/cjs/vest.production.js +1 -1
  9. package/dist/es/enforce/compose.development.js +1 -1
  10. package/dist/es/enforce/compose.production.js +1 -1
  11. package/dist/es/enforce/compounds.development.js +1 -1
  12. package/dist/es/enforce/compounds.production.js +1 -1
  13. package/dist/es/enforce/schema.development.js +1 -1
  14. package/dist/es/enforce/schema.production.js +1 -1
  15. package/dist/es/vest.development.js +148 -97
  16. package/dist/es/vest.production.js +1 -1
  17. package/dist/umd/classnames.development.js +11 -59
  18. package/dist/umd/classnames.production.js +1 -1
  19. package/dist/umd/enforce/compose.development.js +9 -682
  20. package/dist/umd/enforce/compose.production.js +1 -1
  21. package/dist/umd/enforce/compounds.development.js +17 -684
  22. package/dist/umd/enforce/compounds.production.js +1 -1
  23. package/dist/umd/enforce/schema.development.js +12 -685
  24. package/dist/umd/enforce/schema.production.js +1 -1
  25. package/dist/umd/parser.development.js +10 -58
  26. package/dist/umd/parser.production.js +1 -1
  27. package/dist/umd/promisify.development.js +5 -31
  28. package/dist/umd/promisify.production.js +1 -1
  29. package/dist/umd/vest.development.js +255 -997
  30. package/dist/umd/vest.production.js +1 -1
  31. package/package.json +3 -3
  32. package/types/enforce/compounds.d.ts +6 -8
  33. package/types/enforce/schema.d.ts +5 -4
  34. package/types/vest.d.ts +36 -28
@@ -1,6 +1,6 @@
1
1
  export { enforce } from 'n4s';
2
- import { isUndefined, isStringValue, assign, cache as cache$2, optionalFunctionValue, nestedArray, asArray, seq, isFunction, isNullish, deferThrow, invariant, bindNot, either, isEmpty, isNotEmpty, isPositive, numberEquals, hasOwnProperty, isArray, callEach, bus, defaultTo, isPromise, isNull } from 'vest-utils';
3
- import { createContext } from 'context';
2
+ import { isUndefined, isStringValue, assign, cache as cache$2, nestedArray, asArray, seq, optionalFunctionValue, isFunction, isNullish, deferThrow, invariant, bindNot, either, isArray, isEmpty, isNotEmpty, isPositive, numberEquals, hasOwnProperty, callEach, bus, defaultTo, isPromise, isNull } from 'vest-utils';
3
+ import { createCascade } from 'context';
4
4
 
5
5
  function shouldUseErrorAsMessage(message, error) {
6
6
  // kind of cheating with this safe guard, but it does the job
@@ -58,7 +58,7 @@ function generateIsolate(type, path) {
58
58
  };
59
59
  }
60
60
 
61
- var context = createContext(function (ctxRef, parentContext) {
61
+ var context = createCascade(function (ctxRef, parentContext) {
62
62
  return parentContext
63
63
  ? null
64
64
  : assign({
@@ -88,29 +88,22 @@ function useTestCallbacks() {
88
88
  return useStateRef().testCallbacks();
89
89
  }
90
90
  // OPTIONAL FIELDS
91
- function useOptionalField(fieldName) {
92
- var optionalFields = useOptionalFields()[0];
93
- return optionalFields[fieldName];
94
- }
95
91
  function useOptionalFields() {
96
92
  return useStateRef().optionalFields();
97
93
  }
98
94
  function useSetOptionalField(fieldName, setter) {
99
95
  var _a = useOptionalFields(), setOptionalFields = _a[1];
100
- setOptionalFields(function (optionalFields) {
96
+ setOptionalFields(function (prev) {
101
97
  var _a;
102
- return assign(optionalFields, (_a = {},
103
- _a[fieldName] = optionalFunctionValue(setter, optionalFields[fieldName]),
98
+ return assign(prev, (_a = {},
99
+ _a[fieldName] = assign({}, prev[fieldName], setter(prev[fieldName])),
104
100
  _a));
105
101
  });
106
102
  }
107
- function useOptionalFieldApplied(fieldName) {
108
- var _a;
109
- return (_a = useOptionalField(fieldName)) === null || _a === void 0 ? void 0 : _a[1];
110
- }
111
- function useOptionalFieldConfig(fieldName) {
103
+ function useOptionalField(fieldName) {
112
104
  var _a;
113
- return (_a = useOptionalField(fieldName)) === null || _a === void 0 ? void 0 : _a[0];
105
+ var optionalFields = useOptionalFields()[0];
106
+ return (_a = optionalFields[fieldName]) !== null && _a !== void 0 ? _a : {};
114
107
  }
115
108
  function useTestObjects() {
116
109
  return useStateRef().testObjects();
@@ -240,18 +233,9 @@ var VestTest = /** @class */ (function () {
240
233
  VestTest.prototype.valueOf = function () {
241
234
  return !this.isFailing();
242
235
  };
243
- VestTest.prototype.hasFailures = function () {
244
- return this.isFailing() || this.isWarning();
245
- };
246
- VestTest.prototype.isNonActionable = function () {
247
- return this.isSkipped() || this.isOmitted() || this.isCanceled();
248
- };
249
236
  VestTest.prototype.isPending = function () {
250
237
  return this.statusEquals(STATUS_PENDING);
251
238
  };
252
- VestTest.prototype.isTested = function () {
253
- return this.hasFailures() || this.isPassing();
254
- };
255
239
  VestTest.prototype.isOmitted = function () {
256
240
  return this.statusEquals(STATUS_OMITTED);
257
241
  };
@@ -273,6 +257,20 @@ var VestTest = /** @class */ (function () {
273
257
  VestTest.prototype.isWarning = function () {
274
258
  return this.statusEquals(STATUS_WARNING);
275
259
  };
260
+ VestTest.prototype.hasFailures = function () {
261
+ return this.isFailing() || this.isWarning();
262
+ };
263
+ VestTest.prototype.isNonActionable = function () {
264
+ return this.isSkipped() || this.isOmitted() || this.isCanceled();
265
+ };
266
+ VestTest.prototype.isTested = function () {
267
+ return this.hasFailures() || this.isPassing();
268
+ };
269
+ VestTest.prototype.awaitsResolution = function () {
270
+ // Is the test in a state where it can still be run, or complete running
271
+ // and its final status is indeterminate?
272
+ return this.isSkipped() || this.isUntested() || this.isPending();
273
+ };
276
274
  VestTest.prototype.statusEquals = function (status) {
277
275
  return this.status === status;
278
276
  };
@@ -512,26 +510,85 @@ function hasFailuresByTestObject(testObject, severityKey, fieldName) {
512
510
  return true;
513
511
  }
514
512
 
513
+ /**
514
+ * Marks a field as optional, either just by name, or by a given condition.
515
+ *
516
+ * @example
517
+ *
518
+ * optional('field_name');
519
+ *
520
+ * optional({
521
+ * username: () => allowUsernameEmpty,
522
+ * });
523
+ */
524
+ function optional(optionals) {
525
+ // There are two types of optional field declarations:
526
+ // 1. Delayed: A string, which is the name of the field to be optional.
527
+ // We will only determine whether to omit the test after the suite is done running
528
+ //
529
+ // 2. Immediate: Either a boolean or a function, which is used to determine
530
+ // if the field should be optional.
531
+ // Delayed case (field name)
532
+ if (isArray(optionals) || isStringValue(optionals)) {
533
+ asArray(optionals).forEach(function (optionalField) {
534
+ useSetOptionalField(optionalField, function () { return ({
535
+ type: OptionalFieldTypes.Delayed,
536
+ applied: false,
537
+ rule: null
538
+ }); });
539
+ });
540
+ }
541
+ else {
542
+ var _loop_1 = function (field) {
543
+ var value = optionals[field];
544
+ useSetOptionalField(field, function () { return ({
545
+ type: OptionalFieldTypes.Immediate,
546
+ rule: value,
547
+ applied: optionalFunctionValue(value)
548
+ }); });
549
+ };
550
+ // Immediately case (function or boolean)
551
+ for (var field in optionals) {
552
+ _loop_1(field);
553
+ }
554
+ }
555
+ }
556
+ function optionalFiedIsApplied(fieldName) {
557
+ if (!fieldName) {
558
+ return false;
559
+ }
560
+ return useOptionalField(fieldName).applied;
561
+ }
562
+ var OptionalFieldTypes;
563
+ (function (OptionalFieldTypes) {
564
+ OptionalFieldTypes[OptionalFieldTypes["Immediate"] = 0] = "Immediate";
565
+ OptionalFieldTypes[OptionalFieldTypes["Delayed"] = 1] = "Delayed";
566
+ })(OptionalFieldTypes || (OptionalFieldTypes = {}));
567
+
515
568
  // eslint-disable-next-line max-statements, complexity
516
569
  function shouldAddValidProperty(fieldName) {
517
- if (fieldIsOmitted(fieldName)) {
570
+ // Is the field optional, and the optional condition is applied
571
+ if (optionalFiedIsApplied(fieldName)) {
518
572
  return true;
519
573
  }
520
- if (hasErrorsByTestObjects(fieldName)) {
521
- return false;
522
- }
523
574
  var testObjects = useTestsFlat();
575
+ // Are there no tests?
524
576
  if (isEmpty(testObjects)) {
525
577
  return false;
526
578
  }
579
+ // Does the field have any tests with errors?
580
+ if (hasErrorsByTestObjects(fieldName)) {
581
+ return false;
582
+ }
527
583
  // Does the given field have any pending tests that are not optional?
528
584
  if (hasNonOptionalIncomplete(fieldName)) {
529
585
  return false;
530
586
  }
587
+ // Does the field have no missing tests?
531
588
  return noMissingTests(fieldName);
532
589
  }
533
590
  function shouldAddValidPropertyInGroup(groupName, fieldName) {
534
- if (fieldIsOmitted(fieldName)) {
591
+ if (optionalFiedIsApplied(fieldName)) {
535
592
  return true;
536
593
  }
537
594
  if (hasGroupFailuresByTestObjects(Severity.ERRORS, groupName, fieldName)) {
@@ -543,16 +600,10 @@ function shouldAddValidPropertyInGroup(groupName, fieldName) {
543
600
  }
544
601
  return noMissingTestsByGroup(groupName, fieldName);
545
602
  }
546
- function fieldIsOmitted(fieldName) {
547
- if (!fieldName) {
548
- return false;
549
- }
550
- return useOptionalFieldApplied(fieldName) === true;
551
- }
552
603
  // Does the given field have any pending tests that are not optional?
553
604
  function hasNonOptionalIncomplete(fieldName) {
554
605
  return isNotEmpty(useAllIncomplete().filter(function (testObject) {
555
- return isOptionalFieldIncomplete(testObject, fieldName);
606
+ return isTestObjectOptional(testObject, fieldName);
556
607
  }));
557
608
  }
558
609
  // Do the given group/field have any pending tests that are not optional?
@@ -561,41 +612,57 @@ function hasNonOptionalIncompleteByGroup(groupName, fieldName) {
561
612
  if (nonMatchingGroupName(testObject, groupName)) {
562
613
  return false;
563
614
  }
564
- return isOptionalFieldIncomplete(testObject, fieldName);
615
+ return isTestObjectOptional(testObject, fieldName);
565
616
  }));
566
617
  }
567
- function isOptionalFieldIncomplete(testObject, fieldName) {
618
+ function isTestObjectOptional(testObject, fieldName) {
568
619
  if (nonMatchingFieldName(testObject, fieldName)) {
569
620
  return false;
570
621
  }
571
- return useOptionalFieldConfig(testObject.fieldName) !== true;
622
+ return optionalFiedIsApplied(fieldName);
572
623
  }
624
+ // Did all of the tests for the provided field run/omit?
625
+ // This makes sure that the fields are not skipped or pending.
573
626
  function noMissingTests(fieldName) {
574
627
  var testObjects = useTestsFlat();
575
628
  return testObjects.every(function (testObject) {
576
- if (nonMatchingFieldName(testObject, fieldName)) {
577
- return true;
578
- }
579
- return missingTestsLogic(testObject, fieldName);
629
+ return noMissingTestsLogic(testObject, fieldName);
580
630
  });
581
631
  }
632
+ // Does the group have no missing tests?
582
633
  function noMissingTestsByGroup(groupName, fieldName) {
583
634
  var testObjects = useTestsFlat();
584
635
  return testObjects.every(function (testObject) {
585
636
  if (nonMatchingGroupName(testObject, groupName)) {
586
637
  return true;
587
638
  }
588
- return missingTestsLogic(testObject, fieldName);
639
+ return noMissingTestsLogic(testObject, fieldName);
589
640
  });
590
641
  }
591
- function missingTestsLogic(testObject, fieldName) {
642
+ // Does the object qualify as either tested or omitted (but not skipped!)
643
+ function noMissingTestsLogic(testObject, fieldName) {
592
644
  if (nonMatchingFieldName(testObject, fieldName)) {
593
645
  return true;
594
646
  }
595
- return (useOptionalFieldConfig(testObject.fieldName) === true ||
647
+ /**
648
+ * The reason we're checking for the optional field here and not in "omitOptionalFields"
649
+ * is because that unlike the bool/function check we do there, here it only depends on
650
+ * whether the field was tested alredy or not.
651
+ *
652
+ * We qualify the test as not missing only if it was already run, if it is omitted,
653
+ * or if it is marked as optional, even if the optional check did not apply yet -
654
+ * but the test did not reach its final state.
655
+ */
656
+ return (optionalTestAwaitsResolution(testObject) ||
596
657
  testObject.isTested() ||
597
658
  testObject.isOmitted());
598
659
  }
660
+ function optionalTestAwaitsResolution(testObject) {
661
+ // Does the test belong to an optional field,
662
+ // and the test itself is still in an indeterminate state?
663
+ return (useOptionalField(testObject.fieldName).type ===
664
+ OptionalFieldTypes.Delayed && testObject.awaitsResolution());
665
+ }
599
666
 
600
667
  /**
601
668
  * Reads the testObjects list and gets full validation result from it.
@@ -899,34 +966,48 @@ function deferDoneCallback(doneCallback, fieldName) {
899
966
  });
900
967
  }
901
968
 
969
+ /**
970
+ * This module gets triggered once the suite is done running its sync tests.
971
+ *
972
+ * It goes over all the tests in the state, and checks if they need to be omitted.
973
+ */
902
974
  function omitOptionalFields() {
903
975
  var optionalFields = useOptionalFields()[0];
976
+ // If there are no optional fields, we don't need to do anything
904
977
  if (isEmpty(optionalFields)) {
905
978
  return;
906
979
  }
980
+ // Create an object to store the fields that need to be omitted
907
981
  var shouldOmit = {};
908
- useSetTests(function (tests) {
909
- return nestedArray.transform(tests, function (testObject) {
910
- var fieldName = testObject.fieldName;
911
- if (hasOwnProperty(shouldOmit, fieldName)) {
912
- verifyAndOmit(testObject);
913
- }
914
- else {
915
- runOptionalConfig(testObject);
916
- }
917
- return testObject;
918
- });
982
+ // iterate over each of the tests in the state
983
+ useTestsFlat().forEach(function (testObject) {
984
+ // If we already added the current field (not this test specifically)
985
+ // no need for further checks, go and omit the test
986
+ if (hasOwnProperty(shouldOmit, testObject.fieldName)) {
987
+ verifyAndOmit(testObject);
988
+ }
989
+ else {
990
+ // check if the field has an optional function
991
+ // if so, run it and verify/omit the test
992
+ runOptionalConfig(testObject);
993
+ }
919
994
  });
995
+ // refresh the tests in the state so that the omitted fields are applied
996
+ useRefreshTestObjects();
920
997
  function verifyAndOmit(testObject) {
921
998
  if (shouldOmit[testObject.fieldName]) {
922
999
  testObject.omit();
923
- useSetOptionalField(testObject.fieldName, function (current) { return [current[0], true]; });
1000
+ useSetOptionalField(testObject.fieldName, function () { return ({
1001
+ applied: true
1002
+ }); });
924
1003
  }
925
1004
  }
926
1005
  function runOptionalConfig(testObject) {
927
- var optionalConfig = useOptionalFieldConfig(testObject.fieldName);
928
- if (isFunction(optionalConfig)) {
929
- shouldOmit[testObject.fieldName] = optionalConfig();
1006
+ // Ge the optional configuration for the given field
1007
+ var optionalConfig = useOptionalField(testObject.fieldName);
1008
+ // If the optional was set to a function or a boolean, run it and verify/omit the test
1009
+ if (optionalConfig.type === OptionalFieldTypes.Immediate) {
1010
+ shouldOmit[testObject.fieldName] = optionalFunctionValue(optionalConfig.rule);
930
1011
  verifyAndOmit(testObject);
931
1012
  }
932
1013
  }
@@ -1350,44 +1431,16 @@ function setMode(nextMode) {
1350
1431
  function omitWhen(conditional, callback) {
1351
1432
  isolate({ type: IsolateTypes.OMIT_WHEN }, function () {
1352
1433
  context.run({
1353
- omitted: isOmitted() ||
1434
+ omitted: inActiveOmitWhen() ||
1354
1435
  optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
1355
1436
  }, function () { return callback(); });
1356
1437
  });
1357
1438
  }
1358
- function isOmitted() {
1439
+ // Checks that we're currently in an active omitWhen block
1440
+ function inActiveOmitWhen() {
1359
1441
  return !!context.useX().omitted;
1360
1442
  }
1361
1443
 
1362
- /**
1363
- * Marks a field as optional, either just by name, or by a given condition.
1364
- *
1365
- * @example
1366
- *
1367
- * optional('field_name');
1368
- *
1369
- * optional({
1370
- * username: () => allowUsernameEmpty,
1371
- * });
1372
- */
1373
- function optional(optionals) {
1374
- // When the optional is given as a string or a list of strings
1375
- // we just add them to the list of optional fields.
1376
- if (isArray(optionals) || isStringValue(optionals)) {
1377
- asArray(optionals).forEach(function (optionalField) {
1378
- useSetOptionalField(optionalField, [true, false]);
1379
- });
1380
- }
1381
- else {
1382
- // if it's an object, we iterate over the keys and add them to the list
1383
- var optionalFunctions = optionals;
1384
- for (var field in optionalFunctions) {
1385
- var predicate = optionalFunctions[field];
1386
- useSetOptionalField(field, [predicate, false]);
1387
- }
1388
- }
1389
- }
1390
-
1391
1444
  /******************************************************************************
1392
1445
  Copyright (c) Microsoft Corporation.
1393
1446
 
@@ -1413,8 +1466,6 @@ function __spreadArray(to, from, pack) {
1413
1466
  return to.concat(ar || Array.prototype.slice.call(from));
1414
1467
  }
1415
1468
 
1416
- bindNot(isStringValue);
1417
-
1418
1469
  function isSameProfileTest(testObject1, testObject2) {
1419
1470
  return (testObject1.fieldName === testObject2.fieldName &&
1420
1471
  testObject1.groupName === testObject2.groupName);
@@ -1577,7 +1628,7 @@ function registerPrevRunTest(testObject) {
1577
1628
  return testObject;
1578
1629
  }
1579
1630
  var prevRunTest = useTestAtCursor(testObject);
1580
- if (isOmitted()) {
1631
+ if (inActiveOmitWhen() || optionalFiedIsApplied(testObject.fieldName)) {
1581
1632
  prevRunTest.omit();
1582
1633
  cursor.next();
1583
1634
  return prevRunTest;
@@ -1678,6 +1729,6 @@ function warn() {
1678
1729
  ctx.currentTest.warn();
1679
1730
  }
1680
1731
 
1681
- var VERSION = "4.5.0";
1732
+ var VERSION = "5.0.0-dev-781e21";
1682
1733
 
1683
1734
  export { VERSION, context, create, each, eager, group, include, omitWhen, only, optional, skip, skipWhen, suiteSelectors, test, warn };
@@ -1 +1 @@
1
- import{createContext as t}from"context";import{isUndefined as n,isStringValue as e,assign as r,cache as i,optionalFunctionValue as u,nestedArray as o,asArray as s,seq as a,isFunction as c,isNullish as f,deferThrow as l,invariant as d,bindNot as p,either as v,isEmpty as E,isNotEmpty as N,isPositive as h,numberEquals as g,hasOwnProperty as m,isArray as y,callEach as R,bus as S,defaultTo as C,isPromise as T,isNull as _}from"vest-utils";export{enforce}from"n4s";var O,I=O||(O={});I[I.DEFAULT=0]="DEFAULT",I[I.SUITE=1]="SUITE",I[I.EACH=2]="EACH",I[I.SKIP_WHEN=3]="SKIP_WHEN",I[I.OMIT_WHEN=4]="OMIT_WHEN",I[I.GROUP=5]="GROUP";var A,b=A||(A={});function k(){var t=0;return{current:function(){return t},next:function(){t++}}}function L(t,n){return void 0===n&&(n=[]),{cursor:k(),keys:{current:{},prev:{}},path:n,type:t}}b[b.ALL=0]="ALL",b[b.EAGER=1]="EAGER";var U=t((function(t,n){return n?null:r({exclusion:{tests:{},groups:{}},inclusion:{},isolate:L(O.DEFAULT),mode:[A.ALL]},t)}));function F(){return U.useX().stateRef}function W(t){return F().optionalFields()[0][t]}function G(t,n){(0,F().optionalFields()[1])((function(e){var i;return r(e,((i={})[t]=u(n,e[t]),i))}))}function P(t){var n;return null===(n=W(t))||void 0===n?void 0:n[0]}function D(){x((function(t){return t}))}function x(t){(0,F().testObjects()[1])((function(n){return{prev:n.prev,current:s(t(n.current))}}))}function w(){return H().filter((function(t){return t.isPending()}))}var X=i();function H(){var t=F().testObjects()[0].current;return X([t],(function(){return o.flatten(t)}))}var K,M=K||(K={});M.Error="error",M.Warning="warning";var q=function(){function t(t,n,e){var r=void 0===e?{}:e;e=r.message;var i=r.groupName;r=r.key,this.key=null,this.id=a(),this.severity=K.Error,this.status=B,this.fieldName=t,this.testFn=n,i&&(this.groupName=i),e&&(this.message=e),r&&(this.key=r)}return t.prototype.run=function(){try{var t=this.testFn()}catch(r){t=r,n(this.message)&&e(t)&&(this.message=r),t=!1}return!1===t&&this.fail(),t},t.prototype.setStatus=function(t){this.isFinalStatus()&&t!==Z||(this.status=t)},t.prototype.warns=function(){return this.severity===K.Warning},t.prototype.setPending=function(){this.setStatus(z)},t.prototype.fail=function(){this.setStatus(this.warns()?Y:j)},t.prototype.done=function(){this.isFinalStatus()||this.setStatus(J)},t.prototype.warn=function(){this.severity=K.Warning},t.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},t.prototype.skip=function(t){this.isPending()&&!t||this.setStatus(V)},t.prototype.cancel=function(){this.setStatus(Q),D()},t.prototype.reset=function(){this.status=B,D()},t.prototype.omit=function(){this.setStatus(Z)},t.prototype.valueOf=function(){return!this.isFailing()},t.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},t.prototype.isNonActionable=function(){return this.isSkipped()||this.isOmitted()||this.isCanceled()},t.prototype.isPending=function(){return this.statusEquals(z)},t.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},t.prototype.isOmitted=function(){return this.statusEquals(Z)},t.prototype.isUntested=function(){return this.statusEquals(B)},t.prototype.isFailing=function(){return this.statusEquals(j)},t.prototype.isCanceled=function(){return this.statusEquals(Q)},t.prototype.isSkipped=function(){return this.statusEquals(V)},t.prototype.isPassing=function(){return this.statusEquals(J)},t.prototype.isWarning=function(){return this.statusEquals(Y)},t.prototype.statusEquals=function(t){return this.status===t},t}(),B="UNTESTED",V="SKIPPED",j="FAILED",Y="WARNING",J="PASSING",z="PENDING",Q="CANCELED",Z="OMITTED";function $(t){function n(t,n,i){return r.references.push(),e(t,u(n,i)),function(){return[r.references[t],function(n){return e(t,u(n,r.references[t]))}]}}function e(n,e){var u=r.references[n];r.references[n]=e,n=i[n][1],c(n)&&n(e,u),c(t)&&t()}var r={references:[]},i=[];return{registerStateKey:function(t,e){var r=i.length;return i.push([t,e]),n(r,t)},reset:function(){var t=r.references;r.references=[],i.forEach((function(e,r){return n(r,e[0],t[r])}))}}}function tt(t,n){var e=n.suiteId;return n=n.suiteName,{optionalFields:t.registerStateKey((function(){return{}})),suiteId:t.registerStateKey(e),suiteName:t.registerStateKey(n),testCallbacks:t.registerStateKey((function(){return{fieldCallbacks:{},doneCallbacks:[]}})),testObjects:t.registerStateKey((function(t){return{prev:t?t.current:[],current:[]}}))}}function nt(){return U.useX().isolate}function et(){var t=nt();return t.path.concat(t.cursor.current())}function rt(t,n){t=void 0===(t=t.type)?O.DEFAULT:t,d(c(n));var e=L(t,et());return t=U.run({isolate:e},(function(){return e.keys.prev=function(){var t=F().testObjects()[0].prev;return s(o.getCurrent(t,et())).reduce((function(t,n){return n instanceof q&&!f(n.key)?(t[n.key]=n,t):t}),{})}(),x((function(t){return o.setValueAtPath(t,e.path,[])})),n()})),nt().cursor.next(),t}var it,ut=it||(it={});ut.WARNINGS="warnings",ut.ERRORS="errors";var ot,st=ot||(ot={});function at(t,n){return!(!n||t.fieldName!==n)}st.ERROR_COUNT="errorCount",st.WARN_COUNT="warnCount";var ct=p((function(t,n){return t.groupName===n}));function ft(t,n){return H().some((function(e){return lt(e,t,n)}))}function lt(t,n,e){return!(!t.hasFailures()||e&&!at(t,e)||v(n===it.WARNINGS,t.warns()))}function dt(t){if(pt(t))return!0;if(ft(it.ERRORS,t))return!1;var n=H();return!E(n)&&!function(t){return N(w().filter((function(n){return vt(n,t)})))}(t)&&function(t){return H().every((function(n){return!(!t||at(n,t))||Et(n,t)}))}(t)}function pt(t){return!!t&&!0===(null===(n=W(t))||void 0===n?void 0:n[1]);var n}function vt(t,n){return!(n&&!at(t,n))&&!0!==P(t.fieldName)}function Et(t,n){return!(!n||at(t,n))||(!0===P(t.fieldName)||t.isTested()||t.isOmitted())}function Nt(){var t=H(),n=r({errorCount:0,warnCount:0,testCount:0},{groups:{},tests:{},valid:!1});return t.reduce((function(t,n){var e=t.tests;e[n.fieldName]=ht(e,n),e[n.fieldName].valid=!1!==e[n.fieldName].valid&&dt(n.fieldName);var r=t.groups,i=n.groupName;return i&&(r[i]=r[i]||{},r[i][n.fieldName]=ht(r[i],n),e=r[i][n.fieldName],!1===r[i][n.fieldName].valid?n=!1:n=!!pt(n=n.fieldName)||!function(t,n,e){return H().some((function(r){return!ct(r,n)&&lt(r,t,e)}))}(it.ERRORS,i,n)&&!function(t,n){return N(w().filter((function(e){return!ct(e,t)&&vt(e,n)})))}(i,n)&&function(t,n){return H().every((function(e){return!!ct(e,t)||Et(e,n)}))}(i,n),e.valid=n),t}),n),n.valid=dt(),function(t){for(var n in t.tests)t.errorCount+=t.tests[n].errorCount,t.warnCount+=t.tests[n].warnCount,t.testCount+=t.tests[n].testCount;return t}(n)}function ht(t,n){function e(t){o[t===it.ERRORS?ot.ERROR_COUNT:ot.WARN_COUNT]++,u&&(o[t]=(o[t]||[]).concat(u))}var i=n.fieldName,u=n.message;t[i]=t[i]||r({errorCount:0,warnCount:0,testCount:0},{errors:[],warnings:[]});var o=t[i];return n.isNonActionable()||(t[i].testCount++,n.isFailing()?e(it.ERRORS):n.isWarning()&&e(it.WARNINGS)),o}function gt(t,n,e){if(e){var r;t=(null===(r=null==t?void 0:t[e])||void 0===r?void 0:r[n])||[]}else{for(var i in r={},e=n===it.ERRORS?ot.ERROR_COUNT:ot.WARN_COUNT,t)h(t[i][e])&&(r[i]=t[i][n]||[]);t=r}return t}function mt(t){return{getErrors:function(n){return gt(t.tests,it.ERRORS,n)},getErrorsByGroup:function(n,e){return gt(t.groups[n],it.ERRORS,e)},getWarnings:function(n){return gt(t.tests,it.WARNINGS,n)},getWarningsByGroup:function(n,e){return gt(t.groups[n],it.WARNINGS,e)},hasErrors:function(n){return St(t,ot.ERROR_COUNT,n)},hasErrorsByGroup:function(n,e){return Rt(t,ot.ERROR_COUNT,n,e)},hasWarnings:function(n){return St(t,ot.WARN_COUNT,n)},hasWarningsByGroup:function(n,e){return Rt(t,ot.WARN_COUNT,n,e)},isValid:function(n){var e;return n?!(null===(e=t.tests[n])||void 0===e||!e.valid):t.valid},isValidByGroup:function(n,e){if(!(n=t.groups[n]))return!1;if(e)return yt(n,e);for(var r in n)if(!yt(n,r))return!1;return!0}}}function yt(t,n){var e;return!(null===(e=t[n])||void 0===e||!e.valid)}function Rt(t,n,e,r){var i,u;if(!(t=t.groups[e]))return!1;if(r)return h(null===(i=t[r])||void 0===i?void 0:i[n]);for(var o in t)if(h(null===(u=t[o])||void 0===u?void 0:u[n]))return!0;return!1}function St(t,n,e){var r;return t=e?null===(r=t.tests[e])||void 0===r?void 0:r[n]:t[n]||0,h(t)}var Ct=i(1);function Tt(){var t=H(),n={stateRef:F()};return Ct([t],U.bind(n,(function(){var t=Nt(),n=F().suiteName()[0];return r(t,mt(t),{suiteName:n})})))}function _t(t){var n=w();return!E(n)&&(!t||n.some((function(n){return at(n,t)})))}var Ot=i(20);function It(){var t=H(),n={stateRef:F()};return Ot([t],U.bind(n,(function(){return r({},Tt(),{done:U.bind(n,kt)})})))}function At(t,n,e){var r;return!!(!c(t)||n&&g(null===(r=e.tests[n])||void 0===r?void 0:r.testCount,0))}function bt(t){return!(_t()&&(!t||_t(t)))}function kt(){function t(){return r(Tt())}for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var r=(n=n.reverse())[0];return n=n[1],e=It(),At(r,n,e)?e:bt(n)?(t(),e):(Lt(t,n),e)}function Lt(t,n){(0,F().testCallbacks()[1])((function(e){return n?e.fieldCallbacks[n]=(e.fieldCallbacks[n]||[]).concat(t):e.doneCallbacks.push(t),e}))}function Ut(){var t=S.createBus();return t.on(Wt.TEST_COMPLETED,(function(n){if(!n.isCanceled()){n.done(),n=n.fieldName;var e=F().testCallbacks()[0].fieldCallbacks;n&&!_t(n)&&y(e[n])&&R(e[n]),_t()||t.emit(Wt.ALL_RUNNING_TESTS_FINISHED)}})),t.on(Wt.SUITE_CALLBACK_DONE_RUNNING,(function(){!function(){function t(t){e[t.fieldName]&&(t.omit(),G(t.fieldName,(function(t){return[t[0],!0]})))}var n=F().optionalFields()[0];if(!E(n)){var e={};x((function(n){return o.transform(n,(function(n){if(m(e,n.fieldName))t(n);else{var r=P(n.fieldName);c(r)&&(e[n.fieldName]=r(),t(n))}return n}))}))}}()})),t.on(Wt.ALL_RUNNING_TESTS_FINISHED,(function(){var t=F().testCallbacks()[0].doneCallbacks;R(t)})),t.on(Wt.REMOVE_FIELD,(function(t){H().forEach((function(n){at(n,t)&&(n.cancel(),function(t){x((function(n){return o.transform(n,(function(n){return t!==n?n:null}))}))}(n))}))})),t.on(Wt.RESET_FIELD,(function(t){H().forEach((function(n){at(n,t)&&n.reset()}))})),t}function Ft(){var t=U.useX();return d(t.bus),t.bus}var Wt,Gt=Wt||(Wt={});function Pt(t){return xt(0,"tests",t)}function Dt(t){return xt(1,"tests",t)}function xt(t,n,r){var i=U.useX("hook called outside of a running suite.");r&&s(r).forEach((function(r){e(r)&&(i.exclusion[n][r]=0===t)}))}function wt(t){for(var n in t)if(!0===t[n])return!0;return!1}function Xt(){var t,n=U.useX().exclusion;for(t in n.groups)if(n.groups[t])return!0;return!1}function Ht(t){return"Wrong arguments passed to group. Group ".concat(t,".")}function Kt(t,n,e){if(e||2===arguments.length)for(var r,i=0,u=n.length;i<u;i++)!r&&i in n||(r||(r=Array.prototype.slice.call(n,0,i)),r[i]=n[i]);return t.concat(r||Array.prototype.slice.call(n))}function Mt(t){var n=t.asyncTest,r=t.message;if(T(n)){var i=Ft().emit,u=F(),o=U.bind({stateRef:u},(function(){D(),i(Wt.TEST_COMPLETED,t)}));u=U.bind({stateRef:u},(function(n){t.isCanceled()||(t.message=e(n)?n:r,t.fail(),o())}));try{n.then(o,u)}catch(t){u()}}}function qt(t){var n=F().testObjects()[0].prev;if(E(n))return Bt(t),t;var e=et();if(n=o.valueAtPath(n,e),!f(t.key)){n=t.key,(e=nt().keys.prev[n])&&(t=e),e=t;var r=nt().keys.current;return f(r[n])?r[n]=e:l('Encountered the same test key "'.concat(n,"\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.")),Bt(t),t}return!N(e=n)||e.fieldName===t.fieldName&&e.groupName===t.groupName||(nt().type===O.EACH||l("Vest Critical Error: Tests called in different order than previous run.\n expected: ".concat(n.fieldName,"\n received: ").concat(t.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.')),function(){var t=nt().cursor.current();x((function(n){return n.splice(t),n}))}(),n=null),Bt(t=C(n,t)),t}function Bt(t){var n=et();x((function(e){return o.setValueAtPath(e,n,t)}))}function Vt(t){var n=nt().cursor,e=A.EAGER;if(U.useX().mode[0]===e&&ft(it.ERRORS,t.fieldName))return t.skip(),qt(t),n.next(),t;if(e=qt(t),U.useX().omitted)return e.omit(),n.next(),e;if(function(t){var n=t.fieldName;if(t=t.groupName,U.useX().skipped)return!0;var e=U.useX(),r=e.exclusion;e=e.inclusion;var i=r.tests,o=i[n];if(!1===o)return!0;if(o=!0===o,t){var s=U.useX().exclusion.groups;if(s=m(s,t)?!1===s[t]:Xt())return!0;if(!0===r.groups[t])return!(o||!wt(i)&&!1!==i[n])}return!!(t=!!Xt()&&!t)||!o&&!!wt(i)&&!u(e[n])}(t))return e.skip(!!U.useX().skipped),n.next(),e;if(t!==e&&e.fieldName===t.fieldName&&e.groupName===t.groupName&&e.isPending()&&e.cancel(),Bt(t),t.isUntested()){e=Ft();var r=function(t){return U.run({currentTest:t},(function(){return t.run()}))}(t);try{T(r)?(t.asyncTest=r,t.setPending(),Mt(t)):e.emit(Wt.TEST_COMPLETED,t)}catch(n){throw Error("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(t),".\n Error: ").concat(n,"."))}}else T(t.asyncTest)&&(t.setPending(),Mt(t));return n.next(),t}function jt(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var i=c(n[1])?n:Kt([void 0],n,!0);n=i[0],r=i[1],i=i[2],d(e(t),Qt("fieldName","string")),d(c(r),Qt("Test callback","function"));var u=U.useX();return Vt(n=new q(t,r,{message:n,groupName:u.groupName,key:i}))}Gt.TEST_COMPLETED="test_completed",Gt.ALL_RUNNING_TESTS_FINISHED="all_running_tests_finished",Gt.REMOVE_FIELD="remove_field",Gt.RESET_FIELD="reset_field",Gt.SUITE_CALLBACK_DONE_RUNNING="suite_callback_done_running",Pt.group=function(t){return xt(0,"groups",t)},Dt.group=function(t){return xt(1,"groups",t)},p(e);var Yt,Jt,zt=r(jt,{memo:(Yt=jt,Jt=i(10),function(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];e=nt().cursor.current();var r=(n=n.reverse())[0],i=n[1],u=n[2];return e=[F().suiteId()[0],t,e].concat(r),n=Jt.get(e),_(n)?Jt(e,(function(){return Yt(t,u,i)})):n[1].isCanceled()?(Jt.invalidate(e),Jt(e,(function(){return Yt(t,u,i)}))):Vt(n[1])})});function Qt(t,n){return"Incompatible params passed to test function. ".concat(t," must be a ").concat(n)}var Zt="4.5.0";function $t(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=(t=t.reverse())[0];t=t[1],d(c(e),"vest.create: Expected callback to be a function.");var i=Ut(),u=$();return t={stateRef:tt(u,{suiteId:a(),suiteName:t}),bus:i},r(U.bind(t,(function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return u.reset(),rt({type:O.SUITE},(function(){e.apply(void 0,t)})),i.emit(Wt.SUITE_CALLBACK_DONE_RUNNING),It()})),{get:U.bind(t,Tt),remove:U.bind(t,(function(t){i.emit(Wt.REMOVE_FIELD,t)})),reset:u.reset,resetField:U.bind(t,(function(t){i.emit(Wt.RESET_FIELD,t)}))})}function tn(t,n){d(c(n),"each callback must be a function"),rt({type:O.EACH},(function(){t.forEach((function(t,e){n(t,e)}))}))}function nn(){var t=A.EAGER;U.useX().mode[0]=t}function en(t,n){d(e(t),Ht("name must be a string")),d(c(n),Ht("callback must be a function")),rt({type:O.GROUP},(function(){U.run({groupName:t},n)}))}function rn(t){var n=U.useX(),r=n.inclusion;return n=n.exclusion,d(e(t)),r[t]=C(n.tests[t],!0),{when:function(n){var r=U.useX(),i=r.exclusion;r.inclusion[t]=function(){return m(i.tests,t)?C(i.tests[t],!0):e(n)?!!i.tests[n]:u(n,u(Tt))}}}}function un(t,n){rt({type:O.OMIT_WHEN},(function(){U.run({omitted:!!U.useX().omitted||u(t,u(Tt))},(function(){return n()}))}))}function on(t){if(y(t)||e(t))s(t).forEach((function(t){G(t,[!0,!1])}));else for(var n in t)G(n,[t[n],!1])}function sn(t,n){rt({type:O.SKIP_WHEN},(function(){U.run({skipped:!!U.useX().skipped||u(t,u(Tt))},(function(){return n()}))}))}function an(){var t=U.useX("warn hook called outside of a running suite.");d(t.currentTest,"warn called outside of a test."),t.currentTest.warn()}export{Zt as VERSION,U as context,$t as create,tn as each,nn as eager,en as group,rn as include,un as omitWhen,Pt as only,on as optional,Dt as skip,sn as skipWhen,mt as suiteSelectors,zt as test,an as warn};
1
+ import{createCascade as t}from"context";import{isUndefined as n,isStringValue as e,assign as r,cache as i,nestedArray as u,asArray as s,seq as o,optionalFunctionValue as a,isFunction as c,isNullish as f,deferThrow as l,invariant as d,bindNot as p,either as v,isArray as E,isEmpty as N,isNotEmpty as h,isPositive as m,numberEquals as g,hasOwnProperty as y,callEach as R,bus as S,defaultTo as C,isPromise as T,isNull as _}from"vest-utils";export{enforce}from"n4s";var O,I=O||(O={});I[I.DEFAULT=0]="DEFAULT",I[I.SUITE=1]="SUITE",I[I.EACH=2]="EACH",I[I.SKIP_WHEN=3]="SKIP_WHEN",I[I.OMIT_WHEN=4]="OMIT_WHEN",I[I.GROUP=5]="GROUP";var A,k=A||(A={});function b(){var t=0;return{current:function(){return t},next:function(){t++}}}function U(t,n){return void 0===n&&(n=[]),{cursor:b(),keys:{current:{},prev:{}},path:n,type:t}}k[k.ALL=0]="ALL",k[k.EAGER=1]="EAGER";var L=t((function(t,n){return n?null:r({exclusion:{tests:{},groups:{}},inclusion:{},isolate:U(O.DEFAULT),mode:[A.ALL]},t)}));function F(){return L.useX().stateRef}function D(t,n){(0,F().optionalFields()[1])((function(e){var i;return r(e,((i={})[t]=r({},e[t],n(e[t])),i))}))}function W(t){var n;return null!==(n=F().optionalFields()[0][t])&&void 0!==n?n:{}}function P(){G((function(t){return t}))}function G(t){(0,F().testObjects()[1])((function(n){return{prev:n.prev,current:s(t(n.current))}}))}function w(){return X().filter((function(t){return t.isPending()}))}var x=i();function X(){var t=F().testObjects()[0].current;return x([t],(function(){return u.flatten(t)}))}var H,K=H||(H={});K.Error="error",K.Warning="warning";var M=function(){function t(t,n,e){var r=void 0===e?{}:e;e=r.message;var i=r.groupName;r=r.key,this.key=null,this.id=o(),this.severity=H.Error,this.status=q,this.fieldName=t,this.testFn=n,i&&(this.groupName=i),e&&(this.message=e),r&&(this.key=r)}return t.prototype.run=function(){try{var t=this.testFn()}catch(r){t=r,n(this.message)&&e(t)&&(this.message=r),t=!1}return!1===t&&this.fail(),t},t.prototype.setStatus=function(t){this.isFinalStatus()&&t!==Q||(this.status=t)},t.prototype.warns=function(){return this.severity===H.Warning},t.prototype.setPending=function(){this.setStatus(J)},t.prototype.fail=function(){this.setStatus(this.warns()?j:V)},t.prototype.done=function(){this.isFinalStatus()||this.setStatus(Y)},t.prototype.warn=function(){this.severity=H.Warning},t.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},t.prototype.skip=function(t){this.isPending()&&!t||this.setStatus(B)},t.prototype.cancel=function(){this.setStatus(z),P()},t.prototype.reset=function(){this.status=q,P()},t.prototype.omit=function(){this.setStatus(Q)},t.prototype.valueOf=function(){return!this.isFailing()},t.prototype.isPending=function(){return this.statusEquals(J)},t.prototype.isOmitted=function(){return this.statusEquals(Q)},t.prototype.isUntested=function(){return this.statusEquals(q)},t.prototype.isFailing=function(){return this.statusEquals(V)},t.prototype.isCanceled=function(){return this.statusEquals(z)},t.prototype.isSkipped=function(){return this.statusEquals(B)},t.prototype.isPassing=function(){return this.statusEquals(Y)},t.prototype.isWarning=function(){return this.statusEquals(j)},t.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},t.prototype.isNonActionable=function(){return this.isSkipped()||this.isOmitted()||this.isCanceled()},t.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},t.prototype.awaitsResolution=function(){return this.isSkipped()||this.isUntested()||this.isPending()},t.prototype.statusEquals=function(t){return this.status===t},t}(),q="UNTESTED",B="SKIPPED",V="FAILED",j="WARNING",Y="PASSING",J="PENDING",z="CANCELED",Q="OMITTED";function Z(t){function n(t,n,i){return r.references.push(),e(t,a(n,i)),function(){return[r.references[t],function(n){return e(t,a(n,r.references[t]))}]}}function e(n,e){var u=r.references[n];r.references[n]=e,n=i[n][1],c(n)&&n(e,u),c(t)&&t()}var r={references:[]},i=[];return{registerStateKey:function(t,e){var r=i.length;return i.push([t,e]),n(r,t)},reset:function(){var t=r.references;r.references=[],i.forEach((function(e,r){return n(r,e[0],t[r])}))}}}function $(t,n){var e=n.suiteId;return n=n.suiteName,{optionalFields:t.registerStateKey((function(){return{}})),suiteId:t.registerStateKey(e),suiteName:t.registerStateKey(n),testCallbacks:t.registerStateKey((function(){return{fieldCallbacks:{},doneCallbacks:[]}})),testObjects:t.registerStateKey((function(t){return{prev:t?t.current:[],current:[]}}))}}function tt(){return L.useX().isolate}function nt(){var t=tt();return t.path.concat(t.cursor.current())}function et(t,n){t=void 0===(t=t.type)?O.DEFAULT:t,d(c(n));var e=U(t,nt());return t=L.run({isolate:e},(function(){return e.keys.prev=function(){var t=F().testObjects()[0].prev;return s(u.getCurrent(t,nt())).reduce((function(t,n){return n instanceof M&&!f(n.key)?(t[n.key]=n,t):t}),{})}(),G((function(t){return u.setValueAtPath(t,e.path,[])})),n()})),tt().cursor.next(),t}var rt,it=rt||(rt={});it.WARNINGS="warnings",it.ERRORS="errors";var ut,st=ut||(ut={});function ot(t,n){return!(!n||t.fieldName!==n)}st.ERROR_COUNT="errorCount",st.WARN_COUNT="warnCount";var at=p((function(t,n){return t.groupName===n}));function ct(t,n){return X().some((function(e){return ft(e,t,n)}))}function ft(t,n,e){return!(!t.hasFailures()||e&&!ot(t,e)||v(n===rt.WARNINGS,t.warns()))}function lt(t){return!!t&&W(t).applied}var dt,pt=dt||(dt={});function vt(t){if(lt(t))return!0;var n=X();return!(N(n)||ct(rt.ERRORS,t)||function(t){return h(w().filter((function(n){return Et(n,t)})))}(t))&&function(t){return X().every((function(n){return Nt(n,t)}))}(t)}function Et(t,n){return!(n&&!ot(t,n))&&lt(n)}function Nt(t,n){return!(!n||ot(t,n))||(W(t.fieldName).type===dt.Delayed&&t.awaitsResolution()||t.isTested()||t.isOmitted())}function ht(){var t=X(),n=r({errorCount:0,warnCount:0,testCount:0},{groups:{},tests:{},valid:!1});return t.reduce((function(t,n){var e=t.tests;e[n.fieldName]=mt(e,n),e[n.fieldName].valid=!1!==e[n.fieldName].valid&&vt(n.fieldName);var r=t.groups,i=n.groupName;return i&&(r[i]=r[i]||{},r[i][n.fieldName]=mt(r[i],n),e=r[i][n.fieldName],!1===r[i][n.fieldName].valid?n=!1:n=!!lt(n=n.fieldName)||!function(t,n,e){return X().some((function(r){return!at(r,n)&&ft(r,t,e)}))}(rt.ERRORS,i,n)&&!function(t,n){return h(w().filter((function(e){return!at(e,t)&&Et(e,n)})))}(i,n)&&function(t,n){return X().every((function(e){return!!at(e,t)||Nt(e,n)}))}(i,n),e.valid=n),t}),n),n.valid=vt(),function(t){for(var n in t.tests)t.errorCount+=t.tests[n].errorCount,t.warnCount+=t.tests[n].warnCount,t.testCount+=t.tests[n].testCount;return t}(n)}function mt(t,n){function e(t){s[t===rt.ERRORS?ut.ERROR_COUNT:ut.WARN_COUNT]++,u&&(s[t]=(s[t]||[]).concat(u))}var i=n.fieldName,u=n.message;t[i]=t[i]||r({errorCount:0,warnCount:0,testCount:0},{errors:[],warnings:[]});var s=t[i];return n.isNonActionable()||(t[i].testCount++,n.isFailing()?e(rt.ERRORS):n.isWarning()&&e(rt.WARNINGS)),s}function gt(t,n,e){if(e){var r;t=(null===(r=null==t?void 0:t[e])||void 0===r?void 0:r[n])||[]}else{for(var i in r={},e=n===rt.ERRORS?ut.ERROR_COUNT:ut.WARN_COUNT,t)m(t[i][e])&&(r[i]=t[i][n]||[]);t=r}return t}function yt(t){return{getErrors:function(n){return gt(t.tests,rt.ERRORS,n)},getErrorsByGroup:function(n,e){return gt(t.groups[n],rt.ERRORS,e)},getWarnings:function(n){return gt(t.tests,rt.WARNINGS,n)},getWarningsByGroup:function(n,e){return gt(t.groups[n],rt.WARNINGS,e)},hasErrors:function(n){return Ct(t,ut.ERROR_COUNT,n)},hasErrorsByGroup:function(n,e){return St(t,ut.ERROR_COUNT,n,e)},hasWarnings:function(n){return Ct(t,ut.WARN_COUNT,n)},hasWarningsByGroup:function(n,e){return St(t,ut.WARN_COUNT,n,e)},isValid:function(n){var e;return n?!(null===(e=t.tests[n])||void 0===e||!e.valid):t.valid},isValidByGroup:function(n,e){if(!(n=t.groups[n]))return!1;if(e)return Rt(n,e);for(var r in n)if(!Rt(n,r))return!1;return!0}}}function Rt(t,n){var e;return!(null===(e=t[n])||void 0===e||!e.valid)}function St(t,n,e,r){var i,u;if(!(t=t.groups[e]))return!1;if(r)return m(null===(i=t[r])||void 0===i?void 0:i[n]);for(var s in t)if(m(null===(u=t[s])||void 0===u?void 0:u[n]))return!0;return!1}function Ct(t,n,e){var r;return t=e?null===(r=t.tests[e])||void 0===r?void 0:r[n]:t[n]||0,m(t)}pt[pt.Immediate=0]="Immediate",pt[pt.Delayed=1]="Delayed";var Tt=i(1);function _t(){var t=X(),n={stateRef:F()};return Tt([t],L.bind(n,(function(){var t=ht(),n=F().suiteName()[0];return r(t,yt(t),{suiteName:n})})))}function Ot(t){var n=w();return!N(n)&&(!t||n.some((function(n){return ot(n,t)})))}var It=i(20);function At(){var t=X(),n={stateRef:F()};return It([t],L.bind(n,(function(){return r({},_t(),{done:L.bind(n,Ut)})})))}function kt(t,n,e){var r;return!!(!c(t)||n&&g(null===(r=e.tests[n])||void 0===r?void 0:r.testCount,0))}function bt(t){return!(Ot()&&(!t||Ot(t)))}function Ut(){function t(){return r(_t())}for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var r=(n=n.reverse())[0];return n=n[1],e=At(),kt(r,n,e)?e:bt(n)?(t(),e):(Lt(t,n),e)}function Lt(t,n){(0,F().testCallbacks()[1])((function(e){return n?e.fieldCallbacks[n]=(e.fieldCallbacks[n]||[]).concat(t):e.doneCallbacks.push(t),e}))}function Ft(){var t=S.createBus();return t.on(Wt.TEST_COMPLETED,(function(n){if(!n.isCanceled()){n.done(),n=n.fieldName;var e=F().testCallbacks()[0].fieldCallbacks;n&&!Ot(n)&&E(e[n])&&R(e[n]),Ot()||t.emit(Wt.ALL_RUNNING_TESTS_FINISHED)}})),t.on(Wt.SUITE_CALLBACK_DONE_RUNNING,(function(){!function(){function t(t){e[t.fieldName]&&(t.omit(),D(t.fieldName,(function(){return{applied:!0}})))}var n=F().optionalFields()[0];if(!N(n)){var e={};X().forEach((function(n){if(y(e,n.fieldName))t(n);else{var r=W(n.fieldName);r.type===dt.Immediate&&(e[n.fieldName]=a(r.rule),t(n))}})),P()}}()})),t.on(Wt.ALL_RUNNING_TESTS_FINISHED,(function(){var t=F().testCallbacks()[0].doneCallbacks;R(t)})),t.on(Wt.REMOVE_FIELD,(function(t){X().forEach((function(n){ot(n,t)&&(n.cancel(),function(t){G((function(n){return u.transform(n,(function(n){return t!==n?n:null}))}))}(n))}))})),t.on(Wt.RESET_FIELD,(function(t){X().forEach((function(n){ot(n,t)&&n.reset()}))})),t}function Dt(){var t=L.useX();return d(t.bus),t.bus}var Wt,Pt=Wt||(Wt={});function Gt(t){return xt(0,"tests",t)}function wt(t){return xt(1,"tests",t)}function xt(t,n,r){var i=L.useX("hook called outside of a running suite.");r&&s(r).forEach((function(r){e(r)&&(i.exclusion[n][r]=0===t)}))}function Xt(t){for(var n in t)if(!0===t[n])return!0;return!1}function Ht(){var t,n=L.useX().exclusion;for(t in n.groups)if(n.groups[t])return!0;return!1}function Kt(t){return"Wrong arguments passed to group. Group ".concat(t,".")}function Mt(t,n,e){if(e||2===arguments.length)for(var r,i=0,u=n.length;i<u;i++)!r&&i in n||(r||(r=Array.prototype.slice.call(n,0,i)),r[i]=n[i]);return t.concat(r||Array.prototype.slice.call(n))}function qt(t){var n=t.asyncTest,r=t.message;if(T(n)){var i=Dt().emit,u=F(),s=L.bind({stateRef:u},(function(){P(),i(Wt.TEST_COMPLETED,t)}));u=L.bind({stateRef:u},(function(n){t.isCanceled()||(t.message=e(n)?n:r,t.fail(),s())}));try{n.then(s,u)}catch(t){u()}}}function Bt(t){var n=F().testObjects()[0].prev;if(N(n))return Vt(t),t;var e=nt();if(n=u.valueAtPath(n,e),!f(t.key)){n=t.key,(e=tt().keys.prev[n])&&(t=e),e=t;var r=tt().keys.current;return f(r[n])?r[n]=e:l('Encountered the same test key "'.concat(n,"\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.")),Vt(t),t}return!h(e=n)||e.fieldName===t.fieldName&&e.groupName===t.groupName||(tt().type===O.EACH||l("Vest Critical Error: Tests called in different order than previous run.\n expected: ".concat(n.fieldName,"\n received: ").concat(t.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.')),function(){var t=tt().cursor.current();G((function(n){return n.splice(t),n}))}(),n=null),Vt(t=C(n,t)),t}function Vt(t){var n=nt();G((function(e){return u.setValueAtPath(e,n,t)}))}function jt(t){var n=tt().cursor,e=A.EAGER;if(L.useX().mode[0]===e&&ct(rt.ERRORS,t.fieldName))return t.skip(),Bt(t),n.next(),t;if(e=Bt(t),L.useX().omitted||lt(t.fieldName))return e.omit(),n.next(),e;if(function(t){var n=t.fieldName;if(t=t.groupName,L.useX().skipped)return!0;var e=L.useX(),r=e.exclusion;e=e.inclusion;var i=r.tests,u=i[n];if(!1===u)return!0;if(u=!0===u,t){var s=L.useX().exclusion.groups;if(s=y(s,t)?!1===s[t]:Ht())return!0;if(!0===r.groups[t])return!(u||!Xt(i)&&!1!==i[n])}return!!(t=!!Ht()&&!t)||!u&&!!Xt(i)&&!a(e[n])}(t))return e.skip(!!L.useX().skipped),n.next(),e;if(t!==e&&e.fieldName===t.fieldName&&e.groupName===t.groupName&&e.isPending()&&e.cancel(),Vt(t),t.isUntested()){e=Dt();var r=function(t){return L.run({currentTest:t},(function(){return t.run()}))}(t);try{T(r)?(t.asyncTest=r,t.setPending(),qt(t)):e.emit(Wt.TEST_COMPLETED,t)}catch(n){throw Error("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(t),".\n Error: ").concat(n,"."))}}else T(t.asyncTest)&&(t.setPending(),qt(t));return n.next(),t}function Yt(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var i=c(n[1])?n:Mt([void 0],n,!0);n=i[0],r=i[1],i=i[2],d(e(t),Zt("fieldName","string")),d(c(r),Zt("Test callback","function"));var u=L.useX();return jt(n=new M(t,r,{message:n,groupName:u.groupName,key:i}))}Pt.TEST_COMPLETED="test_completed",Pt.ALL_RUNNING_TESTS_FINISHED="all_running_tests_finished",Pt.REMOVE_FIELD="remove_field",Pt.RESET_FIELD="reset_field",Pt.SUITE_CALLBACK_DONE_RUNNING="suite_callback_done_running",Gt.group=function(t){return xt(0,"groups",t)},wt.group=function(t){return xt(1,"groups",t)};var Jt,zt,Qt=r(Yt,{memo:(Jt=Yt,zt=i(10),function(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];e=tt().cursor.current();var r=(n=n.reverse())[0],i=n[1],u=n[2];return e=[F().suiteId()[0],t,e].concat(r),n=zt.get(e),_(n)?zt(e,(function(){return Jt(t,u,i)})):n[1].isCanceled()?(zt.invalidate(e),zt(e,(function(){return Jt(t,u,i)}))):jt(n[1])})});function Zt(t,n){return"Incompatible params passed to test function. ".concat(t," must be a ").concat(n)}var $t="5.0.0-dev-781e21";function tn(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=(t=t.reverse())[0];t=t[1],d(c(e),"vest.create: Expected callback to be a function.");var i=Ft(),u=Z();return t={stateRef:$(u,{suiteId:o(),suiteName:t}),bus:i},r(L.bind(t,(function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return u.reset(),et({type:O.SUITE},(function(){e.apply(void 0,t)})),i.emit(Wt.SUITE_CALLBACK_DONE_RUNNING),At()})),{get:L.bind(t,_t),remove:L.bind(t,(function(t){i.emit(Wt.REMOVE_FIELD,t)})),reset:u.reset,resetField:L.bind(t,(function(t){i.emit(Wt.RESET_FIELD,t)}))})}function nn(t,n){d(c(n),"each callback must be a function"),et({type:O.EACH},(function(){t.forEach((function(t,e){n(t,e)}))}))}function en(){var t=A.EAGER;L.useX().mode[0]=t}function rn(t,n){d(e(t),Kt("name must be a string")),d(c(n),Kt("callback must be a function")),et({type:O.GROUP},(function(){L.run({groupName:t},n)}))}function un(t){var n=L.useX(),r=n.inclusion;return n=n.exclusion,d(e(t)),r[t]=C(n.tests[t],!0),{when:function(n){var r=L.useX(),i=r.exclusion;r.inclusion[t]=function(){return y(i.tests,t)?C(i.tests[t],!0):e(n)?!!i.tests[n]:a(n,a(_t))}}}}function sn(t,n){et({type:O.OMIT_WHEN},(function(){L.run({omitted:!!L.useX().omitted||a(t,a(_t))},(function(){return n()}))}))}function on(t){if(E(t)||e(t))s(t).forEach((function(t){D(t,(function(){return{type:dt.Delayed,applied:!1,rule:null}}))}));else{var n,r=function(n){var e=t[n];D(n,(function(){return{type:dt.Immediate,rule:e,applied:a(e)}}))};for(n in t)r(n)}}function an(t,n){et({type:O.SKIP_WHEN},(function(){L.run({skipped:!!L.useX().skipped||a(t,a(_t))},(function(){return n()}))}))}function cn(){var t=L.useX("warn hook called outside of a running suite.");d(t.currentTest,"warn called outside of a test."),t.currentTest.warn()}export{$t as VERSION,L as context,tn as create,nn as each,en as eager,rn as group,un as include,sn as omitWhen,Gt as only,on as optional,wt as skip,an as skipWhen,yt as suiteSelectors,Qt as test,cn as warn};
@@ -1,60 +1,12 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('vest')) :
3
- typeof define === 'function' && define.amd ? define(['vest'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.classnames = factory(global.vest));
5
- }(this, (function (vest) { 'use strict';
6
-
7
- function isNumeric(value) {
8
- var str = String(value);
9
- var num = Number(value);
10
- var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
11
- return Boolean(result);
12
- }
13
-
14
- function greaterThan(value, gt) {
15
- return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
16
- }
17
-
18
- function isFunction(value) {
19
- return typeof value === 'function';
20
- }
21
-
22
- function optionalFunctionValue(value) {
23
- var args = [];
24
- for (var _i = 1; _i < arguments.length; _i++) {
25
- args[_i - 1] = arguments[_i];
26
- }
27
- return isFunction(value) ? value.apply(void 0, args) : value;
28
- }
29
-
30
- /**
31
- * A safe hasOwnProperty access
32
- */
33
- function hasOwnProperty(obj, key) {
34
- return Object.prototype.hasOwnProperty.call(obj, key);
35
- }
36
-
37
- function invariant(condition,
38
- // eslint-disable-next-line @typescript-eslint/ban-types
39
- message) {
40
- if (condition) {
41
- return;
42
- }
43
- // If message is a string object (rather than string literal)
44
- // Throw the value directly as a string
45
- // Alternatively, throw an error with the message
46
- throw message instanceof String
47
- ? message.valueOf()
48
- : new Error(message ? optionalFunctionValue(message) : message);
49
- }
50
-
51
- function isPositive(value) {
52
- return greaterThan(value, 0);
53
- }
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('vest-utils'), require('vest')) :
3
+ typeof define === 'function' && define.amd ? define(['vest-utils', 'vest'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.classnames = factory(global['vest-utils'], global.vest));
5
+ }(this, (function (vestUtils, vest) { 'use strict';
54
6
 
55
7
  // eslint-disable-next-line max-statements
56
8
  function parse(summary) {
57
- invariant(summary && hasOwnProperty(summary, 'valid'), "Vest parser: expected argument at position 0 to be Vest's result object.");
9
+ vestUtils.invariant(summary && vestUtils.hasOwnProperty(summary, 'valid'), "Vest parser: expected argument at position 0 to be Vest's result object.");
58
10
  var sel = vest.suiteSelectors(summary);
59
11
  var testedStorage = {};
60
12
  var selectors = {
@@ -68,17 +20,17 @@
68
20
  // Booleans
69
21
  function isTested(fieldName) {
70
22
  if (!fieldName) {
71
- return isPositive(summary.testCount);
23
+ return vestUtils.isPositive(summary.testCount);
72
24
  }
73
- if (hasOwnProperty(testedStorage, fieldName))
25
+ if (vestUtils.hasOwnProperty(testedStorage, fieldName))
74
26
  return testedStorage[fieldName];
75
27
  testedStorage[fieldName] =
76
- hasOwnProperty(summary.tests, fieldName) &&
77
- isPositive(summary.tests[fieldName].testCount);
28
+ vestUtils.hasOwnProperty(summary.tests, fieldName) &&
29
+ vestUtils.isPositive(summary.tests[fieldName].testCount);
78
30
  return selectors.tested(fieldName);
79
31
  }
80
32
  function isUntested(fieldName) {
81
- return !(isPositive(summary.testCount) && selectors.tested(fieldName));
33
+ return !(vestUtils.isPositive(summary.testCount) && selectors.tested(fieldName));
82
34
  }
83
35
  }
84
36
 
@@ -92,7 +44,7 @@
92
44
  var classesArray = [];
93
45
  for (var selector in classes) {
94
46
  var sel = selector;
95
- if (isFunction(selectors[sel]) && selectors[sel](key)) {
47
+ if (vestUtils.isFunction(selectors[sel]) && selectors[sel](key)) {
96
48
  classesArray.push(classes[sel]);
97
49
  }
98
50
  }
@@ -1 +1 @@
1
- "use strict";!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("vest")):"function"==typeof define&&define.amd?define(["vest"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).classnames=e(t.vest)}(this,(function(t){function e(t){var e=Number(t);return!(isNaN(parseFloat(String(t)))||isNaN(Number(t))||!isFinite(e))}function n(t,n){return e(t)&&e(n)&&Number(t)>Number(n)}function r(e){!function(t,e){if(!t)throw e instanceof String?e.valueOf():Error(e?function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];return"function"==typeof t?t.apply(void 0,e):t}(e):e)}(e&&Object.prototype.hasOwnProperty.call(e,"valid"),"Vest parser: expected argument at position 0 to be Vest's result object.");var r=t.suiteSelectors(e),o={},i={invalid:r.hasErrors,tested:function(t){return t?Object.prototype.hasOwnProperty.call(o,t)?o[t]:(o[t]=Object.prototype.hasOwnProperty.call(e.tests,t)&&n(e.tests[t].testCount,0),i.tested(t)):n(e.testCount,0)},untested:function(t){return!(n(e.testCount,0)&&i.tested(t))},valid:r.isValid,warning:r.hasWarnings};return i}return function(t,e){void 0===e&&(e={});var n=r(t);return function(t){var r,o=[];for(r in e){var i=r;"function"==typeof n[i]&&n[i](t)&&o.push(e[i])}return o.join(" ")}}}));
1
+ "use strict";!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("vest-utils"),require("vest")):"function"==typeof define&&define.amd?define(["vest-utils","vest"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).classnames=e(t["vest-utils"],t.vest)}(this,(function(t,e){return function(s,n){void 0===n&&(n={});var i=function(s){t.invariant(s&&t.hasOwnProperty(s,"valid"),"Vest parser: expected argument at position 0 to be Vest's result object.");var n=e.suiteSelectors(s),i={},r={invalid:n.hasErrors,tested:function(e){return e?t.hasOwnProperty(i,e)?i[e]:(i[e]=t.hasOwnProperty(s.tests,e)&&t.isPositive(s.tests[e].testCount),r.tested(e)):t.isPositive(s.testCount)},untested:function(e){return!(t.isPositive(s.testCount)&&r.tested(e))},valid:n.isValid,warning:n.hasWarnings};return r}(s);return function(e){var s,r=[];for(s in n){var o=s;t.isFunction(i[o])&&i[o](e)&&r.push(n[o])}return r.join(" ")}}}));