Comparing version 0.0.1-alpha3 to 0.0.1-alpha4
@@ -12,3 +12,3 @@ | ||
exports.version = '0.0.1-alpha3'; | ||
exports.version = '0.0.1-alpha4'; | ||
@@ -15,0 +15,0 @@ exports.interfaces = require('./interfaces'); |
@@ -68,3 +68,5 @@ | ||
width: isatty | ||
? process.stdout.getWindowSize(1)[0] | ||
? tty.getWindowSize | ||
? tty.getWindowSize() | ||
: process.stdout.getWindowSize(1)[0] | ||
: 75 | ||
@@ -71,0 +73,0 @@ }; |
{ | ||
"name": "mocha" | ||
, "version": "0.0.1-alpha3" | ||
, "version": "0.0.1-alpha4" | ||
, "description": "Test framework inspired by JSpec, Expresso, & Qunit" | ||
@@ -5,0 +5,0 @@ , "keywords": ["test", "bdd", "tdd", "tap"] |
112
Readme.md
@@ -25,2 +25,5 @@ | ||
- easily meta-generate suites & test-cases | ||
- mocha.opts file support | ||
- `mocha-debug(1)` for node debugger support | ||
- detects multiple calls to `done()` | ||
- extensible reporting | ||
@@ -44,25 +47,32 @@ - dot matrix | ||
Usage: mocha [options] <files> | ||
Usage: mocha [options] [files] | ||
Options: | ||
Options: | ||
-h, --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 (bdd|tdd|exports) | ||
-g, --grep <pattern> only run tests matching <pattern> | ||
-t, --timeout <ms> set test-case timeout in milliseconds [2000] | ||
-G, --growl enable growl support | ||
-h, --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 (bdd|tdd|exports) | ||
-g, --grep <pattern> only run tests matching <pattern> | ||
-t, --timeout <ms> set test-case timeout in milliseconds [2000] | ||
-s, --slow <ms> "slow" test threshold in milliseconds [75] | ||
-G, --growl enable growl support | ||
Reporters: | ||
Reporters: | ||
dot - dot matrix | ||
json - single json object | ||
progress - progress bar | ||
list - spec-style listing | ||
tap - test-anything-protocol | ||
landing - unicode landing strip | ||
json-stream - newline delimited json events | ||
dot - dot matrix | ||
json - single json object | ||
progress - progress bar | ||
list - spec-style listing | ||
tap - test-anything-protocol | ||
landing - unicode landing strip | ||
json-stream - newline delimited json events | ||
Interfaces: | ||
bdd - describe() / it() | ||
tdd - suite() / test() | ||
exports - module.exports | ||
``` | ||
@@ -193,18 +203,54 @@ | ||
## Running tests | ||
## Async tests | ||
Run mocha tests: | ||
Testing async code with mocha is simple, invoke the `done()` callback | ||
when complete, if called multiple times (due to a race-condition etc) | ||
will cause mocha to fail, this is invaluable for testing async code. | ||
$ make test | ||
```js | ||
describe('something async', function(){ | ||
it('should finish after 300ms', function(done){ | ||
setTimeout(done, 300); | ||
}) | ||
}) | ||
``` | ||
Run all tests, including interfaces: | ||
The `done()` callback also accepts an error, so it's easy to write | ||
tests that adhere to node's callback convention of `(err, result)`: | ||
$ make test-all | ||
```js | ||
describe('User.save()', function(){ | ||
it('should save without failing', function(done){ | ||
var user = new User('tj'); | ||
user.save(done); | ||
}) | ||
}) | ||
``` | ||
Alter the reporter: | ||
## Best practices | ||
$ make test REPORTER=list | ||
### test/* | ||
## Best practices | ||
By default `mocha(1)` will use the pattern `./test/*.js`, so | ||
it's usually a good place to put your tests. | ||
### mocha.opts | ||
Mocha will attempt to load `./test/mocha.opts`, these are concatenated with `process.argv`, though command-line args will take precedence. For example suppose you have the following _mocha.opts_ file: | ||
``` | ||
--require should | ||
--reporter dot | ||
--ui bdd | ||
``` | ||
This will default the reporter to `dot`, require the `should` library, | ||
and use `bdd` as the interface. With this you may then invoke `mocha(1)` | ||
with additional arguments, here enabling growl support and changing | ||
the reporter to `spec`: | ||
``` | ||
$ mocha --reporter list --growl | ||
``` | ||
### Makefiles | ||
@@ -223,2 +269,16 @@ | ||
## Running tests | ||
Run mocha tests: | ||
$ make test | ||
Run all tests, including interfaces: | ||
$ make test-all | ||
Alter the reporter: | ||
$ make test REPORTER=list | ||
## License | ||
@@ -225,0 +285,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
57417
1813
303