Using Travis-CI for client-side JavaScript libraries? Using Travis-CI for client-side JavaScript libraries? javascript javascript

Using Travis-CI for client-side JavaScript libraries?


Yes of course you should use continous integration with client side libraries.

I personally use PhantomJS (headless webkit browser) which is already installed in Travis-CI. I think this is the better option for client-side stuff than NodeJs.

If you use Grunt, it gets even easier to use, all you need is a simple Gruntfile.js file, your tests that run in browser (I use QUnit), and a simple .travis.yml

Gruntfile.js:

module.exports = function(grunt) {    // Project configuration.    grunt.initConfig({        qunit: {            files: ['test/index.html']        }    });    // Load plugin    grunt.loadNpmTasks('grunt-contrib-qunit');    // Task to run tests    grunt.registerTask('test', 'qunit');};

.travis.yml:

before_script:  - sudo npm install -g gruntscript: grunt test --verbose --force

You can see it in action at one of my projects (source on GitHub).


I started with the answer from Odi and moved to gulp to get it working. If you specify node_js as your language in your travis file, travis will automatically run

npm install

followed by

npm test

The first will install any devDependencies specified in a package.json file, the second will run the script named "test" also from package.json. Below you'll find the three files I needed to have in the top level of my repo for travis to run a single qunit suite.

.travis.yml

language: node_jsnode_js:  - "0.10"

gulpfile.js

var gulp = require('gulp'),    qunit = require('gulp-qunit');gulp.task('default', function() {    return gulp.src('./tests/unit/unittests_nupic-js.html')        .pipe(qunit());});

package.json

{  "name": "nupic-js",  "version": "0.0.1",  "description": "JavaScript port of NuPIC",  "license": "GPL-3.0",  "repository": "iandanforth/nupic-js",  "bugs": { "url" : "http://github.com/iandanforth/nupic-js/issues"  },  "author": {    "name": "Ian Danforth",    "email": "iandanforth@gmail.com"  },  "engines": {    "node": ">=0.10.0"  },  "scripts": {    "test": "gulp"  },  "keywords": [    "numenta",    "nupic",    "machine learning"  ],  "devDependencies": {    "gulp-qunit": "~0.2.1",    "gulp-util": "~2.2.14",    "gulp": "~3.5.1"  }}


Odi's answer updated and using npm to resolve dependencies:

.travis.yml

language: node_jsnode_js:  - "6"

.Gruntfile.js

module.exports = function(grunt) {  // Project configuration.  grunt.initConfig({    qunit: {      files: ['./test/qunit.html']    }  });  // Load plugin  grunt.loadNpmTasks('grunt-contrib-qunit');  // Task to run tests  grunt.registerTask('test', 'qunit');};

Package.json (relevant parts)

  "devDependencies": {    "grunt": "^1.0.1",    "grunt-contrib-qunit": "^1.3.0"  },  "scripts": {    "test": "grunt test"  }

You can try the configuration locally by running npm install and then npm test.