Running CoffeeScript Mocha tests on Travis CI

Travis CI will run npm test by default, so you will need to add the following to your package.json file:

"scripts": {
    "test": "mocha --compilers coffee:coffee-script/register tests/my_test.coffee"
  }

  "devDependencies": {
    "coffee-script": "^1.10.0"
  }

Invoking the npm test command will run the test command in the scripts section.

Mocha does not support CoffeeScript out of the box, so you will need to add the compilers option.

For CoffeeScript 1.6 and under use:

 mocha --compilers coffee:coffee-script

For CoffeeScript 1.7 and above use:

mocha --compilers coffee:coffee-script/register

The tests/my_test.coffee is the test file to execute. You can also set it to use a directory instead (i.e. tests directory in this case).

Now, you just need to setup your .travis.yml file. I followed the instructions from the Travis Docs which resulted in the following .travis.yml file:

language: node_js
node_js:
 - "stable"
# following is from: https://docs.travis-ci.com/user/languages/javascript-with-nodejs#Node.js-v4-(or-io.js-v3)-compiler-requirements
env:
 - CXX=g++-4.8
addons:
 apt:
   sources:
     - ubuntu-toolchain-r-test
   packages:
     - g++-4.8

Next, turn the CI button on for your repository on the Travis CI site and do a git push. That’s it!