Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Added -t, --timeout <ms>

Tj Holowaychuk028586a18208
diff --git a/bin/mocha b/bin/mocha
index 52b8c26f..1224c944 100755
--- a/bin/mocha
+++ b/bin/mocha
@@ -32,6 +32,7 @@ program
.option('-R, --reporter <name>', 'specify the reporter to use', 'dot')
.option('-u, --ui <name>', 'specify user-interface (bdd|tdd|exports)', 'bdd')
.option('-g, --grep <pattern>', 'only run tests matching <pattern>')
+ .option('-t, --timeout <ms>', 'set test-case timeout in milliseconds [2000]')
.option('-G, --growl', 'enable growl support')
// report help
@@ -69,6 +70,10 @@ var suite = new Suite('')
, Reporter = require('../lib/reporters/' + program.reporter)
, ui = interfaces[program.ui](suite);
+// --timeout
+
+if (program.timeout) suite.timeout(~~program.timeout);
+
// files
var files = program.args;
diff --git a/lib/suite.js b/lib/suite.js
index 56391cfd..e1661b9d 100644
--- a/lib/suite.js
+++ b/lib/suite.js
@@ -34,6 +34,19 @@ function Suite(title) {
Suite.prototype.__proto__ = EventEmitter.prototype;
+/**
+ * Set timeout `ms`.
+ *
+ * @param {Number} ms
+ * @return {Suite} for chaining
+ * @api private
+ */
+
+Suite.prototype.timeout = function(ms){
+ this._timeout = ms;
+ return this;
+};
+
/**
* Run `fn(test[, done])` before running tests.
*
@@ -96,6 +109,7 @@ Suite.prototype.afterEach = function(fn){
Suite.prototype.addSuite = function(suite){
suite.parent = this;
+ if (this._timeout) suite.timeout(this._timeout);
this.suites.push(suite);
return this;
};
@@ -110,6 +124,7 @@ Suite.prototype.addSuite = function(suite){
Suite.prototype.addTest = function(test){
test.parent = this;
+ if (this._timeout) test.timeout(this._timeout);
this.tests.push(test);
return this;
};