https://github.com/carbonfive/mocha-server
https://github.com/carbonfive/mocha-server
Last synced: 23 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/carbonfive/mocha-server
- Owner: carbonfive
- Created: 2013-01-23T18:24:31.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2018-01-16T05:03:47.000Z (almost 8 years ago)
- Last Synced: 2024-10-20T20:03:54.700Z (about 1 year ago)
- Language: JavaScript
- Size: 228 KB
- Stars: 8
- Watchers: 74
- Forks: 4
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mocha-server
Run your front-end [mocha][mocha] tests where they belong; in the browser! Much like [jasmine-gem](https://github.com/pivotal/jasmine),
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][mocha-phantomjs] so they can be part of your build
process!
## Installation
```sh
npm install mocha-server
```
## Usage
In its simplest form, you run mocha-server from the
command-line:
```sh
$ mocha-server
```
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:
```sh
Usage: mocha-server [options]
Options:
--help output usage information
-V, --version output the version number
-r, --require require the given module
-R, --reporter specify the reporter to use
-u, --ui specify user-interface (bdd|tdd|exports)
-b, --bail bail after first test failure
-h, --headless run headless with phantomjs
-c, --compilers pass in [ext]:[path to compiler]
--agent specify the user agent to use
--cookie = specify cookie
--header = specify custom header
--setting = specify specific phantom settings
--view x specify phantom viewport size
--ignore-leaks ignore global variable leaks
--recursive include sub directories
```
By default, tests are pulled in from the test directory.
### Load Order
As dependencies can be very important in running Javascripts code and tests,
mocha-server provides two mechanisms for ensuring the load
order.
#### --require
First, the --require or -r flags can be used
repeatedly to identify files that should be loaded first. For example:
```sh
$ mocha-server -r ./test/test-helper.js ./test/my-tests
```
Will load ./test/test-helper.js before it loads any of the
tests found uncer ./test/my-tests.
#### Sprocket-style require
Alternatively, you can use [sprockets][sprockets] style
require directives to indicate depdencies. This
functionality is supplied by [snockets][snockets].
#### Adding Additional Javascript Compilers
Out of the box, mocha-server supports Javascript and
[coffeescript][coffeescript] files through [snockets][snockets]. You can
pass in additional compilers through the --compiler.jade extension using the
compiler defined in ./test/compilers/jade.js.
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.
### mocha-server.opts
Much like [mocha][mocha] will attempt to load
./test/mocha.opts, mocha-server will attempt
to load ./test/mocha-server.opts, concatenating the
arguments to those passed on the command line. For example, suppose you
have the following:
```
--require ./test/support
-h
test/assets
```
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.
### Running Headlessly
mocha-server uses [mocha-phantomjs][mocha-phantomjs] to run
headlessly. You need to install [PhantomJS v.1.7.0][phantomjs] or
greater and then you can enter:
```sh
$ mocha-server --headless
```
Or:
```sh
$ mocha-server -h
```
This launches the server, then runs mocha-phantomjs
against it. Several command-line arguments are passed through to it.
## Examples
The files under test folder provide examples of writing
tests for the system. You can run them by:
```sh
$ mocha-server
```
## Contributing
Fork the repo, make a branch, add tests, make your changes, and submit a pull-request!
### Testing
You can test mocha-server by cloning this repository and
running:
```sh
$ cake test
```
This will run the tests under the spec folder.
## Contributors
* [Rudy Jahchan][rudy-jahchan]
* [Hugo Melo][squanto]
* [Andrew Peterson][ndp]
* [Jon Rogers][bunnymatic]
[bunnymatic]: http://github.com/bunnymatic
[ndp]: http://github.com/ndp
[squanto]: http://github.com/squanto
[rudy-jahchan]: http://github.com/rudyjahchan
[mocha-server]: http://github.com/carbonfive/mocha-server
[mocha]: http://visionmedia.github.com/mocha/
[mocha-phantomjs]: https://github.com/metaskills/mocha-phantomjs
[phantomjs]: http://phantomjs.org/
[sprockets]: https://github.com/sstephenson/sprockets
[snockets]: https://github.com/TrevorBurnham/snockets
[coffeescript]: http://coffeescript.org/