Coveralls is used to show you the test coverage of your JavaScript application. Letâs see how it can be used for your JavaScript project which is already on GitHub and connected to your Travis CI due to the previous CI setup tutorial. First, sign up at Coveralls.io with your GitHub account. Second, synchronize your GitHub repositories and toggle a specific repository to be used for code coverage.
Afterward, hit the âDetailsâ button to copy your coveralls_repo_token to your clipboard. Since you donât want to add this private token directly to your public project, you can add it on your Travis CI dashboard to your repositoryâs environment variables. You will find it via the settings option of your Travis repository.
Then, create a new environment variable for your project. You can name it coveralls_repo_token:
Last but not least, modify your project the following way. First, install the coveralls library on the command line to your dev dependencies:
Second, add a new script to your package.json file to introduce Coveralls to it:
And third, extend your Travis CI configuration for reporting the coveralls information to your coveralls.io dashboard.
Thatâs it. By adding, committing and pushing your changes to GitHub now, you can see how a report shows up on your Coveralls.io dashboard.
Perhaps you can see that the coverage isnât too high. Then itâs up to you the add tests to increase the percentage for your project.
Last but not least, you can add the fancy Coveralls badge to your GitHubâs README.md file. You find the badge on the Coveralls dashboard for embedding it as markdown:
Make sure to change the URL to your repositoryâs URL.
If you are using Jest as a test runner, you can enforce a certain coverage for your JavaScript project. Also you can include and exclude specific folders/files from your source code to be added/removed from your testing coverage report:
Thatâs everythin in a nutshell about testing coverage in JavaScript projects.