This guide details using Blanket.js with a mocha testrunner, and the travis-cov reporter in NodeJS.
It is assumed you have already read the Getting Started guide.
To begin you will need:
npm install mocha -g
)Install Blanket: npm install blanket
Add the following to top of your test runner file:
var blanket = require("blanket")({
/* options are passed as an argument object to the require statement */
"pattern": "/source/"
});
… where /source/
matches partially or fully the directory where the source files to be instrumented are stored.
You can also provide an array of regular expression.
Omitting the object argument will default to “src”. Additionally, any value provided there will override values set in the package.json file.
Since we’ve explicit referenced blanket we don’t need to require it in the mocha command.
Install the travis-cov reporter: npm install travis-cov
We will set the coverage threshold in the package.json file. The following will set the coverage threshold at 70%. Any tests falling below 70% will fail, and (when run on travis-ci) will cause the build to fail:
"scripts": {
"travis-cov": {
"threshold": 70
}
}
Use the travis-cov reporter to display coverage percentage:
mocha <path to test runner> -R travis-cov