nyc: One file missing from coverage

Expected Behavior

All files in a certain directory instrumented and reported on for coverage. Four files are here:

image

The test suite includes four tests, each of which exercises one of these files. The code within the createFlag.js file is successfully executed:

image

Observed Behavior

The file actions/flags/createFlag.js is missing from the coverage output. All other files in the entire project (there are 30+ files in various folders) are properly instrumented and reported on:

image

Environment

https://gist.github.com/crrobinson14/b09ae1d65eade891cdd26c811e940dc9

  "scripts": {
        "test": "cross-env NODE_ENV=test node_modules/.bin/nyc --reporter=text-summary --reporter=html mocha"
   },
  "nyc": {
    "exclude": [
      "config/**/*.js",
      "bin/**/*.js",
      "test/**/*.js"
    ]
  },

This project is NodeJS-only and does not include Babel. There is no .babelrc file in the folder. There are no other exclusions specified anywhere. There are no Istanbul “ignore” comments in any of these files. I have tested using various combinations of “all” and “manually requiring the file” in the test.

I realize this is a mystery that may not be solved in a single response. What I’m asking for here is any ideas or guidance about how I can even begin to debug this issue. The test suite is running 100% properly. I have verified that the code within this file is actually being executed in various ways (e.g. console logging output from it). I can’t for the life of me figure out why it’s not included in the coverage report.

Where do I start? Is there some way to view verbose output from the instrumenter and reporter to determine where and why it might be getting excluded?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 7
  • Comments: 19

Most upvoted comments

For some reason I can’t identify (npm update reported no modules to update, and on a whim I had tried a rm -rf node_modules/.cache to no effect), a complete removal of node_modules and package-lock.json followed by an npm i has resolved this issue.

I got this error as well, @ashwani-pandey’s suggestion pointed me in the right direction. One of my files wasn’t getting picked up despite having 100% coverage and passing tests. Turns out I had a variable called “package”, which I suppose is legal but ill-advised. If you have a file that refuses to show up in your coverage list, comment all code out and rerun cover, if the file shows up, you likely have a soft error somewhere.

If this gets fixed I will be super happy. I have had to stop using NYC because of this very issue.

I had a similar problem with a file not showing in coverage. The problem was a line that was something like

let x = y * 001;

The 001 for some reason stopped the file from being included.

Quick note, and similar to @ashwani. After using arguments as a variable name (with const, not let), nyc would break and not render any coverage (on that file only, but the rest would be fine).

function()
{
  if (something)
  {
     const arguments = ...
  }
}

It’s not something that is raised by linters or Js.

I faced this issue too. Turns out nyc ignores files which has issues that, in general, won’t throw an error either. In my case, I had two functions with same name in my file. This was by mistake, and shouldn’t be there. But since JS doesn’t throw error for this, I had no idea till I started to check after nyc coverage was missing for this file.

Good option - Use a default linting guide like the one from Airbnb - https://github.com/airbnb/javascript

I’ve discovered that when I see this issue, i can resolve it by updating to the latest “sub-dependecies” by running yarn upgrade (i can do this as I run fixed versions for my dependencies)

I am having the same problem. I deleted node_modules and my lock file, and reinstalled all dependencies but no luck.