CI Code Coverage + Tests in 5 Minutes!
2 min read

CI Code Coverage + Tests in 5 Minutes!

Building open source software can be lots of fun. For some reason, it brings me way too much joy seeing code coverage and tests run on every push to github. It doesn't need to be hard to setup; I'm going to show you how to add automated testing and code coverage reporting to your apps and libraries for every push, pull request, and merge! Here's what we need to get started:


Jest is the best test runner out there right now. It may not be the absolute fastest, but it has the easiest and most useful features that you're going to need. If you use mocha, you'll end up installing istanbul or something else that will run coverage. You want snapshot testing? Jest has that built in too.


Coveralls is a free service for open source projects that will store your coverage report and give you a badge to add in your repo with the latest stats! We'll use node-coveralls to handle sending it over.


I use circleci for automated builds, it's free for open source as well. This will trigger a build that runs our tests and coverage report on every push to github.

That's all we need! If you're overwhelmed, you'll be shocked to find out how easy this is to setup. We only need to create a few files and then our app is set up!

App Setup

yarn add jest babel-jest coveralls

Now, create config.json in your app:

  "testMatch": ["<rootDir>/tests/unit/*.js"],
  "setupFiles": ["<rootDir>/tests/setup.js"],
  "transform": {".*": "<rootDir>/node_modules/babel-jest"},
  "moduleFileExtensions": ["js"],
  "collectCoverageFrom": [
    "!src/index.js" //exclude files

Modify this to your needs! It should be easy to understand, if not, take a look at the jest docs.

Now, let's make the file for circleci, it needs to be circle.yml in the root of your app:

    version: 7.7.4
    - npm run test-ci

Let's add that command to our package.json:

    "test-ci": "jest --config config.json --coverage && cat ./coverage/ | ./node_modules/coveralls/bin/coveralls.js"

We are so close! Go sign in to circleci, find your project and tell it to build. Now go to this page:

Change that to your github org / project name. Open a new tab, sign up for coveralls. It will be a similar process as signing up for CircleCI.

Once you add your repo, you will be presented with a repo_token. Copy this key, go back into circle ci, and add an env variable called COVERALLS_REPO_TOKEN and paste the value from coveralls.

Now if you add some tests to jest and push it up to github, it will be tested and coverage will be sent to coveralls.


Phew, I can breathe now. After copying, pasting, and signing up for these services, you should have clocked in at just under 5 minutes!

Add this to the top of your project readme, and let me know if you liked this quick guide!


[![Coverage Status](](

If anything needs clarification, feel free to comment or tweet me.

Enjoying these posts? Subscribe for more