-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
#5067 Add forceCoverageRegex configuration option #5081
#5067 Add forceCoverageRegex configuration option #5081
Conversation
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.
This is failing on Appveyor.
Could you also update the changelog?
docs/Configuration.md
Outdated
{ | ||
... | ||
"jest": { | ||
"forceCollectCoverage": ".*\\.t.js$" |
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.
Should it include pattern
in the name to indicate it's a regexp?
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.
Seems like it's called forceCoverageRegex
elsewhere, can you make sure it's consistent?
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.
I actually wrote it wrong on the docs :) it is forceCoverageRegex
. Just updated the PR
Codecov Report
@@ Coverage Diff @@
## master #5081 +/- ##
==========================================
+ Coverage 60.65% 60.76% +0.11%
==========================================
Files 199 199
Lines 6643 6645 +2
Branches 4 4
==========================================
+ Hits 4029 4038 +9
+ Misses 2614 2607 -7
Continue to review full report at Codecov.
|
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.
I see no reason to not support this. Thanks for the PR!
I have a few concerns about the naming here. Jest's options normally use "Pattern" rather than "Regex", even if they are regex. Most users only use |
docs/Configuration.md
Outdated
|
||
Default: `''` | ||
|
||
The pattern to enforceCollecting coverage even if the file is in the ignored |
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.
Can you rewrite this? What about "Test files are normally ignored from collecting code coverage. With this option, you can overwrite this behavior and include otherwise ignored files in code coverage."
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.
Sure thing. 👍
One more thought: if this is primarily to enable coverage for test files, should we instead make this a boolean flag "includeTestsInCoverage" instead of having people fumble with regex/globs? |
@cpojer for the "includeTestsInCoverage" concerns of yours, I have some cases which we have regular tests like It is probably a better idea to use globs though I agree, I will update the PR accordingly |
Add forceCoverageMatch config option to allow collecting coverage even if the file is ignored. This way you can collect coverage from the source files with tests or specific files you ignored manually.
Hey I updated the PR and changed regex to Glob. |
Thanks for the PR and for making changes to it :) |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
As explained in #5067 if you have tests in source files there is no way to collect coverage from those files since jest returns false for should instrument checks.
This PR adds forceCoverageRegex config option to allow collecting coverage even
if the file is ignored. This way you can collect coverage from the
source files with tests or specific files you ignored manually.
Test plan
Create a file which includes the tests with source files as following:
Add 'forceCoverageRegex' field to the jest options same as
testRegex
. Run jest with collectCoverage option.In this PR I add unit tests for
jest-runtime/src/should_instrument.js
also.