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,231 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Test Vest's \`test\` function test params creates a test with a message and with a key 1`] = `
|
|
4
|
+
IsolateTest {
|
|
5
|
+
"children": null,
|
|
6
|
+
"fieldName": "field_name",
|
|
7
|
+
"id": "23",
|
|
8
|
+
"key": "keyboardcat",
|
|
9
|
+
"keys": {},
|
|
10
|
+
"message": "failure message",
|
|
11
|
+
"output": undefined,
|
|
12
|
+
"parent": Isolate {
|
|
13
|
+
"children": [
|
|
14
|
+
[Circular],
|
|
15
|
+
],
|
|
16
|
+
"key": null,
|
|
17
|
+
"keys": {
|
|
18
|
+
"keyboardcat": [Circular],
|
|
19
|
+
},
|
|
20
|
+
"output": {
|
|
21
|
+
"done": [Function],
|
|
22
|
+
"errorCount": 0,
|
|
23
|
+
"getErrors": [Function],
|
|
24
|
+
"getErrorsByGroup": [Function],
|
|
25
|
+
"getWarnings": [Function],
|
|
26
|
+
"getWarningsByGroup": [Function],
|
|
27
|
+
"groups": {},
|
|
28
|
+
"hasErrors": [Function],
|
|
29
|
+
"hasErrorsByGroup": [Function],
|
|
30
|
+
"hasWarnings": [Function],
|
|
31
|
+
"hasWarningsByGroup": [Function],
|
|
32
|
+
"isValid": [Function],
|
|
33
|
+
"isValidByGroup": [Function],
|
|
34
|
+
"suiteName": undefined,
|
|
35
|
+
"testCount": 1,
|
|
36
|
+
"tests": {
|
|
37
|
+
"field_name": {
|
|
38
|
+
"errorCount": 0,
|
|
39
|
+
"errors": [],
|
|
40
|
+
"testCount": 1,
|
|
41
|
+
"valid": true,
|
|
42
|
+
"warnCount": 0,
|
|
43
|
+
"warnings": [],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
"valid": true,
|
|
47
|
+
"warnCount": 0,
|
|
48
|
+
},
|
|
49
|
+
"parent": null,
|
|
50
|
+
"type": "SUITE",
|
|
51
|
+
},
|
|
52
|
+
"severity": "error",
|
|
53
|
+
"stateMachine": {
|
|
54
|
+
"getState": [Function],
|
|
55
|
+
"transition": [Function],
|
|
56
|
+
},
|
|
57
|
+
"testFn": [Function],
|
|
58
|
+
"type": "TEST",
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
|
|
62
|
+
exports[`Test Vest's \`test\` function test params creates a test without a key 1`] = `
|
|
63
|
+
IsolateTest {
|
|
64
|
+
"children": null,
|
|
65
|
+
"fieldName": "field_name",
|
|
66
|
+
"id": "19",
|
|
67
|
+
"key": null,
|
|
68
|
+
"keys": {},
|
|
69
|
+
"message": "failure message",
|
|
70
|
+
"output": undefined,
|
|
71
|
+
"parent": Isolate {
|
|
72
|
+
"children": [
|
|
73
|
+
[Circular],
|
|
74
|
+
],
|
|
75
|
+
"key": null,
|
|
76
|
+
"keys": {},
|
|
77
|
+
"output": {
|
|
78
|
+
"done": [Function],
|
|
79
|
+
"errorCount": 0,
|
|
80
|
+
"getErrors": [Function],
|
|
81
|
+
"getErrorsByGroup": [Function],
|
|
82
|
+
"getWarnings": [Function],
|
|
83
|
+
"getWarningsByGroup": [Function],
|
|
84
|
+
"groups": {},
|
|
85
|
+
"hasErrors": [Function],
|
|
86
|
+
"hasErrorsByGroup": [Function],
|
|
87
|
+
"hasWarnings": [Function],
|
|
88
|
+
"hasWarningsByGroup": [Function],
|
|
89
|
+
"isValid": [Function],
|
|
90
|
+
"isValidByGroup": [Function],
|
|
91
|
+
"suiteName": undefined,
|
|
92
|
+
"testCount": 1,
|
|
93
|
+
"tests": {
|
|
94
|
+
"field_name": {
|
|
95
|
+
"errorCount": 0,
|
|
96
|
+
"errors": [],
|
|
97
|
+
"testCount": 1,
|
|
98
|
+
"valid": true,
|
|
99
|
+
"warnCount": 0,
|
|
100
|
+
"warnings": [],
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
"valid": true,
|
|
104
|
+
"warnCount": 0,
|
|
105
|
+
},
|
|
106
|
+
"parent": null,
|
|
107
|
+
"type": "SUITE",
|
|
108
|
+
},
|
|
109
|
+
"severity": "error",
|
|
110
|
+
"stateMachine": {
|
|
111
|
+
"getState": [Function],
|
|
112
|
+
"transition": [Function],
|
|
113
|
+
},
|
|
114
|
+
"testFn": [Function],
|
|
115
|
+
"type": "TEST",
|
|
116
|
+
}
|
|
117
|
+
`;
|
|
118
|
+
|
|
119
|
+
exports[`Test Vest's \`test\` function test params creates a test without a message and with a key 1`] = `
|
|
120
|
+
IsolateTest {
|
|
121
|
+
"children": null,
|
|
122
|
+
"fieldName": "field_name",
|
|
123
|
+
"id": "21",
|
|
124
|
+
"key": "keyboardcat",
|
|
125
|
+
"keys": {},
|
|
126
|
+
"output": undefined,
|
|
127
|
+
"parent": Isolate {
|
|
128
|
+
"children": [
|
|
129
|
+
[Circular],
|
|
130
|
+
],
|
|
131
|
+
"key": null,
|
|
132
|
+
"keys": {
|
|
133
|
+
"keyboardcat": [Circular],
|
|
134
|
+
},
|
|
135
|
+
"output": {
|
|
136
|
+
"done": [Function],
|
|
137
|
+
"errorCount": 0,
|
|
138
|
+
"getErrors": [Function],
|
|
139
|
+
"getErrorsByGroup": [Function],
|
|
140
|
+
"getWarnings": [Function],
|
|
141
|
+
"getWarningsByGroup": [Function],
|
|
142
|
+
"groups": {},
|
|
143
|
+
"hasErrors": [Function],
|
|
144
|
+
"hasErrorsByGroup": [Function],
|
|
145
|
+
"hasWarnings": [Function],
|
|
146
|
+
"hasWarningsByGroup": [Function],
|
|
147
|
+
"isValid": [Function],
|
|
148
|
+
"isValidByGroup": [Function],
|
|
149
|
+
"suiteName": undefined,
|
|
150
|
+
"testCount": 1,
|
|
151
|
+
"tests": {
|
|
152
|
+
"field_name": {
|
|
153
|
+
"errorCount": 0,
|
|
154
|
+
"errors": [],
|
|
155
|
+
"testCount": 1,
|
|
156
|
+
"valid": true,
|
|
157
|
+
"warnCount": 0,
|
|
158
|
+
"warnings": [],
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
"valid": true,
|
|
162
|
+
"warnCount": 0,
|
|
163
|
+
},
|
|
164
|
+
"parent": null,
|
|
165
|
+
"type": "SUITE",
|
|
166
|
+
},
|
|
167
|
+
"severity": "error",
|
|
168
|
+
"stateMachine": {
|
|
169
|
+
"getState": [Function],
|
|
170
|
+
"transition": [Function],
|
|
171
|
+
},
|
|
172
|
+
"testFn": [Function],
|
|
173
|
+
"type": "TEST",
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
|
|
177
|
+
exports[`Test Vest's \`test\` function test params creates a test without a message and without a key 1`] = `
|
|
178
|
+
IsolateTest {
|
|
179
|
+
"children": null,
|
|
180
|
+
"fieldName": "field_name",
|
|
181
|
+
"id": "17",
|
|
182
|
+
"key": null,
|
|
183
|
+
"keys": {},
|
|
184
|
+
"output": undefined,
|
|
185
|
+
"parent": Isolate {
|
|
186
|
+
"children": [
|
|
187
|
+
[Circular],
|
|
188
|
+
],
|
|
189
|
+
"key": null,
|
|
190
|
+
"keys": {},
|
|
191
|
+
"output": {
|
|
192
|
+
"done": [Function],
|
|
193
|
+
"errorCount": 0,
|
|
194
|
+
"getErrors": [Function],
|
|
195
|
+
"getErrorsByGroup": [Function],
|
|
196
|
+
"getWarnings": [Function],
|
|
197
|
+
"getWarningsByGroup": [Function],
|
|
198
|
+
"groups": {},
|
|
199
|
+
"hasErrors": [Function],
|
|
200
|
+
"hasErrorsByGroup": [Function],
|
|
201
|
+
"hasWarnings": [Function],
|
|
202
|
+
"hasWarningsByGroup": [Function],
|
|
203
|
+
"isValid": [Function],
|
|
204
|
+
"isValidByGroup": [Function],
|
|
205
|
+
"suiteName": undefined,
|
|
206
|
+
"testCount": 1,
|
|
207
|
+
"tests": {
|
|
208
|
+
"field_name": {
|
|
209
|
+
"errorCount": 0,
|
|
210
|
+
"errors": [],
|
|
211
|
+
"testCount": 1,
|
|
212
|
+
"valid": true,
|
|
213
|
+
"warnCount": 0,
|
|
214
|
+
"warnings": [],
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
"valid": true,
|
|
218
|
+
"warnCount": 0,
|
|
219
|
+
},
|
|
220
|
+
"parent": null,
|
|
221
|
+
"type": "SUITE",
|
|
222
|
+
},
|
|
223
|
+
"severity": "error",
|
|
224
|
+
"stateMachine": {
|
|
225
|
+
"getState": [Function],
|
|
226
|
+
"transition": [Function],
|
|
227
|
+
},
|
|
228
|
+
"testFn": [Function],
|
|
229
|
+
"type": "TEST",
|
|
230
|
+
}
|
|
231
|
+
`;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { TDeferThrow } from 'vest-utils/src/deferThrow';
|
|
2
|
+
|
|
3
|
+
import { TVestMock } from '../../../../testUtils/TVestMock';
|
|
4
|
+
import mockThrowError from '../../../../testUtils/mockThrowError';
|
|
5
|
+
|
|
6
|
+
import * as vest from 'vest';
|
|
7
|
+
|
|
8
|
+
describe('key', () => {
|
|
9
|
+
describe('When key is provided', () => {
|
|
10
|
+
describe('When tests change their order between runs', () => {
|
|
11
|
+
it('Should retain test results', () => {
|
|
12
|
+
let count = 0;
|
|
13
|
+
const suite = vest.create(() => {
|
|
14
|
+
/**
|
|
15
|
+
* This test is pretty confusing, but its the most effective way to test this behavior.
|
|
16
|
+
*
|
|
17
|
+
* It basically checks that when provided, key is used to override default test order behavior.
|
|
18
|
+
* We don't mind the order of tests, because the key tells us which test really needs to get which state.
|
|
19
|
+
*
|
|
20
|
+
* The reason we have both skipWhen and and if block is this:
|
|
21
|
+
* if/else: to simulate reordering between runs
|
|
22
|
+
* skipWhen: to prevent running the tests so they have to get the previous state
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
vest.skipWhen(count === 1, () => {
|
|
26
|
+
if (count === 0) {
|
|
27
|
+
vest.test('field_1', () => false, 'field_1_key_1');
|
|
28
|
+
vest.test('field_1', () => undefined, 'field_1_key_2');
|
|
29
|
+
vest.test('field_2', () => false, 'field_2_key_1');
|
|
30
|
+
vest.test('field_2', () => undefined, 'field_2_key_2');
|
|
31
|
+
} else {
|
|
32
|
+
vest.test('field_2', () => undefined, 'field_2_key_2');
|
|
33
|
+
vest.test('field_2', () => false, 'field_2_key_1');
|
|
34
|
+
vest.test('field_1', () => undefined, 'field_1_key_2');
|
|
35
|
+
vest.test('field_1', () => false, 'field_1_key_1');
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
count++;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const res1 = suite();
|
|
42
|
+
const res2 = suite();
|
|
43
|
+
|
|
44
|
+
expect(res1.tests).toEqual(res2.tests);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('When two tests in two different isolates have the same key', () => {
|
|
49
|
+
it('Should regarad each key as unique and retain each tests individual result', () => {
|
|
50
|
+
const calls: vest.IsolateTest[][] = [];
|
|
51
|
+
const suite = vest.create(() => {
|
|
52
|
+
const currentCall: vest.IsolateTest[] = [];
|
|
53
|
+
|
|
54
|
+
vest.skipWhen(calls.length === 1, () => {
|
|
55
|
+
vest.group('group_1', () => {
|
|
56
|
+
currentCall.push(vest.test('field1', () => false, 'key_1'));
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
vest.group('group_2', () => {
|
|
60
|
+
currentCall.push(vest.test('field2', () => false, 'key_1'));
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
calls.push(currentCall);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const res1 = suite();
|
|
68
|
+
const res2 = suite();
|
|
69
|
+
|
|
70
|
+
expect(calls[0][0]).toBe(calls[1][0]);
|
|
71
|
+
expect(calls[0][1]).toBe(calls[1][1]);
|
|
72
|
+
expect(calls[0][0]).not.toBe(calls[0][1]);
|
|
73
|
+
expect(calls[1][0]).not.toBe(calls[1][1]);
|
|
74
|
+
expect(res1.tests).toEqual(res2.tests);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('When tests without a key reorder get added above a test with a key', () => {
|
|
79
|
+
let vest: TVestMock;
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
vest = mockThrowError().vest;
|
|
82
|
+
});
|
|
83
|
+
afterEach(() => {
|
|
84
|
+
jest.resetModules();
|
|
85
|
+
jest.resetAllMocks();
|
|
86
|
+
});
|
|
87
|
+
it('Should retain keyd tests', () => {
|
|
88
|
+
const calls: vest.IsolateTest[][] = [];
|
|
89
|
+
const suite = vest.create(() => {
|
|
90
|
+
const currentCall: vest.IsolateTest[] = [];
|
|
91
|
+
vest.skipWhen(calls.length === 1, () => {
|
|
92
|
+
if (calls.length === 1) {
|
|
93
|
+
vest.test('reordered', () => false);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
currentCall.push(vest.test('field1', () => false, 'key_1'));
|
|
97
|
+
currentCall.push(vest.test('field2', () => false, 'key_2'));
|
|
98
|
+
currentCall.push(vest.test('field3', () => false, 'key_3'));
|
|
99
|
+
|
|
100
|
+
if (calls.length === 0) {
|
|
101
|
+
vest.test('reordered', () => false);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
calls.push(currentCall);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const res1 = suite();
|
|
108
|
+
const res2 = suite();
|
|
109
|
+
|
|
110
|
+
expect(calls[0][0]).toBe(calls[1][0]);
|
|
111
|
+
expect(calls[0][1]).toBe(calls[1][1]);
|
|
112
|
+
expect(calls[0][2]).toBe(calls[1][2]);
|
|
113
|
+
expect(res1.tests.reordered).toEqual({
|
|
114
|
+
errorCount: 1,
|
|
115
|
+
errors: [],
|
|
116
|
+
testCount: 1,
|
|
117
|
+
valid: false,
|
|
118
|
+
warnCount: 0,
|
|
119
|
+
warnings: [],
|
|
120
|
+
});
|
|
121
|
+
expect(res2.tests.reordered).toEqual({
|
|
122
|
+
errorCount: 0,
|
|
123
|
+
errors: [],
|
|
124
|
+
testCount: 0,
|
|
125
|
+
valid: false,
|
|
126
|
+
warnCount: 0,
|
|
127
|
+
warnings: [],
|
|
128
|
+
});
|
|
129
|
+
expect(res1.tests).not.toEqual(res2.tests);
|
|
130
|
+
expect(res2.tests).toMatchInlineSnapshot(`
|
|
131
|
+
{
|
|
132
|
+
"field1": {
|
|
133
|
+
"errorCount": 1,
|
|
134
|
+
"errors": [],
|
|
135
|
+
"testCount": 1,
|
|
136
|
+
"valid": false,
|
|
137
|
+
"warnCount": 0,
|
|
138
|
+
"warnings": [],
|
|
139
|
+
},
|
|
140
|
+
"field2": {
|
|
141
|
+
"errorCount": 1,
|
|
142
|
+
"errors": [],
|
|
143
|
+
"testCount": 1,
|
|
144
|
+
"valid": false,
|
|
145
|
+
"warnCount": 0,
|
|
146
|
+
"warnings": [],
|
|
147
|
+
},
|
|
148
|
+
"field3": {
|
|
149
|
+
"errorCount": 1,
|
|
150
|
+
"errors": [],
|
|
151
|
+
"testCount": 1,
|
|
152
|
+
"valid": false,
|
|
153
|
+
"warnCount": 0,
|
|
154
|
+
"warnings": [],
|
|
155
|
+
},
|
|
156
|
+
"reordered": {
|
|
157
|
+
"errorCount": 0,
|
|
158
|
+
"errors": [],
|
|
159
|
+
"testCount": 0,
|
|
160
|
+
"valid": false,
|
|
161
|
+
"warnCount": 0,
|
|
162
|
+
"warnings": [],
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
`);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe('When the same key is encountered twice', () => {
|
|
170
|
+
let deferThrow: TDeferThrow, vest: TVestMock;
|
|
171
|
+
beforeEach(() => {
|
|
172
|
+
const mock = mockThrowError();
|
|
173
|
+
|
|
174
|
+
deferThrow = mock.deferThrow;
|
|
175
|
+
vest = mock.vest;
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
afterEach(() => {
|
|
179
|
+
jest.resetAllMocks();
|
|
180
|
+
jest.resetModules();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('Should throw a deferred error', () => {
|
|
184
|
+
const suite = vest.create(() => {
|
|
185
|
+
vest.test('field1', () => false, 'key_1');
|
|
186
|
+
vest.test('field2', () => false, 'key_1');
|
|
187
|
+
});
|
|
188
|
+
suite();
|
|
189
|
+
expect(deferThrow).toHaveBeenCalledWith(
|
|
190
|
+
`Encountered the same test key "key_1" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.`
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import wait from 'wait';
|
|
2
|
+
|
|
3
|
+
import { TestPromise } from '../../../../testUtils/testPromise';
|
|
4
|
+
|
|
5
|
+
import promisify from 'promisify';
|
|
6
|
+
import * as vest from 'vest';
|
|
7
|
+
import { test as vestTest, enforce } from 'vest';
|
|
8
|
+
|
|
9
|
+
describe('test.memo', () => {
|
|
10
|
+
describe('cache hit', () => {
|
|
11
|
+
it('Should return without calling callback', () => {
|
|
12
|
+
const cb1 = jest.fn();
|
|
13
|
+
const cb2 = jest.fn(() => TestPromise(() => undefined));
|
|
14
|
+
const suite = vest.create(() => {
|
|
15
|
+
vestTest.memo('f1', cb1, [1]);
|
|
16
|
+
vestTest.memo('f1', cb2, [2]);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
suite();
|
|
20
|
+
expect(cb1).toHaveBeenCalledTimes(1);
|
|
21
|
+
expect(cb2).toHaveBeenCalledTimes(1);
|
|
22
|
+
suite();
|
|
23
|
+
expect(cb1).toHaveBeenCalledTimes(1);
|
|
24
|
+
expect(cb2).toHaveBeenCalledTimes(1);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('Should produce correct initial result', () => {
|
|
28
|
+
const res = vest.create(() => {
|
|
29
|
+
vestTest.memo('field1', 'msg1', () => false, [{}]);
|
|
30
|
+
vestTest.memo('field1', 'msg2', () => undefined, [{}]);
|
|
31
|
+
vestTest.memo('field2', () => undefined, [{}]);
|
|
32
|
+
vestTest.memo(
|
|
33
|
+
'field3',
|
|
34
|
+
() => {
|
|
35
|
+
vest.warn();
|
|
36
|
+
return false;
|
|
37
|
+
},
|
|
38
|
+
[{}]
|
|
39
|
+
);
|
|
40
|
+
})();
|
|
41
|
+
|
|
42
|
+
expect(res.hasErrors('field1')).toBe(true);
|
|
43
|
+
expect(res.hasErrors('field2')).toBe(false);
|
|
44
|
+
expect(res.hasWarnings('field3')).toBe(true);
|
|
45
|
+
expect(res).toMatchSnapshot();
|
|
46
|
+
});
|
|
47
|
+
describe('sync', () => {
|
|
48
|
+
it('Should restore previous result on re-run', () => {
|
|
49
|
+
const suite = vest.create(() => {
|
|
50
|
+
vestTest.memo('field1', 'msg1', () => false, [1]);
|
|
51
|
+
vestTest.memo('field1', 'msg2', () => undefined, [2]);
|
|
52
|
+
vestTest.memo('field2', () => undefined, [3]);
|
|
53
|
+
vestTest.memo(
|
|
54
|
+
'field3',
|
|
55
|
+
() => {
|
|
56
|
+
vest.warn();
|
|
57
|
+
return false;
|
|
58
|
+
},
|
|
59
|
+
[4]
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const res = suite();
|
|
64
|
+
|
|
65
|
+
expect(res.hasErrors('field1')).toBe(true);
|
|
66
|
+
expect(res.hasErrors('field2')).toBe(false);
|
|
67
|
+
expect(res.hasWarnings('field3')).toBe(true);
|
|
68
|
+
expect(res).toMatchSnapshot();
|
|
69
|
+
|
|
70
|
+
const res2 = suite();
|
|
71
|
+
expect(res2.hasErrors('field1')).toBe(true);
|
|
72
|
+
expect(res2.hasErrors('field2')).toBe(false);
|
|
73
|
+
expect(res2.hasWarnings('field3')).toBe(true);
|
|
74
|
+
expect(res).isDeepCopyOf(res2);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('async', () => {
|
|
79
|
+
it('Should immediately return previous result on re-run', async () => {
|
|
80
|
+
{
|
|
81
|
+
const suite = vest.create(() => {
|
|
82
|
+
vestTest.memo(
|
|
83
|
+
'field1',
|
|
84
|
+
async () => {
|
|
85
|
+
await wait(500);
|
|
86
|
+
enforce(1).equals(2);
|
|
87
|
+
},
|
|
88
|
+
[1]
|
|
89
|
+
);
|
|
90
|
+
vestTest.memo(
|
|
91
|
+
'field2',
|
|
92
|
+
async () => {
|
|
93
|
+
await wait(500);
|
|
94
|
+
enforce(1).equals(2);
|
|
95
|
+
},
|
|
96
|
+
[2]
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const asyncSuite = promisify(suite);
|
|
101
|
+
|
|
102
|
+
let start = Date.now();
|
|
103
|
+
const res1 = await asyncSuite();
|
|
104
|
+
enforce(Date.now() - start).gte(500);
|
|
105
|
+
|
|
106
|
+
start = Date.now();
|
|
107
|
+
const res2 = suite();
|
|
108
|
+
|
|
109
|
+
expect(res1).isDeepCopyOf(res2);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('Test is canceled', () => {
|
|
115
|
+
it('Should refresh', async () => {
|
|
116
|
+
let count = 0;
|
|
117
|
+
const tests: vest.IsolateTest[] = [];
|
|
118
|
+
const suite = vest.create(() => {
|
|
119
|
+
count++;
|
|
120
|
+
|
|
121
|
+
tests.push(
|
|
122
|
+
vestTest.memo(
|
|
123
|
+
'f1',
|
|
124
|
+
async () => {
|
|
125
|
+
await wait(10);
|
|
126
|
+
},
|
|
127
|
+
[true]
|
|
128
|
+
)
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
if (count === 1) {
|
|
132
|
+
tests[0].cancel();
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
suite();
|
|
137
|
+
suite();
|
|
138
|
+
suite();
|
|
139
|
+
|
|
140
|
+
expect(tests[0]).not.toBe(tests[1]);
|
|
141
|
+
expect(tests[1]).toBe(tests[2]);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe('cache miss', () => {
|
|
147
|
+
it('Should run test normally', () => {
|
|
148
|
+
const cb1 = jest.fn(res => res);
|
|
149
|
+
const cb2 = jest.fn(
|
|
150
|
+
res => new Promise<void>((resolve, rej) => (res ? resolve() : rej()))
|
|
151
|
+
);
|
|
152
|
+
const suite = vest.create((key, res) => {
|
|
153
|
+
vestTest.memo('f1', () => cb1(res), [1, key]);
|
|
154
|
+
vestTest.memo('f2', () => cb2(res), [2, key]);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
expect(cb1).toHaveBeenCalledTimes(0);
|
|
158
|
+
expect(cb2).toHaveBeenCalledTimes(0);
|
|
159
|
+
suite('a', false);
|
|
160
|
+
expect(cb1).toHaveBeenCalledTimes(1);
|
|
161
|
+
expect(cb2).toHaveBeenCalledTimes(1);
|
|
162
|
+
expect(suite.get().hasErrors()).toBe(true);
|
|
163
|
+
suite('b', true);
|
|
164
|
+
expect(cb1).toHaveBeenCalledTimes(2);
|
|
165
|
+
expect(cb2).toHaveBeenCalledTimes(2);
|
|
166
|
+
expect(suite.get().hasErrors()).toBe(false);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe('Collision detection', () => {
|
|
171
|
+
describe('cross-field collision', () => {
|
|
172
|
+
it('Should factor in field name', () => {
|
|
173
|
+
const suite = vest.create(() => {
|
|
174
|
+
vestTest.memo('f1', () => false, [1]);
|
|
175
|
+
vestTest.memo('f2', () => true, [1]);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
suite();
|
|
179
|
+
suite();
|
|
180
|
+
expect(suite.get().hasErrors('f1')).toBe(true);
|
|
181
|
+
expect(suite.get().hasErrors('f2')).toBe(false);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('same-field-same-suite collision', () => {
|
|
186
|
+
it('Should factor in execution order', () => {
|
|
187
|
+
const suite = vest.create(() => {
|
|
188
|
+
vestTest.memo('f1', () => false, [1]);
|
|
189
|
+
vestTest.memo('f1', () => true, [1]);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
suite();
|
|
193
|
+
suite();
|
|
194
|
+
expect(suite.get().hasErrors('f1')).toBe(true);
|
|
195
|
+
expect(suite.get().errorCount).toBe(1);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
describe('cross-suite collision', () => {
|
|
199
|
+
it('Should factor in field name', () => {
|
|
200
|
+
const suite1 = vest.create(() => {
|
|
201
|
+
vestTest.memo('f1', () => false, [1]);
|
|
202
|
+
vestTest.memo('f2', () => true, [1]);
|
|
203
|
+
});
|
|
204
|
+
const suite2 = vest.create(() => {
|
|
205
|
+
vestTest.memo('f1', () => true, [1]);
|
|
206
|
+
vestTest.memo('f2', () => false, [1]);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
suite1();
|
|
210
|
+
suite2();
|
|
211
|
+
expect(suite1.get().hasErrors('f1')).toBe(true);
|
|
212
|
+
expect(suite1.get().hasErrors('f2')).toBe(false);
|
|
213
|
+
expect(suite2.get().hasErrors('f1')).toBe(false);
|
|
214
|
+
expect(suite2.get().hasErrors('f2')).toBe(true);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
});
|