How to setup Travis CI, Coveralls and Code Climate with your Nodejs project

Benjamin Ajewole
2 min readJan 24, 2020

--

Travis CI is a hosted continuous integration service used to build and test software projects hosted at GitHub. It runs your test files. So, if all your tests pass, your Travis badge will show passing or else it will show failing. You can add the badge to your GitHub account.

Continuous Integration (CI) is the practice of merging all developers’ working copies to shared mainline several times a day.

Coveralls is a hosted analysis tool, providing statistics about your code coverage. Line-by-line test coverage reports and statistics gives engineering teams insight to spot gaps where bugs may be hiding. Your team can get notified by a number of methods when newly deployed code changes coverage. Add a Coveralls coverage badge to your projects’ readme on Github and show off your test coverage. It’s the best way to let everyone know your software has a complete test suite.

Code Climate is a tool that encourages you to write better and pure codes. Code Climate consolidates the results from a suite of static analysis tools into a single, real-time report, giving your team the information it needs to identify hotspots, evaluate new approaches, and improve code quality.

Steps to follow

Create a GitHub repo

Clone the GitHub repo you just created to your local machinegit clone <github-repo-link>

Initialize npm with npm init -y

Install the following dependencies: mocha, chai, coveralls and nyc

npm i mocha chai coveralls nyc

Create an app.js file

Create an app.test.js file

Add a test script to your package.json

"test": "nyc mocha app.test.js --exit"

Then run npm t to run your tests, your tests should all pass

Integrate Travis CI to your GitHub repo

  • Create a Travis account with your GitHub account
  • Enable the repository you wish to integrate by flicking the switch next to it.
  • Create a .travis.yml file

How to get cc_test_reporter_id after creating an account on Code Climate account with your GitHub account

.travis.yml

Integrate Coveralls to your GitHub repo

  • Create a Coveralls account with your GitHub account
  • Enable the repository you wish to integrate by clicking on Add Repo and flicking the switch.
  • Create a .coveralls.yml file

How to get the repo_token from coveralls.io

.coveralls.yml

Add Code Climate file

  • Create a .codeclimate.yml file
codeclimate.yml

Your package.json’s script section should look like this

"scripts": {"test": "nyc mocha app.test.js --exit""start": "node app.js","coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls","coverage": "nyc report --reporter=text-lcov | coveralls && nyc report --reporter=lcov"},

When you push to GitHub, Travis automatically runs your test file.

Adding badges to your README.md

--

--

No responses yet