Run your front-end mocha tests where they belong; in the browser! Much like [jasmine-gem][jasmine-gem],
mocha-server serves up your Mocha suite in a web page so you don't have to spend time writing HTML
test runners and can focus on the code itself. You can even run them
them headlessly with mocha-phamtomjs so they can be part of your build
npm install mocha-server
In its simplest form, you run
mocha-server from the
This will launch a server that can be accessed at http://localhost:8888 ; open it with a browser to run the mounted tests.
The following flags can also be used:
Usage: mocha-server [options]Options:--help output usage information-V, --version output the version number-r, --require <name> require the given module-R, --reporter <name> specify the reporter to use-u, --ui <name> specify user-interface-b, --bail bail after first test failure-h, --headless run headless with phantomjs-c, --compilers <name> pass in [ext]:[path to compiler]--agent <userAgent> specify the user agent to use--cookie <name>=<value> specify cookie--header <name>=<value> specify custom header--setting <key>=<value> specify specific phantom settings--view <width>x<height> specify phantom viewport size--ignore-leaks ignore global variable leaks--recursive include sub directories
By default, tests are pulled in from the
mocha-server provides two mechanisms for ensuring the load
-r flags can be used
repeatedly to identify files that should be loaded first. For example:
$ mocha-server -r ./test/test-helper.js ./test/my-tests
./test/test-helper.js before it loads any of the
tests found uncer
$ mocha-server --compiler jade:./test/compilers/jade.js
Will compile all files with the
.jade extension using the
compiler defined in
A compiler is made up of a
match property that is
regular-expression that indicates the files type returned and a
compileSync function that will return the source generated.
Look under the
spec/support for an example compiler.
Much like mocha will attempt to load
mocha-server will attempt
./test/mocha-server.opts, concatenating the
arguments to those passed on the command line. For example, suppose you
have the following:
It will ensure the contents of
test/support is loaded
first, that the tests are run headlessly, and that all the tests in
test/assets are run.
$ mocha-server --headless
$ mocha-server -h
This launches the server, then runs
against it. Several command-line arguments are passed through to it.
The files under
test folder provide examples of writing
tests for the system. You can run them by:
Fork the repo, make a branch, add tests, make your changes, and submit a pull-request!
You can test
mocha-server by cloning this repository and
$ cake test
This will run the tests under the