☕️ Classic, reliable, trusted test framework for Node.js and the browser
allow calling .timeout for hooks
Konstantin Käfer794e43db4007
diff --git a/lib/context.js b/lib/context.jsindex 0f72bbda..f636f1b4 100644--- a/lib/context.js+++ b/lib/context.js@@ -14,15 +14,15 @@ module.exports = Context;function Context(){}/**- * Set the context `Test` to `test`.+ * Set the context `Runnable` to `runnable`.*- * @param {Test} test+ * @param {Runnable} runnable* @return {Context}* @api private*/-Context.prototype.test = function(test){- this._test = test;+Context.prototype.runnable = function(runnable){+ this._runnable = runnable;return this;};@@ -35,12 +35,12 @@ Context.prototype.test = function(test){*/Context.prototype.timeout = function(ms){- this._test.timeout(ms);+ this._runnable.timeout(ms);return this;};/**- * Inspect the context void of `._test`.+ * Inspect the context void of `._runnable`.** @return {String}* @api private@@ -48,7 +48,7 @@ Context.prototype.timeout = function(ms){Context.prototype.inspect = function(){return JSON.stringify(this, function(key, val){- return '_test' == key+ return '_runnable' == key? undefined: val;}, 2);diff --git a/lib/runnable.js b/lib/runnable.jsindex 7b5da3e2..9f75810b 100644--- a/lib/runnable.js+++ b/lib/runnable.js@@ -134,6 +134,10 @@ Runnable.prototype.run = function(fn){fn(err);}+ if (ctx) {+ ctx.runnable(this);+ }+// for .resetTimeout()this.callback = done;diff --git a/lib/runner.js b/lib/runner.jsindex e65cffdd..c836d6b6 100644--- a/lib/runner.js+++ b/lib/runner.js@@ -156,7 +156,6 @@ Runner.prototype.hook = function(name, fn){var hook = hooks[i];if (!hook) return fn();self.currentRunnable = hook;- hook.ctx.test(self.test);self.emit('hook', hook);@@ -265,7 +264,6 @@ Runner.prototype.runTest = function(fn){, self = this;try {- test.ctx.test(test);test.on('error', function(err){self.fail(test, err);});diff --git a/test/hook.timeout.js b/test/hook.timeout.jsnew file mode 100644index 00000000..5b158e27--- /dev/null+++ b/test/hook.timeout.js@@ -0,0 +1,9 @@++before(function(done){+ this.timeout(100);+ setTimeout(done, 50);+})++it('should work', function(done) {+ done();+});\ No newline at end of file