vest 4.5.0 → 4.6.2-dev-fcaa09

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 (81) hide show
  1. package/dist/cjs/enforce_compose.development.js +2 -0
  2. package/dist/cjs/enforce_compose.js +7 -0
  3. package/dist/cjs/enforce_compose.production.js +1 -0
  4. package/dist/cjs/enforce_compounds.development.js +4 -0
  5. package/dist/cjs/enforce_compounds.js +7 -0
  6. package/dist/cjs/enforce_compounds.production.js +1 -0
  7. package/dist/cjs/enforce_schema.development.js +4 -0
  8. package/dist/cjs/enforce_schema.js +7 -0
  9. package/dist/cjs/enforce_schema.production.js +1 -0
  10. package/dist/cjs/vest.development.js +149 -168
  11. package/dist/cjs/vest.production.js +1 -1
  12. package/dist/es/enforce_compose.development.js +1 -0
  13. package/dist/es/enforce_compose.production.js +1 -0
  14. package/dist/es/enforce_compounds.development.js +1 -0
  15. package/dist/es/enforce_compounds.production.js +1 -0
  16. package/dist/es/enforce_schema.development.js +1 -0
  17. package/dist/es/enforce_schema.production.js +1 -0
  18. package/dist/es/vest.development.js +150 -169
  19. package/dist/es/vest.production.js +1 -1
  20. package/dist/umd/classnames.development.js +11 -59
  21. package/dist/umd/classnames.production.js +1 -1
  22. package/dist/umd/enforce_compose.development.js +8 -0
  23. package/dist/umd/enforce_compose.production.js +1 -0
  24. package/dist/umd/enforce_compounds.development.js +8 -0
  25. package/dist/umd/enforce_compounds.production.js +1 -0
  26. package/dist/umd/enforce_schema.development.js +8 -0
  27. package/dist/umd/enforce_schema.production.js +1 -0
  28. package/dist/umd/parser.development.js +10 -58
  29. package/dist/umd/parser.production.js +1 -1
  30. package/dist/umd/promisify.development.js +5 -31
  31. package/dist/umd/promisify.production.js +1 -1
  32. package/dist/umd/vest.development.js +253 -1066
  33. package/dist/umd/vest.production.js +1 -1
  34. package/enforce_compose/package.json +9 -0
  35. package/enforce_compounds/package.json +9 -0
  36. package/enforce_schema/package.json +9 -0
  37. package/package.json +80 -79
  38. package/tsconfig.json +85 -1
  39. package/types/classnames.d.ts +1 -0
  40. package/types/classnames.d.ts.map +1 -0
  41. package/types/enforce_compose.d.ts +2 -0
  42. package/types/enforce_compose.d.ts.map +1 -0
  43. package/types/enforce_compounds.d.ts +2 -0
  44. package/types/enforce_compounds.d.ts.map +1 -0
  45. package/types/enforce_schema.d.ts +2 -0
  46. package/types/enforce_schema.d.ts.map +1 -0
  47. package/types/parser.d.ts +1 -0
  48. package/types/parser.d.ts.map +1 -0
  49. package/types/promisify.d.ts +1 -0
  50. package/types/promisify.d.ts.map +1 -0
  51. package/types/vest.d.ts +40 -37
  52. package/types/vest.d.ts.map +1 -0
  53. package/dist/cjs/compose.js +0 -7
  54. package/dist/cjs/compounds.js +0 -7
  55. package/dist/cjs/enforce/compose.development.js +0 -60
  56. package/dist/cjs/enforce/compose.production.js +0 -1
  57. package/dist/cjs/enforce/compounds.development.js +0 -92
  58. package/dist/cjs/enforce/compounds.production.js +0 -1
  59. package/dist/cjs/enforce/package.json +0 -1
  60. package/dist/cjs/enforce/schema.development.js +0 -92
  61. package/dist/cjs/enforce/schema.production.js +0 -1
  62. package/dist/cjs/schema.js +0 -7
  63. package/dist/es/enforce/compose.development.js +0 -58
  64. package/dist/es/enforce/compose.production.js +0 -1
  65. package/dist/es/enforce/compounds.development.js +0 -90
  66. package/dist/es/enforce/compounds.production.js +0 -1
  67. package/dist/es/enforce/package.json +0 -1
  68. package/dist/es/enforce/schema.development.js +0 -88
  69. package/dist/es/enforce/schema.production.js +0 -1
  70. package/dist/umd/enforce/compose.development.js +0 -736
  71. package/dist/umd/enforce/compose.production.js +0 -1
  72. package/dist/umd/enforce/compounds.development.js +0 -762
  73. package/dist/umd/enforce/compounds.production.js +0 -1
  74. package/dist/umd/enforce/schema.development.js +0 -768
  75. package/dist/umd/enforce/schema.production.js +0 -1
  76. package/enforce/compose/package.json +0 -9
  77. package/enforce/compounds/package.json +0 -9
  78. package/enforce/schema/package.json +0 -9
  79. package/types/enforce/compose.d.ts +0 -126
  80. package/types/enforce/compounds.d.ts +0 -138
  81. package/types/enforce/schema.d.ts +0 -143
@@ -1,6 +1,7 @@
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, isNullish, deferThrow, invariant, isFunction, bindNot, either, isArray, optionalFunctionValue, isEmpty, isNotEmpty, isPositive, numberEquals, hasOwnProperty, callEach, bus, defaultTo, isPromise, isNull } from 'vest-utils';
3
+ import { createCascade } from 'context';
4
+ import { createState } from 'vast';
4
5
 
5
6
  function shouldUseErrorAsMessage(message, error) {
6
7
  // kind of cheating with this safe guard, but it does the job
@@ -58,7 +59,7 @@ function generateIsolate(type, path) {
58
59
  };
59
60
  }
60
61
 
61
- var context = createContext(function (ctxRef, parentContext) {
62
+ var context = createCascade(function (ctxRef, parentContext) {
62
63
  return parentContext
63
64
  ? null
64
65
  : assign({
@@ -88,29 +89,22 @@ function useTestCallbacks() {
88
89
  return useStateRef().testCallbacks();
89
90
  }
90
91
  // OPTIONAL FIELDS
91
- function useOptionalField(fieldName) {
92
- var optionalFields = useOptionalFields()[0];
93
- return optionalFields[fieldName];
94
- }
95
92
  function useOptionalFields() {
96
93
  return useStateRef().optionalFields();
97
94
  }
98
95
  function useSetOptionalField(fieldName, setter) {
99
96
  var _a = useOptionalFields(), setOptionalFields = _a[1];
100
- setOptionalFields(function (optionalFields) {
97
+ setOptionalFields(function (prev) {
101
98
  var _a;
102
- return assign(optionalFields, (_a = {},
103
- _a[fieldName] = optionalFunctionValue(setter, optionalFields[fieldName]),
99
+ return assign(prev, (_a = {},
100
+ _a[fieldName] = assign({}, prev[fieldName], setter(prev[fieldName])),
104
101
  _a));
105
102
  });
106
103
  }
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) {
104
+ function useOptionalField(fieldName) {
112
105
  var _a;
113
- return (_a = useOptionalField(fieldName)) === null || _a === void 0 ? void 0 : _a[0];
106
+ var optionalFields = useOptionalFields()[0];
107
+ return (_a = optionalFields[fieldName]) !== null && _a !== void 0 ? _a : {};
114
108
  }
115
109
  function useTestObjects() {
116
110
  return useStateRef().testObjects();
@@ -240,18 +234,9 @@ var VestTest = /** @class */ (function () {
240
234
  VestTest.prototype.valueOf = function () {
241
235
  return !this.isFailing();
242
236
  };
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
237
  VestTest.prototype.isPending = function () {
250
238
  return this.statusEquals(STATUS_PENDING);
251
239
  };
252
- VestTest.prototype.isTested = function () {
253
- return this.hasFailures() || this.isPassing();
254
- };
255
240
  VestTest.prototype.isOmitted = function () {
256
241
  return this.statusEquals(STATUS_OMITTED);
257
242
  };
@@ -273,6 +258,20 @@ var VestTest = /** @class */ (function () {
273
258
  VestTest.prototype.isWarning = function () {
274
259
  return this.statusEquals(STATUS_WARNING);
275
260
  };
261
+ VestTest.prototype.hasFailures = function () {
262
+ return this.isFailing() || this.isWarning();
263
+ };
264
+ VestTest.prototype.isNonActionable = function () {
265
+ return this.isSkipped() || this.isOmitted() || this.isCanceled();
266
+ };
267
+ VestTest.prototype.isTested = function () {
268
+ return this.hasFailures() || this.isPassing();
269
+ };
270
+ VestTest.prototype.awaitsResolution = function () {
271
+ // Is the test in a state where it can still be run, or complete running
272
+ // and its final status is indeterminate?
273
+ return this.isSkipped() || this.isUntested() || this.isPending();
274
+ };
276
275
  VestTest.prototype.statusEquals = function (status) {
277
276
  return this.status === status;
278
277
  };
@@ -287,70 +286,6 @@ var STATUS_PENDING = 'PENDING';
287
286
  var STATUS_CANCELED = 'CANCELED';
288
287
  var STATUS_OMITTED = 'OMITTED';
289
288
 
290
- // eslint-disable-next-line max-lines-per-function
291
- function createState(onStateChange) {
292
- var state = {
293
- references: []
294
- };
295
- var registrations = [];
296
- return {
297
- registerStateKey: registerStateKey,
298
- reset: reset
299
- };
300
- /**
301
- * Registers a new key in the state, takes the initial value (may be a function that returns the initial value), returns a function.
302
- *
303
- * @example
304
- *
305
- * const useColor = state.registerStateKey("blue");
306
- *
307
- * let [color, setColor] = useColor(); // -> ["blue", Function]
308
- *
309
- * setColor("green");
310
- *
311
- * useColor()[0]; -> "green"
312
- */
313
- function registerStateKey(initialState, onUpdate) {
314
- var key = registrations.length;
315
- registrations.push([initialState, onUpdate]);
316
- return initKey(key, initialState);
317
- }
318
- function reset() {
319
- var prev = current();
320
- state.references = [];
321
- registrations.forEach(function (_a, index) {
322
- var initialValue = _a[0];
323
- return initKey(index, initialValue, prev[index]);
324
- });
325
- }
326
- function initKey(key, initialState, prevState) {
327
- current().push();
328
- set(key, optionalFunctionValue(initialState, prevState));
329
- return function useStateKey() {
330
- return [
331
- current()[key],
332
- function (nextState) {
333
- return set(key, optionalFunctionValue(nextState, current()[key]));
334
- },
335
- ];
336
- };
337
- }
338
- function current() {
339
- return state.references;
340
- }
341
- function set(index, value) {
342
- var prevValue = state.references[index];
343
- state.references[index] = value;
344
- var _a = registrations[index], onUpdate = _a[1];
345
- if (isFunction(onUpdate)) {
346
- onUpdate(value, prevValue);
347
- }
348
- if (isFunction(onStateChange)) {
349
- onStateChange();
350
- }
351
- }
352
- }
353
-
354
289
  function createStateRef(state, _a) {
355
290
  var suiteId = _a.suiteId, suiteName = _a.suiteName;
356
291
  return {
@@ -512,26 +447,85 @@ function hasFailuresByTestObject(testObject, severityKey, fieldName) {
512
447
  return true;
513
448
  }
514
449
 
450
+ /**
451
+ * Marks a field as optional, either just by name, or by a given condition.
452
+ *
453
+ * @example
454
+ *
455
+ * optional('field_name');
456
+ *
457
+ * optional({
458
+ * username: () => allowUsernameEmpty,
459
+ * });
460
+ */
461
+ function optional(optionals) {
462
+ // There are two types of optional field declarations:
463
+ // 1. Delayed: A string, which is the name of the field to be optional.
464
+ // We will only determine whether to omit the test after the suite is done running
465
+ //
466
+ // 2. Immediate: Either a boolean or a function, which is used to determine
467
+ // if the field should be optional.
468
+ // Delayed case (field name)
469
+ if (isArray(optionals) || isStringValue(optionals)) {
470
+ asArray(optionals).forEach(function (optionalField) {
471
+ useSetOptionalField(optionalField, function () { return ({
472
+ type: OptionalFieldTypes.Delayed,
473
+ applied: false,
474
+ rule: null
475
+ }); });
476
+ });
477
+ }
478
+ else {
479
+ var _loop_1 = function (field) {
480
+ var value = optionals[field];
481
+ useSetOptionalField(field, function () { return ({
482
+ type: OptionalFieldTypes.Immediate,
483
+ rule: value,
484
+ applied: optionalFunctionValue(value)
485
+ }); });
486
+ };
487
+ // Immediately case (function or boolean)
488
+ for (var field in optionals) {
489
+ _loop_1(field);
490
+ }
491
+ }
492
+ }
493
+ function optionalFiedIsApplied(fieldName) {
494
+ if (!fieldName) {
495
+ return false;
496
+ }
497
+ return useOptionalField(fieldName).applied;
498
+ }
499
+ var OptionalFieldTypes;
500
+ (function (OptionalFieldTypes) {
501
+ OptionalFieldTypes[OptionalFieldTypes["Immediate"] = 0] = "Immediate";
502
+ OptionalFieldTypes[OptionalFieldTypes["Delayed"] = 1] = "Delayed";
503
+ })(OptionalFieldTypes || (OptionalFieldTypes = {}));
504
+
515
505
  // eslint-disable-next-line max-statements, complexity
516
506
  function shouldAddValidProperty(fieldName) {
517
- if (fieldIsOmitted(fieldName)) {
507
+ // Is the field optional, and the optional condition is applied
508
+ if (optionalFiedIsApplied(fieldName)) {
518
509
  return true;
519
510
  }
520
- if (hasErrorsByTestObjects(fieldName)) {
521
- return false;
522
- }
523
511
  var testObjects = useTestsFlat();
512
+ // Are there no tests?
524
513
  if (isEmpty(testObjects)) {
525
514
  return false;
526
515
  }
516
+ // Does the field have any tests with errors?
517
+ if (hasErrorsByTestObjects(fieldName)) {
518
+ return false;
519
+ }
527
520
  // Does the given field have any pending tests that are not optional?
528
521
  if (hasNonOptionalIncomplete(fieldName)) {
529
522
  return false;
530
523
  }
524
+ // Does the field have no missing tests?
531
525
  return noMissingTests(fieldName);
532
526
  }
533
527
  function shouldAddValidPropertyInGroup(groupName, fieldName) {
534
- if (fieldIsOmitted(fieldName)) {
528
+ if (optionalFiedIsApplied(fieldName)) {
535
529
  return true;
536
530
  }
537
531
  if (hasGroupFailuresByTestObjects(Severity.ERRORS, groupName, fieldName)) {
@@ -543,16 +537,10 @@ function shouldAddValidPropertyInGroup(groupName, fieldName) {
543
537
  }
544
538
  return noMissingTestsByGroup(groupName, fieldName);
545
539
  }
546
- function fieldIsOmitted(fieldName) {
547
- if (!fieldName) {
548
- return false;
549
- }
550
- return useOptionalFieldApplied(fieldName) === true;
551
- }
552
540
  // Does the given field have any pending tests that are not optional?
553
541
  function hasNonOptionalIncomplete(fieldName) {
554
542
  return isNotEmpty(useAllIncomplete().filter(function (testObject) {
555
- return isOptionalFieldIncomplete(testObject, fieldName);
543
+ return isTestObjectOptional(testObject, fieldName);
556
544
  }));
557
545
  }
558
546
  // Do the given group/field have any pending tests that are not optional?
@@ -561,41 +549,57 @@ function hasNonOptionalIncompleteByGroup(groupName, fieldName) {
561
549
  if (nonMatchingGroupName(testObject, groupName)) {
562
550
  return false;
563
551
  }
564
- return isOptionalFieldIncomplete(testObject, fieldName);
552
+ return isTestObjectOptional(testObject, fieldName);
565
553
  }));
566
554
  }
567
- function isOptionalFieldIncomplete(testObject, fieldName) {
555
+ function isTestObjectOptional(testObject, fieldName) {
568
556
  if (nonMatchingFieldName(testObject, fieldName)) {
569
557
  return false;
570
558
  }
571
- return useOptionalFieldConfig(testObject.fieldName) !== true;
559
+ return optionalFiedIsApplied(fieldName);
572
560
  }
561
+ // Did all of the tests for the provided field run/omit?
562
+ // This makes sure that the fields are not skipped or pending.
573
563
  function noMissingTests(fieldName) {
574
564
  var testObjects = useTestsFlat();
575
565
  return testObjects.every(function (testObject) {
576
- if (nonMatchingFieldName(testObject, fieldName)) {
577
- return true;
578
- }
579
- return missingTestsLogic(testObject, fieldName);
566
+ return noMissingTestsLogic(testObject, fieldName);
580
567
  });
581
568
  }
569
+ // Does the group have no missing tests?
582
570
  function noMissingTestsByGroup(groupName, fieldName) {
583
571
  var testObjects = useTestsFlat();
584
572
  return testObjects.every(function (testObject) {
585
573
  if (nonMatchingGroupName(testObject, groupName)) {
586
574
  return true;
587
575
  }
588
- return missingTestsLogic(testObject, fieldName);
576
+ return noMissingTestsLogic(testObject, fieldName);
589
577
  });
590
578
  }
591
- function missingTestsLogic(testObject, fieldName) {
579
+ // Does the object qualify as either tested or omitted (but not skipped!)
580
+ function noMissingTestsLogic(testObject, fieldName) {
592
581
  if (nonMatchingFieldName(testObject, fieldName)) {
593
582
  return true;
594
583
  }
595
- return (useOptionalFieldConfig(testObject.fieldName) === true ||
584
+ /**
585
+ * The reason we're checking for the optional field here and not in "omitOptionalFields"
586
+ * is because that unlike the bool/function check we do there, here it only depends on
587
+ * whether the field was tested alredy or not.
588
+ *
589
+ * We qualify the test as not missing only if it was already run, if it is omitted,
590
+ * or if it is marked as optional, even if the optional check did not apply yet -
591
+ * but the test did not reach its final state.
592
+ */
593
+ return (optionalTestAwaitsResolution(testObject) ||
596
594
  testObject.isTested() ||
597
595
  testObject.isOmitted());
598
596
  }
597
+ function optionalTestAwaitsResolution(testObject) {
598
+ // Does the test belong to an optional field,
599
+ // and the test itself is still in an indeterminate state?
600
+ return (useOptionalField(testObject.fieldName).type ===
601
+ OptionalFieldTypes.Delayed && testObject.awaitsResolution());
602
+ }
599
603
 
600
604
  /**
601
605
  * Reads the testObjects list and gets full validation result from it.
@@ -899,34 +903,48 @@ function deferDoneCallback(doneCallback, fieldName) {
899
903
  });
900
904
  }
901
905
 
906
+ /**
907
+ * This module gets triggered once the suite is done running its sync tests.
908
+ *
909
+ * It goes over all the tests in the state, and checks if they need to be omitted.
910
+ */
902
911
  function omitOptionalFields() {
903
912
  var optionalFields = useOptionalFields()[0];
913
+ // If there are no optional fields, we don't need to do anything
904
914
  if (isEmpty(optionalFields)) {
905
915
  return;
906
916
  }
917
+ // Create an object to store the fields that need to be omitted
907
918
  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
- });
919
+ // iterate over each of the tests in the state
920
+ useTestsFlat().forEach(function (testObject) {
921
+ // If we already added the current field (not this test specifically)
922
+ // no need for further checks, go and omit the test
923
+ if (hasOwnProperty(shouldOmit, testObject.fieldName)) {
924
+ verifyAndOmit(testObject);
925
+ }
926
+ else {
927
+ // check if the field has an optional function
928
+ // if so, run it and verify/omit the test
929
+ runOptionalConfig(testObject);
930
+ }
919
931
  });
932
+ // refresh the tests in the state so that the omitted fields are applied
933
+ useRefreshTestObjects();
920
934
  function verifyAndOmit(testObject) {
921
935
  if (shouldOmit[testObject.fieldName]) {
922
936
  testObject.omit();
923
- useSetOptionalField(testObject.fieldName, function (current) { return [current[0], true]; });
937
+ useSetOptionalField(testObject.fieldName, function () { return ({
938
+ applied: true
939
+ }); });
924
940
  }
925
941
  }
926
942
  function runOptionalConfig(testObject) {
927
- var optionalConfig = useOptionalFieldConfig(testObject.fieldName);
928
- if (isFunction(optionalConfig)) {
929
- shouldOmit[testObject.fieldName] = optionalConfig();
943
+ // Ge the optional configuration for the given field
944
+ var optionalConfig = useOptionalField(testObject.fieldName);
945
+ // If the optional was set to a function or a boolean, run it and verify/omit the test
946
+ if (optionalConfig.type === OptionalFieldTypes.Immediate) {
947
+ shouldOmit[testObject.fieldName] = optionalFunctionValue(optionalConfig.rule);
930
948
  verifyAndOmit(testObject);
931
949
  }
932
950
  }
@@ -1350,44 +1368,16 @@ function setMode(nextMode) {
1350
1368
  function omitWhen(conditional, callback) {
1351
1369
  isolate({ type: IsolateTypes.OMIT_WHEN }, function () {
1352
1370
  context.run({
1353
- omitted: isOmitted() ||
1371
+ omitted: inActiveOmitWhen() ||
1354
1372
  optionalFunctionValue(conditional, optionalFunctionValue(produceSuiteResult))
1355
1373
  }, function () { return callback(); });
1356
1374
  });
1357
1375
  }
1358
- function isOmitted() {
1376
+ // Checks that we're currently in an active omitWhen block
1377
+ function inActiveOmitWhen() {
1359
1378
  return !!context.useX().omitted;
1360
1379
  }
1361
1380
 
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
1381
  /******************************************************************************
1392
1382
  Copyright (c) Microsoft Corporation.
1393
1383
 
@@ -1413,8 +1403,6 @@ function __spreadArray(to, from, pack) {
1413
1403
  return to.concat(ar || Array.prototype.slice.call(from));
1414
1404
  }
1415
1405
 
1416
- bindNot(isStringValue);
1417
-
1418
1406
  function isSameProfileTest(testObject1, testObject2) {
1419
1407
  return (testObject1.fieldName === testObject2.fieldName &&
1420
1408
  testObject1.groupName === testObject2.groupName);
@@ -1452,14 +1440,7 @@ function runAsyncTest(testObject) {
1452
1440
  testObject.fail();
1453
1441
  done();
1454
1442
  });
1455
- try {
1456
- asyncTest.then(done, fail);
1457
- }
1458
- catch (e) {
1459
- // We will probably never get here, unless the consumer uses a buggy custom Promise
1460
- // implementation that behaves differently than the native one, or if they for some
1461
- fail();
1462
- }
1443
+ asyncTest.then(done, fail);
1463
1444
  }
1464
1445
 
1465
1446
  /**
@@ -1577,7 +1558,7 @@ function registerPrevRunTest(testObject) {
1577
1558
  return testObject;
1578
1559
  }
1579
1560
  var prevRunTest = useTestAtCursor(testObject);
1580
- if (isOmitted()) {
1561
+ if (inActiveOmitWhen() || optionalFiedIsApplied(testObject.fieldName)) {
1581
1562
  prevRunTest.omit();
1582
1563
  cursor.next();
1583
1564
  return prevRunTest;
@@ -1678,6 +1659,6 @@ function warn() {
1678
1659
  ctx.currentTest.warn();
1679
1660
  }
1680
1661
 
1681
- var VERSION = "4.5.0";
1662
+ var VERSION = "4.6.2-dev-fcaa09";
1682
1663
 
1683
1664
  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{createState as t}from"vast";import{createCascade as n}from"context";import{isUndefined as e,isStringValue as r,assign as i,cache as u,nestedArray as s,asArray as o,seq as a,isNullish as c,deferThrow as f,invariant as l,isFunction as d,bindNot as p,either as v,isArray as E,optionalFunctionValue as N,isEmpty as m,isNotEmpty as h,isPositive as g,numberEquals as y,hasOwnProperty as R,callEach as S,bus as C,defaultTo as T,isPromise as _,isNull as O}from"vest-utils";export{enforce}from"n4s";var I,A=I||(I={});A[A.DEFAULT=0]="DEFAULT",A[A.SUITE=1]="SUITE",A[A.EACH=2]="EACH",A[A.SKIP_WHEN=3]="SKIP_WHEN",A[A.OMIT_WHEN=4]="OMIT_WHEN",A[A.GROUP=5]="GROUP";var k,b=k||(k={});function U(){var t=0;return{current:function(){return t},next:function(){t++}}}function L(t,n){return void 0===n&&(n=[]),{cursor:U(),keys:{current:{},prev:{}},path:n,type:t}}b[b.ALL=0]="ALL",b[b.EAGER=1]="EAGER";var F=n((function(t,n){return n?null:i({exclusion:{tests:{},groups:{}},inclusion:{},isolate:L(I.DEFAULT),mode:[k.ALL]},t)}));function D(){return F.useX().stateRef}function W(t,n){(0,D().optionalFields()[1])((function(e){var r;return i(e,((r={})[t]=i({},e[t],n(e[t])),r))}))}function P(t){var n;return null!==(n=D().optionalFields()[0][t])&&void 0!==n?n:{}}function G(){w((function(t){return t}))}function w(t){(0,D().testObjects()[1])((function(n){return{prev:n.prev,current:o(t(n.current))}}))}function x(){return H().filter((function(t){return t.isPending()}))}var X=u();function H(){var t=D().testObjects()[0].current;return X([t],(function(){return s.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(n){t=n,e(this.message)&&r(t)&&(this.message=n),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),G()},t.prototype.reset=function(){this.status=B,G()},t.prototype.omit=function(){this.setStatus(Z)},t.prototype.valueOf=function(){return!this.isFailing()},t.prototype.isPending=function(){return this.statusEquals(z)},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.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}(),B="UNTESTED",V="SKIPPED",j="FAILED",Y="WARNING",J="PASSING",z="PENDING",Q="CANCELED",Z="OMITTED";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 F.useX().isolate}function nt(){var t=tt();return t.path.concat(t.cursor.current())}function et(t,n){t=void 0===(t=t.type)?I.DEFAULT:t,l(d(n));var e=L(t,nt());return t=F.run({isolate:e},(function(){return e.keys.prev=function(){var t=D().testObjects()[0].prev;return o(s.getCurrent(t,nt())).reduce((function(t,n){return n instanceof q&&!c(n.key)?(t[n.key]=n,t):t}),{})}(),w((function(t){return s.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 H().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&&P(t).applied}var dt,pt=dt||(dt={});function vt(t){if(lt(t))return!0;var n=H();return!(m(n)||ct(rt.ERRORS,t)||function(t){return h(x().filter((function(n){return Et(n,t)})))}(t))&&function(t){return H().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))||(P(t.fieldName).type===dt.Delayed&&t.awaitsResolution()||t.isTested()||t.isOmitted())}function mt(){var t=H(),n=i({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&&vt(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=!!lt(n=n.fieldName)||!function(t,n,e){return H().some((function(r){return!at(r,n)&&ft(r,t,e)}))}(rt.ERRORS,i,n)&&!function(t,n){return h(x().filter((function(e){return!at(e,t)&&Et(e,n)})))}(i,n)&&function(t,n){return H().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 ht(t,n){function e(t){s[t===rt.ERRORS?ut.ERROR_COUNT:ut.WARN_COUNT]++,u&&(s[t]=(s[t]||[]).concat(u))}var r=n.fieldName,u=n.message;t[r]=t[r]||i({errorCount:0,warnCount:0,testCount:0},{errors:[],warnings:[]});var s=t[r];return n.isNonActionable()||(t[r].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)g(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 g(null===(i=t[r])||void 0===i?void 0:i[n]);for(var s in t)if(g(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,g(t)}pt[pt.Immediate=0]="Immediate",pt[pt.Delayed=1]="Delayed";var Tt=u(1);function _t(){var t=H(),n={stateRef:D()};return Tt([t],F.bind(n,(function(){var t=mt(),n=D().suiteName()[0];return i(t,yt(t),{suiteName:n})})))}function Ot(t){var n=x();return!m(n)&&(!t||n.some((function(n){return ot(n,t)})))}var It=u(20);function At(){var t=H(),n={stateRef:D()};return It([t],F.bind(n,(function(){return i({},_t(),{done:F.bind(n,Ut)})})))}function kt(t,n,e){var r;return!!(!d(t)||n&&y(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,D().testCallbacks()[1])((function(e){return n?e.fieldCallbacks[n]=(e.fieldCallbacks[n]||[]).concat(t):e.doneCallbacks.push(t),e}))}function Ft(){var t=C.createBus();return t.on(Wt.TEST_COMPLETED,(function(n){if(!n.isCanceled()){n.done(),n=n.fieldName;var e=D().testCallbacks()[0].fieldCallbacks;n&&!Ot(n)&&E(e[n])&&S(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(),W(t.fieldName,(function(){return{applied:!0}})))}var n=D().optionalFields()[0];if(!m(n)){var e={};H().forEach((function(n){if(R(e,n.fieldName))t(n);else{var r=P(n.fieldName);r.type===dt.Immediate&&(e[n.fieldName]=N(r.rule),t(n))}})),G()}}()})),t.on(Wt.ALL_RUNNING_TESTS_FINISHED,(function(){var t=D().testCallbacks()[0].doneCallbacks;S(t)})),t.on(Wt.REMOVE_FIELD,(function(t){H().forEach((function(n){ot(n,t)&&(n.cancel(),function(t){w((function(n){return s.transform(n,(function(n){return t!==n?n:null}))}))}(n))}))})),t.on(Wt.RESET_FIELD,(function(t){H().forEach((function(n){ot(n,t)&&n.reset()}))})),t}function Dt(){var t=F.useX();return l(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,e){var i=F.useX("hook called outside of a running suite.");e&&o(e).forEach((function(e){r(e)&&(i.exclusion[n][e]=0===t)}))}function Xt(t){for(var n in t)if(!0===t[n])return!0;return!1}function Ht(){var t,n=F.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,e=t.message;if(_(n)){var i=Dt().emit,u=D(),s=F.bind({stateRef:u},(function(){G(),i(Wt.TEST_COMPLETED,t)}));u=F.bind({stateRef:u},(function(n){t.isCanceled()||(t.message=r(n)?n:e,t.fail(),s())})),n.then(s,u)}}function Bt(t){var n=D().testObjects()[0].prev;if(m(n))return Vt(t),t;var e=nt();if(n=s.valueAtPath(n,e),!c(t.key)){n=t.key,(e=tt().keys.prev[n])&&(t=e),e=t;var r=tt().keys.current;return c(r[n])?r[n]=e:f('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===I.EACH||f("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();w((function(n){return n.splice(t),n}))}(),n=null),Vt(t=T(n,t)),t}function Vt(t){var n=nt();w((function(e){return s.setValueAtPath(e,n,t)}))}function jt(t){var n=tt().cursor,e=k.EAGER;if(F.useX().mode[0]===e&&ct(rt.ERRORS,t.fieldName))return t.skip(),Bt(t),n.next(),t;if(e=Bt(t),F.useX().omitted||lt(t.fieldName))return e.omit(),n.next(),e;if(function(t){var n=t.fieldName;if(t=t.groupName,F.useX().skipped)return!0;var e=F.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=F.useX().exclusion.groups;if(s=R(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)&&!N(e[n])}(t))return e.skip(!!F.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 F.run({currentTest:t},(function(){return t.run()}))}(t);try{_(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.asyncTest)&&(t.setPending(),qt(t));return n.next(),t}function Yt(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];var i=d(n[1])?n:Mt([void 0],n,!0);n=i[0],e=i[1],i=i[2],l(r(t),Zt("fieldName","string")),l(d(e),Zt("Test callback","function"));var u=F.useX();return jt(n=new q(t,e,{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=i(Yt,{memo:(Jt=Yt,zt=u(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=[D().suiteId()[0],t,e].concat(r),n=zt.get(e),O(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="4.6.2-dev-fcaa09";function tn(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var r=(n=n.reverse())[0];n=n[1],l(d(r),"vest.create: Expected callback to be a function.");var u=Ft(),s=t();return n={stateRef:$(s,{suiteId:a(),suiteName:n}),bus:u},i(F.bind(n,(function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return s.reset(),et({type:I.SUITE},(function(){r.apply(void 0,t)})),u.emit(Wt.SUITE_CALLBACK_DONE_RUNNING),At()})),{get:F.bind(n,_t),remove:F.bind(n,(function(t){u.emit(Wt.REMOVE_FIELD,t)})),reset:s.reset,resetField:F.bind(n,(function(t){u.emit(Wt.RESET_FIELD,t)}))})}function nn(t,n){l(d(n),"each callback must be a function"),et({type:I.EACH},(function(){t.forEach((function(t,e){n(t,e)}))}))}function en(){var t=k.EAGER;F.useX().mode[0]=t}function rn(t,n){l(r(t),Kt("name must be a string")),l(d(n),Kt("callback must be a function")),et({type:I.GROUP},(function(){F.run({groupName:t},n)}))}function un(t){var n=F.useX(),e=n.inclusion;return n=n.exclusion,l(r(t)),e[t]=T(n.tests[t],!0),{when:function(n){var e=F.useX(),i=e.exclusion;e.inclusion[t]=function(){return R(i.tests,t)?T(i.tests[t],!0):r(n)?!!i.tests[n]:N(n,N(_t))}}}}function sn(t,n){et({type:I.OMIT_WHEN},(function(){F.run({omitted:!!F.useX().omitted||N(t,N(_t))},(function(){return n()}))}))}function on(t){if(E(t)||r(t))o(t).forEach((function(t){W(t,(function(){return{type:dt.Delayed,applied:!1,rule:null}}))}));else{var n,e=function(n){var e=t[n];W(n,(function(){return{type:dt.Immediate,rule:e,applied:N(e)}}))};for(n in t)e(n)}}function an(t,n){et({type:I.SKIP_WHEN},(function(){F.run({skipped:!!F.useX().skipped||N(t,N(_t))},(function(){return n()}))}))}function cn(){var t=F.useX("warn hook called outside of a running suite.");l(t.currentTest,"warn called outside of a test."),t.currentTest.warn()}export{$t as VERSION,F 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
  }