Istanbul nyc to exclude test files
Asked Answered
S

1

37

I'm currently getting my test files in the final coverage. That's probably because they sit alongside my components instead of having their own test folder. How can I exclude these from the coverage?

I have installed istanbul and nyc and I'm using mocha.

My script looks like:

"test": "nyc --reporter=html mocha tools/testSetup.js app/**/*.spec.js || true"

Salzhauer answered 8/2, 2017 at 13:32 Comment(0)
S
61

Right, after some digging I've managed to get this working. I've added

"nyc": {
    "include": "app", // Only looks in the app folder
    "exclude": "**/*.spec.js" 
}

to my package.json. Since I'm using webpack I'll probably try and find a way of defining this rule in the webpack.config.js file (if possible at all). I'll come back if I get an answer to this.

Salzhauer answered 8/2, 2017 at 14:30 Comment(1)
Just complementing: include and exclude may be arrays.Refreshment

© 2022 - 2024 — McMap. All rights reserved.