vest 5.0.0-dev-781e21 → 5.0.2-dev-d315d9
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 +18 -16
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/enforce/compose.development.js +5 -54
- package/dist/cjs/enforce/compose.production.js +1 -1
- package/dist/cjs/enforce/compounds.development.js +20 -83
- package/dist/cjs/enforce/compounds.production.js +1 -1
- package/dist/cjs/enforce/schema.development.js +19 -82
- package/dist/cjs/enforce/schema.production.js +1 -1
- package/dist/cjs/parser.development.js +12 -9
- package/dist/cjs/parser.production.js +1 -1
- package/dist/cjs/promisify.development.js +4 -8
- package/dist/cjs/promisify.production.js +1 -1
- package/dist/cjs/vest.development.js +1287 -1153
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +20 -18
- 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 +12 -9
- package/dist/es/parser.production.js +1 -1
- package/dist/es/promisify.development.js +5 -9
- package/dist/es/promisify.production.js +1 -1
- package/dist/es/vest.development.js +1286 -1148
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +21 -19
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +9 -57
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +32 -94
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +32 -94
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/parser.development.js +16 -13
- package/dist/umd/parser.production.js +1 -1
- package/dist/umd/promisify.development.js +7 -11
- package/dist/umd/promisify.production.js +1 -1
- package/dist/umd/vest.development.js +1289 -1155
- package/dist/umd/vest.production.js +1 -1
- package/package.json +12 -16
- package/src/__tests__/__snapshots__/integration.async-tests.test.ts.snap +71 -0
- package/src/__tests__/__snapshots__/integration.base.test.ts.snap +71 -0
- package/src/__tests__/__snapshots__/integration.stateful-async.test.ts.snap +243 -0
- package/src/__tests__/__snapshots__/integration.stateful-tests.test.ts.snap +376 -0
- package/src/__tests__/integration.async-tests.test.ts +90 -0
- package/src/__tests__/integration.base.test.ts +45 -0
- package/src/__tests__/integration.exclusive.test.ts +88 -0
- package/src/__tests__/integration.stateful-async.test.ts +137 -0
- package/src/__tests__/integration.stateful-tests.test.ts +155 -0
- package/src/__tests__/isolate.test.ts +288 -0
- package/src/__tests__/state_refill.test.ts +41 -0
- package/src/core/SuiteWalker/SuiteWalker.ts +64 -0
- package/src/core/SuiteWalker/__tests__/hasRemainingTests.test.ts +130 -0
- package/src/core/VestBus/VestBus.ts +78 -0
- package/src/core/context/PersistedContext.ts +243 -0
- package/src/core/context/SuiteContext.ts +74 -0
- package/src/core/isolate/IsolateTest/IsolateTest.ts +213 -0
- package/src/core/isolate/IsolateTest/IsolateTestReconciler.ts +156 -0
- package/src/core/isolate/IsolateTest/IsolateTestStateMachine.ts +69 -0
- package/src/core/isolate/IsolateTest/SimpleStateMachine.ts +43 -0
- package/src/core/isolate/IsolateTest/TestWalker.ts +77 -0
- package/src/core/isolate/IsolateTypes.ts +10 -0
- package/src/core/isolate/isIsolate.ts +6 -0
- package/src/core/isolate/isolate.ts +110 -0
- package/src/core/isolate/reconciler/Reconciler/Reconciler.ts +123 -0
- package/src/core/isolate/reconciler/cancelOverriddenPendingTest.ts +15 -0
- package/src/core/isolate/reconciler/isSameProfileTest.ts +12 -0
- package/src/core/isolate/walker.ts +127 -0
- package/src/core/test/TestTypes.ts +3 -0
- package/src/core/test/__tests__/IsolateTest.test.ts +152 -0
- package/src/core/test/__tests__/__snapshots__/IsolateTest.test.ts.snap +39 -0
- package/src/core/test/__tests__/__snapshots__/memo.test.ts.snap +101 -0
- package/src/core/test/__tests__/__snapshots__/test.test.ts.snap +231 -0
- package/src/core/test/__tests__/key.test.ts +195 -0
- package/src/core/test/__tests__/memo.test.ts +218 -0
- package/src/core/test/__tests__/merging_of_previous_test_runs.test.ts +341 -0
- package/src/core/test/__tests__/runAsyncTest.test.ts +175 -0
- package/src/core/test/__tests__/test.test.ts +226 -0
- package/src/core/test/helpers/__tests__/nonMatchingSeverityProfile.test.ts +52 -0
- package/src/core/test/helpers/asVestTest.ts +9 -0
- package/src/core/test/helpers/matchingFieldName.ts +16 -0
- package/src/core/test/helpers/matchingGroupName.ts +12 -0
- package/src/core/test/helpers/nonMatchingSeverityProfile.ts +14 -0
- package/src/core/test/helpers/shouldUseErrorMessage.ts +9 -0
- package/src/core/test/test.memo.ts +81 -0
- package/src/core/test/test.ts +64 -0
- package/src/core/test/testLevelFlowControl/runTest.ts +86 -0
- package/src/core/test/testLevelFlowControl/verifyTestRun.ts +32 -0
- package/src/core/test/testObjectIsolate.ts +11 -0
- package/src/errors/ErrorStrings.ts +4 -0
- package/src/exports/__tests__/classnames.test.ts +92 -0
- package/src/exports/__tests__/parser.test.ts +441 -0
- package/src/exports/__tests__/promisify.test.ts +77 -0
- package/src/exports/classnames.ts +35 -0
- package/src/exports/enforce@compose.ts +1 -0
- package/src/exports/enforce@compounds.ts +1 -0
- package/src/exports/enforce@schema.ts +1 -0
- package/src/exports/parser.ts +63 -0
- package/src/exports/promisify.ts +18 -0
- package/src/hooks/__tests__/__snapshots__/include.test.ts.snap +794 -0
- package/src/hooks/__tests__/eager.test.ts +130 -0
- package/src/hooks/__tests__/exclusive.test.ts +578 -0
- package/src/hooks/__tests__/include.test.ts +431 -0
- package/src/hooks/__tests__/optional.test.ts +83 -0
- package/src/hooks/__tests__/warn.test.ts +42 -0
- package/src/hooks/exclusive.ts +179 -0
- package/src/hooks/include.ts +54 -0
- package/src/hooks/mode.ts +47 -0
- package/src/hooks/optional/OptionalTypes.ts +31 -0
- package/src/hooks/optional/optional.ts +69 -0
- package/src/hooks/warn.ts +19 -0
- package/src/isolates/__tests__/__snapshots__/each.test.ts.snap +3 -0
- package/src/isolates/__tests__/__snapshots__/group.test.ts.snap +114 -0
- package/src/isolates/__tests__/__snapshots__/omitWhen.test.ts.snap +443 -0
- package/src/isolates/__tests__/__snapshots__/skipWhen.test.ts.snap +99 -0
- package/src/isolates/__tests__/each.test.ts +35 -0
- package/src/isolates/__tests__/group.test.ts +362 -0
- package/src/isolates/__tests__/omitWhen.test.ts +246 -0
- package/src/isolates/__tests__/skipWhen.test.ts +163 -0
- package/src/isolates/each.ts +30 -0
- package/src/isolates/group.ts +9 -0
- package/src/isolates/omitWhen.ts +41 -0
- package/src/isolates/skipWhen.ts +42 -0
- package/src/suite/__tests__/__snapshots__/create.test.ts.snap +67 -0
- package/src/suite/__tests__/create.test.ts +109 -0
- package/src/suite/__tests__/remove.test.ts +50 -0
- package/src/suite/__tests__/resetField.test.ts +74 -0
- package/src/suite/createSuite.ts +94 -0
- package/src/suite/runCallbacks.ts +28 -0
- package/src/suiteResult/Severity.ts +15 -0
- package/src/suiteResult/SuiteResultTypes.ts +42 -0
- package/src/suiteResult/__tests__/done.test.ts +334 -0
- package/src/suiteResult/__tests__/produce.test.ts +163 -0
- package/src/suiteResult/done/deferDoneCallback.ts +28 -0
- package/src/suiteResult/done/shouldSkipDoneRegistration.ts +20 -0
- package/src/suiteResult/selectors/__tests__/__snapshots__/collectFailureMessages.test.ts.snap +89 -0
- package/src/suiteResult/selectors/__tests__/collectFailureMessages.test.ts +124 -0
- package/src/suiteResult/selectors/__tests__/getFailures.test.ts +158 -0
- package/src/suiteResult/selectors/__tests__/getFailuresByGroup.test.ts +199 -0
- package/src/suiteResult/selectors/__tests__/hasFailures.test.ts +141 -0
- package/src/suiteResult/selectors/__tests__/hasFailuresByGroup.test.ts +185 -0
- package/src/suiteResult/selectors/__tests__/hasFailuresByTestObject.test.ts +88 -0
- package/src/suiteResult/selectors/__tests__/isValid.test.ts +359 -0
- package/src/suiteResult/selectors/__tests__/isValidByGroup.test.ts +480 -0
- package/src/suiteResult/selectors/collectFailures.ts +43 -0
- package/src/suiteResult/selectors/hasFailuresByTestObjects.ts +62 -0
- package/src/suiteResult/selectors/produceSuiteSummary.ts +135 -0
- package/src/suiteResult/selectors/shouldAddValidProperty.ts +148 -0
- package/src/suiteResult/selectors/suiteSelectors.ts +199 -0
- package/src/suiteResult/suiteResult.ts +15 -0
- package/src/suiteResult/suiteRunResult.ts +43 -0
- package/src/vest.ts +36 -0
- package/testUtils/TVestMock.ts +5 -0
- package/testUtils/__tests__/partition.test.ts +4 -4
- package/testUtils/mockThrowError.ts +4 -2
- package/testUtils/suiteDummy.ts +2 -1
- package/testUtils/testDummy.ts +12 -10
- package/testUtils/testPromise.ts +3 -0
- package/tsconfig.json +84 -2
- package/types/classnames.d.ts +39 -4
- 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 +45 -10
- package/types/parser.d.ts.map +1 -0
- package/types/promisify.d.ts +36 -34
- package/types/promisify.d.ts.map +1 -0
- package/types/vest.d.ts +169 -224
- 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
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { dummyTest } from '../../../testUtils/testDummy';
|
|
2
|
+
import classnames from '../classnames';
|
|
3
|
+
import promisify from '../promisify';
|
|
4
|
+
|
|
5
|
+
import * as vest from 'vest';
|
|
6
|
+
|
|
7
|
+
describe('Utility: classnames', () => {
|
|
8
|
+
describe('When called without a vest result object', () => {
|
|
9
|
+
it('Should throw an error', () => {
|
|
10
|
+
expect(classnames).toThrow();
|
|
11
|
+
// @ts-expect-error - testing invalid input
|
|
12
|
+
expect(() => classnames({})).toThrow();
|
|
13
|
+
// @ts-expect-error - testing invalid input
|
|
14
|
+
expect(() => classnames([])).toThrow();
|
|
15
|
+
// @ts-expect-error - testing invalid input
|
|
16
|
+
expect(() => classnames('invalid')).toThrow();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('When called with a vest result object', () => {
|
|
21
|
+
it('Should return a function', async () => {
|
|
22
|
+
const validate = vest.create(jest.fn());
|
|
23
|
+
expect(typeof classnames(validate())).toBe('function');
|
|
24
|
+
const promisifed = await promisify(vest.create(jest.fn()))();
|
|
25
|
+
expect(typeof classnames(promisifed)).toBe('function');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const validate = vest.create(() => {
|
|
30
|
+
vest.skip('field_1');
|
|
31
|
+
|
|
32
|
+
dummyTest.failing('field_1');
|
|
33
|
+
dummyTest.failing('field_2');
|
|
34
|
+
dummyTest.failingWarning('field_2');
|
|
35
|
+
dummyTest.failingWarning('field_3');
|
|
36
|
+
dummyTest.passing('field_4');
|
|
37
|
+
dummyTest.failing('field_5');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const res = validate();
|
|
41
|
+
|
|
42
|
+
describe('when all keys are provided', () => {
|
|
43
|
+
const genClass = classnames(res, {
|
|
44
|
+
invalid: 'invalid_string',
|
|
45
|
+
tested: 'tested_string',
|
|
46
|
+
untested: 'untested_string',
|
|
47
|
+
valid: 'valid_string',
|
|
48
|
+
warning: 'warning_string',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('Should produce a string matching the classnames object for each field', () => {
|
|
52
|
+
expect(genClass('field_1')).toBe('untested_string');
|
|
53
|
+
|
|
54
|
+
// splitting and sorting to not rely on object order which is unspecified in the language
|
|
55
|
+
expect(genClass('field_2').split(' ').sort()).toEqual(
|
|
56
|
+
'invalid_string tested_string warning_string'.split(' ').sort()
|
|
57
|
+
);
|
|
58
|
+
expect(genClass('field_3').split(' ').sort()).toEqual(
|
|
59
|
+
'tested_string valid_string warning_string'.split(' ').sort()
|
|
60
|
+
);
|
|
61
|
+
expect(genClass('field_4').split(' ').sort()).toEqual(
|
|
62
|
+
'tested_string valid_string'.split(' ').sort()
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(genClass('field_5').split(' ').sort()).toEqual(
|
|
66
|
+
'tested_string invalid_string'.split(' ').sort()
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
expect(genClass('field_6').split(' ').sort()).toEqual(
|
|
70
|
+
'untested_string'.split(' ').sort()
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('When only some keys are provided', () => {
|
|
76
|
+
const genClass = classnames(res, {
|
|
77
|
+
invalid: 'invalid_string',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('Should produce a string matching the classnames object for each field', () => {
|
|
81
|
+
expect(genClass('field_1')).toBe('');
|
|
82
|
+
|
|
83
|
+
// splitting and sorting to not rely on object order which is unspecified in the language
|
|
84
|
+
expect(genClass('field_2').split(' ').sort()).toEqual(
|
|
85
|
+
'invalid_string'.split(' ').sort()
|
|
86
|
+
);
|
|
87
|
+
expect(genClass('field_3').split(' ').sort()).toEqual(
|
|
88
|
+
''.split(' ').sort()
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import * as suiteDummy from '../../../testUtils/suiteDummy';
|
|
2
|
+
import { ser } from '../../../testUtils/suiteDummy';
|
|
3
|
+
|
|
4
|
+
import { parse } from 'parser';
|
|
5
|
+
import * as vest from 'vest';
|
|
6
|
+
|
|
7
|
+
describe('parser.parse', () => {
|
|
8
|
+
describe('parse().invalid', () => {
|
|
9
|
+
it('Should return true when provided suite result is failing and no field name is provided', () => {
|
|
10
|
+
expect(parse(suiteDummy.failing()).invalid()).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('Should return false when provided suite result is passing and no field name is provided', () => {
|
|
14
|
+
expect(parse(suiteDummy.passing()).invalid()).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('Should return true when provided field is failing', () => {
|
|
18
|
+
expect(parse(suiteDummy.failing('username')).invalid('username')).toBe(
|
|
19
|
+
true
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('Should return false when provided field is passing', () => {
|
|
24
|
+
expect(parse(suiteDummy.passing('username')).invalid('username')).toBe(
|
|
25
|
+
false
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('Serialized Result', () => {
|
|
30
|
+
it('Should return true when provided suite result is failing and no field name is provided', () => {
|
|
31
|
+
expect(parse(ser(suiteDummy.failing())).invalid()).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('Should return false when provided suite result is passing and no field name is provided', () => {
|
|
35
|
+
expect(parse(ser(suiteDummy.passing())).invalid()).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('Should return true when provided field is failing', () => {
|
|
39
|
+
expect(
|
|
40
|
+
parse(ser(suiteDummy.failing('username'))).invalid('username')
|
|
41
|
+
).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('Should return false when provided field is passing', () => {
|
|
45
|
+
expect(
|
|
46
|
+
parse(ser(suiteDummy.passing('username'))).invalid('username')
|
|
47
|
+
).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('parse().tested', () => {
|
|
53
|
+
it('Should return true if any field is tested but no field is provided', () => {
|
|
54
|
+
expect(parse(suiteDummy.passing()).tested()).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
it('Should return true if no field is tested', () => {
|
|
57
|
+
expect(parse(suiteDummy.untested()).tested()).toBe(false);
|
|
58
|
+
expect(parse(suiteDummy.untested()).tested('field')).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
it('Should return true if provided field is tested', () => {
|
|
61
|
+
expect(parse(suiteDummy.passing('username')).tested('username')).toBe(
|
|
62
|
+
true
|
|
63
|
+
);
|
|
64
|
+
expect(parse(suiteDummy.failing('username')).tested('username')).toBe(
|
|
65
|
+
true
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('Serialized Result', () => {
|
|
70
|
+
it('Should return true if any field is tested but no field is provided', () => {
|
|
71
|
+
expect(parse(ser(suiteDummy.passing())).tested()).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
it('Should return true if no field is tested', () => {
|
|
74
|
+
expect(parse(ser(suiteDummy.untested())).tested()).toBe(false);
|
|
75
|
+
expect(parse(ser(suiteDummy.untested())).tested('field')).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
it('Should return true if provided field is tested', () => {
|
|
78
|
+
expect(
|
|
79
|
+
parse(ser(suiteDummy.passing('username'))).tested('username')
|
|
80
|
+
).toBe(true);
|
|
81
|
+
expect(
|
|
82
|
+
parse(ser(suiteDummy.failing('username'))).tested('username')
|
|
83
|
+
).toBe(true);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('parse().untested', () => {
|
|
89
|
+
it('Should return true if no field is tested', () => {
|
|
90
|
+
expect(parse(suiteDummy.untested()).untested()).toBe(true);
|
|
91
|
+
expect(parse(suiteDummy.untested()).untested('username')).toBe(true);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('Should return true if provided field is untested while others are', () => {
|
|
95
|
+
expect(
|
|
96
|
+
parse(
|
|
97
|
+
vest.create(() => {
|
|
98
|
+
vest.test('x', () => {});
|
|
99
|
+
vest.skipWhen(true, () => {
|
|
100
|
+
vest.test('untested', () => {});
|
|
101
|
+
});
|
|
102
|
+
})()
|
|
103
|
+
).untested('untested')
|
|
104
|
+
).toBe(true);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('Should return false if any field is tested', () => {
|
|
108
|
+
expect(parse(suiteDummy.passing('username')).untested()).toBe(false);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('Should return false if provided field is tested', () => {
|
|
112
|
+
expect(parse(suiteDummy.passing('username')).untested('username')).toBe(
|
|
113
|
+
false
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe('Serialized Result', () => {
|
|
118
|
+
it('Should return true if no field is tested', () => {
|
|
119
|
+
expect(parse(ser(suiteDummy.untested())).untested()).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('Should return true if provided field is untested while others are', () => {
|
|
123
|
+
expect(
|
|
124
|
+
parse(
|
|
125
|
+
ser(
|
|
126
|
+
vest.create(() => {
|
|
127
|
+
vest.test('x', () => {});
|
|
128
|
+
vest.skipWhen(true, () => {
|
|
129
|
+
vest.test('untested', () => {});
|
|
130
|
+
});
|
|
131
|
+
})()
|
|
132
|
+
)
|
|
133
|
+
).untested('untested')
|
|
134
|
+
).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('Should return false if any field is tested', () => {
|
|
138
|
+
expect(parse(ser(suiteDummy.passing('username'))).untested()).toBe(
|
|
139
|
+
false
|
|
140
|
+
);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('Should return false if provided field is tested', () => {
|
|
144
|
+
expect(
|
|
145
|
+
parse(ser(suiteDummy.passing('username'))).untested('username')
|
|
146
|
+
).toBe(false);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe('parse().valid', () => {
|
|
152
|
+
it('Should return true if all fields are passing', () => {
|
|
153
|
+
expect(parse(suiteDummy.passing(['f1', 'f2', 'f3'])).valid()).toBe(true);
|
|
154
|
+
expect(parse(suiteDummy.passing(['f1', 'f2', 'f3'])).valid('f2')).toBe(
|
|
155
|
+
true
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('Should return true if all required fields have been tested and are passing', () => {
|
|
160
|
+
expect(
|
|
161
|
+
parse(suiteDummy.passingWithUntestedOptional('optional')).valid()
|
|
162
|
+
).toBe(true);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('Should return true if all fields, including optional, pass', () => {
|
|
166
|
+
expect(parse(suiteDummy.passingWithOptional('optional')).valid()).toBe(
|
|
167
|
+
true
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('Should return false if suite has errors', () => {
|
|
172
|
+
expect(parse(suiteDummy.failing()).valid()).toBe(false);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('Should return false if suite has failing optional tests', () => {
|
|
176
|
+
expect(parse(suiteDummy.failingOptional()).valid()).toBe(false);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('Should return true if suite only has warnings', () => {
|
|
180
|
+
expect(parse(suiteDummy.warning(['f1', 'f2', 'f3'])).valid()).toBe(true);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('Should return false if no tests ran', () => {
|
|
184
|
+
expect(parse(suiteDummy.untested()).valid()).toBe(false);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('should return false if not all required fields ran', () => {
|
|
188
|
+
expect(
|
|
189
|
+
parse(
|
|
190
|
+
vest.create(() => {
|
|
191
|
+
vest.test('x', () => {});
|
|
192
|
+
vest.test('untested', () => {});
|
|
193
|
+
vest.skipWhen(true, () => {
|
|
194
|
+
vest.test('untested', () => {});
|
|
195
|
+
});
|
|
196
|
+
})()
|
|
197
|
+
).valid()
|
|
198
|
+
).toBe(false);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
describe('With field name', () => {
|
|
202
|
+
it('Should return false when field is untested', () => {
|
|
203
|
+
expect(
|
|
204
|
+
parse(
|
|
205
|
+
vest.create(() => {
|
|
206
|
+
vest.skipWhen(true, () => {
|
|
207
|
+
vest.test('f1', () => {});
|
|
208
|
+
});
|
|
209
|
+
})()
|
|
210
|
+
).valid('f1')
|
|
211
|
+
).toBe(false);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('Should return true if optional field is untested', () => {
|
|
215
|
+
expect(
|
|
216
|
+
parse(
|
|
217
|
+
vest.create(() => {
|
|
218
|
+
vest.optional('f1');
|
|
219
|
+
vest.skipWhen(true, () => {
|
|
220
|
+
vest.test('f1', () => {});
|
|
221
|
+
});
|
|
222
|
+
})()
|
|
223
|
+
).valid('f1')
|
|
224
|
+
).toBe(true);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('Should return true if field is passing', () => {
|
|
228
|
+
expect(
|
|
229
|
+
parse(
|
|
230
|
+
vest.create(() => {
|
|
231
|
+
vest.test('f1', () => {});
|
|
232
|
+
vest.test('f2', () => false);
|
|
233
|
+
})()
|
|
234
|
+
).valid('f1')
|
|
235
|
+
).toBe(true);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('Should return false if field is failing', () => {
|
|
239
|
+
expect(
|
|
240
|
+
parse(
|
|
241
|
+
vest.create(() => {
|
|
242
|
+
vest.test('f1', () => {});
|
|
243
|
+
vest.test('f2', () => false);
|
|
244
|
+
})()
|
|
245
|
+
).valid('f2')
|
|
246
|
+
).toBe(false);
|
|
247
|
+
expect(
|
|
248
|
+
parse(
|
|
249
|
+
vest.create(() => {
|
|
250
|
+
vest.test('f1', () => {});
|
|
251
|
+
vest.test('f2', () => {});
|
|
252
|
+
vest.test('f2', () => false);
|
|
253
|
+
})()
|
|
254
|
+
).valid('f2')
|
|
255
|
+
).toBe(false);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('Should return true if field is warning', () => {
|
|
259
|
+
expect(
|
|
260
|
+
parse(
|
|
261
|
+
vest.create(() => {
|
|
262
|
+
vest.test('f1', () => {
|
|
263
|
+
vest.warn();
|
|
264
|
+
return false;
|
|
265
|
+
});
|
|
266
|
+
})()
|
|
267
|
+
).valid('f1')
|
|
268
|
+
).toBe(true);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
describe('Serialized Result', () => {
|
|
273
|
+
it('Should return true if all fields are passing', () => {
|
|
274
|
+
expect(parse(ser(suiteDummy.passing(['f1', 'f2', 'f3']))).valid()).toBe(
|
|
275
|
+
true
|
|
276
|
+
);
|
|
277
|
+
expect(
|
|
278
|
+
parse(ser(suiteDummy.passing(['f1', 'f2', 'f3']))).valid('f2')
|
|
279
|
+
).toBe(true);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('Should return true if all required fields have been tested and are passing', () => {
|
|
283
|
+
expect(
|
|
284
|
+
parse(ser(suiteDummy.passingWithUntestedOptional('optional'))).valid()
|
|
285
|
+
).toBe(true);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it('Should return true if all fields, including optional, pass', () => {
|
|
289
|
+
expect(
|
|
290
|
+
parse(ser(suiteDummy.passingWithOptional('optional'))).valid()
|
|
291
|
+
).toBe(true);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('Should return false if suite has errors', () => {
|
|
295
|
+
expect(parse(ser(suiteDummy.failing())).valid()).toBe(false);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('Should return false if suite has failing optional tests', () => {
|
|
299
|
+
expect(parse(ser(suiteDummy.failingOptional())).valid()).toBe(false);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('Should return true if suite only has warnings', () => {
|
|
303
|
+
expect(parse(ser(suiteDummy.warning(['f1', 'f2', 'f3']))).valid()).toBe(
|
|
304
|
+
true
|
|
305
|
+
);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it('Should return false if no tests ran', () => {
|
|
309
|
+
expect(parse(ser(suiteDummy.untested())).valid()).toBe(false);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('should return false if not all required fields ran', () => {
|
|
313
|
+
expect(
|
|
314
|
+
parse(
|
|
315
|
+
ser(
|
|
316
|
+
vest.create(() => {
|
|
317
|
+
vest.test('x', () => {});
|
|
318
|
+
vest.test('untested', () => {});
|
|
319
|
+
vest.skipWhen(true, () => {
|
|
320
|
+
vest.test('untested', () => {});
|
|
321
|
+
});
|
|
322
|
+
})()
|
|
323
|
+
)
|
|
324
|
+
).valid()
|
|
325
|
+
).toBe(false);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
describe('With field name', () => {
|
|
329
|
+
it('Should return false when field is untested', () => {
|
|
330
|
+
expect(
|
|
331
|
+
parse(
|
|
332
|
+
ser(
|
|
333
|
+
vest.create(() => {
|
|
334
|
+
vest.skipWhen(true, () => {
|
|
335
|
+
vest.test('f1', () => {});
|
|
336
|
+
});
|
|
337
|
+
})()
|
|
338
|
+
)
|
|
339
|
+
).valid('f1')
|
|
340
|
+
).toBe(false);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it('Should return true if optional field is untested', () => {
|
|
344
|
+
expect(
|
|
345
|
+
parse(
|
|
346
|
+
ser(
|
|
347
|
+
vest.create(() => {
|
|
348
|
+
vest.optional('f1');
|
|
349
|
+
vest.skipWhen(true, () => {
|
|
350
|
+
vest.test('f1', () => {});
|
|
351
|
+
});
|
|
352
|
+
})()
|
|
353
|
+
)
|
|
354
|
+
).valid('f1')
|
|
355
|
+
).toBe(true);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it('Should return true if field is passing', () => {
|
|
359
|
+
expect(
|
|
360
|
+
parse(
|
|
361
|
+
ser(
|
|
362
|
+
vest.create(() => {
|
|
363
|
+
vest.test('f1', () => {});
|
|
364
|
+
vest.test('f2', () => false);
|
|
365
|
+
})()
|
|
366
|
+
)
|
|
367
|
+
).valid('f1')
|
|
368
|
+
).toBe(true);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it('Should return false if field is failing', () => {
|
|
372
|
+
expect(
|
|
373
|
+
parse(
|
|
374
|
+
ser(
|
|
375
|
+
vest.create(() => {
|
|
376
|
+
vest.test('f1', () => {});
|
|
377
|
+
vest.test('f2', () => false);
|
|
378
|
+
})()
|
|
379
|
+
)
|
|
380
|
+
).valid('f2')
|
|
381
|
+
).toBe(false);
|
|
382
|
+
expect(
|
|
383
|
+
parse(
|
|
384
|
+
ser(
|
|
385
|
+
vest.create(() => {
|
|
386
|
+
vest.test('f1', () => {});
|
|
387
|
+
vest.test('f2', () => {});
|
|
388
|
+
vest.test('f2', () => false);
|
|
389
|
+
})()
|
|
390
|
+
)
|
|
391
|
+
).valid('f2')
|
|
392
|
+
).toBe(false);
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it('Should return true if field is warning', () => {
|
|
396
|
+
expect(
|
|
397
|
+
parse(
|
|
398
|
+
ser(
|
|
399
|
+
vest.create(() => {
|
|
400
|
+
vest.test('f1', () => {
|
|
401
|
+
vest.warn();
|
|
402
|
+
return false;
|
|
403
|
+
});
|
|
404
|
+
})()
|
|
405
|
+
)
|
|
406
|
+
).valid('f1')
|
|
407
|
+
).toBe(true);
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
describe('parse().warning', () => {
|
|
414
|
+
it('Should return true when the suite has warnings', () => {
|
|
415
|
+
expect(parse(suiteDummy.warning()).warning()).toBe(true);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it('Should return false when the suite is not warnings', () => {
|
|
419
|
+
expect(parse(suiteDummy.failing()).warning()).toBe(false);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
describe('serialized result', () => {
|
|
423
|
+
it('Should return true when the suite has warnings', () => {
|
|
424
|
+
expect(parse(ser(suiteDummy.warning())).warning()).toBe(true);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it('Should return false when the suite is not warnings', () => {
|
|
428
|
+
expect(parse(ser(suiteDummy.failing())).warning()).toBe(false);
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
describe('When input is not a Vest object', () => {
|
|
434
|
+
it('Should throw an error', () => {
|
|
435
|
+
expect(() => {
|
|
436
|
+
// @ts-ignore - this is not a vest object
|
|
437
|
+
parse({});
|
|
438
|
+
}).toThrow();
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker';
|
|
2
|
+
|
|
3
|
+
import { dummyTest } from '../../../testUtils/testDummy';
|
|
4
|
+
import { TestPromise } from '../../../testUtils/testPromise';
|
|
5
|
+
import promisify from '../promisify';
|
|
6
|
+
|
|
7
|
+
import * as vest from 'vest';
|
|
8
|
+
|
|
9
|
+
describe('Utility: promisify', () => {
|
|
10
|
+
let validatorFn: jest.Mock<vest.SuiteRunResult<string>, any>;
|
|
11
|
+
let validateAsync: (...args: any[]) => Promise<vest.SuiteResult<string>>;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
validatorFn = jest.fn(vest.create(jest.fn()));
|
|
15
|
+
validateAsync = promisify(validatorFn);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('Test arguments', () => {
|
|
19
|
+
it('Should throw an error', () => {
|
|
20
|
+
// @ts-expect-error - testing invalid input
|
|
21
|
+
const invalidValidateAsync = promisify('invalid');
|
|
22
|
+
expect(() => invalidValidateAsync()).toThrow();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('Return value', () => {
|
|
27
|
+
it('should be a function', () => {
|
|
28
|
+
expect(typeof promisify(jest.fn())).toBe('function');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should be a promise', () =>
|
|
32
|
+
TestPromise(done => {
|
|
33
|
+
const res = validateAsync();
|
|
34
|
+
expect(typeof res?.then).toBe('function');
|
|
35
|
+
res.then(() => done());
|
|
36
|
+
}));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('When returned function is invoked', () => {
|
|
40
|
+
it('Calls `validatorFn` argument', () =>
|
|
41
|
+
TestPromise(done => {
|
|
42
|
+
const validateAsync = promisify(vest.create(() => done()));
|
|
43
|
+
validateAsync();
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
it('Passes all arguments over to tests callback', async () => {
|
|
47
|
+
const params = [
|
|
48
|
+
1,
|
|
49
|
+
{ [faker.random.word()]: [1, 2, 3] },
|
|
50
|
+
false,
|
|
51
|
+
[faker.random.word()],
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
await validateAsync(...params);
|
|
55
|
+
expect(validatorFn).toHaveBeenCalledWith(...params);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('Initial run', () => {
|
|
60
|
+
it('Produces correct validation', () =>
|
|
61
|
+
TestPromise(done => {
|
|
62
|
+
const validate = vest.create(() => {
|
|
63
|
+
dummyTest.failing('field_0');
|
|
64
|
+
dummyTest.failingAsync('field_1');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const validatorAsync = promisify(validate);
|
|
68
|
+
const p = validatorAsync('me');
|
|
69
|
+
|
|
70
|
+
p.then(result => {
|
|
71
|
+
expect(result.hasErrors('field_0')).toBe(true);
|
|
72
|
+
expect(result.hasErrors('field_1')).toBe(true);
|
|
73
|
+
done();
|
|
74
|
+
});
|
|
75
|
+
}));
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isFunction } from 'vest-utils';
|
|
2
|
+
|
|
3
|
+
import { SuiteSummary, TFieldName } from 'SuiteResultTypes';
|
|
4
|
+
import { parse } from 'parser';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a function that returns class names that match the validation result
|
|
8
|
+
*/
|
|
9
|
+
export default function classnames<F extends TFieldName>(
|
|
10
|
+
res: SuiteSummary<F>,
|
|
11
|
+
classes: SupportedClasses = {}
|
|
12
|
+
): (fieldName: F) => string {
|
|
13
|
+
const selectors = parse(res);
|
|
14
|
+
|
|
15
|
+
return function cn(fieldName: F): string {
|
|
16
|
+
const classesArray: string[] = [];
|
|
17
|
+
|
|
18
|
+
for (const selector in classes) {
|
|
19
|
+
const sel = selector as keyof SupportedClasses;
|
|
20
|
+
if (isFunction(selectors[sel]) && selectors[sel](fieldName)) {
|
|
21
|
+
classesArray.push(classes[sel] as string);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return classesArray.join(' ');
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type SupportedClasses = {
|
|
30
|
+
valid?: string;
|
|
31
|
+
tested?: string;
|
|
32
|
+
invalid?: string;
|
|
33
|
+
warning?: string;
|
|
34
|
+
untested?: string;
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from 'n4s/compose';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as compounds from 'n4s/compounds';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as schema from 'n4s/schema';
|