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.
Files changed (182) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +2 -57
  3. package/dist/cjs/classnames.development.js +18 -16
  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 +12 -9
  12. package/dist/cjs/parser.production.js +1 -1
  13. package/dist/cjs/promisify.development.js +4 -8
  14. package/dist/cjs/promisify.production.js +1 -1
  15. package/dist/cjs/vest.development.js +1287 -1153
  16. package/dist/cjs/vest.production.js +1 -1
  17. package/dist/es/classnames.development.js +20 -18
  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 +12 -9
  26. package/dist/es/parser.production.js +1 -1
  27. package/dist/es/promisify.development.js +5 -9
  28. package/dist/es/promisify.production.js +1 -1
  29. package/dist/es/vest.development.js +1286 -1148
  30. package/dist/es/vest.production.js +1 -1
  31. package/dist/umd/classnames.development.js +21 -19
  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 +16 -13
  40. package/dist/umd/parser.production.js +1 -1
  41. package/dist/umd/promisify.development.js +7 -11
  42. package/dist/umd/promisify.production.js +1 -1
  43. package/dist/umd/vest.development.js +1289 -1155
  44. package/dist/umd/vest.production.js +1 -1
  45. package/package.json +12 -16
  46. package/src/__tests__/__snapshots__/integration.async-tests.test.ts.snap +71 -0
  47. package/src/__tests__/__snapshots__/integration.base.test.ts.snap +71 -0
  48. package/src/__tests__/__snapshots__/integration.stateful-async.test.ts.snap +243 -0
  49. package/src/__tests__/__snapshots__/integration.stateful-tests.test.ts.snap +376 -0
  50. package/src/__tests__/integration.async-tests.test.ts +90 -0
  51. package/src/__tests__/integration.base.test.ts +45 -0
  52. package/src/__tests__/integration.exclusive.test.ts +88 -0
  53. package/src/__tests__/integration.stateful-async.test.ts +137 -0
  54. package/src/__tests__/integration.stateful-tests.test.ts +155 -0
  55. package/src/__tests__/isolate.test.ts +288 -0
  56. package/src/__tests__/state_refill.test.ts +41 -0
  57. package/src/core/SuiteWalker/SuiteWalker.ts +64 -0
  58. package/src/core/SuiteWalker/__tests__/hasRemainingTests.test.ts +130 -0
  59. package/src/core/VestBus/VestBus.ts +78 -0
  60. package/src/core/context/PersistedContext.ts +243 -0
  61. package/src/core/context/SuiteContext.ts +74 -0
  62. package/src/core/isolate/IsolateTest/IsolateTest.ts +213 -0
  63. package/src/core/isolate/IsolateTest/IsolateTestReconciler.ts +156 -0
  64. package/src/core/isolate/IsolateTest/IsolateTestStateMachine.ts +69 -0
  65. package/src/core/isolate/IsolateTest/SimpleStateMachine.ts +43 -0
  66. package/src/core/isolate/IsolateTest/TestWalker.ts +77 -0
  67. package/src/core/isolate/IsolateTypes.ts +10 -0
  68. package/src/core/isolate/isIsolate.ts +6 -0
  69. package/src/core/isolate/isolate.ts +110 -0
  70. package/src/core/isolate/reconciler/Reconciler/Reconciler.ts +123 -0
  71. package/src/core/isolate/reconciler/cancelOverriddenPendingTest.ts +15 -0
  72. package/src/core/isolate/reconciler/isSameProfileTest.ts +12 -0
  73. package/src/core/isolate/walker.ts +127 -0
  74. package/src/core/test/TestTypes.ts +3 -0
  75. package/src/core/test/__tests__/IsolateTest.test.ts +152 -0
  76. package/src/core/test/__tests__/__snapshots__/IsolateTest.test.ts.snap +39 -0
  77. package/src/core/test/__tests__/__snapshots__/memo.test.ts.snap +101 -0
  78. package/src/core/test/__tests__/__snapshots__/test.test.ts.snap +231 -0
  79. package/src/core/test/__tests__/key.test.ts +195 -0
  80. package/src/core/test/__tests__/memo.test.ts +218 -0
  81. package/src/core/test/__tests__/merging_of_previous_test_runs.test.ts +341 -0
  82. package/src/core/test/__tests__/runAsyncTest.test.ts +175 -0
  83. package/src/core/test/__tests__/test.test.ts +226 -0
  84. package/src/core/test/helpers/__tests__/nonMatchingSeverityProfile.test.ts +52 -0
  85. package/src/core/test/helpers/asVestTest.ts +9 -0
  86. package/src/core/test/helpers/matchingFieldName.ts +16 -0
  87. package/src/core/test/helpers/matchingGroupName.ts +12 -0
  88. package/src/core/test/helpers/nonMatchingSeverityProfile.ts +14 -0
  89. package/src/core/test/helpers/shouldUseErrorMessage.ts +9 -0
  90. package/src/core/test/test.memo.ts +81 -0
  91. package/src/core/test/test.ts +64 -0
  92. package/src/core/test/testLevelFlowControl/runTest.ts +86 -0
  93. package/src/core/test/testLevelFlowControl/verifyTestRun.ts +32 -0
  94. package/src/core/test/testObjectIsolate.ts +11 -0
  95. package/src/errors/ErrorStrings.ts +4 -0
  96. package/src/exports/__tests__/classnames.test.ts +92 -0
  97. package/src/exports/__tests__/parser.test.ts +441 -0
  98. package/src/exports/__tests__/promisify.test.ts +77 -0
  99. package/src/exports/classnames.ts +35 -0
  100. package/src/exports/enforce@compose.ts +1 -0
  101. package/src/exports/enforce@compounds.ts +1 -0
  102. package/src/exports/enforce@schema.ts +1 -0
  103. package/src/exports/parser.ts +63 -0
  104. package/src/exports/promisify.ts +18 -0
  105. package/src/hooks/__tests__/__snapshots__/include.test.ts.snap +794 -0
  106. package/src/hooks/__tests__/eager.test.ts +130 -0
  107. package/src/hooks/__tests__/exclusive.test.ts +578 -0
  108. package/src/hooks/__tests__/include.test.ts +431 -0
  109. package/src/hooks/__tests__/optional.test.ts +83 -0
  110. package/src/hooks/__tests__/warn.test.ts +42 -0
  111. package/src/hooks/exclusive.ts +179 -0
  112. package/src/hooks/include.ts +54 -0
  113. package/src/hooks/mode.ts +47 -0
  114. package/src/hooks/optional/OptionalTypes.ts +31 -0
  115. package/src/hooks/optional/optional.ts +69 -0
  116. package/src/hooks/warn.ts +19 -0
  117. package/src/isolates/__tests__/__snapshots__/each.test.ts.snap +3 -0
  118. package/src/isolates/__tests__/__snapshots__/group.test.ts.snap +114 -0
  119. package/src/isolates/__tests__/__snapshots__/omitWhen.test.ts.snap +443 -0
  120. package/src/isolates/__tests__/__snapshots__/skipWhen.test.ts.snap +99 -0
  121. package/src/isolates/__tests__/each.test.ts +35 -0
  122. package/src/isolates/__tests__/group.test.ts +362 -0
  123. package/src/isolates/__tests__/omitWhen.test.ts +246 -0
  124. package/src/isolates/__tests__/skipWhen.test.ts +163 -0
  125. package/src/isolates/each.ts +30 -0
  126. package/src/isolates/group.ts +9 -0
  127. package/src/isolates/omitWhen.ts +41 -0
  128. package/src/isolates/skipWhen.ts +42 -0
  129. package/src/suite/__tests__/__snapshots__/create.test.ts.snap +67 -0
  130. package/src/suite/__tests__/create.test.ts +109 -0
  131. package/src/suite/__tests__/remove.test.ts +50 -0
  132. package/src/suite/__tests__/resetField.test.ts +74 -0
  133. package/src/suite/createSuite.ts +94 -0
  134. package/src/suite/runCallbacks.ts +28 -0
  135. package/src/suiteResult/Severity.ts +15 -0
  136. package/src/suiteResult/SuiteResultTypes.ts +42 -0
  137. package/src/suiteResult/__tests__/done.test.ts +334 -0
  138. package/src/suiteResult/__tests__/produce.test.ts +163 -0
  139. package/src/suiteResult/done/deferDoneCallback.ts +28 -0
  140. package/src/suiteResult/done/shouldSkipDoneRegistration.ts +20 -0
  141. package/src/suiteResult/selectors/__tests__/__snapshots__/collectFailureMessages.test.ts.snap +89 -0
  142. package/src/suiteResult/selectors/__tests__/collectFailureMessages.test.ts +124 -0
  143. package/src/suiteResult/selectors/__tests__/getFailures.test.ts +158 -0
  144. package/src/suiteResult/selectors/__tests__/getFailuresByGroup.test.ts +199 -0
  145. package/src/suiteResult/selectors/__tests__/hasFailures.test.ts +141 -0
  146. package/src/suiteResult/selectors/__tests__/hasFailuresByGroup.test.ts +185 -0
  147. package/src/suiteResult/selectors/__tests__/hasFailuresByTestObject.test.ts +88 -0
  148. package/src/suiteResult/selectors/__tests__/isValid.test.ts +359 -0
  149. package/src/suiteResult/selectors/__tests__/isValidByGroup.test.ts +480 -0
  150. package/src/suiteResult/selectors/collectFailures.ts +43 -0
  151. package/src/suiteResult/selectors/hasFailuresByTestObjects.ts +62 -0
  152. package/src/suiteResult/selectors/produceSuiteSummary.ts +135 -0
  153. package/src/suiteResult/selectors/shouldAddValidProperty.ts +148 -0
  154. package/src/suiteResult/selectors/suiteSelectors.ts +199 -0
  155. package/src/suiteResult/suiteResult.ts +15 -0
  156. package/src/suiteResult/suiteRunResult.ts +43 -0
  157. package/src/vest.ts +36 -0
  158. package/testUtils/TVestMock.ts +5 -0
  159. package/testUtils/__tests__/partition.test.ts +4 -4
  160. package/testUtils/mockThrowError.ts +4 -2
  161. package/testUtils/suiteDummy.ts +2 -1
  162. package/testUtils/testDummy.ts +12 -10
  163. package/testUtils/testPromise.ts +3 -0
  164. package/tsconfig.json +84 -2
  165. package/types/classnames.d.ts +39 -4
  166. package/types/classnames.d.ts.map +1 -0
  167. package/types/enforce/compose.d.ts +2 -126
  168. package/types/enforce/compose.d.ts.map +1 -0
  169. package/types/enforce/compounds.d.ts +2 -136
  170. package/types/enforce/compounds.d.ts.map +1 -0
  171. package/types/enforce/schema.d.ts +2 -144
  172. package/types/enforce/schema.d.ts.map +1 -0
  173. package/types/parser.d.ts +45 -10
  174. package/types/parser.d.ts.map +1 -0
  175. package/types/promisify.d.ts +36 -34
  176. package/types/promisify.d.ts.map +1 -0
  177. package/types/vest.d.ts +169 -224
  178. package/types/vest.d.ts.map +1 -0
  179. package/CHANGELOG.md +0 -87
  180. package/testUtils/expandStateRef.ts +0 -8
  181. package/testUtils/runCreateRef.ts +0 -10
  182. 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';