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.

Support Jest's coverage options

See original GitHub issue

I was surprised when I got a warning from npm test stating that Jest’s coverage options aren’t supported. As a prior Jest user I expected them to be supported since Jest’s --coverage option works fine.

While I know I could just change my test script or eject, I think it would reduce confusion to support this out of the box. Is seems like there’s a whitelist for options, how easy would it be to implement support for all the coverage* options?

Output

> react-scripts test --env=jsdom

Out of the box, Create React App only supports overriding these Jest options:

  • collectCoverageFrom
  • coverageReporters
  • coverageThreshold
  • snapshotSerializers.

These options in your package.json Jest configuration are not currently supported by Create React App:

  • collectCoverage
  • coveragePathIgnorePatterns

If you wish to override other Jest options, you need to eject from the default setup. You can do so by running npm ru
n eject but remember that this is a one-way operation. You may also file an issue with Create React App to discuss su
pporting more options out of the box.                                                                               

npm ERR! Test failed.  See above for more details.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

13reactions
gaearoncommented, Jul 20, 2017

I don’t think you need to put collectCoverage into package.json. Just run npm test -- --coverage as described here to get the coverage report.

I am also not sure why you need coveragePathIgnorePatterns. Isn’t collectCoverageFrom enough to specify where you want it to be collected?

1reaction
nickmccurdycommented, Jul 20, 2017

Whoops, I just double checked and react-scripts test --coverage actually doesn’t run the watcher, it just runs tests once with coverage as if you ran jest --coverage. My mistake, I’m not sure if that functionality is intentional though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest CLI Options
The jest command line runner has a number of useful options. You can run jest --help to view all available options. Many of...
Read more >
Configuring code coverage in Jest, the right way
If you're using Jest, here are three options that should always be present in your Jest configuration: collectCoverage; collectCoverageFrom ...
Read more >
Jest: support Coverage option : WEB-25778 - YouTrack
Jest provides Coverage when option --coverage is applied (https://facebook.github.io/jest/docs/cli.html#coverage). You can see output table in the console.
Read more >
Configuring Code Coverage for TypeScript Files in Jest
In this lesson I demonstrate using the collectCoverageFrom configuration option to improve jest's coverage support for TypeScript files and ...
Read more >
How to get the code coverage report using Jest?
After you write the tests, run the command npm run jest-coverage . This will create a coverage folder in the root directory. /coverage/icov- ......
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