-
Notifications
You must be signed in to change notification settings - Fork 75
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
Configure Jest to scan all files in src dirs when measuring coverage #1232
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.
:clap
Please get coverage % before and after the change and add it to a need 2021/01/08 tab at https://docs.google.com/spreadsheets/d/1_33VpvHmgW5fXwoWzSgfCKHYsBIza1d3Es5F7BztXm4/edit#gid=1543842881
so that we can calculate how much we have improved during the last quarter
@@ -1,6 +1,6 @@ | |||
// Options about JS are for compiling @botonic .js/jsx files |
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 there's no jest.config.js for core.
Can you add one with minimal contents? Not sure if by default it was already adding src to the roots
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.
good catch @dpinol ! There were some files missing from src.
I added a jest config file for taking care of that.
Codecov Report
@@ Coverage Diff @@
## master #1232 +/- ##
==========================================
- Coverage 66.00% 61.81% -4.20%
==========================================
Files 205 221 +16
Lines 5466 5822 +356
Branches 1038 1088 +50
==========================================
- Hits 3608 3599 -9
- Misses 1113 1428 +315
- Partials 745 795 +50
Flags with carried forward coverage won't be shown. Click here to find out more.
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.
LGTM! Go for it! 💪
'.*.helper.js', | ||
'tests/__mocks__', | ||
], | ||
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!/node_modules/'], |
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 think that we don't have any file with this extension, but if we want to cover all Javascript scenarios, I would add also mjs
extension. https://medium.com/passpill-project/files-with-mjs-extension-for-javascript-modules-ced195d7c84a
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.
thanks for the observation, I think we can add it when we have that kind of files
Description
Configure Jest to look for all files in src dir in order to measure coverage properly.
Same config has been propposed to bots-definition in https://github.com/metis-ai/bots-definition/pull/404
Context
With the previous configuration, Jest would only look for items imported in the tests files, resulting in an unrealistic coverage. e.g. A src file without tests and not referenced by other tests, will not be taken into account for the coverage.
Approach taken / Explain the design
Adding src dir to the roots of the Jest configuration will force Jest to scan ALL src files no matter if they are imported or not.
In all jest config files, we have changed the line
roots: ['tests/'],
toroots: ['src/', 'tests/'],
Testing
Tested in
packages/botonic-react
folder withnpm test
:After applying the changes, we observe that coverage has slighltly decreased, since more files are taken into account for measuring the whole coverage