Start measuring code coverage with Jest, Travis CI and Coveralls
Using a continuous integration tool will make your life easier when collaborating on a software project. By automatically running tests and measuring coverage on new commits and pull-requests you will make it easier to detect unwanted change or coverage decreases.
This article describes how to get started with coverage measurements during Travis CI builds using Jest, Coveralls and GitHub.
Add you repo to Travis CI and Coveralls.io
If you haven’t already, the first thing you need to do is to head over to Travis and login using your Github account. Once logged in hit the “Add New Repository” button to activate your repo. Repeat this procedure at Coveralls.io.
Configure Coveralls
To be able to send coverage reports to Coveralls we need to install the coveralls
package.
npm install coveralls --save-dev
Once it is installed, add the following script to your package.json
to be able to generate a coverage reports that can be processed by Coveralls.
Configure Travis CI
To get Travis CI up and running we need to create a Travis configuration file in the root of our project. If you are already using Travis, you can go ahead and add npm run coveralls
to the script section of your .travis.yml
file.
touch .travis.yml
Add the following configuration to your newly created .travis.yml
Done
You should now be all set. Each time a new commit is made to the master branch or when a contributor opens a PR in your repo, Travis will run all of your tests and send a coverage report to Coveralls. If you wish to promote your build status or coverage percentage you can get some cool badges from Travis and Coveralls.io to put in your README.
Read more about configuring Travis in the Travis CI documentation.