☕️ Classic, reliable, trusted test framework for Node.js and the browser
resolves #1300 again: timeout(0) will work at suite level
Christopher Hiller35da58bdd551
diff --git a/lib/suite.js b/lib/suite.jsindex ee5983e5..9073e02c 100644--- a/lib/suite.js+++ b/lib/suite.js@@ -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);diff --git a/mocha.js b/mocha.jsindex 079aa583..77117a60 100644--- a/mocha.js+++ b/mocha.js@@ -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(){@@ -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));@@ -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.jsrequire.register("reporters/landing.js", function(module, exports, require){@@ -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;@@ -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);diff --git a/test/acceptance/timeout.js b/test/acceptance/timeout.jsindex 3e865f97..7f16fac9 100644--- a/test/acceptance/timeout.js+++ b/test/acceptance/timeout.js@@ -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);+ })++ })+ })});})