How to test a bower package with travis-ci

First, you have to make a Bower package. See my previous post: how to build a Bower package.

Then, you have to make your Bower package a NPM package. WTF? You must be wondering, why? Because Travis-CI needs additional packages to run your tests, and it runs “npm install” inside your project folder to do that.

To make it a NPM package, just run

npm init

Then, you have to install grunt, mocha etc. In the end, your package.json should have this section

  "devDependencies": {
    "grunt-mocha-test": "~0.6.3",
    "grunt": "~0.4.1",
    "chai": "~1.7.2",
    "grunt-cli": "~0.1.9"


npm install grunt --save-dev 

so that it will save your npm install history to the package.json file.

Then, you have to set up .travis.yml for Travis CI. My file looks like this:

language: node_js
  - '0.8'
  - '0.10'
  - npm install -g bower
  - bower install
script: grunt test

It does a couple of things:
– It runs “npm install” to get grunt, mocha and all that …
– It runs “npm install -g bower” for the next command
– It runs “bower install”, which reads bower.json and install the Bower package we want to test
– It runs “grunt test”, which runs mocha to test the Bower package

Now, it is time to write some serious tests…