Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Istanbul nyc to exclude test files

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"

like image 796
Manu Avatar asked Feb 08 '17 13:02

Manu


People also ask

What is Istanbul in testing?

How Istanbul works. Istanbul instruments your ES5 and ES2015+ JavaScript code with line counters, so that you can track how well your unit-tests exercise your codebase. The nyc command-line-client for Istanbul works well with most JavaScript testing frameworks: tap, mocha, AVA, etc.

What is Istanbul code coverage?

Istanbul is a JavaScript code coverage tool that works by analyzing your codebase and providing you with the coverage insights you need in order to understand, file by file, where unit tests are needed in your app.

Does jest use Istanbul?

The good news is that Istanbul is built into Jest. That means configuration is handled directly by Jest. The catch here is that Istanbul is not running by default when you create your app with the Create React App template.

How does NYC code coverage work?

Nyc is a code coverage tool. This simply means that it is a package that goes through your tests to determine the percentage of code that are confirmed to be working. Imagine shipping a product with the full confidence that every single line of code works.


1 Answers

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.

like image 82
Manu Avatar answered Sep 20 '22 08:09

Manu