vest 5.0.0-dev-781e21 → 5.0.0-dev-ec989a
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.
- package/LICENSE +2 -2
- package/README.md +2 -57
- package/dist/cjs/classnames.development.js +37 -17
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/enforce/compose.development.js +1 -54
- package/dist/cjs/enforce/compose.production.js +1 -1
- package/dist/cjs/enforce/compounds.development.js +18 -84
- package/dist/cjs/enforce/compounds.production.js +1 -1
- package/dist/cjs/enforce/schema.development.js +18 -84
- package/dist/cjs/enforce/schema.production.js +1 -1
- package/dist/cjs/parser.development.js +30 -11
- package/dist/cjs/parser.production.js +1 -1
- package/dist/cjs/promisify.development.js +21 -9
- package/dist/cjs/promisify.production.js +1 -1
- package/dist/cjs/vest.development.js +1324 -1294
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +39 -19
- package/dist/es/classnames.production.js +1 -1
- package/dist/es/enforce/compose.development.js +1 -58
- package/dist/es/enforce/compose.production.js +1 -1
- package/dist/es/enforce/compounds.development.js +2 -90
- package/dist/es/enforce/compounds.production.js +1 -1
- package/dist/es/enforce/schema.development.js +2 -88
- package/dist/es/enforce/schema.production.js +1 -1
- package/dist/es/parser.development.js +31 -10
- package/dist/es/parser.production.js +1 -1
- package/dist/es/promisify.development.js +22 -10
- package/dist/es/promisify.production.js +1 -1
- package/dist/es/vest.development.js +1321 -1286
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +40 -20
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +6 -60
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +29 -94
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +29 -94
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/parser.development.js +33 -14
- package/dist/umd/parser.production.js +1 -1
- package/dist/umd/promisify.development.js +24 -12
- package/dist/umd/promisify.production.js +1 -1
- package/dist/umd/vest.development.js +1327 -1298
- package/dist/umd/vest.production.js +1 -1
- package/package.json +144 -147
- package/testUtils/TVestMock.ts +7 -0
- package/testUtils/__tests__/partition.test.ts +4 -4
- package/testUtils/asVestTest.ts +9 -0
- package/testUtils/mockThrowError.ts +4 -2
- package/testUtils/suiteDummy.ts +4 -1
- package/testUtils/testDummy.ts +12 -10
- package/testUtils/testPromise.ts +3 -0
- package/types/classnames.d.ts +141 -12
- package/types/classnames.d.ts.map +1 -0
- package/types/enforce/compose.d.ts +2 -126
- package/types/enforce/compose.d.ts.map +1 -0
- package/types/enforce/compounds.d.ts +2 -136
- package/types/enforce/compounds.d.ts.map +1 -0
- package/types/enforce/schema.d.ts +2 -144
- package/types/enforce/schema.d.ts.map +1 -0
- package/types/parser.d.ts +147 -18
- package/types/parser.d.ts.map +1 -0
- package/types/promisify.d.ts +139 -43
- package/types/promisify.d.ts.map +1 -0
- package/types/vest.d.ts +257 -242
- package/types/vest.d.ts.map +1 -0
- package/CHANGELOG.md +0 -87
- package/testUtils/expandStateRef.ts +0 -8
- package/testUtils/runCreateRef.ts +0 -10
- package/testUtils/testObjects.ts +0 -6
- package/tsconfig.json +0 -8
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
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
|
-
#
|
|
1
|
+
# vest-5
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[](https://discord.gg/WmADZpJnSe) [](https://github.com/ealush/vest) [](https://www.npmjs.com/package/vest) [](https://www.npmjs.com/package/vest) [](https://bundlephobia.com/package/vest) [](https://github.com/ealush/vest/actions)
|
|
6
|
-
|
|
7
|
-

|
|
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,51 @@
|
|
|
3
3
|
var vestUtils = require('vest-utils');
|
|
4
4
|
var vest = require('vest');
|
|
5
5
|
|
|
6
|
-
|
|
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["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["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.";
|
|
18
|
+
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}.";
|
|
19
|
+
ErrorStrings["UNEXPECTED_TEST_RUN_ERROR"] = "Unexpected error encountered during test run. Please report this issue to Vest's Github repository.\n Test Object: {testObject}.";
|
|
20
|
+
})(ErrorStrings || (ErrorStrings = {}));
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
23
|
+
// @ts-ignore - Need to understand why Vest is not being recognized
|
|
7
24
|
function parse(summary) {
|
|
8
|
-
vestUtils.invariant(summary && vestUtils.hasOwnProperty(summary, 'valid'),
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
25
|
+
vestUtils.invariant(summary && vestUtils.hasOwnProperty(summary, 'valid'), ErrorStrings.PARSER_EXPECT_RESULT_OBJECT);
|
|
26
|
+
const sel = vest.suiteSelectors(summary);
|
|
27
|
+
const testedStorage = {};
|
|
28
|
+
const selectors = {
|
|
12
29
|
invalid: sel.hasErrors,
|
|
13
30
|
tested: isTested,
|
|
14
31
|
untested: isUntested,
|
|
15
32
|
valid: sel.isValid,
|
|
16
|
-
warning: sel.hasWarnings
|
|
33
|
+
warning: sel.hasWarnings,
|
|
17
34
|
};
|
|
18
35
|
return selectors;
|
|
19
36
|
// Booleans
|
|
20
37
|
function isTested(fieldName) {
|
|
21
|
-
if (
|
|
38
|
+
if (vestUtils.isNullish(fieldName)) {
|
|
22
39
|
return vestUtils.isPositive(summary.testCount);
|
|
23
40
|
}
|
|
24
|
-
if (vestUtils.hasOwnProperty(testedStorage, fieldName))
|
|
41
|
+
if (vestUtils.hasOwnProperty(testedStorage, fieldName)) {
|
|
25
42
|
return testedStorage[fieldName];
|
|
43
|
+
}
|
|
44
|
+
addFieldToTestedStorage(fieldName);
|
|
45
|
+
return selectors.tested(fieldName);
|
|
46
|
+
}
|
|
47
|
+
function addFieldToTestedStorage(fieldName) {
|
|
26
48
|
testedStorage[fieldName] =
|
|
27
49
|
vestUtils.hasOwnProperty(summary.tests, fieldName) &&
|
|
28
50
|
vestUtils.isPositive(summary.tests[fieldName].testCount);
|
|
29
|
-
return selectors.tested(fieldName);
|
|
30
51
|
}
|
|
31
52
|
function isUntested(fieldName) {
|
|
32
53
|
return !(vestUtils.isPositive(summary.testCount) && selectors.tested(fieldName));
|
|
@@ -36,14 +57,13 @@ function parse(summary) {
|
|
|
36
57
|
/**
|
|
37
58
|
* Creates a function that returns class names that match the validation result
|
|
38
59
|
*/
|
|
39
|
-
function classnames(res, classes) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (vestUtils.isFunction(selectors[sel]) && selectors[sel](key)) {
|
|
60
|
+
function classnames(res, classes = {}) {
|
|
61
|
+
const selectors = parse(res);
|
|
62
|
+
return function cn(fieldName) {
|
|
63
|
+
const classesArray = [];
|
|
64
|
+
for (const selector in classes) {
|
|
65
|
+
const sel = selector;
|
|
66
|
+
if (vestUtils.isFunction(selectors[sel]) && selectors[sel](fieldName)) {
|
|
47
67
|
classesArray.push(classes[sel]);
|
|
48
68
|
}
|
|
49
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("vest-utils"),
|
|
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.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.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.UNEXPECTED_TEST_RUN_ERROR="Unexpected error encountered during test run. Please report this issue to Vest's Github repository.\n Test Object: {testObject}."}(e||(e={})),module.exports=function(n,i={}){const r=function(n){t.invariant(n&&t.hasOwnProperty(n,"valid"),e.PARSER_EXPECT_RESULT_OBJECT);const i=s.suiteSelectors(n),r={},o={invalid:i.hasErrors,tested:function(e){return t.isNullish(e)?t.isPositive(n.testCount):t.hasOwnProperty(r,e)?r[e]:(a(e),o.tested(e))},untested:function(e){return!(t.isPositive(n.testCount)&&o.tested(e))},valid:i.isValid,warning:i.hasWarnings};return o;function a(e){r[e]=t.hasOwnProperty(n.tests,e)&&t.isPositive(n.tests[e].testCount)}}(n);return function(e){const s=[];for(const n in i){const o=n;t.isFunction(r[o])&&r[o](e)&&s.push(i[o])}return s.join(" ")}};
|
|
@@ -1,60 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
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
|
-
}
|
|
22
5
|
|
|
23
|
-
function runLazyRule(lazyRule, currentValue) {
|
|
24
|
-
try {
|
|
25
|
-
return lazyRule.run(currentValue);
|
|
26
|
-
}
|
|
27
|
-
catch (_a) {
|
|
28
|
-
return failing();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
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
6
|
|
|
60
7
|
module.exports = compose;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var e=require("n4s/compose");module.exports=e;
|
|
@@ -1,92 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var vestUtils = require('vest-utils');
|
|
3
|
+
var compounds = require('n4s/compounds');
|
|
5
4
|
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
function defaultToPassing(callback) {
|
|
23
|
-
return vestUtils.defaultTo(callback, passing());
|
|
5
|
+
function _interopNamespaceDefault(e) {
|
|
6
|
+
var n = Object.create(null);
|
|
7
|
+
if (e) {
|
|
8
|
+
Object.keys(e).forEach(function (k) {
|
|
9
|
+
if (k !== 'default') {
|
|
10
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return e[k]; }
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
n.default = e;
|
|
19
|
+
return Object.freeze(n);
|
|
24
20
|
}
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
return lazyRule.run(currentValue);
|
|
29
|
-
}
|
|
30
|
-
catch (_a) {
|
|
31
|
-
return failing();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
22
|
+
var compounds__namespace = /*#__PURE__*/_interopNamespaceDefault(compounds);
|
|
34
23
|
|
|
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
|
-
}
|
|
45
24
|
|
|
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
|
-
}));
|
|
55
|
-
}
|
|
56
|
-
|
|
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
|
-
}
|
|
67
|
-
|
|
68
|
-
function equals(value, arg1) {
|
|
69
|
-
return value === arg1;
|
|
70
|
-
}
|
|
71
|
-
vestUtils.bindNot(equals);
|
|
72
|
-
|
|
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
25
|
|
|
92
|
-
|
|
26
|
+
exports.compounds = compounds__namespace;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";function e(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var t=e(require("n4s/compounds"));exports.compounds=t;
|
|
@@ -1,92 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var schema = require('n4s/schema');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
function defaultToPassing(callback) {
|
|
22
|
-
return vestUtils.defaultTo(callback, passing());
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function runLazyRule(lazyRule, currentValue) {
|
|
26
|
-
try {
|
|
27
|
-
return lazyRule.run(currentValue);
|
|
28
|
-
}
|
|
29
|
-
catch (_a) {
|
|
30
|
-
return failing();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
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();
|
|
5
|
+
function _interopNamespaceDefault(e) {
|
|
6
|
+
var n = Object.create(null);
|
|
7
|
+
if (e) {
|
|
8
|
+
Object.keys(e).forEach(function (k) {
|
|
9
|
+
if (k !== 'default') {
|
|
10
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return e[k]; }
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
n.default = e;
|
|
19
|
+
return Object.freeze(n);
|
|
58
20
|
}
|
|
59
21
|
|
|
60
|
-
|
|
61
|
-
if (vestUtils.isNullish(value)) {
|
|
62
|
-
return passing();
|
|
63
|
-
}
|
|
64
|
-
return runLazyRule(ruleChain, value);
|
|
65
|
-
}
|
|
22
|
+
var schema__namespace = /*#__PURE__*/_interopNamespaceDefault(schema);
|
|
66
23
|
|
|
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
24
|
|
|
90
|
-
n4s.enforce.extend({ isArrayOf: isArrayOf, loose: loose, optional: optional, shape: shape });
|
|
91
25
|
|
|
92
|
-
exports.
|
|
26
|
+
exports.schema = schema__namespace;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";function e(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var c=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,c.get?c:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var t=e(require("n4s/schema"));exports.schema=t;
|
|
@@ -1,34 +1,53 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var vest = require('vest');
|
|
6
4
|
var vestUtils = require('vest-utils');
|
|
7
5
|
|
|
8
|
-
|
|
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["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["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.";
|
|
18
|
+
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}.";
|
|
19
|
+
ErrorStrings["UNEXPECTED_TEST_RUN_ERROR"] = "Unexpected error encountered during test run. Please report this issue to Vest's Github repository.\n Test Object: {testObject}.";
|
|
20
|
+
})(ErrorStrings || (ErrorStrings = {}));
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
23
|
+
// @ts-ignore - Need to understand why Vest is not being recognized
|
|
9
24
|
function parse(summary) {
|
|
10
|
-
vestUtils.invariant(summary && vestUtils.hasOwnProperty(summary, 'valid'),
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
25
|
+
vestUtils.invariant(summary && vestUtils.hasOwnProperty(summary, 'valid'), ErrorStrings.PARSER_EXPECT_RESULT_OBJECT);
|
|
26
|
+
const sel = vest.suiteSelectors(summary);
|
|
27
|
+
const testedStorage = {};
|
|
28
|
+
const selectors = {
|
|
14
29
|
invalid: sel.hasErrors,
|
|
15
30
|
tested: isTested,
|
|
16
31
|
untested: isUntested,
|
|
17
32
|
valid: sel.isValid,
|
|
18
|
-
warning: sel.hasWarnings
|
|
33
|
+
warning: sel.hasWarnings,
|
|
19
34
|
};
|
|
20
35
|
return selectors;
|
|
21
36
|
// Booleans
|
|
22
37
|
function isTested(fieldName) {
|
|
23
|
-
if (
|
|
38
|
+
if (vestUtils.isNullish(fieldName)) {
|
|
24
39
|
return vestUtils.isPositive(summary.testCount);
|
|
25
40
|
}
|
|
26
|
-
if (vestUtils.hasOwnProperty(testedStorage, fieldName))
|
|
41
|
+
if (vestUtils.hasOwnProperty(testedStorage, fieldName)) {
|
|
27
42
|
return testedStorage[fieldName];
|
|
43
|
+
}
|
|
44
|
+
addFieldToTestedStorage(fieldName);
|
|
45
|
+
return selectors.tested(fieldName);
|
|
46
|
+
}
|
|
47
|
+
function addFieldToTestedStorage(fieldName) {
|
|
28
48
|
testedStorage[fieldName] =
|
|
29
49
|
vestUtils.hasOwnProperty(summary.tests, fieldName) &&
|
|
30
50
|
vestUtils.isPositive(summary.tests[fieldName].testCount);
|
|
31
|
-
return selectors.tested(fieldName);
|
|
32
51
|
}
|
|
33
52
|
function isUntested(fieldName) {
|
|
34
53
|
return !(vestUtils.isPositive(summary.testCount) && selectors.tested(fieldName));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";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.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.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.UNEXPECTED_TEST_RUN_ERROR="Unexpected error encountered during test run. Please report this issue to Vest's Github repository.\n Test Object: {testObject}."}(e||(e={})),exports.parse=function(n){s.invariant(n&&s.hasOwnProperty(n,"valid"),e.PARSER_EXPECT_RESULT_OBJECT);const r=t.suiteSelectors(n),i={},o={invalid:r.hasErrors,tested:function(e){if(s.isNullish(e))return s.isPositive(n.testCount);if(s.hasOwnProperty(i,e))return i[e];return a(e),o.tested(e)},untested:function(e){return!(s.isPositive(n.testCount)&&o.tested(e))},valid:r.isValid,warning:r.hasWarnings};return o;function a(e){i[e]=s.hasOwnProperty(n.tests,e)&&s.isPositive(n.tests[e].testCount)}};
|
|
@@ -2,15 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
var vestUtils = require('vest-utils');
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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["PROMISIFY_REQUIRE_FUNCTION"] = "Vest.Promisify must be called with a function";
|
|
12
|
+
ErrorStrings["PARSER_EXPECT_RESULT_OBJECT"] = "Vest parser: expected argument at position 0 to be Vest's result object.";
|
|
13
|
+
ErrorStrings["WARN_MUST_BE_CALLED_FROM_TEST"] = "Warn must be called from within the body of a test function";
|
|
14
|
+
ErrorStrings["EACH_CALLBACK_MUST_BE_A_FUNCTION"] = "Each must be called with a function";
|
|
15
|
+
ErrorStrings["INVALID_PARAM_PASSED_TO_FUNCTION"] = "Incompatible params passed to {fn_name} function. \"{param}\" must be of type {expected}";
|
|
16
|
+
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.";
|
|
17
|
+
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}.";
|
|
18
|
+
ErrorStrings["UNEXPECTED_TEST_RUN_ERROR"] = "Unexpected error encountered during test run. Please report this issue to Vest's Github repository.\n Test Object: {testObject}.";
|
|
19
|
+
})(ErrorStrings || (ErrorStrings = {}));
|
|
20
|
+
|
|
21
|
+
function promisify(validatorFn) {
|
|
22
|
+
return (...args) => {
|
|
23
|
+
vestUtils.invariant(vestUtils.isFunction(validatorFn), ErrorStrings.PROMISIFY_REQUIRE_FUNCTION);
|
|
24
|
+
return new Promise(resolve => validatorFn(...args).done(resolve));
|
|
13
25
|
};
|
|
14
|
-
}
|
|
26
|
+
}
|
|
15
27
|
|
|
16
28
|
module.exports = promisify;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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.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.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.UNEXPECTED_TEST_RUN_ERROR="Unexpected error encountered during test run. Please report this issue to Vest's Github repository.\n Test Object: {testObject}."}(e||(e={})),module.exports=function(s){return(...n)=>(t.invariant(t.isFunction(s),e.PROMISIFY_REQUIRE_FUNCTION),new Promise((e=>s(...n).done(e))))};
|