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,376 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Stateful behavior Should merge skipped fields with previous values 1`] = `
4
+ {
5
+ "done": [Function],
6
+ "errorCount": 1,
7
+ "getErrors": [Function],
8
+ "getErrorsByGroup": [Function],
9
+ "getWarnings": [Function],
10
+ "getWarningsByGroup": [Function],
11
+ "groups": {},
12
+ "hasErrors": [Function],
13
+ "hasErrorsByGroup": [Function],
14
+ "hasWarnings": [Function],
15
+ "hasWarningsByGroup": [Function],
16
+ "isValid": [Function],
17
+ "isValidByGroup": [Function],
18
+ "suiteName": undefined,
19
+ "testCount": 1,
20
+ "tests": {
21
+ "field_1": {
22
+ "errorCount": 1,
23
+ "errors": [
24
+ "field_statement_1",
25
+ ],
26
+ "testCount": 1,
27
+ "valid": false,
28
+ "warnCount": 0,
29
+ "warnings": [],
30
+ },
31
+ "field_2": {
32
+ "errorCount": 0,
33
+ "errors": [],
34
+ "testCount": 0,
35
+ "valid": false,
36
+ "warnCount": 0,
37
+ "warnings": [],
38
+ },
39
+ "field_3": {
40
+ "errorCount": 0,
41
+ "errors": [],
42
+ "testCount": 0,
43
+ "valid": false,
44
+ "warnCount": 0,
45
+ "warnings": [],
46
+ },
47
+ "field_4": {
48
+ "errorCount": 0,
49
+ "errors": [],
50
+ "testCount": 0,
51
+ "valid": false,
52
+ "warnCount": 0,
53
+ "warnings": [],
54
+ },
55
+ "field_5": {
56
+ "errorCount": 0,
57
+ "errors": [],
58
+ "testCount": 0,
59
+ "valid": false,
60
+ "warnCount": 0,
61
+ "warnings": [],
62
+ },
63
+ },
64
+ "valid": false,
65
+ "warnCount": 0,
66
+ }
67
+ `;
68
+
69
+ exports[`Stateful behavior Should merge skipped fields with previous values 2`] = `
70
+ {
71
+ "done": [Function],
72
+ "errorCount": 3,
73
+ "getErrors": [Function],
74
+ "getErrorsByGroup": [Function],
75
+ "getWarnings": [Function],
76
+ "getWarningsByGroup": [Function],
77
+ "groups": {},
78
+ "hasErrors": [Function],
79
+ "hasErrorsByGroup": [Function],
80
+ "hasWarnings": [Function],
81
+ "hasWarningsByGroup": [Function],
82
+ "isValid": [Function],
83
+ "isValidByGroup": [Function],
84
+ "suiteName": undefined,
85
+ "testCount": 3,
86
+ "tests": {
87
+ "field_1": {
88
+ "errorCount": 1,
89
+ "errors": [
90
+ "field_statement_1",
91
+ ],
92
+ "testCount": 1,
93
+ "valid": false,
94
+ "warnCount": 0,
95
+ "warnings": [],
96
+ },
97
+ "field_2": {
98
+ "errorCount": 0,
99
+ "errors": [],
100
+ "testCount": 0,
101
+ "valid": false,
102
+ "warnCount": 0,
103
+ "warnings": [],
104
+ },
105
+ "field_3": {
106
+ "errorCount": 0,
107
+ "errors": [],
108
+ "testCount": 0,
109
+ "valid": false,
110
+ "warnCount": 0,
111
+ "warnings": [],
112
+ },
113
+ "field_4": {
114
+ "errorCount": 0,
115
+ "errors": [],
116
+ "testCount": 0,
117
+ "valid": false,
118
+ "warnCount": 0,
119
+ "warnings": [],
120
+ },
121
+ "field_5": {
122
+ "errorCount": 2,
123
+ "errors": [
124
+ "field_statement_5",
125
+ "field_statement_6",
126
+ ],
127
+ "testCount": 2,
128
+ "valid": false,
129
+ "warnCount": 0,
130
+ "warnings": [],
131
+ },
132
+ },
133
+ "valid": false,
134
+ "warnCount": 0,
135
+ }
136
+ `;
137
+
138
+ exports[`Stateful behavior Should merge skipped fields with previous values 3`] = `
139
+ {
140
+ "done": [Function],
141
+ "errorCount": 4,
142
+ "getErrors": [Function],
143
+ "getErrorsByGroup": [Function],
144
+ "getWarnings": [Function],
145
+ "getWarningsByGroup": [Function],
146
+ "groups": {},
147
+ "hasErrors": [Function],
148
+ "hasErrorsByGroup": [Function],
149
+ "hasWarnings": [Function],
150
+ "hasWarningsByGroup": [Function],
151
+ "isValid": [Function],
152
+ "isValidByGroup": [Function],
153
+ "suiteName": undefined,
154
+ "testCount": 7,
155
+ "tests": {
156
+ "field_1": {
157
+ "errorCount": 1,
158
+ "errors": [
159
+ "field_statement_1",
160
+ ],
161
+ "testCount": 1,
162
+ "valid": false,
163
+ "warnCount": 0,
164
+ "warnings": [],
165
+ },
166
+ "field_2": {
167
+ "errorCount": 1,
168
+ "errors": [
169
+ "field_statement_2",
170
+ ],
171
+ "testCount": 1,
172
+ "valid": false,
173
+ "warnCount": 0,
174
+ "warnings": [],
175
+ },
176
+ "field_3": {
177
+ "errorCount": 0,
178
+ "errors": [],
179
+ "testCount": 1,
180
+ "valid": true,
181
+ "warnCount": 0,
182
+ "warnings": [],
183
+ },
184
+ "field_4": {
185
+ "errorCount": 0,
186
+ "errors": [],
187
+ "testCount": 2,
188
+ "valid": true,
189
+ "warnCount": 1,
190
+ "warnings": [
191
+ "field_statement_4",
192
+ ],
193
+ },
194
+ "field_5": {
195
+ "errorCount": 2,
196
+ "errors": [
197
+ "field_statement_5",
198
+ "field_statement_6",
199
+ ],
200
+ "testCount": 2,
201
+ "valid": false,
202
+ "warnCount": 0,
203
+ "warnings": [],
204
+ },
205
+ },
206
+ "valid": false,
207
+ "warnCount": 1,
208
+ }
209
+ `;
210
+
211
+ exports[`more complex Should run correctly 1`] = `
212
+ {
213
+ "errorCount": 0,
214
+ "getErrors": [Function],
215
+ "getErrorsByGroup": [Function],
216
+ "getWarnings": [Function],
217
+ "getWarningsByGroup": [Function],
218
+ "groups": {},
219
+ "hasErrors": [Function],
220
+ "hasErrorsByGroup": [Function],
221
+ "hasWarnings": [Function],
222
+ "hasWarningsByGroup": [Function],
223
+ "isValid": [Function],
224
+ "isValidByGroup": [Function],
225
+ "suiteName": undefined,
226
+ "testCount": 0,
227
+ "tests": {},
228
+ "valid": false,
229
+ "warnCount": 0,
230
+ }
231
+ `;
232
+
233
+ exports[`more complex Should run correctly 2`] = `
234
+ {
235
+ "errorCount": 0,
236
+ "getErrors": [Function],
237
+ "getErrorsByGroup": [Function],
238
+ "getWarnings": [Function],
239
+ "getWarningsByGroup": [Function],
240
+ "groups": {},
241
+ "hasErrors": [Function],
242
+ "hasErrorsByGroup": [Function],
243
+ "hasWarnings": [Function],
244
+ "hasWarningsByGroup": [Function],
245
+ "isValid": [Function],
246
+ "isValidByGroup": [Function],
247
+ "suiteName": undefined,
248
+ "testCount": 2,
249
+ "tests": {
250
+ "confirm": {
251
+ "errorCount": 0,
252
+ "errors": [],
253
+ "testCount": 0,
254
+ "valid": false,
255
+ "warnCount": 0,
256
+ "warnings": [],
257
+ },
258
+ "password": {
259
+ "errorCount": 0,
260
+ "errors": [],
261
+ "testCount": 0,
262
+ "valid": false,
263
+ "warnCount": 0,
264
+ "warnings": [],
265
+ },
266
+ "username": {
267
+ "errorCount": 0,
268
+ "errors": [],
269
+ "testCount": 2,
270
+ "valid": true,
271
+ "warnCount": 0,
272
+ "warnings": [],
273
+ },
274
+ },
275
+ "valid": false,
276
+ "warnCount": 0,
277
+ }
278
+ `;
279
+
280
+ exports[`more complex Should run correctly 4`] = `
281
+ {
282
+ "errorCount": 1,
283
+ "getErrors": [Function],
284
+ "getErrorsByGroup": [Function],
285
+ "getWarnings": [Function],
286
+ "getWarningsByGroup": [Function],
287
+ "groups": {},
288
+ "hasErrors": [Function],
289
+ "hasErrorsByGroup": [Function],
290
+ "hasWarnings": [Function],
291
+ "hasWarningsByGroup": [Function],
292
+ "isValid": [Function],
293
+ "isValidByGroup": [Function],
294
+ "suiteName": undefined,
295
+ "testCount": 3,
296
+ "tests": {
297
+ "confirm": {
298
+ "errorCount": 0,
299
+ "errors": [],
300
+ "testCount": 0,
301
+ "valid": false,
302
+ "warnCount": 0,
303
+ "warnings": [],
304
+ },
305
+ "password": {
306
+ "errorCount": 1,
307
+ "errors": [
308
+ "password is required",
309
+ ],
310
+ "testCount": 1,
311
+ "valid": false,
312
+ "warnCount": 0,
313
+ "warnings": [],
314
+ },
315
+ "username": {
316
+ "errorCount": 0,
317
+ "errors": [],
318
+ "testCount": 2,
319
+ "valid": true,
320
+ "warnCount": 0,
321
+ "warnings": [],
322
+ },
323
+ },
324
+ "valid": false,
325
+ "warnCount": 0,
326
+ }
327
+ `;
328
+
329
+ exports[`more complex Should run correctly 6`] = `
330
+ {
331
+ "errorCount": 1,
332
+ "getErrors": [Function],
333
+ "getErrorsByGroup": [Function],
334
+ "getWarnings": [Function],
335
+ "getWarningsByGroup": [Function],
336
+ "groups": {},
337
+ "hasErrors": [Function],
338
+ "hasErrorsByGroup": [Function],
339
+ "hasWarnings": [Function],
340
+ "hasWarningsByGroup": [Function],
341
+ "isValid": [Function],
342
+ "isValidByGroup": [Function],
343
+ "suiteName": undefined,
344
+ "testCount": 3,
345
+ "tests": {
346
+ "confirm": {
347
+ "errorCount": 0,
348
+ "errors": [],
349
+ "testCount": 0,
350
+ "valid": false,
351
+ "warnCount": 0,
352
+ "warnings": [],
353
+ },
354
+ "password": {
355
+ "errorCount": 1,
356
+ "errors": [
357
+ "password is required",
358
+ ],
359
+ "testCount": 1,
360
+ "valid": false,
361
+ "warnCount": 0,
362
+ "warnings": [],
363
+ },
364
+ "username": {
365
+ "errorCount": 0,
366
+ "errors": [],
367
+ "testCount": 2,
368
+ "valid": true,
369
+ "warnCount": 0,
370
+ "warnings": [],
371
+ },
372
+ },
373
+ "valid": false,
374
+ "warnCount": 0,
375
+ }
376
+ `;
@@ -0,0 +1,90 @@
1
+ import wait from 'wait';
2
+
3
+ import { TestPromise } from '../../testUtils/testPromise';
4
+
5
+ import * as vest from 'vest';
6
+ import { TTestSuite } from 'testUtils/TVestMock';
7
+
8
+ function genSuite() {
9
+ return vest.create(() => {
10
+ vest.test('field_1', 'field_statement_1', () => false);
11
+ vest.test('field_2', 'field_statement_2', () => {
12
+ vest.enforce(2).equals(3);
13
+ });
14
+ vest.test('field_3', 'field_statement_3', jest.fn());
15
+ vest.test('field_4', 'field_statement_4', () => {
16
+ vest.warn();
17
+ throw new Error();
18
+ });
19
+ vest.test('field_4', 'field_statement_4', () => {
20
+ vest.warn();
21
+ });
22
+ vest.test('field_5', 'field_statement_5', () => false);
23
+ vest.test('field_5', 'field_statement_6', () => false);
24
+ vest.test('field_6', 'async_statement_1', async () => {
25
+ await wait(250);
26
+ });
27
+ vest.test('field_7', () => Promise.reject('async_statement_2'));
28
+ });
29
+ }
30
+
31
+ let suite: TTestSuite;
32
+ describe('Stateful behavior', () => {
33
+ let result,
34
+ callback_1 = jest.fn(),
35
+ callback_2 = jest.fn(),
36
+ callback_3 = jest.fn(),
37
+ control = jest.fn();
38
+
39
+ beforeEach(() => {
40
+ suite = genSuite();
41
+ });
42
+
43
+ beforeAll(() => {
44
+ callback_1 = jest.fn();
45
+ callback_2 = jest.fn();
46
+ callback_3 = jest.fn();
47
+ control = jest.fn();
48
+ });
49
+
50
+ test('Should have all fields', () =>
51
+ TestPromise(done => {
52
+ // ❗️Why is this test async? Because of the `resetState` beforeEach.
53
+ // We must not clean up before the suite is actually done.
54
+ result = suite().done(done);
55
+ expect(result.tests).toHaveProperty('field_1');
56
+ expect(result.tests).toHaveProperty('field_2');
57
+ expect(result.tests).toHaveProperty('field_4');
58
+ expect(result.tests).toHaveProperty('field_5');
59
+ expect(result.tests).toHaveProperty('field_6');
60
+ expect(result.tests).toHaveProperty('field_7');
61
+ expect(result.hasErrors('field_7')).toBe(false);
62
+ expect(result.tests).toMatchSnapshot();
63
+ }));
64
+
65
+ it('Should invoke done callback specified with sync field immediately, and the others after finishing', () =>
66
+ TestPromise(done => {
67
+ result = suite();
68
+ result
69
+ .done('field_1', callback_1)
70
+ .done('field_6', callback_2)
71
+ .done(callback_3);
72
+ expect(callback_1).toHaveBeenCalled();
73
+ expect(callback_2).not.toHaveBeenCalled();
74
+ expect(callback_3).not.toHaveBeenCalled();
75
+
76
+ setTimeout(() => {
77
+ expect(callback_2).not.toHaveBeenCalled();
78
+ expect(callback_3).not.toHaveBeenCalled();
79
+ expect(suite.get().hasErrors('field_7')).toBe(true);
80
+ control();
81
+ });
82
+
83
+ setTimeout(() => {
84
+ expect(callback_2).toHaveBeenCalled();
85
+ expect(callback_3).toHaveBeenCalled();
86
+ expect(control).toHaveBeenCalled();
87
+ done();
88
+ }, 250);
89
+ }));
90
+ });
@@ -0,0 +1,45 @@
1
+ import * as vest from 'vest';
2
+
3
+ const suite = () =>
4
+ vest.create(() => {
5
+ vest.skip('field_5');
6
+ vest.test('field_1', 'field_statement_1', () => false);
7
+ vest.test('field_2', 'field_statement_2', () => {
8
+ expect(2).toBe(3);
9
+ });
10
+ vest.test('field_3', 'field_statement_3', jest.fn());
11
+ vest.test('field_4', 'field_statement_4', () => {
12
+ vest.warn();
13
+ throw new Error();
14
+ });
15
+
16
+ vest.test('field_4', 'field_statement_4', () => {
17
+ vest.warn();
18
+ });
19
+ vest.test('field_5', 'field_statement_5', () => false);
20
+ vest.test('field_5', 'field_statement_6', () => false);
21
+ })();
22
+
23
+ describe('Base behavior', () => {
24
+ let res: vest.SuiteRunResult<string>;
25
+
26
+ beforeEach(() => {
27
+ res = suite();
28
+ });
29
+
30
+ test('Should produce correct validation result', () => {
31
+ expect(res.tests).toHaveProperty('field_1');
32
+ expect(res.tests).toHaveProperty('field_2');
33
+ expect(res.tests).toHaveProperty('field_3');
34
+ expect(res.tests).toHaveProperty('field_4');
35
+ expect(res.tests.field_5.testCount).toBe(0);
36
+ expect(suite()).toMatchSnapshot();
37
+ });
38
+
39
+ it('Should run done callbacks immediately', () => {
40
+ const callback = jest.fn();
41
+ res.done(callback);
42
+
43
+ expect(callback).toHaveBeenCalled();
44
+ });
45
+ });
@@ -0,0 +1,88 @@
1
+ import * as vest from 'vest';
2
+
3
+ let suite: vest.Suite<
4
+ (exclusion?: Record<string, string | string[]>) => void,
5
+ string
6
+ >;
7
+
8
+ beforeEach(() => {
9
+ suite = genSuite();
10
+ });
11
+
12
+ describe('only', () => {
13
+ it('Should only count included fields', () => {
14
+ const res = suite({
15
+ only: ['field_1', 'field_2'],
16
+ });
17
+
18
+ expect(res.tests.field_1.testCount).toBe(1);
19
+ expect(res.tests.field_2.testCount).toBe(1);
20
+ expect(res.tests.field_3.testCount).toBe(0);
21
+ expect(res.tests.field_4.testCount).toBe(0);
22
+ expect(res.tests.field_5.testCount).toBe(0);
23
+ });
24
+ it('Should only count included field', () => {
25
+ const res = suite({
26
+ only: 'field_1',
27
+ });
28
+
29
+ expect(res.tests.field_1.testCount).toBe(1);
30
+ expect(res.tests.field_2.testCount).toBe(0);
31
+ expect(res.tests.field_3.testCount).toBe(0);
32
+ expect(res.tests.field_4.testCount).toBe(0);
33
+ expect(res.tests.field_5.testCount).toBe(0);
34
+ });
35
+ });
36
+ describe('skip', () => {
37
+ it('Should count all but excluded fields', () => {
38
+ const res = suite({
39
+ skip: ['field_1', 'field_2'],
40
+ });
41
+
42
+ expect(res.tests.field_1.testCount).toBe(0);
43
+ expect(res.tests.field_2.testCount).toBe(0);
44
+ expect(res.tests.field_3.testCount).toBe(1);
45
+ expect(res.tests.field_4.testCount).toBe(1);
46
+ expect(res.tests.field_5.testCount).toBe(1);
47
+ });
48
+
49
+ it('Should count all but excluded field', () => {
50
+ const res = suite({
51
+ skip: 'field_1',
52
+ });
53
+
54
+ expect(res.tests.field_1.testCount).toBe(0);
55
+ expect(res.tests.field_2.testCount).toBe(1);
56
+ expect(res.tests.field_3.testCount).toBe(1);
57
+ expect(res.tests.field_4.testCount).toBe(1);
58
+ expect(res.tests.field_5.testCount).toBe(1);
59
+ });
60
+ });
61
+
62
+ describe('Combined', () => {
63
+ test('Last declaration wins', () => {
64
+ const res = suite({
65
+ only: ['field_1', 'field_2', 'field_3'],
66
+ skip: ['field_1'],
67
+ skip_last: 'field_3',
68
+ });
69
+
70
+ expect(res.tests.field_1.testCount).toBe(1);
71
+ expect(res.tests.field_2.testCount).toBe(1);
72
+ expect(res.tests.field_3.testCount).toBe(0);
73
+ });
74
+ });
75
+
76
+ function genSuite() {
77
+ return vest.create((exclusion: Record<string, string | string[]> = {}) => {
78
+ vest.skip(exclusion?.skip);
79
+ vest.only(exclusion?.only);
80
+ vest.skip(exclusion?.skip_last);
81
+
82
+ vest.test('field_1', 'msg', () => {});
83
+ vest.test('field_2', 'msg', () => {});
84
+ vest.test('field_3', 'msg', () => {});
85
+ vest.test('field_4', 'msg', () => {});
86
+ vest.test('field_5', 'msg', () => {});
87
+ });
88
+ }