-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Improve the message when run coverage while there are no tests #6334
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
Merged
thymikee
merged 13 commits into
jestjs:master
from
rhysawilliams2010:coverage-no-tests-warning
Aug 9, 2018
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f238bec
Improve the message when running coverage while there are no tests
94f2331
use Object.assign
71b829e
Only mock specific functions exported by istanbul-lib-coverage
271b542
Add e2e tests for coverage threshold.
c4e749b
Merge branch 'master' into coverage-no-tests-warning
rhysawilliams2010 f4b160b
revert unnecessary test changes
bf81a29
linting
b62e3df
Replace process.cwd() in stderr snapshot test.
3c36107
Merge branch 'master' of https://github.com/facebook/jest into covera…
68a822b
Make the tests more robust by using extractSummary method to compare
f671f8e
Merge remote-tracking branch 'upstream/master' into pr/6334
thymikee 66798eb
move changelog entry
thymikee c8b2189
Merge branch 'master' into coverage-no-tests-warning
thymikee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Improve the message when running coverage while there are no tests
fixes #6141 Update the coverage reporting so that it still conforms to the documentation but doesn't throw an error when there are no files matching "global" threshold group (maybe because they are already matched with a path or glob). Also make sure that a file is matched against all matching path and glob threshold groups instead of just one.
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ let libSourceMaps; | |
| let CoverageReporter; | ||
| let istanbulApi; | ||
|
|
||
| import {CoverageSummary} from 'istanbul-lib-coverage/lib/file'; | ||
| import path from 'path'; | ||
| import mock from 'mock-fs'; | ||
|
|
||
|
|
@@ -32,6 +33,9 @@ beforeEach(() => { | |
|
|
||
| const fileTree = {}; | ||
| fileTree[process.cwd() + '/path-test-files'] = { | ||
| '000pc_coverage_file.js': '', | ||
| '050pc_coverage_file.js': '', | ||
| '100pc_coverage_file.js': '', | ||
| 'full_path_file.js': '', | ||
| 'glob-path': { | ||
| 'file1.js': '', | ||
|
|
@@ -68,37 +72,54 @@ describe('onRunComplete', () => { | |
| }; | ||
|
|
||
| libCoverage.createCoverageMap = jest.fn(() => { | ||
| const files = [ | ||
| './path-test-files/covered_file_without_threshold.js', | ||
| './path-test-files/full_path_file.js', | ||
| './path-test-files/relative_path_file.js', | ||
| './path-test-files/glob-path/file1.js', | ||
| './path-test-files/glob-path/file2.js', | ||
| ].map(p => path.resolve(p)); | ||
| const covSummary = { | ||
| branches: {covered: 0, pct: 0, skipped: 0, total: 0}, | ||
| functions: {covered: 0, pct: 0, skipped: 0, total: 0}, | ||
| lines: {covered: 0, pct: 0, skipped: 0, total: 0}, | ||
| statements: {covered: 5, pct: 50, skipped: 0, total: 10}, | ||
| }; | ||
| const fileCoverage = [ | ||
| ['./path-test-files/covered_file_without_threshold.js'], | ||
| ['./path-test-files/full_path_file.js'], | ||
| ['./path-test-files/relative_path_file.js'], | ||
| ['./path-test-files/glob-path/file1.js'], | ||
| ['./path-test-files/glob-path/file2.js'], | ||
| [ | ||
| './path-test-files/000pc_coverage_file.js', | ||
| {statements: {covered: 0, pct: 0, total: 10}}, | ||
| ], | ||
| [ | ||
| './path-test-files/050pc_coverage_file.js', | ||
| {statements: {covered: 5, pct: 50, total: 10}}, | ||
| ], | ||
| [ | ||
| './path-test-files/100pc_coverage_file.js', | ||
| {statements: {covered: 10, pct: 100, total: 10}}, | ||
| ], | ||
| ].reduce((c, f) => { | ||
| const file = path.resolve(f[0]); | ||
| const override = f[1]; | ||
| c[file] = new CoverageSummary({ | ||
| ...covSummary, | ||
|
||
| ...override, | ||
| }); | ||
| return c; | ||
| }, {}); | ||
|
|
||
| return { | ||
| fileCoverageFor(path) { | ||
| if (files.indexOf(path) !== -1) { | ||
| const covSummary = { | ||
| branches: {covered: 0, pct: 0, skipped: 0, total: 0}, | ||
| functions: {covered: 0, pct: 0, skipped: 0, total: 0}, | ||
| lines: {covered: 0, pct: 0, skipped: 0, total: 0}, | ||
| merge(other) { | ||
| return covSummary; | ||
| }, | ||
| statements: {covered: 0, pct: 50, skipped: 0, total: 0}, | ||
| }; | ||
| if (fileCoverage[path]) { | ||
| return { | ||
| toSummary() { | ||
| return covSummary; | ||
| return fileCoverage[path]; | ||
| }, | ||
| }; | ||
| } else { | ||
| return undefined; | ||
| } | ||
| }, | ||
| files() { | ||
| return files; | ||
| return Object.keys(fileCoverage); | ||
| }, | ||
| }; | ||
| }); | ||
|
|
@@ -281,4 +302,125 @@ describe('onRunComplete', () => { | |
| expect(testReporter.getLastError().message.split('\n')).toHaveLength(1); | ||
| }); | ||
| }); | ||
|
|
||
| test(`getLastError() returns 'undefined' when global threshold group | ||
| is empty because PATH and GLOB threshold groups have matched all the | ||
| files in the coverage data.`, () => { | ||
| const testReporter = new CoverageReporter( | ||
| { | ||
| collectCoverage: true, | ||
| coverageThreshold: { | ||
| './path-test-files/': { | ||
| statements: 50, | ||
| }, | ||
| global: { | ||
| statements: 100, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| maxWorkers: 2, | ||
| }, | ||
| ); | ||
| testReporter.log = jest.fn(); | ||
| return testReporter | ||
| .onRunComplete(new Set(), {}, mockAggResults) | ||
| .then(() => { | ||
| expect(testReporter.getLastError()).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| test(`getLastError() returns 'undefined' when file and directory path | ||
| threshold groups overlap`, () => { | ||
| const covThreshold = {}; | ||
| [ | ||
| './path-test-files/', | ||
| './path-test-files/covered_file_without_threshold.js', | ||
| './path-test-files/full_path_file.js', | ||
| './path-test-files/relative_path_file.js', | ||
| './path-test-files/glob-path/file1.js', | ||
| './path-test-files/glob-path/file2.js', | ||
| './path-test-files/*.js', | ||
| ].forEach(path => { | ||
| covThreshold[path] = { | ||
| statements: 0, | ||
| }; | ||
| }); | ||
|
|
||
| const testReporter = new CoverageReporter( | ||
| { | ||
| collectCoverage: true, | ||
| coverageThreshold: covThreshold, | ||
| }, | ||
| { | ||
| maxWorkers: 2, | ||
| }, | ||
| ); | ||
| testReporter.log = jest.fn(); | ||
| return testReporter | ||
| .onRunComplete(new Set(), {}, mockAggResults) | ||
| .then(() => { | ||
| expect(testReporter.getLastError()).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| test(`that if globs or paths are specified alongside global, coverage | ||
| data for matching paths will be subtracted from overall coverage | ||
| and thresholds will be applied independently`, () => { | ||
| const testReporter = new CoverageReporter( | ||
| { | ||
| collectCoverage: true, | ||
| coverageThreshold: { | ||
| './path-test-files/100pc_coverage_file.js': { | ||
| statements: 100, | ||
| }, | ||
| global: { | ||
| statements: 50, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| maxWorkers: 2, | ||
| }, | ||
| ); | ||
| testReporter.log = jest.fn(); | ||
| // 100% coverage file is removed from overall coverage so | ||
| // coverage drops to < 50% | ||
| return testReporter | ||
| .onRunComplete(new Set(), {}, mockAggResults) | ||
| .then(() => { | ||
| expect(testReporter.getLastError().message.split('\n')).toHaveLength(1); | ||
| }); | ||
| }); | ||
|
|
||
| test(`that files are matched by all matching threshold groups`, () => { | ||
| const testReporter = new CoverageReporter( | ||
| { | ||
| collectCoverage: true, | ||
| coverageThreshold: { | ||
| './path-test-files/': { | ||
| statements: 50, | ||
| }, | ||
| './path-test-files/050pc_coverage_file.js': { | ||
| statements: 50, | ||
| }, | ||
| './path-test-files/100pc_coverage_*.js': { | ||
| statements: 100, | ||
| }, | ||
| './path-test-files/100pc_coverage_file.js': { | ||
| statements: 100, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| maxWorkers: 2, | ||
| }, | ||
| ); | ||
| testReporter.log = jest.fn(); | ||
| return testReporter | ||
| .onRunComplete(new Set(), {}, mockAggResults) | ||
| .then(() => { | ||
| expect(testReporter.getLastError()).toBeUndefined(); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it supported to do a deep import like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better way would be to use public
createCoverageSummaryapihttps://github.com/istanbuljs/istanbuljs/blob/master/packages/istanbul-lib-coverage/index.js#L26-L31