question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect behaviour when using Jest's Array type config (collectCoverageFrom)

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
dawnmistcommented, May 9, 2018

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.

module.exports = {
  jest: (config) => {
    config.collectCoverageFrom = ["src/components/**/*.{js,jsx}"];
    return config;
  }
}
2reactions
hardyscccommented, May 9, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found