zuul
Zuul is a test runner/harness to make running your mocha tests in a browser easier. Just point it at your mocha test files and let zuul consume them!
zuul server
If you want to see the output of your mocha tests in a pretty browser window use zuul with the server
option.
$ zuul --server 9000 /path/to/your/tests
Zuul will start a server on localhost:9000 which you can visit to get awesome html output (courtesy of mocha).
![html](https://raw.github.com/shtylman/zuul/master/img/html.png)
headless zuul
If you just want to run your tests in a headless environment courtesy of mocha-phantomjs and phantomjs, zuul will oblige!
$ zuul /path/to/your/tests
![headless](https://raw.github.com/shtylman/zuul/master/img/headless.png)
finding tests
You can specify either a specific javascript file(s) or a directory(s) to zuul. If you specify a directory, zuul will load all of the .js
files in that directory.
mocha.opts
If test/mocha.opts
is available relative to your launch directory, then zuul will incorporate those options into the mocha setup.
install
$ npm install -g zuul
usage
zuul [options] file(s)|dir
Options:
--server port to start harness server for manual testing
--wwwroot location where the webserver will serve additional static files
--ui mocha ui (bdd, tdd, qunit, exports
--config point to a config file that overrides zuul settings
config
Most likely zuul will serve your needs out of the box, but if you need to customize the browserify
step, the
test fixture and/or want to add extra endpoints to the zuul test server, the --config
option is your friend.
Lets say we have a ./zuul-config.js
file in our current directory, running zuul --config ./zuul-config.js
picks up
eventual overrides specified in it, all of which are optional:
- browserify:
{Function}
that needs to return a browserify instance that can be initialized according to our needs - bundleOpts:
{Object}
options passed to browserify().bundle(options)
- fixture:
{Function}
returning a {String}
that allows overriding the default html
fixture, but needs to keep the necessary setup
(mocha, phantom) in order to work with zuul - initApp:
{Function}
invoked with the app
instance and express
which allows adding endpoints to the app and
whatever else you need to do to properly set up your tests
Here is an example zuul-config.js
:
var fs = require('fs');
var path = require('path');
var browserify = require('browserify');
exports.browserify = function () {
return browserify().transform('brfs');
};
exports.bundleOpts = { ignoreMissing: true, debug: true };
exports.fixture = function () {
return fs.readFileSync(path.join(testroot, 'fixture.html'), 'utf8');
};
exports.initApp = function (app, express) {
var sinonpkg = path.join(path.dirname(require.resolve('sinon')), '..', 'pkg', 'sinon.js');
app.use(express.logger('dev'));
app.get('/sinon.js', function (req, res) {
res.sendfile(sinonpkg);
});
};
credits
This probject is just a tiny tool. The real credit goes to these projects.