- Go to https://travis-ci.org/, and add your GitHub repo.
- From the Repo settings, on Travis, you can set the ENV vars and enable some options such as
- Build on push
- Build pull requests
- Go to https://codeclimate.com/dashboard and add your GitHub repo
- Then go to Settings (you'll need admin rights to do this step) and then to the Test Coverage tab. Scroll down and click on Travis button, copy the code to include on your travis.yml
- Create a
.travis.yml
file on your project folder - Let's use this example to understand the file structure:
language: node_js
node_js:
- "5.5.0"
addons:
code_climate:
repo_token: <supersecrettoken>
script: istanbul cover node_modules/mocha/bin/_mocha -- -R spec
before_script:
- npm install codeclimate-test-reporter istanbul -g
after_script:
- codeclimate-test-reporter < ./coverage/lcov.info
- language: specify the language of your project
- node_js: you can specify the (minimun) version to use your app
- addons: this is what you should copy from code_climate, including repo_token and the token itself
- script: specify the command you use to run your tests. We are using istanbul to generate the file formatted as lcov to send it to climate. A more generic command could be:
istanbul cover [npm command to run the tests. e.g.: test] -- -R spec
, in the example above I'm using mocha - before_script: the commands we need to run before run the script, so we need to install codeclimate-test-reporter and istanbul, globally
- after_script: the commands we need to run after run the script (good names, heh?). In this case we have to send to CodeClimate the report generated by istanbul which is in coverage folder.
- Encrypt repo_token (recommended)
- Install travis:
gem install travis
- run
travis encrypt <supersecrettoken>
- Copy the output in replace of supersecrettoken. Your addons section will be like this:
addons:
code_climate:
repo_token:
secure: "veryverylongstringhere"
Now you just have to commit the .travis.yml file and see Travis do his job
- Add some cool badges to your README.md on GitHub
- Codeclimate provides badges with CodeClimate score and Test Coverage
- Travis provides a badge with the build status (failing or passing)
- Add
coverage/
folder to .gitignore
Thanks for this helpful information.
Since istanbul is deprecated, and is replaced by nyc, here is the modified script I used after referring to this amazing article.
This generated code coverage for code which can be in ES6