Search code examples
javascriptmocha.jsnyc

How to exclude a file from coverage report in Mocha and Nyc


I have a test setup configured with Mocha and nyc.

I'm trying to exclude a certain file from the report. So I tried this:

"nyc": {
    "exclude": [
      "./sites/modules/carousel-widget/",
    ]
  },

And it actually seems to works because the overall percentage moves up (from 48% to 60%). However, I can still see the file under file section in the report as if the above lines do not have any effect on this.

enter image description here

enter image description here I even tried the following. But it didn't work.

"test:coverage": "APOS_TEST=1 nyc --reporter=html mocha --file ./test/lib/setup.js \"test/**/*.{spec,test}.js\"  --ignore ./sites/modules/carousel-widget/",

How can I be able to get this excluded in the reports?


Solution

  • What worked for me is this:

    "nyc": {
       "exclude": ["**/sites/modules/carousel-widget/*",
        ]
      },
    

    Not sure why giving the exact path doesn't work. Wildcard at the start does the job though.