Incorrect behaviour when using Jest's Array type config (collectCoverageFrom)
See original GitHub issueI don’t know whether this is the expected behaviour or not, however i just report this in case someone face the same problem…
in my package.json
"jest": {
"collectCoverageFrom": [
"src/components/**/*.{js,jsx}"
]
}
after apply react-app-rewired, the collectCoverageFrom become [ 'src/components/**/*.{js,jsx}', 'src/**/*.{js,jsx,mjs}' ]
, which is not the default behaviour of react-scripts, as it won’t include the jest default 'src/**/*.{js,jsx,mjs}'
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Configuring Jest
You can collect coverage from those files with setting forceCoverageMatch . JavaScript; TypeScript. /** @type {import('jest').Config} */
Read more >Jest passing tests but --covering option not picking up files
You are missing a setting in the jest.config.js, collectCoverage: true ... I also use a more descriptive collectCoverageFrom:
Read more >How to set up Jest & Enzyme like a boss - freeCodeCamp
This tutorial assumes that you already have a React application set up with webpack & babel . We'll continue from there. This is...
Read more >Configuring package.json · Jest
If you'd like to use your package.json to store Jest's config, the "jest" key ... collectCoverage [boolean]; collectCoverageFrom [array] ... Default: false.
Read more >How To Set Up Next.JS With Jest, React Testing Library and ...
Runs it in an isolated environment with configuration of your choosing; Compares the behaviour of that function with what you expect it to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This has occurred due to a combination of two things.
First - most jest configuration options are not permitted by react-scripts. How react-app-rewired works around this is it takes a copy of all your defined jest options from package.json, and then passes into react-scripts everything except your jest options (i.e. it deletes the jest options part). This means that react-scripts isn’t seeing the overrides for even the few fields it does permit overrides for.
React-app-rewired then merges any array or object values defined in package.json with the original values from react-scripts instead of overwriting them. I don’t know the history of why it was done this way rather than overriding them.
What you can do to make an override setting instead of a setting to be merged is to apply the setting inside the jest function in config-overrides, which is run after the merge has occurred. This lets you make a full replacement instead of a merge replacement.
Thank you very much, IMO the purpose of react-app-rewired is to temporary modify the unsupported config, and remove it once react-scripts is supported… so I think it shouldn’t break the default behaviour of any untouched config unless it has a bigger reason.