Running tests with Buster.JS

If you’ve gone through the Getting started and Loading your code tutorials, this article will show you how to run your tests using Buster.JS.

First, install buster from npm:

$ npm install buster

Then add the following config to example/buster.js. This tells Buster to load jstest.js then use your runner.js script to dynamically load your code and tests.

// example/buster.js

var staticHost = 'http://localhost:4180'

exports.tests = {
  environment:  'browser',
  rootPath:     '..',
  sources:      ['build/jstest.js'],
  tests:        ['example/runner.js'],
  autoRun:      false,

  resources: ['/build', '/example'].map(function(path) {
    return {path: path, backend: staticHost + path}
  })
}

jstest will detect Buster and automatically use the right reporter for it.

You need to start a static file server that Buster can load your project from:

$ python -m SimpleHTTPServer 4180
Serving HTTP on 0.0.0.0 port 4180 ...

Now, start the Buster server:

$ ./node_modules/.bin/buster-server
buster-server running on http://localhost:1111

And open http://localhost:1111/ in your browser. You should see this page:

Click ‘Capture browser’ to connect your browser to the Buster server. Now, Buster has particular places it likes to find its config, so set up a link so that spec/buster.js exists:

$ ln -s example spec

And finally, run the buster-test command to run your tests in all the connected browsers:

$ ./node_modules/.bin/buster-test
Chrome 27.0.1453.110, Mac OS X 10.6.8: ..
2 test cases, 2 tests, 2 assertions, 0 failures, 0 errors, 0 timeouts
Finished in 0.091s