In order to get this up and running you'll need a few things:
3. A Coveralls account. To set this up, go over to Coveralls. Log-in with your Github account.
With all that set-up you should be able to get your project up and running within about 10 minutes, so let's get cracking.
npm install coveralls --save-dev
npm install -g istanbul
With those packages install within your packages.json, you need to create a new script to generate your code coverage report. You can do this, using the following snippet:
"cover": "node_modules/istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha -- -R spec test/*"
Next, if you are using Travis then you should have a.travis.yml file. Update this to call the new script like so:
- npm install
- npm run cover
# Send coverage data to Coveralls
after_script: "cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js"
Next, log-into Coveralls and enable your project, by clicking on the 'Add Repos', finding your project and clicking the on button:
Next, within the project setting, navigate to the bottom and you should see a 'badge your repo section':
Click on the drop-down that says embed and copy the code within the markdown section. Add this snippet within your projects readme file and commit it. In your project, make a change, commit and push it, to trigger a build in Travis. On your Github page, you should now see a badge with your coveralls report. You should now see a report being generated in coveralls and your badge displays your code coverage.
Fist, if you have an issue try running the cover script locally, e.g. npm cover. If that works then you have probably misconfigured something.
If you think you have set everything up, you can take a look at this project to help you figure it out, HTTP Status Lookup.
Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge