Long gone are the days when we used to rely on Java for outputting JavaScript code-coverage data. Now, there are Node-based tools out there that can help us out, such as the following:
Istanbul (https://www.npmjs.org/package/istanbul)
Blanket.js (https://www.npmjs.org/package/blanket)
SteamShovel (https://www.npmjs.org/package/steamshovel)
These kinds of tools instrument your code and usually track statement, branch, function, and line coverage.
Integrating code coverage with istanbul
into our project is a simple process that has two steps:
Installing the module as a development dependency using the following command:
$ npm i istanbul ––save-dev
Adding the CLI command as an NPM script inside
package.json: "coverage": "node node_modules/istanbul/lib/cli.js cover node_modules/.bin/_mocha test/* -- --reporter=spec"
.
Now, if we want to run the tests with code-coverage data, we should see the following output:
If we want to set a hard threshold for code coverage, istanbul
also supports...