RobotWebTools/roslibjs — pull request #24 by baalexander (2013-03-31 21:41:16+00:00)
Title: Adds unit test infrastructure and Travis CI integration

This pull request adds automated test integration with Travis CI with just a little bit of test coverage to try it out.

What happens if it works correctly:

![code-03](https://f.cloud.github.com/assets/83781/322404/4ce0ef12-9a48-11e2-81f3-941731ffe78a.gif)

### Tools

* [Mocha.js](http://visionmedia.github.com/mocha/) is a JavaScript unit testing framework that in addition to unit testing, also provides features like global leak detection, slow test alerts, and solid asynchronous support.
* [Karma](http://karma-runner.github.com/) is a test runner, which runs the Mocha unit tests in multiple browsers and outputs the results in a Continuous Integration-friendly format.
* [Travis CI](http://travis-ci.org) is a free Continuous Integration platform for open source projects. You configure your tests with a .travis-ci file and it'll automatically run the tests on every pull request.
* [PhantomJS](http://phantomjs.org/) - A headless browser based on WebKit. The problem with automating browser-based JavaScript tests is that it, well, needs to run in a browser with access to things like the DOM to pass, but most CI platforms are servers and don't have GUI environments. PhantomJS solves this.

### Installation

I'm going to simplify the process some and will document it better after I do, but for now, to try it out:

1. Install Node.js v0.8 (v0.10 should work too if that's what you have installed already)

```
sudo add-apt-repository ppa:chris-lea/node.js-legacy
sudo apt-get update
sudo apt-get install nodejs npm
```

2. Install PhantomJS. I recommend just downloading the tar.bz2 file from [http://phantomjs.org/download.html](http://phantomjs.org/download.html) and adding it to your path.

3. Install Karma. This will perform the testing.

```
npm install -g karam
```

4. Run the test.

```
karma start test/karma.conf.js
```

Running the steps above will run the test in PhantomJS inside your terminal. But, you can run the tests in **Chrome** or **Firefox** too:

```
karma start test/karma.conf.js --browsers Chrome,Firefox
```

Like I said, I am going to try to make the process smoother after I can verify Travis CI works correctly.