istanbuljs / nyc

the Istanbul command line interface
https://istanbul.js.org/
ISC License
5.58k stars 358 forks source link

NYC don't cover all files #864

Closed DWboutin closed 6 years ago

DWboutin commented 6 years ago

Expected Behavior

Cover all files correctly

Observed Behavior

Some covering are at 0% while the tests are complete

Bonus Points! Code (or Repository) that Reproduces Issue

Forensic Information

screen shot 2018-06-12 at 2 51 43 pm

Node v8.10.0 NPM 5.6.0 Operating System: the operating system you observed the issue on. Environment Information: information about your project's environment, see instructions below:

  1. run the following script:

sh -c 'node --version; npm --version; npm ls' > output.txt

  1. share a gist with the contents of output.txt. https://gist.github.com/DWboutin/0c1ba40dff396cba58a2995305c40554

My codecoverage do this:

screen shot 2018-06-12 at 3 02 31 pm

Lots of 0 when the tests cover all. Like AppMenu.jsx have a 100, but AppHeader.jsx have 0 everywhere but it's covered.

https://gist.github.com/DWboutin/24ee23d185a370ffa8c39acfee4af823

This is my package.json: https://gist.github.com/DWboutin/24ee23d185a370ffa8c39acfee4af823

This is the base boilerplate of my project https://github.com/DWboutin/nextjs-redux-boilerplate

Thank you

coreyfarrell commented 6 years ago

Could you link a repo which demonstrates this issue? Maybe a branch on nextjs-redux-boilerplate?

I suspect AppMenu.jsx is reporting 100% branch coverage means that source has no branches.

DWboutin commented 6 years ago

The repo is private sadly, on bitbucket :(

What do you mean "has no branches"? No Git branch? It has a git branch, that's sure.

Thank you for your help! If I can provide you anything, I will, but I can't let you access directly the repo.

coreyfarrell commented 6 years ago

I was referring to 'execution branches'. For example:

if (someConditional) {
  console.log('The if statement is two branchs - one for true and one for false.');
}

The code which is showing 100% coverage of branches doesn't have any branches so istanbul is reporting 100% (0 out of 0) are covered. Maybe this could be better to report as N/A for those cases but that's a separate question.

I don't need or want access to the real repo, I'm looking for a basic example repo. Something which demonstrates running a similar test and getting similar lack of coverage. What I do need to see is how you are testing these sources with 0% coverage. For example are those sources being tested directly inside node or are they being loaded in a browser?

DWboutin commented 6 years ago

I created this repo https://github.com/DWboutin/nyc-help. It's a frontend app.

Thank you so much for your help!

coreyfarrell commented 6 years ago

I found issues in your nyc-help repo which caused your issues. Both in package.json under the "nyc" section.

  1. The "extension" values must include the dot, so "extension": [".js", ".jsx"]. See section in readme
  2. I had to remove the "compilers" option entirely. You are telling mocha running that so I think this was causing it to run twice.

Once I changed the extensions I was getting better results but still not fully correct. Once I removed the "compilers" option from nyc I got what looks correct to me (obviously I don't know your project).

DWboutin commented 6 years ago

I'll try this this weekend! Thanks a lot for your help! I'm really noob with tests and coverage.

Do you know a good tutorial who teach how to build a stack like mine?

coreyfarrell commented 6 years ago

I'm not sure about specific to your stack but lots of good information including some tutorials at https://istanbul.js.org/. Also an #istanbuljs channel on slack at http://devtoolscommunity.herokuapp.com/.

JaKXz commented 6 years ago

Sounds like this issue can be closed, and more specific questions can come up in the slack channel or as new issues? :)

DWboutin commented 6 years ago

Yes it can be closed! Thank you so much for your help!!!