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

Out of the box test coverage is not 100% #1386

Closed
TheRobBrennan opened this issue Jan 12, 2017 · 9 comments
Closed

Out of the box test coverage is not 100% #1386

TheRobBrennan opened this issue Jan 12, 2017 · 9 comments

Comments

@TheRobBrennan
Copy link

I love this as a starting point for React apps, but I am puzzled by one thing...Having Jest and test coverage built in is awesome, but why isn't coverage 100% out of the box?

If I run the test coverage report, I see:

[Thu Jan 12 11:29:25] fb $ npm test -- --coverage

> fb@0.1.0 test /Users/rob/repos/fb
> react-scripts test --env=jsdom "--coverage"

 PASS  src/App.test.js
  ✓ renders without crashing (18ms)

----------|----------|----------|----------|----------|----------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files |       50 |      100 |      100 |       50 |                |
 App.js   |      100 |      100 |      100 |      100 |                |
 index.js |        0 |      100 |      100 |        0 |              1 |
----------|----------|----------|----------|----------|----------------|
Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.137s
Ran all test suites.

It'd be great to start folks off with 100% tested code - no matter how trivial the index.js file is =)

@wtgtybhertgeghgtwtg
Copy link
Contributor

Does index.js even have any exports?

@TheRobBrennan
Copy link
Author

It doesn't - but it seems like if code coverage is something that is a huge benefit, it'd be great to start folks off with 100% coverage. For the life of me, all the googling I did regarding Jest and configuration options didn't seem to matter one bit for this.

@gaearon
Copy link
Contributor

gaearon commented Feb 11, 2017

Thanks for the issue! I understand where you're coming from, but in real apps the goal of 100% test coverage is often unrealistic and encourages people to create brittle tests that aren't very useful.

I think it’s fine to leave this as is, but I appreciate your opinion.

@gaearon gaearon closed this as completed Feb 11, 2017
@wasifhyder
Copy link

wasifhyder commented Mar 23, 2017

@TheRobBrennan -

You can exclude index.js from coverage reporting.

I remedied the problem by adding
Note: this worked for me on the ejected version of create-react-app. Can't say for sure how this would behave otherwise

"jest": { "coveragePathIgnorePatterns": ["<rootDir>/src/index.js"] }

https://facebook.github.io/jest/docs/configuration.html#coveragepathignorepatterns-array-string

@sebastienbarre
Copy link

@wasifhyder thanks, this looks promising. This isn't working for me though. I added what you mentioned above in package.json, and I'm running react-scripts test --env=jsdom --coverage, yet index.js is still brought up (with 0 coverage). Did you run it differently?

@thecristen
Copy link

thecristen commented Apr 10, 2017

I'm experiencing the same issue. I can't tell if these Jest configs work on an unejected app at all.

edit: However I did have luck adjusting the CLI script. Adding this flag worked for me --collectCoverageFrom='["src/**/*.{js,jsx}", "!src/index.js"]'

@wasifhyder
Copy link

@sebastienbarre, @thecristen

I did this after ejecting react. Haven't tried without ejecting, so can't say for sure how this will behave.

@gaearon
Copy link
Contributor

gaearon commented May 16, 2017

Coverage collection is configurable in the next version.
#1830

@gaearon
Copy link
Contributor

gaearon commented May 16, 2017

Please help beta test the new version that includes this change!
#2172

@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants