First include your coveralls token in.
.coveralls.yml
service_name: travis-pro
repo_token: your_token
We were already using mocha. And to get the coverage data I’ve added istanbul plus the coveralls module for actually submitting that data to coveralls.
package.json
"devDependencies": {
"mocha": "~1.19.0",
"istanbul": "^0.2.10",
"coveralls": "^2.10.0"
}
Makefile
In the Makefile, I’ve added a build step called test-coveralls
test-coveralls:
@NODE_ENV=test ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha */test/*.js --report lcovonly -- -R spec -t 30000
Which, when run will generate coverage data and save it in
./coverage/lcov.info
.travis.yml
Now finally your .travis.yml should look something like bellow. The services and the database creation will all depend on your project and what it needs to run.
The second line inside script: will submit the coverage data to coveralls.
language: node_js
node_js:
- "0.10.28"
services:
- mongodb
- redis-server
script:
- make test-coveralls
- cat ./coverage/lcov.info | ./node_modules/.bin/coveralls --verbose
before_script:
- mysql -e 'create database db_test'
That’s it!