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"
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With