Comparing version 0.0.1-alpha4 to 0.0.1-alpha5
0.0.1-alpha3 / 2011-11-15 | ||
0.0.1-alpha5 / 2011-11-17 | ||
================== | ||
* Added `doc` reporter. Closes #33 | ||
* Added suite merging. Closes #28 | ||
* Added TextMate bundle and `make tm`. Closes #20 | ||
0.0.1-alpha4 / 2011-11-15 | ||
================== | ||
* Fixed getWindowSize() for 0.4.x | ||
0.0.1-alpha3 / 2011-11-15 | ||
================== | ||
* Added `-s, --slow <ms>` to specify "slow" test threshold | ||
@@ -6,0 +18,0 @@ * Added `mocha-debug(1)` |
@@ -70,4 +70,3 @@ | ||
context.describe = function(title, fn){ | ||
var suite = suite = new Suite(title); | ||
suites[0].addSuite(suite); | ||
var suite = Suite.create(suites[0], title); | ||
suites.unshift(suite); | ||
@@ -74,0 +73,0 @@ fn(); |
@@ -53,3 +53,3 @@ | ||
} else { | ||
suites[0].addSuite(suite = new Suite(key)); | ||
var suite = Suite.create(suites[0], key); | ||
suites.unshift(suite); | ||
@@ -56,0 +56,0 @@ visit(obj[key]); |
@@ -54,4 +54,3 @@ | ||
context.suite = function(title, fn){ | ||
var suite = suite = new Suite(title); | ||
suites[0].addSuite(suite); | ||
var suite = Suite.create(suites[0], title); | ||
suites.unshift(suite); | ||
@@ -58,0 +57,0 @@ fn(); |
@@ -12,3 +12,3 @@ | ||
exports.version = '0.0.1-alpha4'; | ||
exports.version = '0.0.1-alpha5'; | ||
@@ -15,0 +15,0 @@ exports.interfaces = require('./interfaces'); |
@@ -69,3 +69,3 @@ | ||
? tty.getWindowSize | ||
? tty.getWindowSize() | ||
? tty.getWindowSize()[1] | ||
: process.stdout.getWindowSize(1)[0] | ||
@@ -72,0 +72,0 @@ : 75 |
exports.Base = require('./base'); | ||
exports.Dot = require('./dot'); | ||
exports.Doc = require('./doc'); | ||
exports.TAP = require('./tap'); | ||
@@ -5,0 +6,0 @@ exports.JSON = require('./json'); |
@@ -12,5 +12,33 @@ | ||
module.exports = Suite; | ||
exports = module.exports = Suite; | ||
/** | ||
* Suite map. | ||
*/ | ||
var map = {}; | ||
/** | ||
* Create a new `Suite` with the given `title` | ||
* and parent `Suite`. When a suite with the | ||
* same title is already present, that suite | ||
* is returned to provide nicer reporter | ||
* and more flexible meta-testing. | ||
* | ||
* @param {Suite} parent | ||
* @param {String} title | ||
* @return {Suite} | ||
* @api public | ||
*/ | ||
exports.create = function(parent, title){ | ||
var suite = new Suite(title); | ||
suite.parent = parent; | ||
title = suite.fullTitle(); | ||
if (map[title]) return map[title]; | ||
parent.addSuite(suite); | ||
return map[title] = suite; | ||
}; | ||
/** | ||
* Initialize a new `Suite` with the given `title`. | ||
@@ -30,2 +58,3 @@ * | ||
this.afterEachCallbacks = []; | ||
this.root = !title; | ||
} | ||
@@ -62,2 +91,3 @@ | ||
this.beforeAllCallbacks.push(fn); | ||
this.emit('beforeAll', fn); | ||
return this; | ||
@@ -76,2 +106,3 @@ }; | ||
this.afterAllCallbacks.push(fn); | ||
this.emit('afterAll', fn); | ||
return this; | ||
@@ -90,2 +121,3 @@ }; | ||
this.beforeEachCallbacks.push(fn); | ||
this.emit('beforeEach', fn); | ||
return this; | ||
@@ -104,2 +136,3 @@ }; | ||
this.afterEachCallbacks.push(fn); | ||
this.emit('afterEach', fn); | ||
return this; | ||
@@ -120,2 +153,3 @@ }; | ||
this.suites.push(suite); | ||
this.emit('suite', suite); | ||
return this; | ||
@@ -136,2 +170,3 @@ }; | ||
this.tests.push(test); | ||
this.emit('test', test); | ||
return this; | ||
@@ -138,0 +173,0 @@ }; |
{ | ||
"name": "mocha" | ||
, "version": "0.0.1-alpha4" | ||
, "version": "0.0.1-alpha5" | ||
, "description": "Test framework inspired by JSpec, Expresso, & Qunit" | ||
@@ -5,0 +5,0 @@ , "keywords": ["test", "bdd", "tdd", "tap"] |
120
Readme.md
# mocha | ||
Mocha aims to combine the best of several popular JavaScript test frameworks, providing a fun, accessible, robust browser & node.js based test experience. | ||
Mocha is a _simple_, _fun_, _extensible_ JavaScript test framework rich with features, running on [node](http://nodejs.org) and the browser. Mocha tests run serially, allowing reporting flexibility, and mapping uncaught exceptions to the correct test cases; This also makes Mocha an ideal choice when mocking and stubbing is involved. | ||
## About | ||
Mocha allows you to use any assertion library you want, if it throws an error, it will work. This means you can utilize libraries such as [should](http://github.com/visionmedia/should.js), node's regular `assert` module, or others. | ||
Mocha tests run serially, easing debugging and making it an ideal choice when mocking and stubbing is involved. Existing frameworks such as [expresso](http://github.com/visionmedia/expresso) can be much faster, though not without cost, Mocha aims to be the simple and "fun" test framework. | ||
Testing asynchronous code with Mocha could not be simpler, when your tests are sync simple omit the callback, when they are async add a callback and invoke it when your test is complete. | ||
## Features | ||
@@ -23,3 +24,3 @@ | ||
- optionally run tests that match a regexp | ||
- auto-exit to prevent "hanging" tests | ||
- auto-exit to prevent "hanging" due to an active event loop | ||
- easily meta-generate suites & test-cases | ||
@@ -29,11 +30,14 @@ - mocha.opts file support | ||
- detects multiple calls to `done()` | ||
- TextMate bundle | ||
- use any assertion library you want ([should](http://github.com/visionmedia/should.js), `assert`, etc) | ||
- extensible reporting | ||
- dot matrix | ||
- landing strip | ||
- test-anything-protocol (TAP) producer | ||
- progress bar | ||
- specification listing | ||
- hierarchical specification | ||
- streaming JSON | ||
- JSON | ||
- `dot`: a dot matrix | ||
- `doc`: a documentation generator (html) based on your tests | ||
- `landing`: a unicode landing strip ✈ | ||
- `tap`: test-anything-protocol (TAP) producer | ||
- `progress`: a progress bar | ||
- `spec`: hierarchical specification | ||
- `list`: similar to `spec` as a flat-list | ||
- `json-stream`: streaming JSON delimited by a LF | ||
- `json`: a single JSON chunk on exit | ||
- extensible test DSLs | ||
@@ -65,2 +69,3 @@ - BDD | ||
dot - dot matrix | ||
doc - html documentation | ||
json - single json object | ||
@@ -204,2 +209,39 @@ progress - progress bar | ||
## Doc | ||
The "doc" reporter outputs a hierarchical HTML body representation | ||
of your tests, wrap it with a header, footer, some styling and you | ||
have some fantastic documentation! | ||
For example suppose you have the following JavaScript: | ||
```js | ||
describe('Array', function(){ | ||
describe('#indexOf()', function(){ | ||
it('should return -1 when the value is not present', function(){ | ||
[1,2,3].indexOf(5).should.equal(-1); | ||
[1,2,3].indexOf(0).should.equal(-1); | ||
}) | ||
}) | ||
}) | ||
``` | ||
The command `mocha --reporter doc array` would yield: | ||
```html | ||
<section class="suite"> | ||
<h1>Array</h1> | ||
<dl> | ||
<section class="suite"> | ||
<h1>#indexOf()</h1> | ||
<dl> | ||
<dt>should return -1 when the value is not present</dt> | ||
<dd><pre><code>[1,2,3].indexOf(5).should.equal(-1); | ||
[1,2,3].indexOf(0).should.equal(-1);</code></pre></dd> | ||
</dl> | ||
</section> | ||
</dl> | ||
</section> | ||
``` | ||
## Async tests | ||
@@ -257,2 +299,42 @@ | ||
### Suite merging | ||
Suites with common names are "merged" in order | ||
to produce unified reporting, especially when | ||
meta-generating tests. | ||
```js | ||
describe('merge', function(){ | ||
describe('stuff', function(){ | ||
describe('one', function(){ | ||
it('should do something', function(){ | ||
}) | ||
}) | ||
}) | ||
}) | ||
describe('merge', function(){ | ||
describe('stuff', function(){ | ||
describe('two', function(){ | ||
it('should do something', function(){ | ||
}) | ||
}) | ||
}) | ||
}) | ||
describe('merge stuff', function(){ | ||
describe('three', function(){ | ||
it('should do something', function(){ | ||
}) | ||
}) | ||
}) | ||
``` | ||
will produce the following: | ||
![mocha suite merging](http://f.cl.ly/items/380R3S1t1t0b0O2K250V/Screenshot.png) | ||
### Makefiles | ||
@@ -271,2 +353,10 @@ | ||
## TextMate Bundle | ||
The Mocha TextMate bundle includes snippets to | ||
make writing tests quicker and more enjoyable. | ||
To install the bundle run: | ||
$ make tm | ||
## Running tests | ||
@@ -276,11 +366,11 @@ | ||
$ make test | ||
$ make test | ||
Run all tests, including interfaces: | ||
$ make test-all | ||
$ make test-all | ||
Alter the reporter: | ||
$ make test REPORTER=list | ||
$ make test REPORTER=list | ||
@@ -287,0 +377,0 @@ ## License |
@@ -16,1 +16,11 @@ | ||
}) | ||
describe('Array', function(){ | ||
describe('#pop()', function(){ | ||
it('should remove and return the last value', function(){ | ||
var arr = [1,2,3]; | ||
arr.pop().should.equal(3); | ||
arr.should.eql([1,2]); | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
66636
58
1935
393