Skip to content

Commit

Permalink
Adding ancestorTitles property to JSON test output (#4293)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehedman authored and cpojer committed Aug 24, 2017
1 parent 82e6639 commit b6c68d3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ All files | 85.71 | 100 | 50 | 85.71 | |

exports[`json reporter printing with --coverage 1`] = `
"Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 passed, 2 total
Tests: 1 failed, 2 passed, 3 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.
Expand Down
46 changes: 41 additions & 5 deletions integration_tests/__tests__/json_reporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,30 @@ describe('JSON Reporter', () => {
);
}

expect(jsonResult.numTotalTests).toBe(2);
expect(jsonResult.numTotalTests).toBe(3);
expect(jsonResult.numTotalTestSuites).toBe(1);
expect(jsonResult.numRuntimeErrorTestSuites).toBe(0);
expect(jsonResult.numPassedTests).toBe(1);
expect(jsonResult.numPassedTests).toBe(2);
expect(jsonResult.numFailedTests).toBe(1);
expect(jsonResult.numPendingTests).toBe(0);

const noAncestors = jsonResult.testResults[0].assertionResults.find(
item => item.title == 'no ancestors',
);
let expected = {ancestorTitles: []};
expect(noAncestors).toEqual(expect.objectContaining(expected));

const addsNumbers = jsonResult.testResults[0].assertionResults.find(
item => item.title == 'adds numbers',
);
expected = {ancestorTitles: ['sum']};
expect(addsNumbers).toEqual(expect.objectContaining(expected));

const failsTheTest = jsonResult.testResults[0].assertionResults.find(
item => item.title == 'fails the test',
);
expected = {ancestorTitles: ['sum', 'failing tests']};
expect(failsTheTest).toEqual(expect.objectContaining(expected));
});

it('outputs coverage report', () => {
Expand All @@ -53,7 +71,7 @@ describe('JSON Reporter', () => {
const stderr = result.stderr.toString();
let jsonResult;

expect(stderr).toMatch(/1 failed, 1 passed/);
expect(stderr).toMatch(/1 failed, 2 passed/);
expect(result.status).toBe(1);

try {
Expand All @@ -64,11 +82,29 @@ describe('JSON Reporter', () => {
);
}

expect(jsonResult.numTotalTests).toBe(2);
expect(jsonResult.numTotalTests).toBe(3);
expect(jsonResult.numTotalTestSuites).toBe(1);
expect(jsonResult.numRuntimeErrorTestSuites).toBe(0);
expect(jsonResult.numPassedTests).toBe(1);
expect(jsonResult.numPassedTests).toBe(2);
expect(jsonResult.numFailedTests).toBe(1);
expect(jsonResult.numPendingTests).toBe(0);

const noAncestors = jsonResult.testResults[0].assertionResults.find(
item => item.title == 'no ancestors',
);
let expected = {ancestorTitles: []};
expect(noAncestors).toEqual(expect.objectContaining(expected));

const addsNumbers = jsonResult.testResults[0].assertionResults.find(
item => item.title == 'adds numbers',
);
expected = {ancestorTitles: ['sum']};
expect(addsNumbers).toEqual(expect.objectContaining(expected));

const failsTheTest = jsonResult.testResults[0].assertionResults.find(
item => item.title == 'fails the test',
);
expected = {ancestorTitles: ['sum', 'failing tests']};
expect(failsTheTest).toEqual(expect.objectContaining(expected));
});
});
10 changes: 8 additions & 2 deletions integration_tests/json_reporter/__tests__/sum.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@

const sum = require('../sum');

it('no ancestors', () => {
expect(true).toBeTruthy();
});

describe('sum', () => {
it('adds numbers', () => {
expect(sum(1, 2)).toEqual(3);
});

it('fails the test', () => {
expect(sum(1, 2)).toEqual(4);
describe('failing tests', () => {
it('fails the test', () => {
expect(sum(1, 2)).toEqual(4);
});
});
});
1 change: 1 addition & 0 deletions packages/jest-util/src/format_test_results.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function formatTestAssertion(
assertion: AssertionResult,
): FormattedAssertionResult {
const result: FormattedAssertionResult = {
ancestorTitles: assertion.ancestorTitles,
failureMessages: null,
fullName: assertion.fullName,
status: assertion.status,
Expand Down

0 comments on commit b6c68d3

Please sign in to comment.