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,341 @@
|
|
|
1
|
+
import { TTestSuite, TVestMock } from '../../../../testUtils/TVestMock';
|
|
2
|
+
import mockThrowError from '../../../../testUtils/mockThrowError';
|
|
3
|
+
import { dummyTest } from '../../../../testUtils/testDummy';
|
|
4
|
+
|
|
5
|
+
import * as vest from 'vest';
|
|
6
|
+
|
|
7
|
+
describe('Merging of previous test runs', () => {
|
|
8
|
+
let suite: TTestSuite;
|
|
9
|
+
let counter = 0;
|
|
10
|
+
let testContainer: vest.IsolateTest[][] = [];
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
counter = 0;
|
|
14
|
+
testContainer = [];
|
|
15
|
+
});
|
|
16
|
+
describe('When test skipped in subsequent run', () => {
|
|
17
|
+
it('Should merge its result from previous runs', () => {
|
|
18
|
+
suite = vest.create(() => {
|
|
19
|
+
vest.skipWhen(counter === 1, () => {
|
|
20
|
+
testContainer.push([
|
|
21
|
+
dummyTest.failing('f1'),
|
|
22
|
+
dummyTest.failing('f2'),
|
|
23
|
+
dummyTest.passing('f3'),
|
|
24
|
+
dummyTest.failingWarning('f5'),
|
|
25
|
+
dummyTest.passingWarning('f6'),
|
|
26
|
+
]);
|
|
27
|
+
});
|
|
28
|
+
counter++;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const resA = suite();
|
|
32
|
+
const resB = suite();
|
|
33
|
+
|
|
34
|
+
const [testsA, testsB] = testContainer;
|
|
35
|
+
|
|
36
|
+
// This checks the the suite result is the same for both runs
|
|
37
|
+
expect(resA).isDeepCopyOf(resB);
|
|
38
|
+
|
|
39
|
+
// This checks that the test objects are the same for both runs
|
|
40
|
+
expect(testsA).toEqual(testsB);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('When test changes in subsequent run', () => {
|
|
45
|
+
it('Should update the result accordingly', () => {
|
|
46
|
+
suite = vest.create(() => {
|
|
47
|
+
testContainer.push([
|
|
48
|
+
counter === 0 ? dummyTest.passing('f1') : dummyTest.failing('f1'),
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
dummyTest.failing('f2');
|
|
52
|
+
counter++;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const resA = suite();
|
|
56
|
+
|
|
57
|
+
// Checking that the result is correct
|
|
58
|
+
expect(resA.isValid('f1')).toBe(true);
|
|
59
|
+
expect(resA.isValid('f2')).toBe(false);
|
|
60
|
+
const resB = suite();
|
|
61
|
+
// Checking that the result is correct
|
|
62
|
+
expect(resB.isValid('f1')).toBe(false);
|
|
63
|
+
expect(resA.isValid('f2')).toBe(false);
|
|
64
|
+
|
|
65
|
+
const [f1A, f1B] = testContainer;
|
|
66
|
+
|
|
67
|
+
// Checking that the result updated
|
|
68
|
+
expect(resA).not.isDeepCopyOf(resB);
|
|
69
|
+
|
|
70
|
+
// Checking that the test updated
|
|
71
|
+
expect(f1A).not.toBe(f1B);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('When tests are passed in a different order between runs', () => {
|
|
76
|
+
let deferThrow: (message: string) => void, vest: TVestMock;
|
|
77
|
+
beforeEach(() => {
|
|
78
|
+
const mock = mockThrowError();
|
|
79
|
+
deferThrow = mock.deferThrow;
|
|
80
|
+
vest = mock.vest;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
afterAll(() => {
|
|
84
|
+
jest.resetAllMocks();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('Should defer-throw an error', () => {
|
|
88
|
+
suite = vest.create(() => {
|
|
89
|
+
testContainer.push([
|
|
90
|
+
counter === 0
|
|
91
|
+
? vest.test('f1', jest.fn())
|
|
92
|
+
: vest.test('f2', () => false),
|
|
93
|
+
]);
|
|
94
|
+
counter++;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
suite();
|
|
98
|
+
expect(deferThrow).not.toHaveBeenCalled();
|
|
99
|
+
|
|
100
|
+
suite();
|
|
101
|
+
|
|
102
|
+
expect(deferThrow).toHaveBeenCalledWith(
|
|
103
|
+
expect.stringContaining(
|
|
104
|
+
'Vest Critical Error: Tests called in different order than previous run.'
|
|
105
|
+
)
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('When test is omitted in subsequent run', () => {
|
|
110
|
+
it('Should omit the test from the results', () => {
|
|
111
|
+
suite = vest.create(() => {
|
|
112
|
+
vest.test('f1', () => false);
|
|
113
|
+
if (counter === 0) {
|
|
114
|
+
vest.test('f2', () => false);
|
|
115
|
+
}
|
|
116
|
+
vest.test('f3', () => false);
|
|
117
|
+
counter++;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const resA = suite();
|
|
121
|
+
expect(resA.tests.f2).toBeDefined();
|
|
122
|
+
expect(resA.hasErrors('f1')).toBe(true);
|
|
123
|
+
expect(resA.hasErrors('f2')).toBe(true);
|
|
124
|
+
expect(resA.hasErrors('f3')).toBe(true);
|
|
125
|
+
expect(resA.tests).toMatchInlineSnapshot(`
|
|
126
|
+
{
|
|
127
|
+
"f1": {
|
|
128
|
+
"errorCount": 1,
|
|
129
|
+
"errors": [],
|
|
130
|
+
"testCount": 1,
|
|
131
|
+
"valid": false,
|
|
132
|
+
"warnCount": 0,
|
|
133
|
+
"warnings": [],
|
|
134
|
+
},
|
|
135
|
+
"f2": {
|
|
136
|
+
"errorCount": 1,
|
|
137
|
+
"errors": [],
|
|
138
|
+
"testCount": 1,
|
|
139
|
+
"valid": false,
|
|
140
|
+
"warnCount": 0,
|
|
141
|
+
"warnings": [],
|
|
142
|
+
},
|
|
143
|
+
"f3": {
|
|
144
|
+
"errorCount": 1,
|
|
145
|
+
"errors": [],
|
|
146
|
+
"testCount": 1,
|
|
147
|
+
"valid": false,
|
|
148
|
+
"warnCount": 0,
|
|
149
|
+
"warnings": [],
|
|
150
|
+
},
|
|
151
|
+
}
|
|
152
|
+
`);
|
|
153
|
+
|
|
154
|
+
const resB = suite();
|
|
155
|
+
expect(resB.tests.f2).toBeUndefined();
|
|
156
|
+
expect(resB.hasErrors('f1')).toBe(true);
|
|
157
|
+
expect(resB.hasErrors('f2')).toBe(false);
|
|
158
|
+
expect(resB.hasErrors('f3')).toBe(true);
|
|
159
|
+
expect(resB.tests).toMatchInlineSnapshot(`
|
|
160
|
+
{
|
|
161
|
+
"f1": {
|
|
162
|
+
"errorCount": 1,
|
|
163
|
+
"errors": [],
|
|
164
|
+
"testCount": 1,
|
|
165
|
+
"valid": false,
|
|
166
|
+
"warnCount": 0,
|
|
167
|
+
"warnings": [],
|
|
168
|
+
},
|
|
169
|
+
"f3": {
|
|
170
|
+
"errorCount": 1,
|
|
171
|
+
"errors": [],
|
|
172
|
+
"testCount": 1,
|
|
173
|
+
"valid": false,
|
|
174
|
+
"warnCount": 0,
|
|
175
|
+
"warnings": [],
|
|
176
|
+
},
|
|
177
|
+
}
|
|
178
|
+
`);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe('When multiple tests are omitted between a test', () => {
|
|
182
|
+
it('Should omit the tests from the results', () => {
|
|
183
|
+
suite = vest.create(() => {
|
|
184
|
+
vest.test('f1', () => false);
|
|
185
|
+
if (counter === 0) {
|
|
186
|
+
vest.test('f2', () => false);
|
|
187
|
+
vest.test('f3', () => false);
|
|
188
|
+
}
|
|
189
|
+
vest.test('f4', () => false);
|
|
190
|
+
if (counter === 0) {
|
|
191
|
+
vest.test('f5', () => false);
|
|
192
|
+
vest.test('f6', () => false);
|
|
193
|
+
vest.test('f7', () => false);
|
|
194
|
+
}
|
|
195
|
+
vest.test('f4', () => false);
|
|
196
|
+
counter++;
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const resA = suite();
|
|
200
|
+
expect(resA.tests.f2).toBeDefined();
|
|
201
|
+
expect(resA.tests.f3).toBeDefined();
|
|
202
|
+
expect(resA.tests.f5).toBeDefined();
|
|
203
|
+
expect(resA.tests.f6).toBeDefined();
|
|
204
|
+
expect(resA.tests.f7).toBeDefined();
|
|
205
|
+
expect(resA.hasErrors('f1')).toBe(true);
|
|
206
|
+
expect(resA.hasErrors('f2')).toBe(true);
|
|
207
|
+
expect(resA.hasErrors('f3')).toBe(true);
|
|
208
|
+
expect(resA.hasErrors('f4')).toBe(true);
|
|
209
|
+
expect(resA.hasErrors('f5')).toBe(true);
|
|
210
|
+
expect(resA.hasErrors('f6')).toBe(true);
|
|
211
|
+
expect(resA.hasErrors('f7')).toBe(true);
|
|
212
|
+
expect(resA.tests).toMatchInlineSnapshot(`
|
|
213
|
+
{
|
|
214
|
+
"f1": {
|
|
215
|
+
"errorCount": 1,
|
|
216
|
+
"errors": [],
|
|
217
|
+
"testCount": 1,
|
|
218
|
+
"valid": false,
|
|
219
|
+
"warnCount": 0,
|
|
220
|
+
"warnings": [],
|
|
221
|
+
},
|
|
222
|
+
"f2": {
|
|
223
|
+
"errorCount": 1,
|
|
224
|
+
"errors": [],
|
|
225
|
+
"testCount": 1,
|
|
226
|
+
"valid": false,
|
|
227
|
+
"warnCount": 0,
|
|
228
|
+
"warnings": [],
|
|
229
|
+
},
|
|
230
|
+
"f3": {
|
|
231
|
+
"errorCount": 1,
|
|
232
|
+
"errors": [],
|
|
233
|
+
"testCount": 1,
|
|
234
|
+
"valid": false,
|
|
235
|
+
"warnCount": 0,
|
|
236
|
+
"warnings": [],
|
|
237
|
+
},
|
|
238
|
+
"f4": {
|
|
239
|
+
"errorCount": 2,
|
|
240
|
+
"errors": [],
|
|
241
|
+
"testCount": 2,
|
|
242
|
+
"valid": false,
|
|
243
|
+
"warnCount": 0,
|
|
244
|
+
"warnings": [],
|
|
245
|
+
},
|
|
246
|
+
"f5": {
|
|
247
|
+
"errorCount": 1,
|
|
248
|
+
"errors": [],
|
|
249
|
+
"testCount": 1,
|
|
250
|
+
"valid": false,
|
|
251
|
+
"warnCount": 0,
|
|
252
|
+
"warnings": [],
|
|
253
|
+
},
|
|
254
|
+
"f6": {
|
|
255
|
+
"errorCount": 1,
|
|
256
|
+
"errors": [],
|
|
257
|
+
"testCount": 1,
|
|
258
|
+
"valid": false,
|
|
259
|
+
"warnCount": 0,
|
|
260
|
+
"warnings": [],
|
|
261
|
+
},
|
|
262
|
+
"f7": {
|
|
263
|
+
"errorCount": 1,
|
|
264
|
+
"errors": [],
|
|
265
|
+
"testCount": 1,
|
|
266
|
+
"valid": false,
|
|
267
|
+
"warnCount": 0,
|
|
268
|
+
"warnings": [],
|
|
269
|
+
},
|
|
270
|
+
}
|
|
271
|
+
`);
|
|
272
|
+
const resB = suite();
|
|
273
|
+
expect(resB.tests.f2).toBeUndefined();
|
|
274
|
+
expect(resB.tests.f3).toBeUndefined();
|
|
275
|
+
expect(resB.tests.f5).toBeUndefined();
|
|
276
|
+
expect(resB.tests.f6).toBeUndefined();
|
|
277
|
+
expect(resB.tests.f7).toBeUndefined();
|
|
278
|
+
expect(resB.hasErrors('f1')).toBe(true);
|
|
279
|
+
expect(resB.hasErrors('f2')).toBe(false);
|
|
280
|
+
expect(resB.hasErrors('f3')).toBe(false);
|
|
281
|
+
expect(resB.hasErrors('f4')).toBe(true);
|
|
282
|
+
expect(resB.hasErrors('f5')).toBe(false);
|
|
283
|
+
expect(resB.hasErrors('f6')).toBe(false);
|
|
284
|
+
expect(resB.hasErrors('f7')).toBe(false);
|
|
285
|
+
expect(resB.tests).toMatchInlineSnapshot(`
|
|
286
|
+
{
|
|
287
|
+
"f1": {
|
|
288
|
+
"errorCount": 1,
|
|
289
|
+
"errors": [],
|
|
290
|
+
"testCount": 1,
|
|
291
|
+
"valid": false,
|
|
292
|
+
"warnCount": 0,
|
|
293
|
+
"warnings": [],
|
|
294
|
+
},
|
|
295
|
+
"f4": {
|
|
296
|
+
"errorCount": 2,
|
|
297
|
+
"errors": [],
|
|
298
|
+
"testCount": 2,
|
|
299
|
+
"valid": false,
|
|
300
|
+
"warnCount": 0,
|
|
301
|
+
"warnings": [],
|
|
302
|
+
},
|
|
303
|
+
}
|
|
304
|
+
`);
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
describe('When tests are added inbetween tests', () => {
|
|
309
|
+
it('Should remove next tests in line', () => {
|
|
310
|
+
const suite = vest.create(() => {
|
|
311
|
+
vest.test('f1', () => false);
|
|
312
|
+
if (counter === 1) {
|
|
313
|
+
vest.test('f2', () => false);
|
|
314
|
+
vest.test('f3', () => false);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
vest.skipWhen(
|
|
318
|
+
() => counter === 1,
|
|
319
|
+
() => {
|
|
320
|
+
vest.test('f4', () => false);
|
|
321
|
+
vest.test('f5', () => false);
|
|
322
|
+
}
|
|
323
|
+
);
|
|
324
|
+
counter++;
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
const resA = suite();
|
|
328
|
+
expect(resA.hasErrors('f4')).toBe(true);
|
|
329
|
+
expect(resA.hasErrors('f5')).toBe(true);
|
|
330
|
+
|
|
331
|
+
// This is testing that fact that the next test in line after f2 and f3
|
|
332
|
+
// got removed. We can see it because in normal situation, the test result is
|
|
333
|
+
// merged into the next test result.
|
|
334
|
+
const resB = suite();
|
|
335
|
+
expect(resB.hasErrors('f4')).toBe(false);
|
|
336
|
+
expect(resB.hasErrors('f5')).toBe(false);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import wait from 'wait';
|
|
2
|
+
|
|
3
|
+
import { asVestTest } from 'asVestTest';
|
|
4
|
+
import * as vest from 'vest';
|
|
5
|
+
|
|
6
|
+
describe('runAsyncTest', () => {
|
|
7
|
+
describe('State Updates', () => {
|
|
8
|
+
it('Should remove pending status from test object', async () => {
|
|
9
|
+
let testObject: void | vest.IsolateTest = undefined;
|
|
10
|
+
const suite = vest.create(() => {
|
|
11
|
+
testObject = vest.test('field_1', async () => {
|
|
12
|
+
await wait(100);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
suite();
|
|
16
|
+
|
|
17
|
+
testObject = asVestTest(testObject);
|
|
18
|
+
|
|
19
|
+
expect(testObject.isPending()).toBe(true);
|
|
20
|
+
await wait(100);
|
|
21
|
+
expect(testObject.isPending()).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('Callbacks', () => {
|
|
26
|
+
describe('When there are no remaining pending tests', () => {
|
|
27
|
+
it('Should run all callbacks', async () => {
|
|
28
|
+
const cb1 = jest.fn();
|
|
29
|
+
const cb2 = jest.fn();
|
|
30
|
+
const cb3 = jest.fn();
|
|
31
|
+
|
|
32
|
+
const suite = vest.create(() => {
|
|
33
|
+
vest.test('field_1', async () => {
|
|
34
|
+
await wait(100);
|
|
35
|
+
});
|
|
36
|
+
vest.test('field_2', () => {});
|
|
37
|
+
vest.test('field_3', async () => {
|
|
38
|
+
await wait(50);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
suite().done(cb1).done(cb2).done('field_1', cb3);
|
|
43
|
+
|
|
44
|
+
expect(cb1).not.toHaveBeenCalled();
|
|
45
|
+
expect(cb2).not.toHaveBeenCalled();
|
|
46
|
+
expect(cb3).not.toHaveBeenCalled();
|
|
47
|
+
await wait(50);
|
|
48
|
+
expect(cb1).not.toHaveBeenCalled();
|
|
49
|
+
expect(cb2).not.toHaveBeenCalled();
|
|
50
|
+
expect(cb3).not.toHaveBeenCalled();
|
|
51
|
+
await wait(50);
|
|
52
|
+
expect(cb1).toHaveBeenCalled();
|
|
53
|
+
expect(cb2).toHaveBeenCalled();
|
|
54
|
+
expect(cb3).toHaveBeenCalled();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('When there are remaining pending tests', () => {
|
|
59
|
+
it('Should only run callbacks for completed tests', async () => {
|
|
60
|
+
const cb1 = jest.fn();
|
|
61
|
+
const cb2 = jest.fn();
|
|
62
|
+
const cb3 = jest.fn();
|
|
63
|
+
|
|
64
|
+
const suite = vest.create(() => {
|
|
65
|
+
vest.test('field_1', async () => {
|
|
66
|
+
await wait(100);
|
|
67
|
+
});
|
|
68
|
+
vest.test('field_2', () => {});
|
|
69
|
+
vest.test('field_3', async () => {
|
|
70
|
+
await wait(50);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
suite().done(cb1).done('field_2', cb2).done('field_3', cb3);
|
|
75
|
+
|
|
76
|
+
expect(cb1).not.toHaveBeenCalled();
|
|
77
|
+
expect(cb2).toHaveBeenCalled();
|
|
78
|
+
expect(cb3).not.toHaveBeenCalled();
|
|
79
|
+
await wait(50);
|
|
80
|
+
expect(cb1).not.toHaveBeenCalled();
|
|
81
|
+
expect(cb3).toHaveBeenCalled();
|
|
82
|
+
await wait(50);
|
|
83
|
+
expect(cb1).toHaveBeenCalled();
|
|
84
|
+
expect(cb2).toHaveBeenCalled();
|
|
85
|
+
expect(cb3).toHaveBeenCalled();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('When the test run was canceled', () => {
|
|
90
|
+
it('Should not run the callbacks', async () => {
|
|
91
|
+
const cb1 = jest.fn();
|
|
92
|
+
const cb2 = jest.fn();
|
|
93
|
+
const cb3 = jest.fn();
|
|
94
|
+
|
|
95
|
+
const testObject: Array<vest.IsolateTest> = [];
|
|
96
|
+
|
|
97
|
+
const suite = vest.create(() => {
|
|
98
|
+
testObject.push(
|
|
99
|
+
vest.test('field_1', async () => {
|
|
100
|
+
await wait(10);
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
vest.test('field_2', () => {});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
suite().done(cb1).done(cb2).done('field_1', cb3);
|
|
107
|
+
|
|
108
|
+
expect(cb1).not.toHaveBeenCalled();
|
|
109
|
+
expect(cb2).not.toHaveBeenCalled();
|
|
110
|
+
expect(cb3).not.toHaveBeenCalled();
|
|
111
|
+
|
|
112
|
+
suite();
|
|
113
|
+
|
|
114
|
+
await wait(10);
|
|
115
|
+
expect(cb1).not.toHaveBeenCalled();
|
|
116
|
+
expect(cb2).not.toHaveBeenCalled();
|
|
117
|
+
expect(cb3).not.toHaveBeenCalled();
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
describe('Final test status', () => {
|
|
122
|
+
describe('When passing', () => {
|
|
123
|
+
it('Should set the test status to passing', async () => {
|
|
124
|
+
let testObject: void | vest.IsolateTest = undefined;
|
|
125
|
+
const suite = vest.create(() => {
|
|
126
|
+
testObject = vest.test('field_1', async () => {
|
|
127
|
+
await wait(100);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
suite();
|
|
131
|
+
|
|
132
|
+
testObject = asVestTest(testObject);
|
|
133
|
+
|
|
134
|
+
expect(testObject.isPassing()).toBe(false);
|
|
135
|
+
await wait(100);
|
|
136
|
+
expect(testObject.isPassing()).toBe(true);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe('When failing', () => {
|
|
140
|
+
it('Should set the test status to failing', async () => {
|
|
141
|
+
let testObject: void | vest.IsolateTest = undefined;
|
|
142
|
+
const suite = vest.create(() => {
|
|
143
|
+
testObject = vest.test('field_1', async () => {
|
|
144
|
+
throw new Error('');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
suite();
|
|
148
|
+
|
|
149
|
+
testObject = asVestTest(testObject);
|
|
150
|
+
|
|
151
|
+
expect(testObject.isFailing()).toBe(false);
|
|
152
|
+
await wait(100);
|
|
153
|
+
expect(testObject.isFailing()).toBe(true);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
describe('When warning', () => {
|
|
157
|
+
it('Should set the test status to failing', async () => {
|
|
158
|
+
let testObject: void | vest.IsolateTest = undefined;
|
|
159
|
+
const suite = vest.create(() => {
|
|
160
|
+
testObject = vest.test('field_1', async () => {
|
|
161
|
+
vest.warn();
|
|
162
|
+
throw new Error('');
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
suite();
|
|
166
|
+
|
|
167
|
+
testObject = asVestTest(testObject);
|
|
168
|
+
|
|
169
|
+
expect(testObject.isWarning()).toBe(false);
|
|
170
|
+
await wait(100);
|
|
171
|
+
expect(testObject.isWarning()).toBe(true);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
});
|