Skip to content

Commit

Permalink
resolves #1300 again: timeout(0) will work at suite level
Browse files Browse the repository at this point in the history
- added tests
- rebuilt mocha.js
  • Loading branch information
Christopher Hiller committed Aug 15, 2014
1 parent bfb4ec1 commit 35da58b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Suite.prototype.clone = function(){

Suite.prototype.timeout = function(ms){
if (0 == arguments.length) return this._timeout;
if (ms === 0) this._enableTimeouts = false;
if ('string' == typeof ms) ms = milliseconds(ms);
debug('timeout %d', ms);
this._timeout = parseInt(ms, 10);
Expand Down
27 changes: 19 additions & 8 deletions mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -3111,12 +3111,8 @@ function JSONReporter(runner) {
passes.push(test);
});

runner.on('fail', function(test, err){
runner.on('fail', function(test){
failures.push(test);
if (err === Object(err)) {
test.errMsg = err.message;
test.errStack = err.stack;
}
});

runner.on('end', function(){
Expand All @@ -3126,6 +3122,7 @@ function JSONReporter(runner) {
failures: failures.map(clean),
passes: passes.map(clean)
};

runner.testResults = obj;

process.stdout.write(JSON.stringify(obj, null, 2));
Expand All @@ -3146,12 +3143,24 @@ function clean(test) {
title: test.title,
fullTitle: test.fullTitle(),
duration: test.duration,
err: test.err,
errStack: test.err.stack,
errMessage: test.err.message
err: errorJSON(test.err)
}
}

/**
* Transform `error` into a JSON object.
* @param {Error} err
* @return {Object}
*/

function errorJSON(err) {
var res = {};
Object.getOwnPropertyNames(err).forEach(function(key) {
res[key] = err[key];
}, err);
return res;
}

}); // module: reporters/json.js

require.register("reporters/landing.js", function(module, exports, require){
Expand Down Expand Up @@ -4203,6 +4212,7 @@ Runnable.prototype.constructor = Runnable;

Runnable.prototype.timeout = function(ms){
if (0 == arguments.length) return this._timeout;
if (ms === 0) this._enableTimeouts = false;
if ('string' == typeof ms) ms = milliseconds(ms);
debug('timeout %d', ms);
this._timeout = ms;
Expand Down Expand Up @@ -5182,6 +5192,7 @@ Suite.prototype.clone = function(){

Suite.prototype.timeout = function(ms){
if (0 == arguments.length) return this._timeout;
if (ms === 0) this._enableTimeouts = false;
if ('string' == typeof ms) ms = milliseconds(ms);
debug('timeout %d', ms);
this._timeout = parseInt(ms, 10);
Expand Down
25 changes: 25 additions & 0 deletions test/acceptance/timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,31 @@ describe('timeouts', function(){
this.timeout(0);
setTimeout(done, 1);
})

describe('using beforeEach', function() {
beforeEach(function () {
this.timeout(0);
})

it('should work with timeout(0)', function(done) {
setTimeout(done, 1);
})
})

describe('suite-level', function() {
this.timeout(0);

it('should work with timeout(0)', function(done) {
setTimeout(done, 1);
})

describe('nested suite', function () {
it('should work with timeout(0)', function(done) {
setTimeout(done, 1);
})

})
})
});

})

0 comments on commit 35da58b

Please sign in to comment.