vest 5.0.0-dev-781e21 → 5.0.0-dev-9c596e

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 (70) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +2 -57
  3. package/dist/cjs/classnames.development.js +38 -17
  4. package/dist/cjs/classnames.production.js +1 -1
  5. package/dist/cjs/enforce/compose.development.js +5 -54
  6. package/dist/cjs/enforce/compose.production.js +1 -1
  7. package/dist/cjs/enforce/compounds.development.js +20 -83
  8. package/dist/cjs/enforce/compounds.production.js +1 -1
  9. package/dist/cjs/enforce/schema.development.js +19 -82
  10. package/dist/cjs/enforce/schema.production.js +1 -1
  11. package/dist/cjs/parser.development.js +31 -9
  12. package/dist/cjs/parser.production.js +1 -1
  13. package/dist/cjs/promisify.development.js +22 -9
  14. package/dist/cjs/promisify.production.js +1 -1
  15. package/dist/cjs/vest.development.js +1421 -1223
  16. package/dist/cjs/vest.production.js +1 -1
  17. package/dist/es/classnames.development.js +40 -19
  18. package/dist/es/classnames.production.js +1 -1
  19. package/dist/es/enforce/compose.development.js +1 -58
  20. package/dist/es/enforce/compose.production.js +1 -1
  21. package/dist/es/enforce/compounds.development.js +2 -90
  22. package/dist/es/enforce/compounds.production.js +1 -1
  23. package/dist/es/enforce/schema.development.js +2 -88
  24. package/dist/es/enforce/schema.production.js +1 -1
  25. package/dist/es/parser.development.js +32 -10
  26. package/dist/es/parser.production.js +1 -1
  27. package/dist/es/promisify.development.js +23 -10
  28. package/dist/es/promisify.production.js +1 -1
  29. package/dist/es/vest.development.js +1415 -1214
  30. package/dist/es/vest.production.js +1 -1
  31. package/dist/umd/classnames.development.js +41 -20
  32. package/dist/umd/classnames.production.js +1 -1
  33. package/dist/umd/enforce/compose.development.js +9 -57
  34. package/dist/umd/enforce/compose.production.js +1 -1
  35. package/dist/umd/enforce/compounds.development.js +32 -94
  36. package/dist/umd/enforce/compounds.production.js +1 -1
  37. package/dist/umd/enforce/schema.development.js +32 -94
  38. package/dist/umd/enforce/schema.production.js +1 -1
  39. package/dist/umd/parser.development.js +34 -12
  40. package/dist/umd/parser.production.js +1 -1
  41. package/dist/umd/promisify.development.js +25 -12
  42. package/dist/umd/promisify.production.js +1 -1
  43. package/dist/umd/vest.development.js +1423 -1225
  44. package/dist/umd/vest.production.js +1 -1
  45. package/package.json +12 -16
  46. package/testUtils/TVestMock.ts +7 -0
  47. package/testUtils/__tests__/partition.test.ts +4 -4
  48. package/testUtils/mockThrowError.ts +4 -2
  49. package/testUtils/suiteDummy.ts +4 -1
  50. package/testUtils/testDummy.ts +12 -10
  51. package/testUtils/testPromise.ts +3 -0
  52. package/types/classnames.d.ts +63 -12
  53. package/types/classnames.d.ts.map +1 -0
  54. package/types/enforce/compose.d.ts +2 -126
  55. package/types/enforce/compose.d.ts.map +1 -0
  56. package/types/enforce/compounds.d.ts +2 -136
  57. package/types/enforce/compounds.d.ts.map +1 -0
  58. package/types/enforce/schema.d.ts +2 -144
  59. package/types/enforce/schema.d.ts.map +1 -0
  60. package/types/parser.d.ts +69 -18
  61. package/types/parser.d.ts.map +1 -0
  62. package/types/promisify.d.ts +60 -42
  63. package/types/promisify.d.ts.map +1 -0
  64. package/types/vest.d.ts +246 -243
  65. package/types/vest.d.ts.map +1 -0
  66. package/CHANGELOG.md +0 -87
  67. package/testUtils/expandStateRef.ts +0 -8
  68. package/testUtils/runCreateRef.ts +0 -10
  69. package/testUtils/testObjects.ts +0 -6
  70. package/tsconfig.json +0 -8
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 ealush
3
+ Copyright (c) 2022 ealush
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,58 +1,3 @@
1
- # Vest - Declarative validations framework
1
+ # vest-5
2
2
 
3
- [Vest Documentation](https://vestjs.dev)
4
-
5
- [![Join Discord](https://badgen.net/discord/online-members/WmADZpJnSe?icon=discord&label=Discord)](https://discord.gg/WmADZpJnSe) [![Github Stars](https://badgen.net/github/stars/ealush/vest?color=yellow&label=Github%20🌟)](https://github.com/ealush/vest) [![Version](https://badgen.net/npm/v/vest?&icon=npm)](https://www.npmjs.com/package/vest) [![Downloads](https://badgen.net/npm/dt/vest?label=Downloads)](https://www.npmjs.com/package/vest) [![bundlephobia](https://badgen.net/bundlephobia/minzip/vest)](https://bundlephobia.com/package/vest) [![Status](https://badgen.net/github/status/ealush/vest)](https://github.com/ealush/vest/actions)
6
-
7
- ![Vest](https://cdn.jsdelivr.net/gh/ealush/vest@assets/logo_250.png 'Vest')
8
-
9
- Vest is a form-validation framework inspired by unit testing libraries like Mocha or Jest; It is designed to be easy to use and easy to learn by introducing their declarative syntax.
10
-
11
- The idea behind Vest is that your validations can be described as a suite - a contract that reflects your form or feature structure. Vest is framework agnostic, meaning it can be used with any UI framework, or without any framework at all.
12
-
13
- Using Vest for form validation can reduce bloat, improve feature readability and maintainability.
14
-
15
- ```js
16
- test('username', 'Username is required', () => {
17
- enforce(data.username).isNotBlank();
18
- });
19
-
20
- test('username', 'Username must be at least 3 chars', () => {
21
- enforce(data.username).longerThanOrEquals(3);
22
- });
23
- ```
24
-
25
- ## Installation
26
-
27
- ```
28
- npm i vest
29
- ```
30
-
31
- ## Motivation
32
-
33
- Writing forms is an integral part of building web apps, and even though it may seem trivial at first - as your feature grows over time, so does your validation logic grows in complexity.
34
-
35
- Vest tries to remediate this by separating validation logic from feature logic, so it's easier to maintain over time and refactor when needed.
36
-
37
- # Why Vest?
38
-
39
- 💡 Vest is easy to Learn. Vest adopts the syntax and style of unit testing frameworks, so you can leverage the knowledge you already have to write your form validations.
40
-
41
- 🎨 Vest is framework agnostic. You can use Vest with any UI framework out there.
42
-
43
- 🧠 Vest takes care of all the annoying parts for you. It manages its validation state, handles async validations, and much more.
44
-
45
- 🧩 Vest is extendable. You can easily add new kinds of validations to Vest according to your needs.
46
-
47
- ♻️ Validation logic in Vest can be shared across multiple features in your app.
48
-
49
- # Getting Started
50
-
51
- [Vest Documentation](https://vestjs.dev)
52
-
53
- Here are some code sandboxes to get you started:
54
-
55
- - [React](https://codesandbox.io/s/react-28jwx)
56
- - [Vue](https://codesandbox.io/s/vue-hsyt8)
57
- - [Svelte](https://codesandbox.io/s/svelte-tsfhx)
58
- - [Vanilla](https://codesandbox.io/s/vest-vanilla-js-35u8e)
3
+ Declarative Form Validations Framework
@@ -3,30 +3,52 @@
3
3
  var vestUtils = require('vest-utils');
4
4
  var vest = require('vest');
5
5
 
6
- // eslint-disable-next-line max-statements
6
+ var ErrorStrings;
7
+ (function (ErrorStrings) {
8
+ ErrorStrings["HOOK_CALLED_OUTSIDE"] = "hook called outside of a running suite.";
9
+ ErrorStrings["EXPECTED_VEST_TEST"] = "Expected value to be an instance of IsolateTest";
10
+ ErrorStrings["FIELD_NAME_REQUIRED"] = "Field name must be passed";
11
+ ErrorStrings["SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION"] = "Suite must be initialized with a function";
12
+ ErrorStrings["NO_ACTIVE_ISOLATE"] = "Not within an active isolate";
13
+ ErrorStrings["PROMISIFY_REQUIRE_FUNCTION"] = "Vest.Promisify must be called with a function";
14
+ ErrorStrings["PARSER_EXPECT_RESULT_OBJECT"] = "Vest parser: expected argument at position 0 to be Vest's result object.";
15
+ ErrorStrings["WARN_MUST_BE_CALLED_FROM_TEST"] = "Warn must be called from within the body of a test function";
16
+ ErrorStrings["EACH_CALLBACK_MUST_BE_A_FUNCTION"] = "Each must be called with a function";
17
+ ErrorStrings["INVALID_PARAM_PASSED_TO_FUNCTION"] = "Incompatible params passed to {fn_name} function. \"{param}\" must be of type {expected}";
18
+ ErrorStrings["ENCOUNTERED_THE_SAME_KEY_TWICE"] = "Encountered the same test key \"{key}\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.";
19
+ ErrorStrings["TESTS_CALLED_IN_DIFFERENT_ORDER"] = "Vest Critical Error: Tests called in different order than previous run.\n expected: {fieldName}\n received: {prevName}\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.";
20
+ ErrorStrings["UNEXPECTED_TEST_REGISTRATION_ERROR"] = "Unexpected error encountered during test registration.\n Please report this issue to Vest's Github repository.\n Test Object: {testObject}.\n Error: {error}.";
21
+ })(ErrorStrings || (ErrorStrings = {}));
22
+
23
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
24
+ // @ts-ignore - Need to understand why Vest is not being recognized
7
25
  function parse(summary) {
8
- vestUtils.invariant(summary && vestUtils.hasOwnProperty(summary, 'valid'), "Vest parser: expected argument at position 0 to be Vest's result object.");
9
- var sel = vest.suiteSelectors(summary);
10
- var testedStorage = {};
11
- var selectors = {
26
+ vestUtils.invariant(summary && vestUtils.hasOwnProperty(summary, 'valid'), ErrorStrings.PARSER_EXPECT_RESULT_OBJECT);
27
+ const sel = vest.suiteSelectors(summary);
28
+ const testedStorage = {};
29
+ const selectors = {
12
30
  invalid: sel.hasErrors,
13
31
  tested: isTested,
14
32
  untested: isUntested,
15
33
  valid: sel.isValid,
16
- warning: sel.hasWarnings
34
+ warning: sel.hasWarnings,
17
35
  };
18
36
  return selectors;
19
37
  // Booleans
20
38
  function isTested(fieldName) {
21
- if (!fieldName) {
39
+ if (vestUtils.isNullish(fieldName)) {
22
40
  return vestUtils.isPositive(summary.testCount);
23
41
  }
24
- if (vestUtils.hasOwnProperty(testedStorage, fieldName))
42
+ if (vestUtils.hasOwnProperty(testedStorage, fieldName)) {
25
43
  return testedStorage[fieldName];
44
+ }
45
+ addFieldToTestedStorage(fieldName);
46
+ return selectors.tested(fieldName);
47
+ }
48
+ function addFieldToTestedStorage(fieldName) {
26
49
  testedStorage[fieldName] =
27
50
  vestUtils.hasOwnProperty(summary.tests, fieldName) &&
28
51
  vestUtils.isPositive(summary.tests[fieldName].testCount);
29
- return selectors.tested(fieldName);
30
52
  }
31
53
  function isUntested(fieldName) {
32
54
  return !(vestUtils.isPositive(summary.testCount) && selectors.tested(fieldName));
@@ -36,14 +58,13 @@ function parse(summary) {
36
58
  /**
37
59
  * Creates a function that returns class names that match the validation result
38
60
  */
39
- function classnames(res, classes) {
40
- if (classes === void 0) { classes = {}; }
41
- var selectors = parse(res);
42
- return function (key) {
43
- var classesArray = [];
44
- for (var selector in classes) {
45
- var sel = selector;
46
- if (vestUtils.isFunction(selectors[sel]) && selectors[sel](key)) {
61
+ function classnames(res, classes = {}) {
62
+ const selectors = parse(res);
63
+ return function cn(fieldName) {
64
+ const classesArray = [];
65
+ for (const selector in classes) {
66
+ const sel = selector;
67
+ if (vestUtils.isFunction(selectors[sel]) && selectors[sel](fieldName)) {
47
68
  classesArray.push(classes[sel]);
48
69
  }
49
70
  }
@@ -1 +1 @@
1
- "use strict";var t=require("vest-utils"),e=require("vest");module.exports=function(s,r){void 0===r&&(r={});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 r=e.suiteSelectors(s),i={},n={invalid:r.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),n.tested(e)):t.isPositive(s.testCount)},untested:function(e){return!(t.isPositive(s.testCount)&&n.tested(e))},valid:r.isValid,warning:r.hasWarnings};return n}(s);return function(e){var s,n=[];for(s in r){var o=s;t.isFunction(i[o])&&i[o](e)&&n.push(r[o])}return n.join(" ")}};
1
+ "use strict";var e,t=require("vest-utils"),s=require("vest");!function(e){e.HOOK_CALLED_OUTSIDE="hook called outside of a running suite.",e.EXPECTED_VEST_TEST="Expected value to be an instance of IsolateTest",e.FIELD_NAME_REQUIRED="Field name must be passed",e.SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION="Suite must be initialized with a function",e.NO_ACTIVE_ISOLATE="Not within an active isolate",e.PROMISIFY_REQUIRE_FUNCTION="Vest.Promisify must be called with a function",e.PARSER_EXPECT_RESULT_OBJECT="Vest parser: expected argument at position 0 to be Vest's result object.",e.WARN_MUST_BE_CALLED_FROM_TEST="Warn must be called from within the body of a test function",e.EACH_CALLBACK_MUST_BE_A_FUNCTION="Each must be called with a function",e.INVALID_PARAM_PASSED_TO_FUNCTION='Incompatible params passed to {fn_name} function. "{param}" must be of type {expected}',e.ENCOUNTERED_THE_SAME_KEY_TWICE='Encountered the same test key "{key}" twice. This may lead to tests overriding each other\'s results, or to tests being unexpectedly omitted.',e.TESTS_CALLED_IN_DIFFERENT_ORDER='Vest Critical Error: Tests called in different order than previous run.\n expected: {fieldName}\n received: {prevName}\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.',e.UNEXPECTED_TEST_REGISTRATION_ERROR="Unexpected error encountered during test registration.\n Please report this issue to Vest's Github repository.\n Test Object: {testObject}.\n Error: {error}."}(e||(e={})),module.exports=function(n,i={}){const o=function(n){t.invariant(n&&t.hasOwnProperty(n,"valid"),e.PARSER_EXPECT_RESULT_OBJECT);const i=s.suiteSelectors(n),o={},r={invalid:i.hasErrors,tested:function(e){return t.isNullish(e)?t.isPositive(n.testCount):t.hasOwnProperty(o,e)?o[e]:(a(e),r.tested(e))},untested:function(e){return!(t.isPositive(n.testCount)&&r.tested(e))},valid:i.isValid,warning:i.hasWarnings};return r;function a(e){o[e]=t.hasOwnProperty(n.tests,e)&&t.isPositive(n.tests[e].testCount)}}(n);return function(e){const s=[];for(const n in i){const r=n;t.isFunction(o[r])&&o[r](e)&&s.push(i[r])}return s.join(" ")}};
@@ -1,60 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var n4s = require('n4s');
4
- var vestUtils = require('vest-utils');
3
+ var compose = require('n4s/compose');
5
4
 
6
- function ruleReturn(pass, message) {
7
- var output = { pass: pass };
8
- if (message) {
9
- output.message = message;
10
- }
11
- return output;
12
- }
13
- function failing() {
14
- return ruleReturn(false);
15
- }
16
- function passing() {
17
- return ruleReturn(true);
18
- }
19
- function defaultToPassing(callback) {
20
- return vestUtils.defaultTo(callback, passing());
21
- }
5
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
22
6
 
23
- function runLazyRule(lazyRule, currentValue) {
24
- try {
25
- return lazyRule.run(currentValue);
26
- }
27
- catch (_a) {
28
- return failing();
29
- }
30
- }
7
+ var compose__default = /*#__PURE__*/_interopDefaultLegacy(compose);
31
8
 
32
- /* eslint-disable max-lines-per-function */
33
- function compose() {
34
- var composites = [];
35
- for (var _i = 0; _i < arguments.length; _i++) {
36
- composites[_i] = arguments[_i];
37
- }
38
- return vestUtils.assign(function (value) {
39
- var res = run(value);
40
- vestUtils.invariant(res.pass, vestUtils.StringObject(res.message));
41
- }, {
42
- run: run,
43
- test: function (value) { return run(value).pass; }
44
- });
45
- function run(value) {
46
- return n4s.ctx.run({ value: value }, function () {
47
- return defaultToPassing(vestUtils.mapFirst(composites, function (composite, breakout) {
48
- /* HACK: Just a small white lie. ~~HELP WANTED~~.
49
- The ideal is that instead of `LazyRuleRunners` We would simply use `Lazy` to begin with.
50
- The problem is that lazy rules can't really be passed to this function due to some generic hell
51
- so we're limiting it to a small set of functions.
52
- */
53
- var res = runLazyRule(composite, value);
54
- breakout(!res.pass, res);
55
- }));
56
- });
57
- }
58
- }
59
9
 
60
- module.exports = compose;
10
+
11
+ module.exports = compose__default["default"];
@@ -1 +1 @@
1
- "use strict";var n=require("n4s"),t=require("vest-utils");function r(n,t){return n={pass:n},t&&(n.message=t),n}function u(n){return t.defaultTo(n,r(!0))}function e(n,t){try{return n.run(t)}catch(n){return r(!1)}}module.exports=function(){function r(r){return n.ctx.run({value:r},(function(){return u(t.mapFirst(s,(function(n,t){t(!(n=e(n,r)).pass,n)})))}))}for(var s=[],i=0;i<arguments.length;i++)s[i]=arguments[i];return t.assign((function(n){n=r(n),t.invariant(n.pass,t.StringObject(n.message))}),{run:r,test:function(n){return r(n).pass}})};
1
+ "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=e(require("n4s/compose"));module.exports=t.default;
@@ -1,92 +1,29 @@
1
1
  'use strict';
2
2
 
3
- var n4s = require('n4s');
4
- var vestUtils = require('vest-utils');
3
+ Object.defineProperty(exports, '__esModule', { value: true });
5
4
 
6
- function ruleReturn(pass, message) {
7
- var output = { pass: pass };
8
- if (message) {
9
- output.message = message;
10
- }
11
- return output;
12
- }
13
- function failing() {
14
- return ruleReturn(false);
15
- }
16
- function passing() {
17
- return ruleReturn(true);
18
- }
19
- function defaultToFailing(callback) {
20
- return vestUtils.defaultTo(callback, failing());
21
- }
22
- function defaultToPassing(callback) {
23
- return vestUtils.defaultTo(callback, passing());
24
- }
25
-
26
- function runLazyRule(lazyRule, currentValue) {
27
- try {
28
- return lazyRule.run(currentValue);
29
- }
30
- catch (_a) {
31
- return failing();
32
- }
33
- }
34
-
35
- function allOf(value) {
36
- var rules = [];
37
- for (var _i = 1; _i < arguments.length; _i++) {
38
- rules[_i - 1] = arguments[_i];
39
- }
40
- return defaultToPassing(vestUtils.mapFirst(rules, function (rule, breakout) {
41
- var res = runLazyRule(rule, value);
42
- breakout(!res.pass, res);
43
- }));
44
- }
5
+ var compounds = require('n4s/compounds');
45
6
 
46
- function anyOf(value) {
47
- var rules = [];
48
- for (var _i = 1; _i < arguments.length; _i++) {
49
- rules[_i - 1] = arguments[_i];
50
- }
51
- return defaultToFailing(vestUtils.mapFirst(rules, function (rule, breakout) {
52
- var res = runLazyRule(rule, value);
53
- breakout(res.pass, res);
54
- }));
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n["default"] = e;
22
+ return Object.freeze(n);
55
23
  }
56
24
 
57
- function noneOf(value) {
58
- var rules = [];
59
- for (var _i = 1; _i < arguments.length; _i++) {
60
- rules[_i - 1] = arguments[_i];
61
- }
62
- return defaultToPassing(vestUtils.mapFirst(rules, function (rule, breakout) {
63
- var res = runLazyRule(rule, value);
64
- breakout(res.pass, failing());
65
- }));
66
- }
25
+ var compounds__namespace = /*#__PURE__*/_interopNamespace(compounds);
67
26
 
68
- function equals(value, arg1) {
69
- return value === arg1;
70
- }
71
- vestUtils.bindNot(equals);
72
27
 
73
- var REQUIRED_COUNT = 1;
74
- function oneOf(value) {
75
- var rules = [];
76
- for (var _i = 1; _i < arguments.length; _i++) {
77
- rules[_i - 1] = arguments[_i];
78
- }
79
- var passingCount = 0;
80
- rules.some(function (rule) {
81
- var res = runLazyRule(rule, value);
82
- if (res.pass) {
83
- passingCount++;
84
- }
85
- if (vestUtils.greaterThan(passingCount, REQUIRED_COUNT)) {
86
- return false;
87
- }
88
- });
89
- return ruleReturn(equals(passingCount, REQUIRED_COUNT));
90
- }
91
28
 
92
- n4s.enforce.extend({ allOf: allOf, anyOf: anyOf, noneOf: noneOf, oneOf: oneOf });
29
+ exports.compounds = compounds__namespace;
@@ -1 +1 @@
1
- "use strict";var n=require("n4s"),r=require("vest-utils");function t(n,r){return n={pass:n},r&&(n.message=r),n}function e(){return t(!1)}function u(n){return r.defaultTo(n,e())}function f(n){return r.defaultTo(n,t(!0))}function o(n,r){try{return n.run(r)}catch(n){return e()}}function i(n,r){return n===r}r.bindNot(i);n.enforce.extend({allOf:function(n){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];return f(r.mapFirst(t,(function(r,t){t(!(r=o(r,n)).pass,r)})))},anyOf:function(n){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];return u(r.mapFirst(t,(function(r,t){t((r=o(r,n)).pass,r)})))},noneOf:function(n){for(var t=[],u=1;u<arguments.length;u++)t[u-1]=arguments[u];return f(r.mapFirst(t,(function(r,t){t((r=o(r,n)).pass,e())})))},oneOf:function(n){for(var e=[],u=1;u<arguments.length;u++)e[u-1]=arguments[u];var f=0;return e.some((function(t){if(o(t,n).pass&&f++,r.greaterThan(f,1))return!1})),t(i(f,1))}});
1
+ "use strict";function e(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}Object.defineProperty(exports,"__esModule",{value:!0});var r=e(require("n4s/compounds"));exports.compounds=r;
@@ -2,91 +2,28 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var n4s = require('n4s');
6
- var vestUtils = require('vest-utils');
5
+ var schema = require('n4s/schema');
7
6
 
8
- function ruleReturn(pass, message) {
9
- var output = { pass: pass };
10
- if (message) {
11
- output.message = message;
12
- }
13
- return output;
14
- }
15
- function failing() {
16
- return ruleReturn(false);
17
- }
18
- function passing() {
19
- return ruleReturn(true);
20
- }
21
- function defaultToPassing(callback) {
22
- return vestUtils.defaultTo(callback, passing());
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n["default"] = e;
22
+ return Object.freeze(n);
23
23
  }
24
24
 
25
- function runLazyRule(lazyRule, currentValue) {
26
- try {
27
- return lazyRule.run(currentValue);
28
- }
29
- catch (_a) {
30
- return failing();
31
- }
32
- }
25
+ var schema__namespace = /*#__PURE__*/_interopNamespace(schema);
33
26
 
34
- function isArrayOf(inputArray, currentRule) {
35
- return defaultToPassing(vestUtils.mapFirst(inputArray, function (currentValue, breakout, index) {
36
- var res = n4s.ctx.run({ value: currentValue, set: true, meta: { index: index } }, function () { return runLazyRule(currentRule, currentValue); });
37
- breakout(!res.pass, res);
38
- }));
39
- }
40
-
41
- function loose(inputObject, shapeObject) {
42
- var _loop_1 = function (key) {
43
- var currentValue = inputObject[key];
44
- var currentRule = shapeObject[key];
45
- var res = n4s.ctx.run({ value: currentValue, set: true, meta: { key: key } }, function () {
46
- return runLazyRule(currentRule, currentValue);
47
- });
48
- if (!res.pass) {
49
- return { value: res };
50
- }
51
- };
52
- for (var key in shapeObject) {
53
- var state_1 = _loop_1(key);
54
- if (typeof state_1 === "object")
55
- return state_1.value;
56
- }
57
- return passing();
58
- }
59
-
60
- function optional(value, ruleChain) {
61
- if (vestUtils.isNullish(value)) {
62
- return passing();
63
- }
64
- return runLazyRule(ruleChain, value);
65
- }
66
-
67
- function shape(inputObject, shapeObject) {
68
- var baseRes = loose(inputObject, shapeObject);
69
- if (!baseRes.pass) {
70
- return baseRes;
71
- }
72
- for (var key in inputObject) {
73
- if (!vestUtils.hasOwnProperty(shapeObject, key)) {
74
- return failing();
75
- }
76
- }
77
- return passing();
78
- }
79
-
80
- // Help needed improving the typings of this file.
81
- // Ideally, we'd be able to extend ShapeObject, but that's not possible.
82
- function partial(shapeObject) {
83
- var output = {};
84
- for (var key in shapeObject) {
85
- output[key] = n4s.enforce.optional(shapeObject[key]);
86
- }
87
- return output;
88
- }
89
27
 
90
- n4s.enforce.extend({ isArrayOf: isArrayOf, loose: loose, optional: optional, shape: shape });
91
28
 
92
- exports.partial = partial;
29
+ exports.schema = schema__namespace;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("n4s"),n=require("vest-utils");function e(r,n){return r={pass:r},n&&(r.message=n),r}function t(){return e(!1)}function u(){return e(!0)}function i(r,n){try{return r.run(n)}catch(r){return t()}}function o(n,e){var t,o=function(t){var u=n[t],o=e[t];if(!(t=r.ctx.run({value:u,set:!0,meta:{key:t}},(function(){return i(o,u)}))).pass)return{value:t}};for(t in e){var a=o(t);if("object"==typeof a)return a.value}return u()}r.enforce.extend({isArrayOf:function(e,t){return function(r){return n.defaultTo(r,u())}(n.mapFirst(e,(function(n,e,u){e(!(u=r.ctx.run({value:n,set:!0,meta:{index:u}},(function(){return i(t,n)}))).pass,u)})))},loose:o,optional:function(r,e){return n.isNullish(r)?u():i(e,r)},shape:function(r,e){var i=o(r,e);if(!i.pass)return i;for(var a in r)if(!n.hasOwnProperty(e,a))return t();return u()}}),exports.partial=function(n){var e,t={};for(e in n)t[e]=r.enforce.optional(n[e]);return t};
1
+ "use strict";function e(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var c=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,c.get?c:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}Object.defineProperty(exports,"__esModule",{value:!0});var r=e(require("n4s/schema"));exports.schema=r;
@@ -5,30 +5,52 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var vest = require('vest');
6
6
  var vestUtils = require('vest-utils');
7
7
 
8
- // eslint-disable-next-line max-statements
8
+ var ErrorStrings;
9
+ (function (ErrorStrings) {
10
+ ErrorStrings["HOOK_CALLED_OUTSIDE"] = "hook called outside of a running suite.";
11
+ ErrorStrings["EXPECTED_VEST_TEST"] = "Expected value to be an instance of IsolateTest";
12
+ ErrorStrings["FIELD_NAME_REQUIRED"] = "Field name must be passed";
13
+ ErrorStrings["SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION"] = "Suite must be initialized with a function";
14
+ ErrorStrings["NO_ACTIVE_ISOLATE"] = "Not within an active isolate";
15
+ ErrorStrings["PROMISIFY_REQUIRE_FUNCTION"] = "Vest.Promisify must be called with a function";
16
+ ErrorStrings["PARSER_EXPECT_RESULT_OBJECT"] = "Vest parser: expected argument at position 0 to be Vest's result object.";
17
+ ErrorStrings["WARN_MUST_BE_CALLED_FROM_TEST"] = "Warn must be called from within the body of a test function";
18
+ ErrorStrings["EACH_CALLBACK_MUST_BE_A_FUNCTION"] = "Each must be called with a function";
19
+ ErrorStrings["INVALID_PARAM_PASSED_TO_FUNCTION"] = "Incompatible params passed to {fn_name} function. \"{param}\" must be of type {expected}";
20
+ ErrorStrings["ENCOUNTERED_THE_SAME_KEY_TWICE"] = "Encountered the same test key \"{key}\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.";
21
+ ErrorStrings["TESTS_CALLED_IN_DIFFERENT_ORDER"] = "Vest Critical Error: Tests called in different order than previous run.\n expected: {fieldName}\n received: {prevName}\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.";
22
+ ErrorStrings["UNEXPECTED_TEST_REGISTRATION_ERROR"] = "Unexpected error encountered during test registration.\n Please report this issue to Vest's Github repository.\n Test Object: {testObject}.\n Error: {error}.";
23
+ })(ErrorStrings || (ErrorStrings = {}));
24
+
25
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
26
+ // @ts-ignore - Need to understand why Vest is not being recognized
9
27
  function parse(summary) {
10
- vestUtils.invariant(summary && vestUtils.hasOwnProperty(summary, 'valid'), "Vest parser: expected argument at position 0 to be Vest's result object.");
11
- var sel = vest.suiteSelectors(summary);
12
- var testedStorage = {};
13
- var selectors = {
28
+ vestUtils.invariant(summary && vestUtils.hasOwnProperty(summary, 'valid'), ErrorStrings.PARSER_EXPECT_RESULT_OBJECT);
29
+ const sel = vest.suiteSelectors(summary);
30
+ const testedStorage = {};
31
+ const selectors = {
14
32
  invalid: sel.hasErrors,
15
33
  tested: isTested,
16
34
  untested: isUntested,
17
35
  valid: sel.isValid,
18
- warning: sel.hasWarnings
36
+ warning: sel.hasWarnings,
19
37
  };
20
38
  return selectors;
21
39
  // Booleans
22
40
  function isTested(fieldName) {
23
- if (!fieldName) {
41
+ if (vestUtils.isNullish(fieldName)) {
24
42
  return vestUtils.isPositive(summary.testCount);
25
43
  }
26
- if (vestUtils.hasOwnProperty(testedStorage, fieldName))
44
+ if (vestUtils.hasOwnProperty(testedStorage, fieldName)) {
27
45
  return testedStorage[fieldName];
46
+ }
47
+ addFieldToTestedStorage(fieldName);
48
+ return selectors.tested(fieldName);
49
+ }
50
+ function addFieldToTestedStorage(fieldName) {
28
51
  testedStorage[fieldName] =
29
52
  vestUtils.hasOwnProperty(summary.tests, fieldName) &&
30
53
  vestUtils.isPositive(summary.tests[fieldName].testCount);
31
- return selectors.tested(fieldName);
32
54
  }
33
55
  function isUntested(fieldName) {
34
56
  return !(vestUtils.isPositive(summary.testCount) && selectors.tested(fieldName));
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("vest"),e=require("vest-utils");exports.parse=function(s){e.invariant(s&&e.hasOwnProperty(s,"valid"),"Vest parser: expected argument at position 0 to be Vest's result object.");var r=t.suiteSelectors(s),i={},n={invalid:r.hasErrors,tested:function(t){return t?e.hasOwnProperty(i,t)?i[t]:(i[t]=e.hasOwnProperty(s.tests,t)&&e.isPositive(s.tests[t].testCount),n.tested(t)):e.isPositive(s.testCount)},untested:function(t){return!(e.isPositive(s.testCount)&&n.tested(t))},valid:r.isValid,warning:r.hasWarnings};return n};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("vest"),s=require("vest-utils");!function(e){e.HOOK_CALLED_OUTSIDE="hook called outside of a running suite.",e.EXPECTED_VEST_TEST="Expected value to be an instance of IsolateTest",e.FIELD_NAME_REQUIRED="Field name must be passed",e.SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION="Suite must be initialized with a function",e.NO_ACTIVE_ISOLATE="Not within an active isolate",e.PROMISIFY_REQUIRE_FUNCTION="Vest.Promisify must be called with a function",e.PARSER_EXPECT_RESULT_OBJECT="Vest parser: expected argument at position 0 to be Vest's result object.",e.WARN_MUST_BE_CALLED_FROM_TEST="Warn must be called from within the body of a test function",e.EACH_CALLBACK_MUST_BE_A_FUNCTION="Each must be called with a function",e.INVALID_PARAM_PASSED_TO_FUNCTION='Incompatible params passed to {fn_name} function. "{param}" must be of type {expected}',e.ENCOUNTERED_THE_SAME_KEY_TWICE='Encountered the same test key "{key}" twice. This may lead to tests overriding each other\'s results, or to tests being unexpectedly omitted.',e.TESTS_CALLED_IN_DIFFERENT_ORDER='Vest Critical Error: Tests called in different order than previous run.\n expected: {fieldName}\n received: {prevName}\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.',e.UNEXPECTED_TEST_REGISTRATION_ERROR="Unexpected error encountered during test registration.\n Please report this issue to Vest's Github repository.\n Test Object: {testObject}.\n Error: {error}."}(e||(e={})),exports.parse=function(n){s.invariant(n&&s.hasOwnProperty(n,"valid"),e.PARSER_EXPECT_RESULT_OBJECT);const i=t.suiteSelectors(n),r={},o={invalid:i.hasErrors,tested:function(e){if(s.isNullish(e))return s.isPositive(n.testCount);if(s.hasOwnProperty(r,e))return r[e];return a(e),o.tested(e)},untested:function(e){return!(s.isPositive(n.testCount)&&o.tested(e))},valid:i.isValid,warning:i.hasWarnings};return o;function a(e){r[e]=s.hasOwnProperty(n.tests,e)&&s.isPositive(n.tests[e].testCount)}};
@@ -2,15 +2,28 @@
2
2
 
3
3
  var vestUtils = require('vest-utils');
4
4
 
5
- var promisify = function (validatorFn) {
6
- return function () {
7
- var args = [];
8
- for (var _i = 0; _i < arguments.length; _i++) {
9
- args[_i] = arguments[_i];
10
- }
11
- vestUtils.invariant(vestUtils.isFunction(validatorFn), 'promisify: Expected validatorFn to be a function.');
12
- return new Promise(function (resolve) { return validatorFn.apply(void 0, args).done(resolve); });
5
+ var ErrorStrings;
6
+ (function (ErrorStrings) {
7
+ ErrorStrings["HOOK_CALLED_OUTSIDE"] = "hook called outside of a running suite.";
8
+ ErrorStrings["EXPECTED_VEST_TEST"] = "Expected value to be an instance of IsolateTest";
9
+ ErrorStrings["FIELD_NAME_REQUIRED"] = "Field name must be passed";
10
+ ErrorStrings["SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION"] = "Suite must be initialized with a function";
11
+ ErrorStrings["NO_ACTIVE_ISOLATE"] = "Not within an active isolate";
12
+ ErrorStrings["PROMISIFY_REQUIRE_FUNCTION"] = "Vest.Promisify must be called with a function";
13
+ ErrorStrings["PARSER_EXPECT_RESULT_OBJECT"] = "Vest parser: expected argument at position 0 to be Vest's result object.";
14
+ ErrorStrings["WARN_MUST_BE_CALLED_FROM_TEST"] = "Warn must be called from within the body of a test function";
15
+ ErrorStrings["EACH_CALLBACK_MUST_BE_A_FUNCTION"] = "Each must be called with a function";
16
+ ErrorStrings["INVALID_PARAM_PASSED_TO_FUNCTION"] = "Incompatible params passed to {fn_name} function. \"{param}\" must be of type {expected}";
17
+ ErrorStrings["ENCOUNTERED_THE_SAME_KEY_TWICE"] = "Encountered the same test key \"{key}\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.";
18
+ ErrorStrings["TESTS_CALLED_IN_DIFFERENT_ORDER"] = "Vest Critical Error: Tests called in different order than previous run.\n expected: {fieldName}\n received: {prevName}\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.";
19
+ ErrorStrings["UNEXPECTED_TEST_REGISTRATION_ERROR"] = "Unexpected error encountered during test registration.\n Please report this issue to Vest's Github repository.\n Test Object: {testObject}.\n Error: {error}.";
20
+ })(ErrorStrings || (ErrorStrings = {}));
21
+
22
+ function promisify(validatorFn) {
23
+ return (...args) => {
24
+ vestUtils.invariant(vestUtils.isFunction(validatorFn), ErrorStrings.PROMISIFY_REQUIRE_FUNCTION);
25
+ return new Promise(resolve => validatorFn(...args).done(resolve));
13
26
  };
14
- };
27
+ }
15
28
 
16
29
  module.exports = promisify;
@@ -1 +1 @@
1
- "use strict";var n=require("vest-utils");module.exports=function(t){return function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return n.invariant(n.isFunction(t),"promisify: Expected validatorFn to be a function."),new Promise((function(n){return t.apply(void 0,r).done(n)}))}};
1
+ "use strict";var e,t=require("vest-utils");!function(e){e.HOOK_CALLED_OUTSIDE="hook called outside of a running suite.",e.EXPECTED_VEST_TEST="Expected value to be an instance of IsolateTest",e.FIELD_NAME_REQUIRED="Field name must be passed",e.SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION="Suite must be initialized with a function",e.NO_ACTIVE_ISOLATE="Not within an active isolate",e.PROMISIFY_REQUIRE_FUNCTION="Vest.Promisify must be called with a function",e.PARSER_EXPECT_RESULT_OBJECT="Vest parser: expected argument at position 0 to be Vest's result object.",e.WARN_MUST_BE_CALLED_FROM_TEST="Warn must be called from within the body of a test function",e.EACH_CALLBACK_MUST_BE_A_FUNCTION="Each must be called with a function",e.INVALID_PARAM_PASSED_TO_FUNCTION='Incompatible params passed to {fn_name} function. "{param}" must be of type {expected}',e.ENCOUNTERED_THE_SAME_KEY_TWICE='Encountered the same test key "{key}" twice. This may lead to tests overriding each other\'s results, or to tests being unexpectedly omitted.',e.TESTS_CALLED_IN_DIFFERENT_ORDER='Vest Critical Error: Tests called in different order than previous run.\n expected: {fieldName}\n received: {prevName}\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.',e.UNEXPECTED_TEST_REGISTRATION_ERROR="Unexpected error encountered during test registration.\n Please report this issue to Vest's Github repository.\n Test Object: {testObject}.\n Error: {error}."}(e||(e={})),module.exports=function(s){return(...n)=>(t.invariant(t.isFunction(s),e.PROMISIFY_REQUIRE_FUNCTION),new Promise((e=>s(...n).done(e))))};