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

fix: coverage summary reporting #7058

Merged
merged 1 commit into from
Oct 2, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Fixes

- `[jest-cli]` Fix coverage summary reporting ([#7058](https://github.com/facebook/jest/pull/7058))
- `[jest-each]` Add each array validation check ([#7033](https://github.com/facebook/jest/pull/7033))
- `[jest-haste-map]` [**BREAKING**] Replace internal data structures to improve performance ([#6960](https://github.com/facebook/jest/pull/6960))
- `[jest-haste-map]` Use relative paths to allow remote caching ([#7020](https://github.com/facebook/jest/pull/7020))
Expand Down
53 changes: 53 additions & 0 deletions e2e/__tests__/__snapshots__/coverage_report.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ All files | 85.71 | 100 | 50 | 100 | |
----------|----------|----------|----------|----------|-------------------|"
`;

exports[`does not output coverage report when html is requested 1`] = `""`;

exports[`json reporter printing with --coverage 1`] = `
"Test Suites: 1 failed, 1 total
Tests: 1 failed, 2 passed, 3 total
Expand All @@ -65,3 +67,54 @@ All files | 56.52 | 0 | 50 | 55.56
Identical.js | 100 | 100 | 100 | 100 | |
-------------------------------------|----------|----------|----------|----------|-------------------|"
`;

exports[`outputs coverage report when text and text-summary is requested 1`] = `
"
=============================== Coverage summary ===============================
Statements : 56.52% ( 13/23 )
Branches : 0% ( 0/4 )
Functions : 50% ( 3/6 )
Lines : 55.56% ( 10/18 )
================================================================================
-------------------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-------------------------------------|----------|----------|----------|----------|-------------------|
All files | 56.52 | 0 | 50 | 55.56 | |
coverage-report | 41.18 | 0 | 25 | 42.86 | |
OtherFile.js | 100 | 100 | 100 | 100 | |
Sum.js | 85.71 | 100 | 50 | 100 | |
SumDependency.js | 0 | 0 | 0 | 0 | 8,10,12 |
notRequiredInTestSuite.js | 0 | 0 | 0 | 0 | 8,15,16,17,19 |
coverage-report/cached-duplicates/a | 100 | 100 | 100 | 100 | |
Identical.js | 100 | 100 | 100 | 100 | |
coverage-report/cached-duplicates/b | 100 | 100 | 100 | 100 | |
Identical.js | 100 | 100 | 100 | 100 | |
-------------------------------------|----------|----------|----------|----------|-------------------|"
`;

exports[`outputs coverage report when text is requested 1`] = `
"-------------------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-------------------------------------|----------|----------|----------|----------|-------------------|
All files | 56.52 | 0 | 50 | 55.56 | |
coverage-report | 41.18 | 0 | 25 | 42.86 | |
OtherFile.js | 100 | 100 | 100 | 100 | |
Sum.js | 85.71 | 100 | 50 | 100 | |
SumDependency.js | 0 | 0 | 0 | 0 | 8,10,12 |
notRequiredInTestSuite.js | 0 | 0 | 0 | 0 | 8,15,16,17,19 |
coverage-report/cached-duplicates/a | 100 | 100 | 100 | 100 | |
Identical.js | 100 | 100 | 100 | 100 | |
coverage-report/cached-duplicates/b | 100 | 100 | 100 | 100 | |
Identical.js | 100 | 100 | 100 | 100 | |
-------------------------------------|----------|----------|----------|----------|-------------------|"
`;

exports[`outputs coverage report when text-summary is requested 1`] = `
"
=============================== Coverage summary ===============================
Statements : 56.52% ( 13/23 )
Branches : 0% ( 0/4 )
Functions : 50% ( 3/6 )
Lines : 55.56% ( 10/18 )
================================================================================"
`;
47 changes: 47 additions & 0 deletions e2e/__tests__/coverage_report.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,53 @@ test('outputs coverage report as json', () => {
}
});

test('outputs coverage report when text is requested', () => {
const {stdout, status} = runJest(DIR, [
'--no-cache',
'--coverage',
'--coverageReporters=text',
'--coverageReporters=html',
]);
expect(status).toBe(0);
expect(stdout).toMatch(/Stmts | . Branch/);
expect(stdout).toMatchSnapshot();
});

test('outputs coverage report when text-summary is requested', () => {
const {stdout, status} = runJest(DIR, [
'--no-cache',
'--coverage',
'--coverageReporters=text-summary',
]);
expect(status).toBe(0);
expect(stdout).toMatch(/Coverage summary/);
expect(stdout).toMatchSnapshot();
});

test('outputs coverage report when text and text-summary is requested', () => {
const {stdout, status} = runJest(DIR, [
'--no-cache',
'--coverage',
'--coverageReporters=text-summary',
'--coverageReporters=text',
]);
expect(status).toBe(0);
expect(stdout).toMatch(/Stmts | . Branch/);
expect(stdout).toMatch(/Coverage summary/);
expect(stdout).toMatchSnapshot();
});

test('does not output coverage report when html is requested', () => {
const {stdout, status} = runJest(DIR, [
'--no-cache',
'--coverage',
'--coverageReporters=html',
]);
expect(status).toBe(0);
expect(stdout).toMatch(/^$/);
expect(stdout).toMatchSnapshot();
});

test('collects coverage from duplicate files avoiding shared cache', () => {
const args = [
'--coverage',
Expand Down
11 changes: 4 additions & 7 deletions packages/jest-cli/src/reporters/coverage_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,10 @@ export default class CoverageReporter extends BaseReporter {
reporter.dir = this._globalConfig.coverageDirectory;
}

let coverageReporters = this._globalConfig.coverageReporters || [];
if (
!this._globalConfig.useStderr &&
coverageReporters.length &&
coverageReporters.indexOf('text') === -1
) {
coverageReporters = coverageReporters.concat(['text-summary']);
const coverageReporters = this._globalConfig.coverageReporters || [];

if (!this._globalConfig.useStderr && coverageReporters.length < 1) {
coverageReporters.push('text-summary');
}

reporter.addAll(coverageReporters);
Expand Down