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,130 @@
|
|
|
1
|
+
import { dummyTest } from '../../../testUtils/testDummy';
|
|
2
|
+
|
|
3
|
+
import { TTestSuite } from 'testUtils/TVestMock';
|
|
4
|
+
import { create, eager, only, group } from 'vest';
|
|
5
|
+
|
|
6
|
+
describe('mode: eager', () => {
|
|
7
|
+
let suite: TTestSuite;
|
|
8
|
+
|
|
9
|
+
describe('When tests fail', () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
suite = create(include => {
|
|
12
|
+
only(include);
|
|
13
|
+
|
|
14
|
+
eager();
|
|
15
|
+
dummyTest.failing('field_1', 'first-of-field_1');
|
|
16
|
+
dummyTest.failing('field_1', 'second-of-field_1'); // Should not run
|
|
17
|
+
dummyTest.failing('field_2', 'first-of-field_2');
|
|
18
|
+
dummyTest.failing('field_2', 'second-of-field_2'); // Should not run
|
|
19
|
+
dummyTest.failing('field_3', 'first-of-field_3');
|
|
20
|
+
dummyTest.failing('field_3', 'second-of-field_3'); // Should not run
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('Should fail fast for every failing field', () => {
|
|
25
|
+
expect(suite.get().testCount).toBe(0); // sanity
|
|
26
|
+
suite();
|
|
27
|
+
expect(suite.get().testCount).toBe(3);
|
|
28
|
+
expect(suite.get().errorCount).toBe(3);
|
|
29
|
+
expect(suite.get().getErrors('field_1')).toEqual(['first-of-field_1']);
|
|
30
|
+
expect(suite.get().getErrors('field_2')).toEqual(['first-of-field_2']);
|
|
31
|
+
expect(suite.get().getErrors('field_3')).toEqual(['first-of-field_3']);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('When test is `only`ed', () => {
|
|
35
|
+
it('Should fail fast for failing field', () => {
|
|
36
|
+
suite('field_1');
|
|
37
|
+
expect(suite.get().testCount).toBe(1);
|
|
38
|
+
expect(suite.get().errorCount).toBe(1);
|
|
39
|
+
expect(suite.get().getErrors('field_1')).toEqual(['first-of-field_1']);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('When test is in a group', () => {
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
suite = create(() => {
|
|
46
|
+
eager();
|
|
47
|
+
group('group_1', () => {
|
|
48
|
+
dummyTest.failing('field_1', 'first-of-field_1');
|
|
49
|
+
});
|
|
50
|
+
dummyTest.failing('field_1', 'second-of-field_1');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
it('Should fail fast for failing field', () => {
|
|
54
|
+
suite();
|
|
55
|
+
expect(suite.get().testCount).toBe(1);
|
|
56
|
+
expect(suite.get().errorCount).toBe(1);
|
|
57
|
+
expect(suite.get().getErrors('field_1')).toEqual(['first-of-field_1']);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('When tests pass', () => {
|
|
63
|
+
beforeEach(() => {
|
|
64
|
+
suite = create(() => {
|
|
65
|
+
eager();
|
|
66
|
+
dummyTest.passing('field_1', 'first-of-field_1');
|
|
67
|
+
dummyTest.failing('field_1', 'second-of-field_1');
|
|
68
|
+
dummyTest.passing('field_2', 'first-of-field_2');
|
|
69
|
+
dummyTest.failing('field_2', 'second-of-field_2');
|
|
70
|
+
dummyTest.passing('field_3', 'first-of-field_3');
|
|
71
|
+
dummyTest.failing('field_3', 'second-of-field_3');
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('Should fail fast for every failing field', () => {
|
|
76
|
+
expect(suite.get().testCount).toBe(0); // sanity
|
|
77
|
+
suite();
|
|
78
|
+
expect(suite.get().testCount).toBe(6);
|
|
79
|
+
expect(suite.get().errorCount).toBe(3);
|
|
80
|
+
expect(suite.get().getErrors('field_1')).toEqual(['second-of-field_1']);
|
|
81
|
+
expect(suite.get().getErrors('field_2')).toEqual(['second-of-field_2']);
|
|
82
|
+
expect(suite.get().getErrors('field_3')).toEqual(['second-of-field_3']);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('sanity', () => {
|
|
87
|
+
beforeEach(() => {
|
|
88
|
+
suite = create(() => {
|
|
89
|
+
dummyTest.failing('field_1', 'first-of-field_1');
|
|
90
|
+
dummyTest.failing('field_1', 'second-of-field_1');
|
|
91
|
+
dummyTest.failing('field_2', 'first-of-field_2');
|
|
92
|
+
dummyTest.failing('field_2', 'second-of-field_2');
|
|
93
|
+
dummyTest.failing('field_3', 'first-of-field_3');
|
|
94
|
+
dummyTest.failing('field_3', 'second-of-field_3');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('Should run all tests', () => {
|
|
99
|
+
expect(suite.get().testCount).toBe(0); // sanity
|
|
100
|
+
suite();
|
|
101
|
+
expect(suite.get().testCount).toBe(6);
|
|
102
|
+
expect(suite.get().errorCount).toBe(6);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('When test used to fail and it now passes', () => {
|
|
107
|
+
let run = 0;
|
|
108
|
+
beforeEach(() => {
|
|
109
|
+
suite = create(() => {
|
|
110
|
+
dummyTest.passing('field_1');
|
|
111
|
+
|
|
112
|
+
if (run === 0) {
|
|
113
|
+
dummyTest.failing('field_1', 'second-of-field_1');
|
|
114
|
+
} else {
|
|
115
|
+
dummyTest.passing('field_1');
|
|
116
|
+
}
|
|
117
|
+
run++;
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('Should treat test as passing', () => {
|
|
122
|
+
suite();
|
|
123
|
+
expect(suite.get().hasErrors()).toBe(true);
|
|
124
|
+
expect(suite.get().getErrors('field_1')).toEqual(['second-of-field_1']);
|
|
125
|
+
suite();
|
|
126
|
+
expect(suite.get().hasErrors()).toBe(false);
|
|
127
|
+
expect(suite.get().getErrors('field_1')).toEqual([]);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker';
|
|
2
|
+
|
|
3
|
+
import { dummyTest } from '../../../testUtils/testDummy';
|
|
4
|
+
|
|
5
|
+
import { ErrorStrings } from 'ErrorStrings';
|
|
6
|
+
import { IsolateTest } from 'IsolateTest';
|
|
7
|
+
import { IsolateTypes } from 'IsolateTypes';
|
|
8
|
+
import { SuiteContext, TExclusion, useExclusion } from 'SuiteContext';
|
|
9
|
+
import { isExcluded, isGroupExcluded, skip, only } from 'exclusive';
|
|
10
|
+
import { group } from 'group';
|
|
11
|
+
import { TTestSuite } from 'testUtils/TVestMock';
|
|
12
|
+
import * as vest from 'vest';
|
|
13
|
+
|
|
14
|
+
let res: boolean, res1: boolean;
|
|
15
|
+
|
|
16
|
+
describe('exclusive hooks', () => {
|
|
17
|
+
let test1: vest.IsolateTest, test2: vest.IsolateTest, test3: vest.IsolateTest;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
test1 = new IsolateTest(IsolateTypes.TEST, {
|
|
21
|
+
fieldName: faker.lorem.word(),
|
|
22
|
+
testFn: jest.fn(),
|
|
23
|
+
});
|
|
24
|
+
test2 = new IsolateTest(IsolateTypes.TEST, {
|
|
25
|
+
fieldName: faker.lorem.slug(),
|
|
26
|
+
testFn: jest.fn(),
|
|
27
|
+
});
|
|
28
|
+
test3 = new IsolateTest(IsolateTypes.TEST, {
|
|
29
|
+
fieldName: faker.random.word(),
|
|
30
|
+
testFn: jest.fn(),
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('isExcluded should respect group exclusion', () => {
|
|
35
|
+
let testObject: vest.IsolateTest;
|
|
36
|
+
let testObject1: vest.IsolateTest;
|
|
37
|
+
|
|
38
|
+
const validate = vest.create(() => {
|
|
39
|
+
vest.skip.group('group_1');
|
|
40
|
+
|
|
41
|
+
testObject = dummyTest.failing();
|
|
42
|
+
|
|
43
|
+
group('group_1', () => {
|
|
44
|
+
testObject1 = dummyTest.failing();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
res = isExcluded(testObject);
|
|
48
|
+
res1 = isExcluded(testObject1);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
validate();
|
|
52
|
+
|
|
53
|
+
expect(res).toBe(false);
|
|
54
|
+
expect(res1).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('`only` hook', () => {
|
|
58
|
+
describe('string input', () => {
|
|
59
|
+
test('isExcluded returns false for included field', () => {
|
|
60
|
+
vest.create(() => {
|
|
61
|
+
vest.only(test1.fieldName);
|
|
62
|
+
res = isExcluded(test1);
|
|
63
|
+
})();
|
|
64
|
+
expect(res).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('isGroupExcluded returns false for included groups', () => {
|
|
68
|
+
vest.create(() => {
|
|
69
|
+
vest.only('group_name');
|
|
70
|
+
|
|
71
|
+
group('group_name', () => {
|
|
72
|
+
res = isGroupExcluded('group_name');
|
|
73
|
+
});
|
|
74
|
+
})();
|
|
75
|
+
expect(res).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('isExcluded returns true for non included field', () => {
|
|
79
|
+
vest.create(() => {
|
|
80
|
+
vest.only(test1.fieldName);
|
|
81
|
+
res1 = isExcluded(test1);
|
|
82
|
+
res = isExcluded(test2);
|
|
83
|
+
})();
|
|
84
|
+
expect(res1).toBe(false);
|
|
85
|
+
expect(res).toBe(true);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('isGroupExcluded returns true for non included group', () => {
|
|
89
|
+
vest.create(() => {
|
|
90
|
+
vest.only.group('group_1');
|
|
91
|
+
|
|
92
|
+
group('group_1', jest.fn());
|
|
93
|
+
group('group_2', jest.fn());
|
|
94
|
+
|
|
95
|
+
res1 = isGroupExcluded('group_1');
|
|
96
|
+
res = isGroupExcluded('group_2');
|
|
97
|
+
})();
|
|
98
|
+
|
|
99
|
+
expect(res1).toBe(false);
|
|
100
|
+
expect(res).toBe(true);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe('array input', () => {
|
|
105
|
+
test('isExcluded returns false for included field', () => {
|
|
106
|
+
vest.create(() => {
|
|
107
|
+
vest.only([test1.fieldName, test2.fieldName]);
|
|
108
|
+
res = isExcluded(test1);
|
|
109
|
+
res1 = isExcluded(test2);
|
|
110
|
+
})();
|
|
111
|
+
expect(res).toBe(false);
|
|
112
|
+
expect(res1).toBe(false);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('isGroupExcluded returns false for included groups', () => {
|
|
116
|
+
const results: boolean[] = [];
|
|
117
|
+
vest.create(() => {
|
|
118
|
+
vest.only.group(['group_1', 'group_2']);
|
|
119
|
+
|
|
120
|
+
group('group_1', jest.fn());
|
|
121
|
+
group('group_2', jest.fn());
|
|
122
|
+
group('group_3', jest.fn());
|
|
123
|
+
|
|
124
|
+
results.push(
|
|
125
|
+
isGroupExcluded('group_1'),
|
|
126
|
+
isGroupExcluded('group_2'),
|
|
127
|
+
isGroupExcluded('group_3')
|
|
128
|
+
);
|
|
129
|
+
})();
|
|
130
|
+
expect(results).toEqual([false, false, true]);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('isExcluded returns true for non included field', () => {
|
|
134
|
+
const results: boolean[] = [];
|
|
135
|
+
const results1: boolean[] = [];
|
|
136
|
+
vest.create(() => {
|
|
137
|
+
results.push(isExcluded(test1), isExcluded(test2), isExcluded(test3));
|
|
138
|
+
vest.only([test1.fieldName, test2.fieldName]);
|
|
139
|
+
results1.push(
|
|
140
|
+
isExcluded(test1),
|
|
141
|
+
isExcluded(test2),
|
|
142
|
+
isExcluded(test3)
|
|
143
|
+
);
|
|
144
|
+
})();
|
|
145
|
+
expect(results).toEqual([false, false, false]);
|
|
146
|
+
expect(results1).toEqual([false, false, true]);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('isGroupExcluded returns true for non included groups', () => {
|
|
150
|
+
const results: boolean[] = [];
|
|
151
|
+
vest.create(() => {
|
|
152
|
+
vest.only.group(['group_1', 'group_2']);
|
|
153
|
+
|
|
154
|
+
group('group_3', jest.fn());
|
|
155
|
+
results.push(
|
|
156
|
+
isGroupExcluded('group_1'),
|
|
157
|
+
isGroupExcluded('group_2'),
|
|
158
|
+
isGroupExcluded('group_3')
|
|
159
|
+
);
|
|
160
|
+
})();
|
|
161
|
+
expect(results).toEqual([false, false, true]);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('`skip` hook', () => {
|
|
167
|
+
describe('string input', () => {
|
|
168
|
+
test('isExcluded returns true for excluded field', () => {
|
|
169
|
+
vest.create(() => {
|
|
170
|
+
vest.skip(test1.fieldName);
|
|
171
|
+
res = isExcluded(test1);
|
|
172
|
+
})();
|
|
173
|
+
expect(res).toBe(true);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('isGroupExcluded returns true for excluded groups', () => {
|
|
177
|
+
vest.create(() => {
|
|
178
|
+
vest.skip.group('group_1');
|
|
179
|
+
res = isGroupExcluded('group_1');
|
|
180
|
+
res1 = isGroupExcluded('group_2');
|
|
181
|
+
})();
|
|
182
|
+
|
|
183
|
+
expect(res).toBe(true);
|
|
184
|
+
expect(res1).toBe(false);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('isExcluded returns false for non excluded field', () => {
|
|
188
|
+
vest.create(() => {
|
|
189
|
+
vest.skip(test1.fieldName);
|
|
190
|
+
res = isExcluded(vest.test(test2.fieldName, jest.fn()));
|
|
191
|
+
})();
|
|
192
|
+
expect(res).toBe(false);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test('isGroupExcluded returns false for tests in non excluded groups', () => {
|
|
197
|
+
vest.create(() => {
|
|
198
|
+
vest.skip('group_1');
|
|
199
|
+
res = isExcluded(vest.test('field_1', jest.fn()));
|
|
200
|
+
})();
|
|
201
|
+
expect(res).toBe(false);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
describe('array input', () => {
|
|
205
|
+
test('isExcluded returns true for excluded field', () => {
|
|
206
|
+
vest.create(() => {
|
|
207
|
+
vest.skip([test1.fieldName, test2.fieldName]);
|
|
208
|
+
|
|
209
|
+
res = isExcluded(test1);
|
|
210
|
+
res1 = isExcluded(test2);
|
|
211
|
+
})();
|
|
212
|
+
expect(res).toBe(true);
|
|
213
|
+
expect(res1).toBe(true);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test('isGroupExcluded returns true for excluded groups', () => {
|
|
217
|
+
const results: boolean[] = [];
|
|
218
|
+
vest.create(() => {
|
|
219
|
+
vest.skip.group(['group_1', 'group_2']);
|
|
220
|
+
results.push(isGroupExcluded('group_1'), isGroupExcluded('group_2'));
|
|
221
|
+
})();
|
|
222
|
+
expect(results).toEqual([true, true]);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('isExcluded returns false for non included field', () => {
|
|
226
|
+
vest.create(() => {
|
|
227
|
+
vest.skip([test1.fieldName, test2.fieldName]);
|
|
228
|
+
res = isExcluded(test3);
|
|
229
|
+
})();
|
|
230
|
+
expect(res).toBe(false);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test('isGroupExcluded returns false for non excluded groups', () => {
|
|
234
|
+
vest.create(() => {
|
|
235
|
+
vest.skip(['group_1', 'group_2']);
|
|
236
|
+
res = isGroupExcluded('group_3');
|
|
237
|
+
})();
|
|
238
|
+
expect(res).toBe(false);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
describe('Field is in a non included group', () => {
|
|
243
|
+
let suite: TTestSuite;
|
|
244
|
+
|
|
245
|
+
beforeEach(() => {
|
|
246
|
+
suite = vest.create(() => {
|
|
247
|
+
vest.only.group('group_1');
|
|
248
|
+
|
|
249
|
+
vest.group('group_1', () => {
|
|
250
|
+
vest.test('field_1', jest.fn());
|
|
251
|
+
});
|
|
252
|
+
vest.group('group_2', () => {
|
|
253
|
+
vest.test('field_2', jest.fn());
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
suite();
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('Should exclude test', () => {
|
|
260
|
+
expect(suite.get().tests.field_2.testCount).toBe(0);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
describe('Error handling', () => {
|
|
266
|
+
describe('When called outside of a suite', () => {
|
|
267
|
+
it('Should throw an error', () => {
|
|
268
|
+
expect(() => only(faker.random.word())).toThrow(
|
|
269
|
+
ErrorStrings.HOOK_CALLED_OUTSIDE
|
|
270
|
+
);
|
|
271
|
+
expect(() => skip(faker.random.word())).toThrow(
|
|
272
|
+
ErrorStrings.HOOK_CALLED_OUTSIDE
|
|
273
|
+
);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
describe('isExcluded', () => {
|
|
280
|
+
let exclusion: Partial<TExclusion>;
|
|
281
|
+
|
|
282
|
+
const runIsExcluded = (
|
|
283
|
+
exclusion: Partial<TExclusion>,
|
|
284
|
+
testObject: IsolateTest
|
|
285
|
+
) =>
|
|
286
|
+
SuiteContext.run({}, () => {
|
|
287
|
+
Object.assign(useExclusion(), exclusion);
|
|
288
|
+
const res = isExcluded(testObject);
|
|
289
|
+
|
|
290
|
+
return res;
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
const genTest = (fieldName: string, groupName?: string) =>
|
|
294
|
+
new IsolateTest(IsolateTypes.TEST, {
|
|
295
|
+
fieldName,
|
|
296
|
+
testFn: jest.fn(),
|
|
297
|
+
groupName,
|
|
298
|
+
});
|
|
299
|
+
describe('skip', () => {
|
|
300
|
+
beforeEach(() => {
|
|
301
|
+
exclusion = { tests: { field_1: false, field_2: false } };
|
|
302
|
+
});
|
|
303
|
+
it('returns true for skipped field', () => {
|
|
304
|
+
expect(runIsExcluded(exclusion, genTest('field_1'))).toBe(true);
|
|
305
|
+
expect(runIsExcluded(exclusion, genTest('field_2', 'group_1'))).toBe(
|
|
306
|
+
true
|
|
307
|
+
);
|
|
308
|
+
});
|
|
309
|
+
it('returns false for non skipped field', () => {
|
|
310
|
+
expect(runIsExcluded(exclusion, genTest('field_3'))).toBe(false);
|
|
311
|
+
expect(runIsExcluded(exclusion, genTest('field_4', 'group_1'))).toBe(
|
|
312
|
+
false
|
|
313
|
+
);
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
describe('only', () => {
|
|
317
|
+
beforeEach(() => {
|
|
318
|
+
exclusion = { tests: { field_1: true, field_2: true } };
|
|
319
|
+
});
|
|
320
|
+
it('returns false for included field', () => {
|
|
321
|
+
expect(runIsExcluded(exclusion, genTest('field_1'))).toBe(false);
|
|
322
|
+
expect(runIsExcluded(exclusion, genTest('field_2', 'group_1'))).toBe(
|
|
323
|
+
false
|
|
324
|
+
);
|
|
325
|
+
});
|
|
326
|
+
it('returns true for non included field', () => {
|
|
327
|
+
expect(runIsExcluded(exclusion, genTest('field_3'))).toBe(true);
|
|
328
|
+
expect(runIsExcluded(exclusion, genTest('field_4', 'group_1'))).toBe(
|
|
329
|
+
true
|
|
330
|
+
);
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
describe('only+skip', () => {
|
|
334
|
+
beforeEach(() => {
|
|
335
|
+
exclusion = {
|
|
336
|
+
tests: { field_1: true, field_2: true, field_3: false, field_4: false },
|
|
337
|
+
};
|
|
338
|
+
});
|
|
339
|
+
it('returns false for included tests', () => {
|
|
340
|
+
expect(runIsExcluded(exclusion, genTest('field_1'))).toBe(false);
|
|
341
|
+
expect(runIsExcluded(exclusion, genTest('field_2', 'group_1'))).toBe(
|
|
342
|
+
false
|
|
343
|
+
);
|
|
344
|
+
});
|
|
345
|
+
it('returns true excluded tests', () => {
|
|
346
|
+
expect(runIsExcluded(exclusion, genTest('field_3'))).toBe(true);
|
|
347
|
+
expect(runIsExcluded(exclusion, genTest('field_4', 'group_1'))).toBe(
|
|
348
|
+
true
|
|
349
|
+
);
|
|
350
|
+
});
|
|
351
|
+
it('returns true for non included field', () => {
|
|
352
|
+
expect(runIsExcluded(exclusion, genTest('field_5'))).toBe(true);
|
|
353
|
+
expect(runIsExcluded(exclusion, genTest('field_6', 'group_1'))).toBe(
|
|
354
|
+
true
|
|
355
|
+
);
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
describe('skip.group', () => {
|
|
359
|
+
beforeEach(() => {
|
|
360
|
+
exclusion = {
|
|
361
|
+
groups: {
|
|
362
|
+
group_1: false,
|
|
363
|
+
group_2: false,
|
|
364
|
+
},
|
|
365
|
+
};
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it('Returns true for tests in skipped group', () => {
|
|
369
|
+
expect(runIsExcluded(exclusion, genTest('field_1', 'group_1'))).toBe(
|
|
370
|
+
true
|
|
371
|
+
);
|
|
372
|
+
expect(runIsExcluded(exclusion, genTest('field_2', 'group_2'))).toBe(
|
|
373
|
+
true
|
|
374
|
+
);
|
|
375
|
+
});
|
|
376
|
+
it('Returns false for tests in non skipped groups', () => {
|
|
377
|
+
expect(runIsExcluded(exclusion, genTest('field_3', 'group_3'))).toBe(
|
|
378
|
+
false
|
|
379
|
+
);
|
|
380
|
+
expect(runIsExcluded(exclusion, genTest('field_4', 'group_4'))).toBe(
|
|
381
|
+
false
|
|
382
|
+
);
|
|
383
|
+
});
|
|
384
|
+
it('Returns false for tests outside of any group', () => {
|
|
385
|
+
expect(runIsExcluded(exclusion, genTest('field_3'))).toBe(false);
|
|
386
|
+
expect(runIsExcluded(exclusion, genTest('field_4'))).toBe(false);
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
describe('only.group', () => {
|
|
390
|
+
beforeEach(() => {
|
|
391
|
+
exclusion = {
|
|
392
|
+
groups: {
|
|
393
|
+
group_1: true,
|
|
394
|
+
group_2: true,
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it('returns false for tests in included groups', () => {
|
|
400
|
+
expect(runIsExcluded(exclusion, genTest('field_1', 'group_1'))).toBe(
|
|
401
|
+
false
|
|
402
|
+
);
|
|
403
|
+
expect(runIsExcluded(exclusion, genTest('field_1', 'group_2'))).toBe(
|
|
404
|
+
false
|
|
405
|
+
);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
it('returns true for groups in non included groups', () => {
|
|
409
|
+
expect(runIsExcluded(exclusion, genTest('field_1', 'group_3'))).toBe(
|
|
410
|
+
true
|
|
411
|
+
);
|
|
412
|
+
expect(runIsExcluded(exclusion, genTest('field_2', 'group_4'))).toBe(
|
|
413
|
+
true
|
|
414
|
+
);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
it('returns true for tests outside of any group', () => {
|
|
418
|
+
expect(runIsExcluded(exclusion, genTest('field_1'))).toBe(true);
|
|
419
|
+
expect(runIsExcluded(exclusion, genTest('field_2'))).toBe(true);
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
describe('only.group + only', () => {
|
|
424
|
+
beforeEach(() => {
|
|
425
|
+
exclusion = {
|
|
426
|
+
groups: {
|
|
427
|
+
group_1: true,
|
|
428
|
+
group_2: true,
|
|
429
|
+
},
|
|
430
|
+
tests: { field_1: true, field_2: true },
|
|
431
|
+
};
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
it('returns true for included tests outside of the group', () => {
|
|
435
|
+
expect(runIsExcluded(exclusion, genTest('field_1'))).toBe(true);
|
|
436
|
+
expect(runIsExcluded(exclusion, genTest('field_2'))).toBe(true);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it('returns false for included tests in included groups', () => {
|
|
440
|
+
expect(runIsExcluded(exclusion, genTest('field_1', 'group_1'))).toBe(
|
|
441
|
+
false
|
|
442
|
+
);
|
|
443
|
+
expect(runIsExcluded(exclusion, genTest('field_2', 'group_2'))).toBe(
|
|
444
|
+
false
|
|
445
|
+
);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
it('returns true for included test in non included group', () => {
|
|
449
|
+
expect(runIsExcluded(exclusion, genTest('field_1', 'group_3'))).toBe(
|
|
450
|
+
true
|
|
451
|
+
);
|
|
452
|
+
expect(runIsExcluded(exclusion, genTest('field_2', 'group_4'))).toBe(
|
|
453
|
+
true
|
|
454
|
+
);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it('returns true for non included test in included group', () => {
|
|
458
|
+
expect(runIsExcluded(exclusion, genTest('field_3', 'group_1'))).toBe(
|
|
459
|
+
true
|
|
460
|
+
);
|
|
461
|
+
expect(runIsExcluded(exclusion, genTest('field_4', 'group_2'))).toBe(
|
|
462
|
+
true
|
|
463
|
+
);
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
it('returns true for non included tests', () => {
|
|
467
|
+
expect(runIsExcluded(exclusion, genTest('field_3'))).toBe(true);
|
|
468
|
+
expect(runIsExcluded(exclusion, genTest('field_4'))).toBe(true);
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
describe('skip.group + only', () => {
|
|
473
|
+
beforeEach(() => {
|
|
474
|
+
exclusion = {
|
|
475
|
+
groups: {
|
|
476
|
+
group_1: false,
|
|
477
|
+
group_2: false,
|
|
478
|
+
},
|
|
479
|
+
tests: { field_1: true, field_2: true },
|
|
480
|
+
};
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it('returns true for included tests in excluded groups', () => {
|
|
484
|
+
expect(runIsExcluded(exclusion, genTest('field_1', 'group_1'))).toBe(
|
|
485
|
+
true
|
|
486
|
+
);
|
|
487
|
+
expect(runIsExcluded(exclusion, genTest('field_2', 'group_1'))).toBe(
|
|
488
|
+
true
|
|
489
|
+
);
|
|
490
|
+
expect(runIsExcluded(exclusion, genTest('field_3', 'group_1'))).toBe(
|
|
491
|
+
true
|
|
492
|
+
);
|
|
493
|
+
expect(runIsExcluded(exclusion, genTest('field_1', 'group_2'))).toBe(
|
|
494
|
+
true
|
|
495
|
+
);
|
|
496
|
+
expect(runIsExcluded(exclusion, genTest('field_2', 'group_2'))).toBe(
|
|
497
|
+
true
|
|
498
|
+
);
|
|
499
|
+
expect(runIsExcluded(exclusion, genTest('field_3', 'group_2'))).toBe(
|
|
500
|
+
true
|
|
501
|
+
);
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
it('returns false for included tests in non excluded groups', () => {
|
|
505
|
+
expect(runIsExcluded(exclusion, genTest('field_1', 'group_3'))).toBe(
|
|
506
|
+
false
|
|
507
|
+
);
|
|
508
|
+
expect(runIsExcluded(exclusion, genTest('field_2', 'group_3'))).toBe(
|
|
509
|
+
false
|
|
510
|
+
);
|
|
511
|
+
expect(runIsExcluded(exclusion, genTest('field_1', 'group_4'))).toBe(
|
|
512
|
+
false
|
|
513
|
+
);
|
|
514
|
+
expect(runIsExcluded(exclusion, genTest('field_2', 'group_4'))).toBe(
|
|
515
|
+
false
|
|
516
|
+
);
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
it('returns true for non included tests', () => {
|
|
520
|
+
expect(runIsExcluded(exclusion, genTest('field_3'))).toBe(true);
|
|
521
|
+
expect(runIsExcluded(exclusion, genTest('field_4'))).toBe(true);
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
it('returns false for included tests outside of the group', () => {
|
|
525
|
+
expect(runIsExcluded(exclusion, genTest('field_1'))).toBe(false);
|
|
526
|
+
expect(runIsExcluded(exclusion, genTest('field_2'))).toBe(false);
|
|
527
|
+
});
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
describe('only.group + skip', () => {
|
|
531
|
+
beforeEach(() => {
|
|
532
|
+
exclusion = {
|
|
533
|
+
groups: {
|
|
534
|
+
group_1: true,
|
|
535
|
+
group_2: true,
|
|
536
|
+
},
|
|
537
|
+
tests: { field_1: false, field_2: false },
|
|
538
|
+
};
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
it('returns true for excluded tests', () => {
|
|
542
|
+
expect(runIsExcluded(exclusion, genTest('field_1'))).toBe(true);
|
|
543
|
+
expect(runIsExcluded(exclusion, genTest('field_2'))).toBe(true);
|
|
544
|
+
});
|
|
545
|
+
it('returns true for excluded test in included group', () => {
|
|
546
|
+
expect(runIsExcluded(exclusion, genTest('field_1', 'group_1'))).toBe(
|
|
547
|
+
true
|
|
548
|
+
);
|
|
549
|
+
expect(runIsExcluded(exclusion, genTest('field_2', 'group_2'))).toBe(
|
|
550
|
+
true
|
|
551
|
+
);
|
|
552
|
+
});
|
|
553
|
+
it('returns true for excluded test in non included group', () => {
|
|
554
|
+
expect(runIsExcluded(exclusion, genTest('field_1', 'group_3'))).toBe(
|
|
555
|
+
true
|
|
556
|
+
);
|
|
557
|
+
expect(runIsExcluded(exclusion, genTest('field_2', 'group_4'))).toBe(
|
|
558
|
+
true
|
|
559
|
+
);
|
|
560
|
+
});
|
|
561
|
+
it('returns false for non excluded test in included group', () => {
|
|
562
|
+
expect(runIsExcluded(exclusion, genTest('field_3', 'group_1'))).toBe(
|
|
563
|
+
false
|
|
564
|
+
);
|
|
565
|
+
expect(runIsExcluded(exclusion, genTest('field_4', 'group_2'))).toBe(
|
|
566
|
+
false
|
|
567
|
+
);
|
|
568
|
+
});
|
|
569
|
+
it('returns true for non excluded test in non included group', () => {
|
|
570
|
+
expect(runIsExcluded(exclusion, genTest('field_3', 'group_3'))).toBe(
|
|
571
|
+
true
|
|
572
|
+
);
|
|
573
|
+
expect(runIsExcluded(exclusion, genTest('field_4', 'group_4'))).toBe(
|
|
574
|
+
true
|
|
575
|
+
);
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
});
|