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

Configure Jest to scan all files in src dirs when measuring coverage #1232

Merged
merged 2 commits into from
Jan 11, 2021

Conversation

manuelfidalgo
Copy link
Contributor

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/'], to roots: ['src/', 'tests/'],

Testing

Tested in packages/botonic-react folder with npm test:
After applying the changes, we observe that coverage has slighltly decreased, since more files are taken into account for measuring the whole coverage

Copy link
Contributor

@dpinol dpinol left a 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
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link

codecov bot commented Jan 8, 2021

Codecov Report

Merging #1232 (433236f) into master (54ad8ca) will decrease coverage by 4.19%.
The diff coverage is n/a.

Impacted file tree graph

@@            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     
Flag Coverage Δ
botonic-core 30.34% <ø> (-23.70%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/botonic-core/src/handoff.js 48.52% <0.00%> (-11.48%) ⬇️
...ntful/src/tools/l10n/reference-field-duplicator.ts 0.00% <0.00%> (ø)
packages/botonic-core/src/i18n.js 0.00% <0.00%> (ø)
...tful/src/tools/l10n/import-csv-from-translators.ts 0.00% <0.00%> (ø)
packages/botonic-core/src/core-bot.js 0.00% <0.00%> (ø)
packages/botonic-core/src/plugins.js 0.00% <0.00%> (ø)
packages/botonic-react/src/app.jsx 0.00% <0.00%> (ø)
...-plugin-contentful/src/tools/search-performance.ts 0.00% <0.00%> (ø)
...plugin-contentful/src/tools/l10n/locale-migrate.ts 0.00% <0.00%> (ø)
packages/botonic-core/src/nlu.js 0.00% <0.00%> (ø)
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 54ad8ca...433236f. Read the comment docs.

Copy link
Contributor

@vanbasten17 vanbasten17 left a 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/'],
Copy link
Contributor

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

Copy link
Contributor Author

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

@manuelfidalgo manuelfidalgo merged commit f9db662 into master Jan 11, 2021
@manuelfidalgo manuelfidalgo deleted the chore/jest-coverage-config branch January 11, 2021 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants