Last Updated: February 25, 2016
·
4.958K
· bensheldon

Integrating Coveralls.io with a Node.js Project

There are so many combinations of javascript code coverage reporters and ways to wire them together, but fortunately this is a dead simple recipe assuming you are already using Mocha for your tests.

First, add istanbul and coveralls packages to your package.json (I keep mine in the devDependencies block:

"devDependencies": {
  "mocha": "~1.17.1",
  "chai": "~1.9.0",
  "sinon": "~1.8.0",
  "istanbul": "~0.2.4",
  "coveralls": "~2.7.1"
 }

Next, add this to your testing process. For example, I added this line to my .travis.yml file:

after_script: NODE_ENV=test istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage

(that _mocha is not a typo)

And boom: code coverage! You can check out nodetiles-core for a working example