Skip to content

Commit

Permalink
minor(vest): isValidByGroup (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed May 12, 2022
1 parent 6a67315 commit 4dbb9c0
Show file tree
Hide file tree
Showing 21 changed files with 762 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 5,
"tests": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ Object {
"errorCount": 0,
"errors": Array [],
"testCount": 0,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
"field_4": Object {
"errorCount": 0,
"errors": Array [],
"testCount": 0,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
Expand All @@ -31,6 +33,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 3,
"tests": Object {
Expand Down Expand Up @@ -87,13 +90,15 @@ Object {
"errorCount": 0,
"errors": Array [],
"testCount": 0,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
"field_4": Object {
"errorCount": 0,
"errors": Array [],
"testCount": 0,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
Expand All @@ -104,6 +109,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 3,
"tests": Object {
Expand Down Expand Up @@ -164,6 +170,7 @@ Object {
"field_1_group_message",
],
"testCount": 1,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
Expand All @@ -173,6 +180,7 @@ Object {
"field_4_group_message",
],
"testCount": 1,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
Expand All @@ -183,6 +191,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 7,
"tests": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 1,
"tests": Object {
Expand Down Expand Up @@ -79,6 +80,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 3,
"tests": Object {
Expand Down Expand Up @@ -147,6 +149,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 7,
"tests": Object {
Expand Down Expand Up @@ -218,6 +221,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 0,
"tests": Object {},
Expand All @@ -239,6 +243,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 2,
"tests": Object {
Expand Down Expand Up @@ -285,6 +290,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 3,
"tests": Object {
Expand Down Expand Up @@ -333,6 +339,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 3,
"tests": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 2,
"tests": Object {
Expand Down Expand Up @@ -289,6 +290,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 2,
"tests": Object {
Expand Down Expand Up @@ -343,6 +345,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 2,
"tests": Object {
Expand Down Expand Up @@ -397,6 +400,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 2,
"tests": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 0,
"tests": Object {},
Expand All @@ -34,6 +35,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 1,
"tests": Object {
Expand Down Expand Up @@ -66,6 +68,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 2,
"tests": Object {
Expand Down
54 changes: 36 additions & 18 deletions packages/vest/src/core/isolate/isolates/__tests__/group.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { enforce } from 'enforce';
import faker from 'faker';
import _ from 'lodash';
import partition from 'partition';

import { dummyTest } from '../../../../../testUtils/testDummy';

import VestTest from 'VestTest';
import group from 'group';
import matchingGroupName from 'matchingGroupName';
import * as vest from 'vest';

let groupName = 'group_name_1';
Expand Down Expand Up @@ -74,34 +76,39 @@ describe('group: exclusion', () => {
"errorCount": 0,
"errors": Array [],
"testCount": 0,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
"field_2": Object {
"errorCount": 0,
"errors": Array [],
"testCount": 0,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
"field_3": Object {
"errorCount": 0,
"errors": Array [],
"testCount": 0,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
"field_4": Object {
"errorCount": 0,
"errors": Array [],
"testCount": 0,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
"field_6": Object {
"errorCount": 0,
"errors": Array [],
"testCount": 0,
"valid": false,
"warnCount": 0,
"warnings": Array [],
},
Expand All @@ -110,23 +117,29 @@ describe('group: exclusion', () => {
});

it('Should skip tests within group', () => {
Object.values(groupTestObjects).forEach(testObject => {
if (testObject.groupName === groupName) {
Object.values(groupTestObjects)
.filter(testObject => {
return matchingGroupName(testObject, groupName);
})
.forEach(testObject => {
expect(testObject.testFn).not.toHaveBeenCalled();
}
});
});
});

it('Should run all tests outside of the group', () => {
Object.values(topLevelTestObjects).forEach(testObject => {
expect(testObject.testFn).toHaveBeenCalled();
});
Object.values(groupTestObjects).forEach(testObject => {
if (testObject.groupName !== groupName) {
expect(testObject.testFn).toHaveBeenCalled();
} else {
expect(testObject.testFn).not.toHaveBeenCalled();
}

const [withGroup, withoutGroup] = partition(
Object.values(groupTestObjects),
testObject => matchingGroupName(testObject, groupName)
);
withGroup.forEach(testObject => {
expect(testObject.testFn).not.toHaveBeenCalled();
});
withoutGroup.forEach(testObject => {
expect(testObject.testFn).toHaveBeenCalled();
});
});
});
Expand Down Expand Up @@ -158,12 +171,19 @@ describe('group: exclusion', () => {
});

it('Should run tests within group', () => {
Object.values(groupTestObjects).forEach(testObject => {
if (testObject.groupName === groupName) {
expect(testObject.testFn).toHaveBeenCalled();
} else if (testObject.groupName) {
expect(testObject.testFn).not.toHaveBeenCalled();
const [withGroup, withoutGroup] = partition(
Object.values(groupTestObjects),
testObject => {
return matchingGroupName(testObject, groupName);
}
);

withGroup.forEach(testObject => {
expect(testObject.testFn).toHaveBeenCalled();
});

withoutGroup.forEach(testObject => {
expect(testObject.testFn).not.toHaveBeenCalled();
});
});
});
Expand Down Expand Up @@ -262,9 +282,7 @@ describe('group: base case', () => {
);

// This one is equal since it has no tests outside the group
expect(_.omit(res.tests['field_6'], 'valid')).toEqual(
res.groups[groupName]['field_6']
);
expect(res.tests['field_6']).toEqual(res.groups[groupName]['field_6']);
});

test('Group object is a subset of test object (negating previous test)', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 0,
"tests": Object {},
Expand All @@ -34,6 +35,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 0,
"tests": Object {},
Expand All @@ -55,6 +57,7 @@ Object {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 0,
"tests": Object {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ describe('produceSuiteResult', () => {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 0,
"tests": Object {},
Expand Down Expand Up @@ -147,6 +148,7 @@ describe('produceFullResult', () => {
"hasWarnings": [Function],
"hasWarningsByGroup": [Function],
"isValid": [Function],
"isValidByGroup": [Function],
"suiteName": undefined,
"testCount": 0,
"tests": Object {},
Expand Down
6 changes: 4 additions & 2 deletions packages/vest/src/core/suite/produce/produceSuiteResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getErrors, getWarnings } from 'getFailures';
import { getErrorsByGroup, getWarningsByGroup } from 'getFailuresByGroup';
import { hasErrors, hasWarnings } from 'hasFailures';
import { hasErrorsByGroup, hasWarningsByGroup } from 'hasFailuresByGroup';
import { isValid } from 'isValid';
import { isValid, isValidByGroup } from 'isValid';
import { useStateRef, useTestsFlat, useSuiteName } from 'stateHooks';

const cache = createCache(1);
Expand All @@ -33,6 +33,7 @@ export function produceSuiteResult(): SuiteResult {
hasWarnings: ctx.bind(ref, hasWarnings),
hasWarningsByGroup: ctx.bind(ref, hasWarningsByGroup),
isValid: ctx.bind(ref, isValid),
isValidByGroup: ctx.bind(ref, isValidByGroup),
suiteName,
});
})
Expand All @@ -45,7 +46,8 @@ export type SuiteResult = ReturnType<typeof genTestsSummary> & {
* Determined if there are no errors, and if no
* required fields are skipped.
*/
isValid: (fieldName?: string) => boolean;
isValid: typeof isValid;
isValidByGroup: typeof isValidByGroup;
hasErrors: typeof hasErrors;
hasWarnings: typeof hasWarnings;
getErrors: typeof getErrors;
Expand Down
Loading

1 comment on commit 4dbb9c0

@vercel
Copy link

@vercel vercel bot commented on 4dbb9c0 May 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest-next – ./website

vest-next-ealush.vercel.app
vest-next.vercel.app
vest-next-git-latest-ealush.vercel.app
vest-website.vercel.app

Please sign in to comment.