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,28 @@
|
|
|
1
|
+
import { isArray, callEach } from 'vest-utils';
|
|
2
|
+
|
|
3
|
+
import { useDoneCallbacks, useFieldCallbacks } from 'PersistedContext';
|
|
4
|
+
import { TFieldName } from 'SuiteResultTypes';
|
|
5
|
+
import { TestWalker } from 'TestWalker';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Runs done callback per field when async tests are finished running.
|
|
9
|
+
*/
|
|
10
|
+
export function runFieldCallbacks(fieldName?: TFieldName): void {
|
|
11
|
+
const [fieldCallbacks] = useFieldCallbacks();
|
|
12
|
+
|
|
13
|
+
if (
|
|
14
|
+
fieldName &&
|
|
15
|
+
!TestWalker.hasRemainingTests(fieldName) &&
|
|
16
|
+
isArray(fieldCallbacks[fieldName])
|
|
17
|
+
) {
|
|
18
|
+
callEach(fieldCallbacks[fieldName]);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Runs unlabelled done callback when async tests are finished running.
|
|
24
|
+
*/
|
|
25
|
+
export function runDoneCallbacks() {
|
|
26
|
+
const [doneCallbacks] = useDoneCallbacks();
|
|
27
|
+
callEach(doneCallbacks);
|
|
28
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export enum Severity {
|
|
2
|
+
WARNINGS = 'warnings',
|
|
3
|
+
ERRORS = 'errors',
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export enum SeverityCount {
|
|
7
|
+
ERROR_COUNT = 'errorCount',
|
|
8
|
+
WARN_COUNT = 'warnCount',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function countKeyBySeverity(severity: Severity): SeverityCount {
|
|
12
|
+
return severity === Severity.ERRORS
|
|
13
|
+
? SeverityCount.ERROR_COUNT
|
|
14
|
+
: SeverityCount.WARN_COUNT;
|
|
15
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Done } from 'suiteRunResult';
|
|
2
|
+
import { SuiteSelectors } from 'suiteSelectors';
|
|
3
|
+
|
|
4
|
+
export type SuiteSummary<F extends TFieldName> = {
|
|
5
|
+
groups: Groups;
|
|
6
|
+
tests: Tests<F>;
|
|
7
|
+
valid: boolean;
|
|
8
|
+
} & SummaryBase;
|
|
9
|
+
|
|
10
|
+
export type TestsContainer<F extends TFieldName> = Group | Tests<F>;
|
|
11
|
+
export type GroupTestSummary = SingleTestSummary;
|
|
12
|
+
|
|
13
|
+
export type Groups = Record<string, Group>;
|
|
14
|
+
export type Group = Record<string, GroupTestSummary>;
|
|
15
|
+
export type Tests<F extends TFieldName> = Record<F, SingleTestSummary>;
|
|
16
|
+
|
|
17
|
+
export type SingleTestSummary = SummaryBase & {
|
|
18
|
+
errors: string[];
|
|
19
|
+
warnings: string[];
|
|
20
|
+
valid: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type SummaryBase = {
|
|
24
|
+
errorCount: number;
|
|
25
|
+
warnCount: number;
|
|
26
|
+
testCount: number;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type GetFailuresResponse = FailureMessages | string[];
|
|
30
|
+
|
|
31
|
+
export type FailureMessages = Record<string, string[]>;
|
|
32
|
+
|
|
33
|
+
export type SuiteResult<F extends TFieldName> = SuiteSummary<F> &
|
|
34
|
+
SuiteSelectors<F> & { suiteName: SuiteName };
|
|
35
|
+
|
|
36
|
+
export type SuiteRunResult<F extends TFieldName> = SuiteResult<F> & {
|
|
37
|
+
done: Done<F>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type SuiteName = string | undefined;
|
|
41
|
+
|
|
42
|
+
export type TFieldName<T extends string = string> = T;
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import wait from 'wait';
|
|
2
|
+
|
|
3
|
+
import { dummyTest } from '../../../testUtils/testDummy';
|
|
4
|
+
import { TestPromise } from '../../../testUtils/testPromise';
|
|
5
|
+
|
|
6
|
+
import * as vest from 'vest';
|
|
7
|
+
|
|
8
|
+
describe('done', () => {
|
|
9
|
+
describe('When no async tests', () => {
|
|
10
|
+
it('Should call done callback immediately', () => {
|
|
11
|
+
const result = vest.create(() => {
|
|
12
|
+
dummyTest.passing();
|
|
13
|
+
dummyTest.passing();
|
|
14
|
+
dummyTest.failing();
|
|
15
|
+
dummyTest.failing();
|
|
16
|
+
dummyTest.passing();
|
|
17
|
+
dummyTest.failingWarning('field_2');
|
|
18
|
+
})();
|
|
19
|
+
|
|
20
|
+
const doneCallback = jest.fn();
|
|
21
|
+
const fieldDoneCallback = jest.fn();
|
|
22
|
+
|
|
23
|
+
result.done(doneCallback).done('field_2', fieldDoneCallback);
|
|
24
|
+
|
|
25
|
+
expect(doneCallback).toHaveBeenCalled();
|
|
26
|
+
expect(fieldDoneCallback).toHaveBeenCalled();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('When suite lags and callbacks are registered again', () => {
|
|
31
|
+
it('should only run most recent registered callbacks', async () => {
|
|
32
|
+
const test = [];
|
|
33
|
+
const suite = vest.create(() => {
|
|
34
|
+
test.push(dummyTest.failingAsync('test', { time: 100 }));
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const doneCallback1 = jest.fn();
|
|
38
|
+
const fieldDoneCallback1 = jest.fn();
|
|
39
|
+
const doneCallback2 = jest.fn();
|
|
40
|
+
const fieldDoneCallback2 = jest.fn();
|
|
41
|
+
|
|
42
|
+
suite().done(doneCallback1).done('test', fieldDoneCallback1);
|
|
43
|
+
await wait(10);
|
|
44
|
+
suite().done(doneCallback2).done('test', fieldDoneCallback2);
|
|
45
|
+
await wait(100);
|
|
46
|
+
expect(doneCallback2).toHaveBeenCalledTimes(1);
|
|
47
|
+
expect(fieldDoneCallback2).toHaveBeenCalledTimes(1);
|
|
48
|
+
expect(doneCallback1).toHaveBeenCalledTimes(0);
|
|
49
|
+
expect(fieldDoneCallback1).toHaveBeenCalledTimes(0);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('When there are async tests', () => {
|
|
54
|
+
describe('When field name is not passed', () => {
|
|
55
|
+
it('Should run the done callback after all the fields finished running', () => {
|
|
56
|
+
const check1 = jest.fn();
|
|
57
|
+
const check2 = jest.fn();
|
|
58
|
+
const check3 = jest.fn();
|
|
59
|
+
return TestPromise(done => {
|
|
60
|
+
const doneCallback = jest.fn(() => {
|
|
61
|
+
expect(check1).toHaveBeenCalled();
|
|
62
|
+
expect(check2).toHaveBeenCalled();
|
|
63
|
+
expect(check3).toHaveBeenCalled();
|
|
64
|
+
done();
|
|
65
|
+
});
|
|
66
|
+
const result = vest.create(() => {
|
|
67
|
+
dummyTest.passingAsync('field_1', { time: 1000 });
|
|
68
|
+
dummyTest.failingAsync('field_2', { time: 100 });
|
|
69
|
+
dummyTest.passingAsync('field_3', { time: 0 });
|
|
70
|
+
dummyTest.failing();
|
|
71
|
+
dummyTest.passing();
|
|
72
|
+
})();
|
|
73
|
+
|
|
74
|
+
result.done(doneCallback);
|
|
75
|
+
|
|
76
|
+
setTimeout(() => {
|
|
77
|
+
expect(doneCallback).not.toHaveBeenCalled();
|
|
78
|
+
check1();
|
|
79
|
+
});
|
|
80
|
+
setTimeout(() => {
|
|
81
|
+
expect(doneCallback).not.toHaveBeenCalled();
|
|
82
|
+
check2();
|
|
83
|
+
}, 150);
|
|
84
|
+
setTimeout(() => {
|
|
85
|
+
expect(doneCallback).not.toHaveBeenCalled();
|
|
86
|
+
check3();
|
|
87
|
+
}, 900);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('done arguments', () => {
|
|
94
|
+
it('Should pass down the up to date validation result', () => {
|
|
95
|
+
return TestPromise(done => {
|
|
96
|
+
const result = vest.create(() => {
|
|
97
|
+
dummyTest.failing('field_1', 'error message');
|
|
98
|
+
dummyTest.passing('field_2');
|
|
99
|
+
dummyTest.passingAsync('field_3', { time: 0 });
|
|
100
|
+
dummyTest.failingAsync('field_4', {
|
|
101
|
+
message: 'error_message',
|
|
102
|
+
time: 100,
|
|
103
|
+
});
|
|
104
|
+
dummyTest.passingAsync('field_5', { time: 1000 });
|
|
105
|
+
})();
|
|
106
|
+
|
|
107
|
+
result
|
|
108
|
+
.done('field_2', res => {
|
|
109
|
+
expect(res.getErrors()).toEqual({
|
|
110
|
+
field_1: ['error message'],
|
|
111
|
+
});
|
|
112
|
+
expect(res).toMatchObject({
|
|
113
|
+
errorCount: 1,
|
|
114
|
+
groups: {},
|
|
115
|
+
testCount: 5,
|
|
116
|
+
tests: {
|
|
117
|
+
field_1: {
|
|
118
|
+
errorCount: 1,
|
|
119
|
+
errors: ['error message'],
|
|
120
|
+
testCount: 1,
|
|
121
|
+
warnCount: 0,
|
|
122
|
+
},
|
|
123
|
+
field_2: {
|
|
124
|
+
errorCount: 0,
|
|
125
|
+
testCount: 1,
|
|
126
|
+
warnCount: 0,
|
|
127
|
+
},
|
|
128
|
+
field_3: {
|
|
129
|
+
errorCount: 0,
|
|
130
|
+
testCount: 1,
|
|
131
|
+
warnCount: 0,
|
|
132
|
+
},
|
|
133
|
+
field_4: {
|
|
134
|
+
errorCount: 0,
|
|
135
|
+
testCount: 1,
|
|
136
|
+
warnCount: 0,
|
|
137
|
+
},
|
|
138
|
+
field_5: {
|
|
139
|
+
errorCount: 0,
|
|
140
|
+
testCount: 1,
|
|
141
|
+
warnCount: 0,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
warnCount: 0,
|
|
145
|
+
});
|
|
146
|
+
})
|
|
147
|
+
.done('field_3', res => {
|
|
148
|
+
expect(res).toMatchObject({
|
|
149
|
+
errorCount: 1,
|
|
150
|
+
groups: {},
|
|
151
|
+
testCount: 5,
|
|
152
|
+
tests: {
|
|
153
|
+
field_1: {
|
|
154
|
+
errorCount: 1,
|
|
155
|
+
errors: ['error message'],
|
|
156
|
+
testCount: 1,
|
|
157
|
+
warnCount: 0,
|
|
158
|
+
},
|
|
159
|
+
field_2: {
|
|
160
|
+
errorCount: 0,
|
|
161
|
+
testCount: 1,
|
|
162
|
+
warnCount: 0,
|
|
163
|
+
},
|
|
164
|
+
field_3: {
|
|
165
|
+
errorCount: 0,
|
|
166
|
+
testCount: 1,
|
|
167
|
+
warnCount: 0,
|
|
168
|
+
},
|
|
169
|
+
field_4: {
|
|
170
|
+
errorCount: 0,
|
|
171
|
+
testCount: 1,
|
|
172
|
+
warnCount: 0,
|
|
173
|
+
},
|
|
174
|
+
field_5: {
|
|
175
|
+
errorCount: 0,
|
|
176
|
+
testCount: 1,
|
|
177
|
+
warnCount: 0,
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
warnCount: 0,
|
|
181
|
+
});
|
|
182
|
+
})
|
|
183
|
+
.done('field_4', res => {
|
|
184
|
+
expect(res.getErrors()).toEqual({
|
|
185
|
+
field_1: ['error message'],
|
|
186
|
+
field_4: ['error_message'],
|
|
187
|
+
});
|
|
188
|
+
expect(res).toMatchObject({
|
|
189
|
+
errorCount: 2,
|
|
190
|
+
groups: {},
|
|
191
|
+
testCount: 5,
|
|
192
|
+
tests: {
|
|
193
|
+
field_1: {
|
|
194
|
+
errorCount: 1,
|
|
195
|
+
errors: ['error message'],
|
|
196
|
+
testCount: 1,
|
|
197
|
+
warnCount: 0,
|
|
198
|
+
},
|
|
199
|
+
field_2: {
|
|
200
|
+
errorCount: 0,
|
|
201
|
+
testCount: 1,
|
|
202
|
+
warnCount: 0,
|
|
203
|
+
},
|
|
204
|
+
field_3: {
|
|
205
|
+
errorCount: 0,
|
|
206
|
+
testCount: 1,
|
|
207
|
+
warnCount: 0,
|
|
208
|
+
},
|
|
209
|
+
field_4: {
|
|
210
|
+
errorCount: 1,
|
|
211
|
+
errors: ['error_message'],
|
|
212
|
+
testCount: 1,
|
|
213
|
+
warnCount: 0,
|
|
214
|
+
},
|
|
215
|
+
field_5: {
|
|
216
|
+
errorCount: 0,
|
|
217
|
+
testCount: 1,
|
|
218
|
+
warnCount: 0,
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
warnCount: 0,
|
|
222
|
+
});
|
|
223
|
+
})
|
|
224
|
+
.done(res => {
|
|
225
|
+
expect(res).toMatchObject({
|
|
226
|
+
errorCount: 2,
|
|
227
|
+
groups: {},
|
|
228
|
+
testCount: 5,
|
|
229
|
+
tests: {
|
|
230
|
+
field_1: {
|
|
231
|
+
errorCount: 1,
|
|
232
|
+
errors: ['error message'],
|
|
233
|
+
testCount: 1,
|
|
234
|
+
warnCount: 0,
|
|
235
|
+
},
|
|
236
|
+
field_2: {
|
|
237
|
+
errorCount: 0,
|
|
238
|
+
testCount: 1,
|
|
239
|
+
warnCount: 0,
|
|
240
|
+
},
|
|
241
|
+
field_3: {
|
|
242
|
+
errorCount: 0,
|
|
243
|
+
testCount: 1,
|
|
244
|
+
warnCount: 0,
|
|
245
|
+
},
|
|
246
|
+
field_4: {
|
|
247
|
+
errorCount: 1,
|
|
248
|
+
errors: ['error_message'],
|
|
249
|
+
testCount: 1,
|
|
250
|
+
warnCount: 0,
|
|
251
|
+
},
|
|
252
|
+
field_5: {
|
|
253
|
+
errorCount: 0,
|
|
254
|
+
testCount: 1,
|
|
255
|
+
warnCount: 0,
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
warnCount: 0,
|
|
259
|
+
});
|
|
260
|
+
done();
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
describe('When a different field is run while a field is pending', () => {
|
|
267
|
+
it('Should wait running done callbacks until all tests complete', () => {
|
|
268
|
+
const suite = vest.create(only => {
|
|
269
|
+
vest.only(only);
|
|
270
|
+
|
|
271
|
+
vest.test('async_1', async () => {
|
|
272
|
+
await wait(1000);
|
|
273
|
+
throw new Error();
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
vest.test('sync_2', () => false);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
suite('async_1');
|
|
280
|
+
|
|
281
|
+
return TestPromise(done => {
|
|
282
|
+
suite('sync_2').done(res => {
|
|
283
|
+
expect(res.hasErrors('async_1')).toBe(true);
|
|
284
|
+
done();
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe('When suite re-runs and a pending test is now skipped', () => {
|
|
291
|
+
it('Should immediately call the second done callback, omit the first', async () => {
|
|
292
|
+
const done_0 = jest.fn();
|
|
293
|
+
const done_1 = jest.fn();
|
|
294
|
+
|
|
295
|
+
const suite = vest.create(username => {
|
|
296
|
+
vest.test('username', () => {
|
|
297
|
+
vest.enforce(username).isNotBlank();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
vest.skipWhen(suite.get().hasErrors('username'), () => {
|
|
301
|
+
vest.test('username', async () => {
|
|
302
|
+
await wait(1000);
|
|
303
|
+
if (username === 'ealush') {
|
|
304
|
+
throw new Error();
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
suite('ealush').done(done_0);
|
|
311
|
+
await wait(0);
|
|
312
|
+
expect(done_0).not.toHaveBeenCalled();
|
|
313
|
+
suite('').done(done_1);
|
|
314
|
+
expect(done_0).not.toHaveBeenCalled();
|
|
315
|
+
expect(done_1).toHaveBeenCalled();
|
|
316
|
+
await wait(1000);
|
|
317
|
+
expect(done_0).not.toHaveBeenCalled();
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
describe('Passing a field that does not exist', () => {
|
|
322
|
+
it('Should call the callback immedaitely', () => {
|
|
323
|
+
const cb = jest.fn();
|
|
324
|
+
|
|
325
|
+
const suite = vest.create(() => {
|
|
326
|
+
vest.test('test', () => {});
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
suite().done('non-existent', cb);
|
|
330
|
+
|
|
331
|
+
expect(cb).toHaveBeenCalled();
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { ser } from '../../../testUtils/suiteDummy';
|
|
2
|
+
import { dummyTest } from '../../../testUtils/testDummy';
|
|
3
|
+
|
|
4
|
+
import * as vest from 'vest';
|
|
5
|
+
|
|
6
|
+
describe('produce method Suite Result', () => {
|
|
7
|
+
describe('Base structure', () => {
|
|
8
|
+
it('Should match snapshot', () => {
|
|
9
|
+
const suite = vest.create(() => {});
|
|
10
|
+
expect(suite()).toMatchObject({
|
|
11
|
+
errorCount: 0,
|
|
12
|
+
groups: {},
|
|
13
|
+
testCount: 0,
|
|
14
|
+
tests: {},
|
|
15
|
+
warnCount: 0,
|
|
16
|
+
});
|
|
17
|
+
expect(ser(suite())).toEqual(ser(suite.get()));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('Its methods should reflect the correct test data', () => {
|
|
21
|
+
const suite = vest.create(() => {
|
|
22
|
+
dummyTest.passing('field_1');
|
|
23
|
+
dummyTest.failing('field_1', 'message');
|
|
24
|
+
dummyTest.failing('field_1', 'failure_message');
|
|
25
|
+
dummyTest.failing('field_1', 'failure_message with group', 'group_1');
|
|
26
|
+
dummyTest.failingWarning('field_2', 'warning test');
|
|
27
|
+
dummyTest.failingWarning('field_2', 'another warning test');
|
|
28
|
+
dummyTest.passing('field_2');
|
|
29
|
+
dummyTest.passing('field_3', '', 'group_1');
|
|
30
|
+
dummyTest.failing('field_3', 'msg');
|
|
31
|
+
dummyTest.passing('field_4');
|
|
32
|
+
dummyTest.passing('field_5', '', 'group_2');
|
|
33
|
+
dummyTest.failingWarning('field_5', 'warning message', 'group_2');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const res = suite();
|
|
37
|
+
|
|
38
|
+
expect(ser(suite.get())).toEqual(ser(res));
|
|
39
|
+
|
|
40
|
+
expect(res.hasErrors()).toBe(true);
|
|
41
|
+
expect(res.hasErrors('field_1')).toBe(true);
|
|
42
|
+
expect(res.hasErrors('field_2')).toBe(false);
|
|
43
|
+
expect(res.hasErrors('field_3')).toBe(true);
|
|
44
|
+
expect(res.hasErrors('field_4')).toBe(false);
|
|
45
|
+
expect(res.hasErrors('field_5')).toBe(false);
|
|
46
|
+
expect(res.hasWarnings('field_1')).toBe(false);
|
|
47
|
+
expect(res.hasWarnings('field_2')).toBe(true);
|
|
48
|
+
expect(res.hasWarnings('field_3')).toBe(false);
|
|
49
|
+
expect(res.hasWarnings('field_4')).toBe(false);
|
|
50
|
+
expect(res.hasWarnings('field_5')).toBe(true);
|
|
51
|
+
expect(res.getErrors()).toEqual({
|
|
52
|
+
field_1: ['message', 'failure_message', 'failure_message with group'],
|
|
53
|
+
field_3: ['msg'],
|
|
54
|
+
});
|
|
55
|
+
expect(res.getWarnings()).toEqual({
|
|
56
|
+
field_2: ['warning test', 'another warning test'],
|
|
57
|
+
field_5: ['warning message'],
|
|
58
|
+
});
|
|
59
|
+
expect(res.getErrors()).toEqual({
|
|
60
|
+
field_1: ['message', 'failure_message', 'failure_message with group'],
|
|
61
|
+
field_3: ['msg'],
|
|
62
|
+
});
|
|
63
|
+
expect(res.hasErrorsByGroup('group_1')).toBe(true);
|
|
64
|
+
expect(res.hasErrorsByGroup('group_1', 'field_1')).toBe(true);
|
|
65
|
+
expect(res.hasErrorsByGroup('group_2')).toBe(false);
|
|
66
|
+
expect(res.hasErrorsByGroup('group_1', 'field_2')).toBe(false);
|
|
67
|
+
expect(res.hasErrorsByGroup('group_3')).toBe(false);
|
|
68
|
+
expect(res.hasWarningsByGroup('group_1')).toBe(false);
|
|
69
|
+
expect(res.hasWarningsByGroup('group_1', 'field_1')).toBe(false);
|
|
70
|
+
expect(res.hasWarningsByGroup('group_2')).toBe(true);
|
|
71
|
+
expect(res.hasWarningsByGroup('group_1', 'field_2')).toBe(false);
|
|
72
|
+
expect(res.hasWarningsByGroup('group_2', 'field_5')).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('Value memoization', () => {
|
|
77
|
+
it('When unchanged, should produce a memoized result', () => {
|
|
78
|
+
const suite = vest.create(() => {
|
|
79
|
+
dummyTest.passing('field_1');
|
|
80
|
+
dummyTest.failing('field_1', 'message');
|
|
81
|
+
});
|
|
82
|
+
const res = suite();
|
|
83
|
+
expect(res).toMatchObject(suite.get());
|
|
84
|
+
expect(suite.get()).toBe(suite.get());
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('When changed, should produce a new result object', () => {
|
|
88
|
+
const suite = vest.create((v1, v2) => {
|
|
89
|
+
vest.test('f1', () => {
|
|
90
|
+
vest.enforce(v1).equals(1);
|
|
91
|
+
});
|
|
92
|
+
vest.test('f2', () => {
|
|
93
|
+
vest.enforce(v2).equals(2);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
const res1 = suite(1, 2);
|
|
97
|
+
const res2 = suite(1, 1);
|
|
98
|
+
suite(2, 1);
|
|
99
|
+
expect(res1).not.toMatchObject(suite.get());
|
|
100
|
+
expect(res1).not.toBe(suite.get());
|
|
101
|
+
expect(res2).not.toMatchObject(suite.get());
|
|
102
|
+
expect(res2).not.toBe(suite.get());
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('suite.get()', () => {
|
|
108
|
+
describe('exposed methods', () => {
|
|
109
|
+
it('Should have all exposed methods', () => {
|
|
110
|
+
const suite = vest.create(() => {});
|
|
111
|
+
expect(suite.get()).toMatchInlineSnapshot(`
|
|
112
|
+
{
|
|
113
|
+
"errorCount": 0,
|
|
114
|
+
"getErrors": [Function],
|
|
115
|
+
"getErrorsByGroup": [Function],
|
|
116
|
+
"getWarnings": [Function],
|
|
117
|
+
"getWarningsByGroup": [Function],
|
|
118
|
+
"groups": {},
|
|
119
|
+
"hasErrors": [Function],
|
|
120
|
+
"hasErrorsByGroup": [Function],
|
|
121
|
+
"hasWarnings": [Function],
|
|
122
|
+
"hasWarningsByGroup": [Function],
|
|
123
|
+
"isValid": [Function],
|
|
124
|
+
"isValidByGroup": [Function],
|
|
125
|
+
"suiteName": undefined,
|
|
126
|
+
"testCount": 0,
|
|
127
|
+
"tests": {},
|
|
128
|
+
"valid": false,
|
|
129
|
+
"warnCount": 0,
|
|
130
|
+
}
|
|
131
|
+
`);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('suite()', () => {
|
|
137
|
+
describe('exposed methods', () => {
|
|
138
|
+
it('Should have all exposed methods', () => {
|
|
139
|
+
expect(vest.create(() => {})()).toMatchInlineSnapshot(`
|
|
140
|
+
{
|
|
141
|
+
"done": [Function],
|
|
142
|
+
"errorCount": 0,
|
|
143
|
+
"getErrors": [Function],
|
|
144
|
+
"getErrorsByGroup": [Function],
|
|
145
|
+
"getWarnings": [Function],
|
|
146
|
+
"getWarningsByGroup": [Function],
|
|
147
|
+
"groups": {},
|
|
148
|
+
"hasErrors": [Function],
|
|
149
|
+
"hasErrorsByGroup": [Function],
|
|
150
|
+
"hasWarnings": [Function],
|
|
151
|
+
"hasWarningsByGroup": [Function],
|
|
152
|
+
"isValid": [Function],
|
|
153
|
+
"isValidByGroup": [Function],
|
|
154
|
+
"suiteName": undefined,
|
|
155
|
+
"testCount": 0,
|
|
156
|
+
"tests": {},
|
|
157
|
+
"valid": false,
|
|
158
|
+
"warnCount": 0,
|
|
159
|
+
}
|
|
160
|
+
`);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { assign } from 'vest-utils';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
DoneCallback,
|
|
5
|
+
useDoneCallbacks,
|
|
6
|
+
useFieldCallbacks,
|
|
7
|
+
} from 'PersistedContext';
|
|
8
|
+
import { TFieldName } from 'SuiteResultTypes';
|
|
9
|
+
|
|
10
|
+
export function deferDoneCallback(
|
|
11
|
+
doneCallback: DoneCallback,
|
|
12
|
+
fieldName?: TFieldName
|
|
13
|
+
): void {
|
|
14
|
+
const [, setFieldCallbacks] = useFieldCallbacks();
|
|
15
|
+
const [, setDoneCallbacks] = useDoneCallbacks();
|
|
16
|
+
|
|
17
|
+
if (fieldName) {
|
|
18
|
+
setFieldCallbacks(fieldCallbacks =>
|
|
19
|
+
assign(fieldCallbacks, {
|
|
20
|
+
[fieldName]: (fieldCallbacks[fieldName] || []).concat(doneCallback),
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
setDoneCallbacks(doneCallbacks => doneCallbacks.concat(doneCallback));
|
|
28
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DONE is here and not in its own module to prevent circular dependency issues.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { isFunction, numberEquals } from 'vest-utils';
|
|
6
|
+
|
|
7
|
+
import { SuiteResult, SuiteRunResult, TFieldName } from 'SuiteResultTypes';
|
|
8
|
+
|
|
9
|
+
export function shouldSkipDoneRegistration(
|
|
10
|
+
callback: (res: SuiteResult<TFieldName>) => void,
|
|
11
|
+
|
|
12
|
+
fieldName: TFieldName | undefined,
|
|
13
|
+
output: SuiteRunResult<TFieldName>
|
|
14
|
+
): boolean {
|
|
15
|
+
// If we do not have any test runs for the current field
|
|
16
|
+
return !!(
|
|
17
|
+
!isFunction(callback) ||
|
|
18
|
+
(fieldName && numberEquals(output.tests[fieldName]?.testCount, 0))
|
|
19
|
+
);
|
|
20
|
+
}
|