Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor(vest): add skipped tests to result as well #600

Merged
merged 1 commit into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/vest/src/__tests__/__snapshots__/infra.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,21 @@ Object {
"name": "inventore-quis-impedit",
"testCount": 1,
"tests": Object {
"autem": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
"doloribus-enim-quisquam": Object {
"errorCount": 0,
"testCount": 1,
"warnCount": 0,
},
"soluta": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
},
"warnCount": 0,
}
Expand Down Expand Up @@ -110,6 +120,11 @@ Object {
"Temporibus ex ex.",
],
},
"doloribus-enim-quisquam": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
},
"warnCount": 1,
}
Expand Down Expand Up @@ -139,6 +154,11 @@ Object {
"Temporibus ex ex.",
],
},
"doloribus-enim-quisquam": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
},
"warnCount": 1,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ Object {
"field_statement_4",
],
},
"field_5": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
},
"warnCount": 1,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@ Object {
"getErrorsByGroup": [Function],
"getWarnings": [Function],
"getWarningsByGroup": [Function],
"groups": Object {},
"groups": Object {
"group": Object {
"field_1": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
"field_4": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
},
},
"hasErrors": [Function],
"hasErrorsByGroup": [Function],
"hasWarnings": [Function],
Expand All @@ -29,6 +42,16 @@ Object {
"testCount": 2,
"warnCount": 0,
},
"field_3": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
"field_4": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
},
"warnCount": 0,
}
Expand All @@ -41,7 +64,20 @@ Object {
"getErrorsByGroup": [Function],
"getWarnings": [Function],
"getWarningsByGroup": [Function],
"groups": Object {},
"groups": Object {
"group": Object {
"field_1": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
"field_4": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
},
},
"hasErrors": [Function],
"hasErrorsByGroup": [Function],
"hasWarnings": [Function],
Expand All @@ -65,6 +101,16 @@ Object {
"testCount": 2,
"warnCount": 0,
},
"field_3": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
"field_4": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
},
"warnCount": 0,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ Object {
"testCount": 1,
"warnCount": 0,
},
"field_2": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
"field_3": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
"field_4": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
"field_5": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
},
"warnCount": 0,
}
Expand Down Expand Up @@ -53,6 +73,21 @@ Object {
"testCount": 1,
"warnCount": 0,
},
"field_2": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
"field_3": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
"field_4": Object {
"errorCount": 0,
"testCount": 0,
"warnCount": 0,
},
"field_5": Object {
"errorCount": 2,
"errors": Array [
Expand Down
2 changes: 1 addition & 1 deletion packages/vest/src/__tests__/integration.base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Base behavior', () => {
expect(res.tests).toHaveProperty('field_2');
expect(res.tests).toHaveProperty('field_3');
expect(res.tests).toHaveProperty('field_4');
expect(res.tests).not.toHaveProperty('field_5');
expect(res.tests.field_5.testCount).toBe(0);
expect(suite(vest)).toMatchSnapshot();
});

Expand Down
55 changes: 28 additions & 27 deletions packages/vest/src/__tests__/integration.exclusive.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,52 @@ beforeEach(() => {
});

describe('only', () => {
it('Should only have `only`ed fields', () => {
it('Should only count included fields', () => {
const res = validate({
only: ['field_1', 'field_2'],
});

expect(res.tests).toHaveProperty('field_1');
expect(res.tests).toHaveProperty('field_2');
expect(res.tests).not.toHaveProperty('field_3');
expect(res.tests).not.toHaveProperty('field_4');
expect(res.tests).not.toHaveProperty('field_5');
expect(res.tests.field_1.testCount).toBe(1);
expect(res.tests.field_2.testCount).toBe(1);
expect(res.tests.field_3.testCount).toBe(0);
expect(res.tests.field_4.testCount).toBe(0);
expect(res.tests.field_5.testCount).toBe(0);
});
it('Should only have `only`ed field', () => {
it('Should only count included field', () => {
const res = validate({
only: 'field_1',
});

expect(res.tests).toHaveProperty('field_1');
expect(res.tests).not.toHaveProperty('field_2');
expect(res.tests).not.toHaveProperty('field_3');
expect(res.tests).not.toHaveProperty('field_4');
expect(res.tests).not.toHaveProperty('field_5');
expect(res.tests.field_1.testCount).toBe(1);
expect(res.tests.field_2.testCount).toBe(0);
expect(res.tests.field_3.testCount).toBe(0);
expect(res.tests.field_4.testCount).toBe(0);
expect(res.tests.field_5.testCount).toBe(0);
});
});
describe('skip', () => {
it('Should have all but `skip`ped fields', () => {
it('Should count all but excluded fields', () => {
const res = validate({
skip: ['field_1', 'field_2'],
});

expect(res.tests).not.toHaveProperty('field_1');
expect(res.tests).not.toHaveProperty('field_2');
expect(res.tests).toHaveProperty('field_3');
expect(res.tests).toHaveProperty('field_4');
expect(res.tests).toHaveProperty('field_5');
expect(res.tests.field_1.testCount).toBe(0);
expect(res.tests.field_2.testCount).toBe(0);
expect(res.tests.field_3.testCount).toBe(1);
expect(res.tests.field_4.testCount).toBe(1);
expect(res.tests.field_5.testCount).toBe(1);
});
it('Should have all but `skip`ped field', () => {

it('Should count all but excluded field', () => {
const res = validate({
skip: 'field_1',
});

expect(res.tests).not.toHaveProperty('field_1');
expect(res.tests).toHaveProperty('field_2');
expect(res.tests).toHaveProperty('field_3');
expect(res.tests).toHaveProperty('field_4');
expect(res.tests).toHaveProperty('field_5');
expect(res.tests.field_1.testCount).toBe(0);
expect(res.tests.field_2.testCount).toBe(1);
expect(res.tests.field_3.testCount).toBe(1);
expect(res.tests.field_4.testCount).toBe(1);
expect(res.tests.field_5.testCount).toBe(1);
});
});

Expand All @@ -63,9 +64,9 @@ describe('Combined', () => {
skip_last: 'field_3',
});

expect(res.tests).toHaveProperty('field_1');
expect(res.tests).toHaveProperty('field_2');
expect(res.tests).not.toHaveProperty('field_3');
expect(res.tests.field_1.testCount).toBe(1);
expect(res.tests.field_2.testCount).toBe(1);
expect(res.tests.field_3.testCount).toBe(0);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ describe('Stateful behavior', () => {
result = validate({ only: 'field_1' });
expect(result.tests.field_1.errorCount).toBe(1);
expect(result.errorCount).toBe(1);
expect(Object.keys(result.tests)).toHaveLength(1);
expect(Object.keys(result.tests)).toHaveLength(5); // including 4 skipped tests
expect(result.tests).toHaveProperty('field_1');
expect(result).toMatchSnapshot();

result = validate({ only: 'field_5' });
expect(result.errorCount).toBe(3);
expect(result.tests.field_1.errorCount).toBe(1);
expect(result.tests.field_5.errorCount).toBe(2);
expect(Object.keys(result.tests)).toHaveLength(2);
expect(Object.keys(result.tests)).toHaveLength(5); // including 4 skipped tests
expect(result.tests).toHaveProperty('field_1');
expect(result.tests).toHaveProperty('field_5');
expect(result).toMatchSnapshot();
Expand Down
9 changes: 7 additions & 2 deletions packages/vest/src/core/produce/genTestsSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,23 @@ export default genTestsSummary;
* @returns {Object} Test result summary
*/
const genTestObject = (summaryKey, testObject) => {
const { fieldName, isWarning, failed, statement } = testObject;
const { fieldName, isWarning, failed, statement, skipped } = testObject;

summaryKey[fieldName] = summaryKey[fieldName] || {
[SEVERITY_COUNT_WARN]: 0,
[SEVERITY_COUNT_ERROR]: 0,
[SEVERITY_COUNT_WARN]: 0,
[TEST_COUNT]: 0,
};

const testKey = summaryKey[fieldName];

if (skipped) {
return testKey;
}

summaryKey[fieldName][TEST_COUNT]++;

// Adds to severity group
const addTo = (count, group) => {
testKey[count]++;
if (statement) {
Expand Down
7 changes: 4 additions & 3 deletions packages/vest/src/core/produce/produce.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import createCache from 'cache';
import context from 'ctx';
import genTestsSummary from 'genTestsSummary';
Expand Down Expand Up @@ -28,8 +27,10 @@ const done = withArgs(args => {

const output = produce();

// If we do not have any tests for current field
const shouldSkipRegistration = fieldName && !output.tests[fieldName];
// If we do not have any test runs for the current field
const shouldSkipRegistration =
fieldName &&
(!output.tests[fieldName] || output.tests[fieldName].testCount === 0);

if (!isFunction(callback) || shouldSkipRegistration) {
return output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Object {
"fieldName": "field_1",
"id": "0",
"isWarning": false,
"skipped": false,
"statement": "some statement string",
"testFn": [Function],
},
Expand Down
Loading