visionmedia/mocha — pull request #602 by hermanjunge (2012-10-05 23:48:13+00:00)
Title: Enable the definition of timeout for a specific suite.

#### From [Mocha's Issue 599](https://github.com/visionmedia/mocha/issues/599)

Use the function `timeout(param)` at the start of the suite definition, to set the timeout's value for a specific suite. The parameter `param` can be an integer or a string representing time, such as seconds (ex: `2s`) or milliseconds (ex: `321ms`). (See [this file](https://github.com/visionmedia/mocha/blob/master/lib/ms.js).

A test example could be the one we call with:

````bash
mocha --timeout 1111
````

Being the test defined by:

````js
describe ('first suite', function () {
timeout(345);

it('should do the first test on first suite', FirstSuiteFirstTest)
it('should do the second test on first suite', FirstSuiteSecondTest)

function FirstSuiteFirstTest (done) {
this.timeout(542)
}

function FirstSuiteSecondTest (done) {
this.timeout(234)
}
});

describe ('second suite', function () {
timeout(345)

it('should do the first test on second suite', SecondSuiteFirstTest)
it('should do the second test on second suite', SecondSuiteSecondTest)

function SecondSuiteFirstTest (done) {
}

function SecondSuiteSecondTest (done) {
}
});
````

(Please note, that I intended to make all tests to fail by timeout!)

The result will be:

````bash
first suite
1) should do the first test on first suite
2) should do the second test on first suite

second suite
3) should do the first test on second suite
4) should do the second test on second suite

✖ 4 of 4 tests failed:

1) first suite should do the first test on first suite:
Error: timeout of 542ms exceeded
at Object. (/Users/hermanjunge/Documents/haj/coding/nodejs/mocha/lib/runnable.js:134:21)
at Timer.list.ontimeout (timers.js:101:19)

2) first suite should do the second test on first suite:
Error: timeout of 234ms exceeded
at Object. (/Users/hermanjunge/Documents/haj/coding/nodejs/mocha/lib/runnable.js:134:21)
at Timer.list.ontimeout (timers.js:101:19)

3) second suite should do the first test on second suite:
Error: timeout of 345ms exceeded
at Object. (/Users/hermanjunge/Documents/haj/coding/nodejs/mocha/lib/runnable.js:161:14)
at Timer.list.ontimeout (timers.js:101:19)

4) second suite should do the second test on second suite:
Error: timeout of 345ms exceeded
at Object. (/Users/hermanjunge/Documents/haj/coding/nodejs/mocha/lib/runnable.js:161:14)
at Timer.list.ontimeout (timers.js:101:19)
````