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,362 @@
1
+ import { faker } from '@faker-js/faker';
2
+ import _ from 'lodash';
3
+ import { enforce } from 'n4s';
4
+
5
+ import partition from '../../../testUtils/partition';
6
+ import { dummyTest } from '../../../testUtils/testDummy';
7
+
8
+ import { IsolateTest } from 'IsolateTest';
9
+ import { group } from 'group';
10
+ import { matchingGroupName } from 'matchingGroupName';
11
+ import { TTestSuite } from 'testUtils/TVestMock';
12
+ import * as vest from 'vest';
13
+
14
+ let groupName = 'group_name_1';
15
+ const groupName2 = 'group_name_2';
16
+
17
+ const topLevelTestObjects: Record<string, IsolateTest> = {};
18
+ const groupTestObjects: Record<string, IsolateTest> = {};
19
+
20
+ describe('group: exclusion', () => {
21
+ const validation = () =>
22
+ vest.create(
23
+ ({
24
+ only,
25
+ skip,
26
+ skipGroup,
27
+ onlyGroup,
28
+ }: {
29
+ only?: string;
30
+ skip?: string;
31
+ skipGroup?: string;
32
+ onlyGroup?: string;
33
+ } = {}) => {
34
+ vest.only(only);
35
+ vest.skip(skip);
36
+ vest.only.group(onlyGroup);
37
+ vest.skip.group(skipGroup);
38
+
39
+ topLevelTestObjects['field_1'] = dummyTest.failing('field_1');
40
+ topLevelTestObjects['field_1'] = dummyTest.failing('field_1');
41
+ topLevelTestObjects['field_2'] = dummyTest.passing('field_2');
42
+ topLevelTestObjects['field_3'] = dummyTest.failingWarning('field_3');
43
+ topLevelTestObjects['field_4'] = dummyTest.passingWarning('field_4');
44
+ topLevelTestObjects['field_5'] = dummyTest.failing('field_5');
45
+
46
+ group(groupName, () => {
47
+ groupTestObjects['field_1'] = dummyTest.failing('field_1');
48
+ groupTestObjects['field_2'] = dummyTest.passing('field_2');
49
+ groupTestObjects['field_3'] = dummyTest.failingWarning('field_3');
50
+ groupTestObjects['field_4'] = dummyTest.passingWarning('field_4');
51
+ groupTestObjects['field_6'] = dummyTest.failing('field_6');
52
+ });
53
+
54
+ group(groupName2, () => {
55
+ groupTestObjects['field_6'] = dummyTest.failing('field_6');
56
+ groupTestObjects['field_7'] = dummyTest.failing('field_7');
57
+ groupTestObjects['field_8'] = dummyTest.passing('field_8');
58
+ });
59
+ }
60
+ );
61
+ let res: vest.SuiteRunResult<string>;
62
+ let suite: TTestSuite;
63
+
64
+ beforeEach(() => {
65
+ groupName = faker.random.word();
66
+ suite = validation();
67
+ });
68
+
69
+ describe('When skipped', () => {
70
+ beforeEach(() => {
71
+ res = suite({ skipGroup: groupName });
72
+ });
73
+
74
+ it('produce result object with the group', () => {
75
+ expect(res.groups[groupName]).toMatchInlineSnapshot(`
76
+ {
77
+ "field_1": {
78
+ "errorCount": 0,
79
+ "errors": [],
80
+ "testCount": 0,
81
+ "valid": false,
82
+ "warnCount": 0,
83
+ "warnings": [],
84
+ },
85
+ "field_2": {
86
+ "errorCount": 0,
87
+ "errors": [],
88
+ "testCount": 0,
89
+ "valid": false,
90
+ "warnCount": 0,
91
+ "warnings": [],
92
+ },
93
+ "field_3": {
94
+ "errorCount": 0,
95
+ "errors": [],
96
+ "testCount": 0,
97
+ "valid": false,
98
+ "warnCount": 0,
99
+ "warnings": [],
100
+ },
101
+ "field_4": {
102
+ "errorCount": 0,
103
+ "errors": [],
104
+ "testCount": 0,
105
+ "valid": false,
106
+ "warnCount": 0,
107
+ "warnings": [],
108
+ },
109
+ "field_6": {
110
+ "errorCount": 0,
111
+ "errors": [],
112
+ "testCount": 0,
113
+ "valid": false,
114
+ "warnCount": 0,
115
+ "warnings": [],
116
+ },
117
+ }
118
+ `);
119
+ });
120
+
121
+ it('Should skip tests within group', () => {
122
+ Object.values(groupTestObjects)
123
+ .filter(testObject => {
124
+ return matchingGroupName(testObject, groupName);
125
+ })
126
+ .forEach(testObject => {
127
+ expect(testObject.testFn).not.toHaveBeenCalled();
128
+ });
129
+ });
130
+
131
+ it('Should run all tests outside of the group', () => {
132
+ Object.values(topLevelTestObjects).forEach(testObject => {
133
+ expect(testObject.testFn).toHaveBeenCalled();
134
+ });
135
+
136
+ const [withGroup, withoutGroup] = partition(
137
+ Object.values(groupTestObjects),
138
+ testObject => matchingGroupName(testObject, groupName)
139
+ );
140
+ withGroup.forEach(testObject => {
141
+ expect(testObject.testFn).not.toHaveBeenCalled();
142
+ });
143
+ withoutGroup.forEach(testObject => {
144
+ expect(testObject.testFn).toHaveBeenCalled();
145
+ });
146
+ });
147
+ });
148
+
149
+ describe('When `only`ed', () => {
150
+ beforeEach(() => {
151
+ res = suite({ onlyGroup: groupName });
152
+ });
153
+ it('produce result object with group', () => {
154
+ expect(res.groups).toHaveProperty(groupName);
155
+ });
156
+
157
+ it('produce correct result object', () => {
158
+ expect(res.testCount).toBe(5);
159
+ expect(res.errorCount).toBe(2);
160
+ expect(res.warnCount).toBe(1);
161
+ expect(res.tests['field_1'].errorCount).toBe(1);
162
+ expect(res.tests['field_1'].warnCount).toBe(0);
163
+ expect(res.tests['field_2'].errorCount).toBe(0);
164
+ expect(res.tests['field_2'].warnCount).toBe(0);
165
+ expect(res.tests['field_3'].errorCount).toBe(0);
166
+ expect(res.tests['field_3'].warnCount).toBe(1);
167
+ expect(res.tests['field_4'].errorCount).toBe(0);
168
+ expect(res.tests['field_4'].warnCount).toBe(0);
169
+ expect(res.tests['field_5'].errorCount).toBe(0);
170
+ expect(res.tests['field_5'].warnCount).toBe(0);
171
+ expect(res.tests['field_6'].errorCount).toBe(1);
172
+ expect(res.tests['field_6'].warnCount).toBe(0);
173
+ });
174
+
175
+ it('Should run tests within group', () => {
176
+ const [withGroup, withoutGroup] = partition(
177
+ Object.values(groupTestObjects),
178
+ testObject => {
179
+ return matchingGroupName(testObject, groupName);
180
+ }
181
+ );
182
+
183
+ withGroup.forEach(testObject => {
184
+ expect(testObject.testFn).toHaveBeenCalled();
185
+ });
186
+
187
+ withoutGroup.forEach(testObject => {
188
+ expect(testObject.testFn).not.toHaveBeenCalled();
189
+ });
190
+ });
191
+ });
192
+
193
+ describe('When skipped field inside `only`ed group', () => {
194
+ beforeEach(() => {
195
+ res = suite({ skip: 'field_1', onlyGroup: groupName });
196
+ });
197
+ it('produce result object with group', () => {
198
+ expect(res.groups).toHaveProperty(groupName);
199
+ });
200
+
201
+ it('Should run all tests within group but skipped test', () => {
202
+ Object.values(groupTestObjects)
203
+ // all but skipped test
204
+ .filter(({ fieldName }) => fieldName !== 'field_1')
205
+ .filter(testObject => testObject.groupName === groupName)
206
+ .forEach(testObject => {
207
+ expect(testObject.testFn).toHaveBeenCalled();
208
+ });
209
+
210
+ Object.values(groupTestObjects)
211
+ // only skipped test
212
+ .filter(({ fieldName }) => fieldName === 'field_1')
213
+ .forEach(testObject => {
214
+ expect(testObject.testFn).not.toHaveBeenCalled();
215
+ });
216
+ });
217
+ it('Should skip all tests outside of the group', () => {
218
+ Object.values(topLevelTestObjects).forEach(testObject => {
219
+ expect(testObject.testFn).not.toHaveBeenCalled();
220
+ });
221
+ });
222
+ });
223
+ });
224
+
225
+ describe('group: base case', () => {
226
+ let inGroup: IsolateTest, outsideGroup: IsolateTest;
227
+ const validation = () =>
228
+ vest.create(() => {
229
+ dummyTest.failing('field_1');
230
+ dummyTest.failing('field_1');
231
+ dummyTest.passing('field_2');
232
+ dummyTest.failingWarning('field_3');
233
+ dummyTest.passingWarning('field_4');
234
+ dummyTest.failing('field_5');
235
+
236
+ group(groupName, () => {
237
+ dummyTest.failing('field_1');
238
+ dummyTest.passing('field_2');
239
+ dummyTest.failingWarning('field_3');
240
+ dummyTest.passingWarning('field_4');
241
+ inGroup = dummyTest.failing('field_6');
242
+ });
243
+
244
+ outsideGroup = dummyTest.failing('last');
245
+ });
246
+ let res: vest.SuiteRunResult<string>;
247
+ beforeEach(() => {
248
+ groupName = faker.random.word();
249
+ const suite = validation();
250
+ res = suite();
251
+ });
252
+
253
+ it('Should contain all tests in tests object', () => {
254
+ expect(res.tests).toHaveProperty('field_1');
255
+ expect(res.tests).toHaveProperty('field_2');
256
+ expect(res.tests).toHaveProperty('field_3');
257
+ expect(res.tests).toHaveProperty('field_4');
258
+ expect(res.tests).toHaveProperty('field_5');
259
+ expect(res.tests).toHaveProperty('field_6');
260
+ });
261
+
262
+ it('Should contain only group test in group object', () => {
263
+ expect(res.groups[groupName]).toHaveProperty('field_1');
264
+ expect(res.groups[groupName]).toHaveProperty('field_2');
265
+ expect(res.groups[groupName]).toHaveProperty('field_3');
266
+ expect(res.groups[groupName]).toHaveProperty('field_4');
267
+ expect(res.groups[groupName]).not.toHaveProperty('field_5');
268
+ expect(res.groups[groupName]).toHaveProperty('field_6');
269
+ });
270
+
271
+ it('Should have all group errors inside test object', () => {
272
+ expect(res.tests['field_1'].errors).toEqual(
273
+ expect.arrayContaining(res.groups[groupName]['field_1'].errors)
274
+ );
275
+
276
+ // This one is equal because it has no errors and no warnings - so both represent the base object
277
+ // The test count is different, though
278
+ expect(_.omit(res.tests['field_2'], 'testCount')).toMatchObject(
279
+ _.omit(res.groups[groupName]['field_2'], 'testCount')
280
+ );
281
+
282
+ expect(res.tests['field_3'].warnings).toEqual(
283
+ expect.arrayContaining(res.groups[groupName]['field_3'].warnings)
284
+ );
285
+
286
+ // This one is equal since it has no tests outside the group
287
+ expect(res.tests['field_6']).toEqual(res.groups[groupName]['field_6']);
288
+ });
289
+
290
+ test('Group object is a subset of test object (negating previous test)', () => {
291
+ expect(res.groups[groupName]['field_1'].errors).not.toEqual(
292
+ expect.arrayContaining(res.tests['field_1'].errors)
293
+ );
294
+
295
+ enforce(res.groups[groupName]['field_1'].errorCount).lte(
296
+ res.tests['field_1'].errorCount
297
+ );
298
+
299
+ expect(res.groups[groupName]['field_3'].warnings).not.toEqual(
300
+ expect.arrayContaining(res.tests['field_3'].warnings)
301
+ );
302
+ enforce(res.groups[groupName]['field_3'].warnCount).lte(
303
+ res.tests['field_3'].warnCount
304
+ );
305
+ });
306
+
307
+ describe('Test object creation', () => {
308
+ it('when in group, should create test with matching group property', () => {
309
+ expect(inGroup.groupName).toBe(groupName);
310
+ });
311
+
312
+ it('after exiting group, should create est without group property', () => {
313
+ expect(outsideGroup).not.toHaveProperty('groupName');
314
+ });
315
+ });
316
+
317
+ test('Group validity', () => {
318
+ const suite = vest.create(() => {
319
+ vest.group('group_1', () => {
320
+ vest.test('field_1', () => {});
321
+ vest.test('field_2', () => {});
322
+ vest.test('field_2', () => false);
323
+ });
324
+ vest.group('group_2', () => {
325
+ vest.test('field_1', () => false);
326
+ vest.test('field_2', () => {});
327
+ });
328
+ vest.group('group_3', () => {
329
+ vest.test('field_1', () => false);
330
+ vest.test('field_2', () => false);
331
+ });
332
+ vest.group('group_4', () => {
333
+ vest.test('field_1', () => {});
334
+ vest.test('field_2', () => {});
335
+ });
336
+ });
337
+
338
+ const res = suite();
339
+
340
+ expect(res.groups.group_1.field_1.valid).toBe(true);
341
+ expect(res.groups.group_1.field_2.valid).toBe(false);
342
+ expect(res.groups.group_2.field_1.valid).toBe(false);
343
+ expect(res.groups.group_2.field_2.valid).toBe(true);
344
+ expect(res.groups.group_3.field_1.valid).toBe(false);
345
+ expect(res.groups.group_3.field_2.valid).toBe(false);
346
+ expect(res.groups.group_4.field_1.valid).toBe(true);
347
+ expect(res.groups.group_4.field_2.valid).toBe(true);
348
+ expect(res.isValidByGroup('group_1')).toBe(false);
349
+ expect(res.isValidByGroup('group_1', 'field_1')).toBe(true);
350
+ expect(res.isValidByGroup('group_1', 'field_2')).toBe(false);
351
+ expect(res.isValidByGroup('group_2')).toBe(false);
352
+ expect(res.isValidByGroup('group_2', 'field_1')).toBe(false);
353
+ expect(res.isValidByGroup('group_2', 'field_2')).toBe(true);
354
+ expect(res.isValidByGroup('group_3')).toBe(false);
355
+ expect(res.isValidByGroup('group_3', 'field_1')).toBe(false);
356
+ expect(res.isValidByGroup('group_3', 'field_2')).toBe(false);
357
+ expect(res.isValidByGroup('group_4')).toBe(true);
358
+ expect(res.isValidByGroup('group_4', 'field_1')).toBe(true);
359
+ expect(res.isValidByGroup('group_4', 'field_2')).toBe(true);
360
+ expect(res).toMatchSnapshot();
361
+ });
362
+ });
@@ -0,0 +1,246 @@
1
+ import { TTestSuite } from 'testUtils/TVestMock';
2
+ import * as vest from 'vest';
3
+ import { omitWhen, only } from 'vest';
4
+
5
+ describe('omitWhen', () => {
6
+ let suite: TTestSuite;
7
+ let cb1 = jest.fn(),
8
+ cb2 = jest.fn(),
9
+ cb3 = jest.fn(),
10
+ cb4 = jest.fn(),
11
+ cb5 = jest.fn(),
12
+ allFieldsPass: boolean | undefined;
13
+
14
+ beforeEach(() => {
15
+ cb1 = jest.fn();
16
+ cb2 = jest.fn(() => (allFieldsPass ? undefined : false));
17
+ cb3 = jest.fn(() => (allFieldsPass ? undefined : false));
18
+ cb4 = jest.fn(() => (allFieldsPass ? undefined : false));
19
+ cb5 = jest.fn();
20
+
21
+ suite = vest.create((omitConditional, currentField) => {
22
+ only(currentField);
23
+ vest.test('field_1', cb1);
24
+ vest.test('field_2', cb2);
25
+
26
+ omitWhen(omitConditional, () => {
27
+ vest.test('field_1', cb3);
28
+ vest.test('field_3', cb4);
29
+ vest.test('field_4', cb5);
30
+ });
31
+ });
32
+ });
33
+
34
+ afterEach(() => {
35
+ allFieldsPass = undefined;
36
+ });
37
+
38
+ describe('When conditional is falsy', () => {
39
+ describe.each([
40
+ ['boolean conditional', false],
41
+ ['function conditional', () => false],
42
+ ])('%s', (_, omitConditional) => {
43
+ it('Should run tests normally', () => {
44
+ suite(omitConditional, 'field_1');
45
+ expect(cb1).toHaveBeenCalledTimes(1);
46
+ expect(cb2).not.toHaveBeenCalled();
47
+ expect(cb3).toHaveBeenCalledTimes(1);
48
+ expect(cb4).not.toHaveBeenCalled();
49
+ expect(cb5).not.toHaveBeenCalled();
50
+ expect(suite.get().hasErrors('field_1')).toBe(true);
51
+ expect(suite.get().tests.field_1.testCount).toBe(2);
52
+ expect(suite.get().tests.field_1.errorCount).toBe(1);
53
+ expect(suite.get().hasErrors('field_2')).toBe(false);
54
+ expect(suite.get().hasErrors('field_3')).toBe(false);
55
+ expect(suite.get().hasErrors('field_4')).toBe(false);
56
+ expect(suite.get().tests).toMatchSnapshot();
57
+ suite(omitConditional, 'field_4');
58
+ expect(cb1).toHaveBeenCalledTimes(1);
59
+ expect(cb2).not.toHaveBeenCalled();
60
+ expect(cb3).toHaveBeenCalledTimes(1);
61
+ expect(cb4).not.toHaveBeenCalled();
62
+ expect(cb5).toHaveBeenCalledTimes(1);
63
+ expect(suite.get().hasErrors('field_1')).toBe(true);
64
+ expect(suite.get().tests.field_1.testCount).toBe(2);
65
+ expect(suite.get().tests.field_1.errorCount).toBe(1);
66
+ expect(suite.get().hasErrors('field_2')).toBe(false);
67
+ expect(suite.get().hasErrors('field_3')).toBe(false);
68
+ expect(suite.get().hasErrors('field_4')).toBe(false);
69
+ expect(suite.get().tests.field_4.testCount).toBe(1);
70
+ expect(suite.get().tests.field_4.errorCount).toBe(0);
71
+ expect(suite.get().tests).toMatchSnapshot();
72
+ });
73
+
74
+ it('Should have all tests within the omit block referenced in the result', () => {
75
+ suite(omitConditional, 'field_1');
76
+ expect(suite.get().tests.field_1).toBeDefined();
77
+ expect(suite.get().tests.field_3).toBeDefined();
78
+ expect(suite.get().tests.field_4).toBeDefined();
79
+ expect(suite.get().tests).toMatchSnapshot();
80
+ });
81
+
82
+ it('Should retain normal `isValid` functionality', () => {
83
+ expect(suite.get().isValid()).toBe(false);
84
+ suite(omitConditional, 'field_1');
85
+ expect(suite.get().isValid()).toBe(false);
86
+ allFieldsPass = true;
87
+ suite(omitConditional);
88
+ expect(suite.get().isValid()).toBe(true);
89
+ });
90
+ });
91
+ });
92
+
93
+ describe('When conditional is truthy', () => {
94
+ describe.each([
95
+ ['boolean conditional', true],
96
+ ['function conditional', () => true],
97
+ ])('%s', (_, omitConditional) => {
98
+ it('Should avoid running the omitted tests', () => {
99
+ suite(omitConditional, 'field_1');
100
+ expect(suite.get().tests.field_1.testCount).toBe(1);
101
+ suite(omitConditional, 'field_2');
102
+ expect(suite.get().tests.field_2.testCount).toBe(1);
103
+ suite(omitConditional, 'field_3');
104
+ expect(suite.get().tests.field_3.testCount).toBe(0);
105
+ suite(omitConditional, 'field_4');
106
+ expect(suite.get().tests.field_4.testCount).toBe(0);
107
+ expect(cb1).toHaveBeenCalledTimes(1);
108
+ expect(cb2).toHaveBeenCalledTimes(1);
109
+ expect(cb3).toHaveBeenCalledTimes(0);
110
+ expect(cb4).toHaveBeenCalledTimes(0);
111
+ expect(cb5).toHaveBeenCalledTimes(0);
112
+ suite(omitConditional);
113
+ expect(cb1).toHaveBeenCalledTimes(2);
114
+ expect(cb2).toHaveBeenCalledTimes(2);
115
+ expect(cb3).toHaveBeenCalledTimes(0);
116
+ expect(cb4).toHaveBeenCalledTimes(0);
117
+ expect(cb5).toHaveBeenCalledTimes(0);
118
+ expect(suite.get()).toMatchSnapshot();
119
+ });
120
+
121
+ it('Should consider the suite as valid even without the omitted tests', () => {
122
+ expect(suite.get().isValid()).toBe(false);
123
+ suite(omitConditional, 'field_1');
124
+ expect(suite.get().isValid()).toBe(false);
125
+ suite(omitConditional, 'field_2');
126
+ expect(suite.get().isValid()).toBe(false);
127
+ allFieldsPass = true;
128
+ suite(omitConditional, 'field_2');
129
+ expect(suite.get().tests.field_1.testCount).toBe(1);
130
+ expect(suite.get().tests.field_2.testCount).toBe(1);
131
+ expect(suite.get().tests.field_3.testCount).toBe(0);
132
+ expect(suite.get().tests.field_4.testCount).toBe(0);
133
+
134
+ expect(suite.get().isValid()).toBe(true);
135
+ });
136
+
137
+ it('Should skip and not run omitted fields when no filter provided', () => {
138
+ suite(omitConditional);
139
+ expect(suite.get().tests.field_1.testCount).toBe(1);
140
+ expect(suite.get().tests.field_2.testCount).toBe(1);
141
+ expect(suite.get().tests.field_3.testCount).toBe(0);
142
+ expect(suite.get().tests.field_4.testCount).toBe(0);
143
+ expect(suite.get()).toMatchSnapshot();
144
+ });
145
+ });
146
+ });
147
+
148
+ describe('When the conditional changes between runs', () => {
149
+ it('Should omit previously run fields if changes to `true`', () => {
150
+ suite(false, 'field_1');
151
+ expect(suite.get().tests.field_1.testCount).toBe(2);
152
+ expect(cb1).toHaveBeenCalledTimes(1);
153
+ expect(cb3).toHaveBeenCalledTimes(1);
154
+ suite(true, 'field_1');
155
+ expect(suite.get().tests.field_1.testCount).toBe(1);
156
+ expect(cb1).toHaveBeenCalledTimes(2);
157
+ expect(cb3).toHaveBeenCalledTimes(1);
158
+ });
159
+
160
+ it('Should run fields that were previously omitted when changing to `false`', () => {
161
+ suite(true, 'field_3');
162
+ expect(suite.get().tests.field_3.testCount).toBe(0);
163
+ expect(cb4).toHaveBeenCalledTimes(0);
164
+ suite(false, 'field_3');
165
+ expect(suite.get().tests.field_3.testCount).toBe(1);
166
+ expect(cb4).toHaveBeenCalledTimes(1);
167
+ });
168
+ });
169
+
170
+ describe('nested calls', () => {
171
+ let suite: TTestSuite;
172
+
173
+ describe('omitted in non-omitted', () => {
174
+ beforeEach(() => {
175
+ suite = vest.create(() => {
176
+ vest.omitWhen(false, () => {
177
+ vest.test('outer', () => false);
178
+
179
+ vest.omitWhen(true, () => {
180
+ vest.test('inner', () => false);
181
+ });
182
+ });
183
+ });
184
+ suite();
185
+ });
186
+ it('Should run `outer` and omit `inner`', () => {
187
+ expect(suite.get().testCount).toBe(1);
188
+ expect(suite.get().hasErrors('outer')).toBe(true);
189
+ expect(suite.get().hasErrors('inner')).toBe(false);
190
+ });
191
+ });
192
+
193
+ describe('omitted in omitted', () => {
194
+ beforeEach(() => {
195
+ suite = vest.create(() => {
196
+ vest.omitWhen(true, () => {
197
+ vest.test('outer', () => false);
198
+
199
+ vest.omitWhen(true, () => {
200
+ vest.test('inner', () => false);
201
+ });
202
+ });
203
+ });
204
+ suite();
205
+ });
206
+ it('Should omit both `outer` and `inner`', () => {
207
+ expect(suite.get().testCount).toBe(0);
208
+ expect(suite.get().hasErrors('outer')).toBe(false);
209
+ expect(suite.get().hasErrors('inner')).toBe(false);
210
+ });
211
+ });
212
+ describe('non-omitted in omitted', () => {
213
+ beforeEach(() => {
214
+ suite = vest.create(() => {
215
+ vest.omitWhen(true, () => {
216
+ vest.test('outer', () => false);
217
+
218
+ vest.omitWhen(false, () => {
219
+ vest.test('inner', () => false);
220
+ });
221
+ });
222
+ });
223
+ suite();
224
+ });
225
+ it('Should omit both', () => {
226
+ expect(suite.get().testCount).toBe(0);
227
+ expect(suite.get().hasErrors('outer')).toBe(false);
228
+ expect(suite.get().hasErrors('inner')).toBe(false);
229
+ });
230
+ });
231
+ });
232
+
233
+ describe('When some tests of the same field are inside omitWhen and some not', () => {
234
+ it('Should mark the field as invalid when failing', () => {
235
+ const res = vest.create(() => {
236
+ vest.test('f1', () => false);
237
+
238
+ vest.omitWhen(true, () => {
239
+ vest.test('f1', () => false);
240
+ });
241
+ })();
242
+ expect(res.isValid()).toBe(false);
243
+ expect(res.isValid('f1')).toBe(false);
244
+ });
245
+ });
246
+ });