Coveralls.io && Travis-CI && Yeoman

Coveralls is a cloud code coverage reporting tool.

What does cloud code coverage reporting tool mean?

Most people agree that automated testing is important in software development. A lot of those people still do not write proper tests for their code. Coveralls helps to keep engineers (and projects) accountable when it comes to testing. It reports on a repo’s code coverage, or how much of the code is actually tested by the test suites.

How does it work?

Coveralls integrates with GitHub and your continuous integration platform of chance. The integration with Travis-CI is automatic. I like using Travis-CI and have written about them here.

When your tests run, code coverage reports need to be created and then sent to coveralls. I have use the node-coveralls module to handle sending to coveralls.

Working with Yeoman (multiple test suites)

I enjoy building yeoman scaffolded applications, specifically the Angular Fullstack generator. By default it includes backend tests in mocha, and frontend jasmine tests run by Karma. The configuration was a little complicated but now works well.

My travis.yml file contains the following:

after_script: - ./node_modules/karma/bin/karma start - istanbul cover ./node_modules/mocha/bin/_mocha server/api/**/*.spec.js - cat ./coverage/lcov.info ./coverage/karma/**/*.info > lcov.info - node node_modules/lcov-filter/index.js lcov.info config | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage

Here is what happens in the file.

Karma runs its tests and outputs its coverage report to the coverage/karma folder. Then istanbul runs the mocha tests and outputs the coverage report to coverage/. Next we concat the two reports and ship them to coveralls via the node-coveralls command.

This setup requires that some additional work be done in the karma config file. I plan on discussing this work in a future blog post. You can check out this repo for a working example: https://github.com/socialSearch/socialSearch.

Results

Now every time there is a commit or pull request you will be able to see if there is a change in code coverage. When you are in coveralls, you can drill down into the code and see which lines of code are not being tested.

Here is an example of a repo I setup like this

https://coveralls.io/r/socialSearch/socialSearch


Originally published at www.parsed.io.

Copyright © 2020.