From 919a0563ef670ec67f0a083756a122d689dbfc02 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Thu, 30 Apr 2020 16:46:42 +0100 Subject: [PATCH 01/14] Reset enableTimeouts. Integration test --- lib/runnable.js | 2 ++ test/integration/fixtures/timeout-override.fixture.js | 9 +++++++++ test/integration/timeout.spec.js | 11 +++++++++++ test/unit/timeout.spec.js | 6 ------ 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 test/integration/fixtures/timeout-override.fixture.js diff --git a/lib/runnable.js b/lib/runnable.js index bdd6fffe5c..cb1a117351 100644 --- a/lib/runnable.js +++ b/lib/runnable.js @@ -84,6 +84,8 @@ Runnable.prototype.timeout = function(ms) { // see #1652 for reasoning if (ms === range[0] || ms === range[1]) { this._enableTimeouts = false; + } else { + this._enableTimeouts = true; } debug('timeout %d', ms); this._timeout = ms; diff --git a/test/integration/fixtures/timeout-override.fixture.js b/test/integration/fixtures/timeout-override.fixture.js new file mode 100644 index 0000000000..1d745d9a8f --- /dev/null +++ b/test/integration/fixtures/timeout-override.fixture.js @@ -0,0 +1,9 @@ +'use strict'; + +describe('timeout override', function() { + it('should fail async test due to re-enable', function(done) { + this.enableTimeouts(false); + this.timeout(1); + setTimeout(done, 2); + }); +}); diff --git a/test/integration/timeout.spec.js b/test/integration/timeout.spec.js index 53dfb58274..deb5f8a754 100644 --- a/test/integration/timeout.spec.js +++ b/test/integration/timeout.spec.js @@ -18,4 +18,15 @@ describe('this.timeout()', function() { done(); }); }); + + it('should allow overriding per-test', function(done) { + run('timeout-override.fixture.js', args, function(err, res) { + if (err) { + done(err); + return; + } + assert.strictEqual(res.stats.failures, 1); + done(); + }); + }); }); diff --git a/test/unit/timeout.spec.js b/test/unit/timeout.spec.js index e96f4b5d23..7725bfe87b 100644 --- a/test/unit/timeout.spec.js +++ b/test/unit/timeout.spec.js @@ -21,12 +21,6 @@ describe('timeouts', function() { }); describe('disabling', function() { - it('should allow overriding per-test', function(done) { - this.enableTimeouts(false); - this.timeout(1); - setTimeout(done, 2); - }); - it('should work with timeout(0)', function(done) { this.timeout(0); setTimeout(done, 1); From 74f6e6b26488dc1afd5f2651785e55d505f1c958 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Thu, 30 Apr 2020 16:49:48 +0100 Subject: [PATCH 02/14] Spec update --- test/integration/timeout.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/timeout.spec.js b/test/integration/timeout.spec.js index deb5f8a754..afe5f0f629 100644 --- a/test/integration/timeout.spec.js +++ b/test/integration/timeout.spec.js @@ -19,7 +19,7 @@ describe('this.timeout()', function() { }); }); - it('should allow overriding per-test', function(done) { + it('should allow overriding if disabled per-test', function(done) { run('timeout-override.fixture.js', args, function(err, res) { if (err) { done(err); From 8906d34d354e85403f64df6c90a6c0382052ef01 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Thu, 30 Apr 2020 17:11:39 +0100 Subject: [PATCH 03/14] Use function which logs --- lib/runnable.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/runnable.js b/lib/runnable.js index cb1a117351..2c24b56ea1 100644 --- a/lib/runnable.js +++ b/lib/runnable.js @@ -83,9 +83,10 @@ Runnable.prototype.timeout = function(ms) { // see #1652 for reasoning if (ms === range[0] || ms === range[1]) { - this._enableTimeouts = false; + this.enableTimeouts(false); } else { - this._enableTimeouts = true; + // Reset now that a new timeout limit has been set + this.enableTimeouts(true); } debug('timeout %d', ms); this._timeout = ms; From d0c2fb3f2f05a367fa5837c43fd9cf8b790fd557 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Fri, 1 May 2020 17:08:46 +0100 Subject: [PATCH 04/14] Remove _enableTimeouts --- lib/context.js | 15 ----- lib/mocha.js | 17 ------ lib/runnable.js | 34 +++-------- lib/suite.js | 24 -------- lib/test.js | 1 - .../fixtures/timeout-override.fixture.js | 2 +- test/unit/context.spec.js | 6 -- test/unit/mocha.spec.js | 13 ---- test/unit/runnable.spec.js | 60 ++++--------------- test/unit/test.spec.js | 5 -- test/unit/timeout.spec.js | 4 +- 11 files changed, 20 insertions(+), 161 deletions(-) diff --git a/lib/context.js b/lib/context.js index 4c6b0c23e5..2497ded868 100644 --- a/lib/context.js +++ b/lib/context.js @@ -45,21 +45,6 @@ Context.prototype.timeout = function(ms) { return this; }; -/** - * Set test timeout `enabled`. - * - * @private - * @param {boolean} enabled - * @return {Context} self - */ -Context.prototype.enableTimeouts = function(enabled) { - if (!arguments.length) { - return this.runnable().enableTimeouts(); - } - this.runnable().enableTimeouts(enabled); - return this; -}; - /** * Set or get test slowness threshold `ms`. * diff --git a/lib/mocha.js b/lib/mocha.js index bc5462daac..d7d1d54709 100644 --- a/lib/mocha.js +++ b/lib/mocha.js @@ -627,7 +627,6 @@ Mocha.prototype.diff = function(diff) { * @public * @see [CLI option](../#-timeout-ms-t-ms) * @see [Timeouts](../#timeouts) - * @see {@link Mocha#enableTimeouts} * @param {number|string} msecs - Timeout threshold value. * @return {Mocha} this * @chainable @@ -686,22 +685,6 @@ Mocha.prototype.slow = function(msecs) { return this; }; -/** - * Enables or disables timeouts. - * - * @public - * @see [CLI option](../#-timeout-ms-t-ms) - * @param {boolean} enableTimeouts - Whether to enable timeouts. - * @return {Mocha} this - * @chainable - */ -Mocha.prototype.enableTimeouts = function(enableTimeouts) { - this.suite.enableTimeouts( - arguments.length && enableTimeouts !== undefined ? enableTimeouts : true - ); - return this; -}; - /** * Forces all tests to either accept a `done` callback or return a promise. * diff --git a/lib/runnable.js b/lib/runnable.js index 2c24b56ea1..2c668b5391 100644 --- a/lib/runnable.js +++ b/lib/runnable.js @@ -35,7 +35,6 @@ function Runnable(title, fn) { this.sync = !this.async; this._timeout = 2000; this._slow = 75; - this._enableTimeouts = true; this.timedOut = false; this._retries = -1; this._currentRetry = 0; @@ -81,13 +80,6 @@ Runnable.prototype.timeout = function(ms) { var range = [0, INT_MAX]; ms = utils.clamp(ms, range); - // see #1652 for reasoning - if (ms === range[0] || ms === range[1]) { - this.enableTimeouts(false); - } else { - // Reset now that a new timeout limit has been set - this.enableTimeouts(true); - } debug('timeout %d', ms); this._timeout = ms; if (this.timer) { @@ -115,22 +107,6 @@ Runnable.prototype.slow = function(ms) { return this; }; -/** - * Set and get whether timeout is `enabled`. - * - * @private - * @param {boolean} enabled - * @return {Runnable|boolean} enabled or Runnable instance. - */ -Runnable.prototype.enableTimeouts = function(enabled) { - if (!arguments.length) { - return this._enableTimeouts; - } - debug('enableTimeouts %s', enabled); - this._enableTimeouts = enabled; - return this; -}; - /** * Halt and mark as pending. * @@ -234,12 +210,16 @@ Runnable.prototype.resetTimeout = function() { var self = this; var ms = this.timeout() || 1e9; - if (!this._enableTimeouts) { + var timeoutIsDisabled = function() { + return ms === 0; + }; + + if (timeoutIsDisabled()) { return; } this.clearTimeout(); this.timer = setTimeout(function() { - if (!self._enableTimeouts) { + if (timeoutIsDisabled()) { return; } self.callback(self._timeoutError(ms)); @@ -309,7 +289,7 @@ Runnable.prototype.run = function(fn) { self.clearTimeout(); self.duration = new Date() - start; finished = true; - if (!err && self.duration > ms && self._enableTimeouts) { + if (!err && self.duration > ms && ms > 0) { err = self._timeoutError(ms); } fn(err); diff --git a/lib/suite.js b/lib/suite.js index 191d946b50..d564d8e515 100644 --- a/lib/suite.js +++ b/lib/suite.js @@ -68,7 +68,6 @@ function Suite(title, parentContext, isRoot) { this._afterAll = []; this.root = isRoot === true; this._timeout = 2000; - this._enableTimeouts = true; this._slow = 75; this._bail = false; this._retries = -1; @@ -105,7 +104,6 @@ Suite.prototype.clone = function() { suite.root = this.root; suite.timeout(this.timeout()); suite.retries(this.retries()); - suite.enableTimeouts(this.enableTimeouts()); suite.slow(this.slow()); suite.bail(this.bail()); return suite; @@ -123,9 +121,6 @@ Suite.prototype.timeout = function(ms) { if (!arguments.length) { return this._timeout; } - if (ms.toString() === '0') { - this._enableTimeouts = false; - } if (typeof ms === 'string') { ms = milliseconds(ms); } @@ -150,22 +145,6 @@ Suite.prototype.retries = function(n) { return this; }; -/** - * Set or get timeout to `enabled`. - * - * @private - * @param {boolean} enabled - * @return {Suite|boolean} self or enabled - */ -Suite.prototype.enableTimeouts = function(enabled) { - if (!arguments.length) { - return this._enableTimeouts; - } - debug('enableTimeouts %s', enabled); - this._enableTimeouts = enabled; - return this; -}; - /** * Set or get slow `ms` or short-hand such as "2s". * @@ -222,7 +201,6 @@ Suite.prototype._createHook = function(title, fn) { hook.parent = this; hook.timeout(this.timeout()); hook.retries(this.retries()); - hook.enableTimeouts(this.enableTimeouts()); hook.slow(this.slow()); hook.ctx = this.ctx; hook.file = this.file; @@ -337,7 +315,6 @@ Suite.prototype.addSuite = function(suite) { suite.root = false; suite.timeout(this.timeout()); suite.retries(this.retries()); - suite.enableTimeouts(this.enableTimeouts()); suite.slow(this.slow()); suite.bail(this.bail()); this.suites.push(suite); @@ -356,7 +333,6 @@ Suite.prototype.addTest = function(test) { test.parent = this; test.timeout(this.timeout()); test.retries(this.retries()); - test.enableTimeouts(this.enableTimeouts()); test.slow(this.slow()); test.ctx = this.ctx; this.tests.push(test); diff --git a/lib/test.js b/lib/test.js index 87f1ccce7d..29c74b4563 100644 --- a/lib/test.js +++ b/lib/test.js @@ -61,7 +61,6 @@ Test.prototype.clone = function() { var test = new Test(this.title, this.fn); test.timeout(this.timeout()); test.slow(this.slow()); - test.enableTimeouts(this.enableTimeouts()); test.retries(this.retries()); test.currentRetry(this.currentRetry()); test.retriedTest(this.retriedTest() || this); diff --git a/test/integration/fixtures/timeout-override.fixture.js b/test/integration/fixtures/timeout-override.fixture.js index 1d745d9a8f..c780024824 100644 --- a/test/integration/fixtures/timeout-override.fixture.js +++ b/test/integration/fixtures/timeout-override.fixture.js @@ -2,7 +2,7 @@ describe('timeout override', function() { it('should fail async test due to re-enable', function(done) { - this.enableTimeouts(false); + this.timeout(0); this.timeout(1); setTimeout(done, 2); }); diff --git a/test/unit/context.spec.js b/test/unit/context.spec.js index 3f4d756469..d04b1ececa 100644 --- a/test/unit/context.spec.js +++ b/test/unit/context.spec.js @@ -90,12 +90,6 @@ describe('methods', function() { }); }); - describe('enableTimeouts()', function() { - it('should return the enableTimeouts', function() { - expect(this.enableTimeouts(), 'to be', true); - }); - }); - describe('retries', function() { it('should return the number of retries', function() { expect(this.retries(), 'to be', -1); diff --git a/test/unit/mocha.spec.js b/test/unit/mocha.spec.js index a317ca7c39..8839a2d0ed 100644 --- a/test/unit/mocha.spec.js +++ b/test/unit/mocha.spec.js @@ -159,19 +159,6 @@ describe('Mocha', function() { }); }); - describe('#enableTimeouts()', function() { - it('should set the suite._enableTimeouts to true if no argument', function() { - var mocha = new Mocha(opts); - mocha.enableTimeouts(); - expect(mocha.suite._enableTimeouts, 'to be', true); - }); - - it('should be chainable', function() { - var mocha = new Mocha(opts); - expect(mocha.enableTimeouts(), 'to be', mocha); - }); - }); - describe('#diff()', function() { it('should set the diff option to true', function() { var mocha = new Mocha(opts); diff --git a/test/unit/runnable.spec.js b/test/unit/runnable.spec.js index 2c079c3b40..417b3039c9 100644 --- a/test/unit/runnable.spec.js +++ b/test/unit/runnable.spec.js @@ -8,19 +8,19 @@ var STATE_FAILED = Runnable.constants.STATE_FAILED; describe('Runnable(title, fn)', function() { describe('#timeout(ms)', function() { - var MIN_TIMEOUT = 0; + var DISABLED_TIMEOUTS = 0; var MAX_TIMEOUT = 2147483647; // INT_MAX (32-bit signed integer) describe('when value is less than lower bound', function() { it('should clamp to lower bound given numeric', function() { var run = new Runnable(); run.timeout(-1); - expect(run.timeout(), 'to be', MIN_TIMEOUT); + expect(run.timeout(), 'to be', DISABLED_TIMEOUTS); }); it('should clamp to lower bound given timestamp', function() { var run = new Runnable(); run.timeout('-1 ms'); - expect(run.timeout(), 'to be', MIN_TIMEOUT); + expect(run.timeout(), 'to be', DISABLED_TIMEOUTS); }); }); @@ -29,25 +29,17 @@ describe('Runnable(title, fn)', function() { beforeEach(function() { run = new Runnable(); - run.timeout(MIN_TIMEOUT); + run.timeout(DISABLED_TIMEOUTS); }); describe('given numeric value', function() { - it('should set the timeout value', function() { - expect(run.timeout(), 'to be', MIN_TIMEOUT); - }); - - it('should disable timeouts', function() { - expect(run.enableTimeouts(), 'to be false'); + it('should set the timeout value to disabled', function() { + expect(run.timeout(), 'to be', DISABLED_TIMEOUTS); }); }); describe('given string timestamp', function() { - it('should set the timeout value', function() { - expect(run.timeout(), 'to be', MIN_TIMEOUT); - }); - - it('should disable timeouts', function() { - expect(run.enableTimeouts(), 'to be false'); + it('should set the timeout value to disabled', function() { + expect(run.timeout(), 'to be', DISABLED_TIMEOUTS); }); }); }); @@ -65,20 +57,12 @@ describe('Runnable(title, fn)', function() { it('should set the timeout value', function() { expect(run.timeout(), 'to be', timeout); }); - - it('should enable timeouts', function() { - expect(run.enableTimeouts(), 'to be true'); - }); }); describe('given string timestamp', function() { it('should set the timeout value', function() { expect(run.timeout(), 'to be', timeout); }); - - it('should enable timeouts', function() { - expect(run.enableTimeouts(), 'to be true'); - }); }); }); @@ -93,20 +77,12 @@ describe('Runnable(title, fn)', function() { it('should set the timeout value', function() { expect(run.timeout(), 'to be', MAX_TIMEOUT); }); - - it('should disable timeouts', function() { - expect(run.enableTimeouts(), 'to be false'); - }); }); describe('given string timestamp', function() { it('should set the timeout value', function() { expect(run.timeout(), 'to be', MAX_TIMEOUT); }); - - it('should disable timeouts', function() { - expect(run.enableTimeouts(), 'to be false'); - }); }); }); @@ -123,32 +99,16 @@ describe('Runnable(title, fn)', function() { it('should clamp the value to max timeout', function() { expect(run.timeout(), 'to be', MAX_TIMEOUT); }); - - it('should enable timeouts', function() { - expect(run.enableTimeouts(), 'to be false'); - }); }); describe('given string timestamp', function() { it('should clamp the value to max timeout', function() { expect(run.timeout(), 'to be', MAX_TIMEOUT); }); - - it('should enable timeouts', function() { - expect(run.enableTimeouts(), 'to be false'); - }); }); }); }); - describe('#enableTimeouts(enabled)', function() { - it('should set enabled', function() { - var run = new Runnable(); - run.enableTimeouts(false); - expect(run.enableTimeouts(), 'to be false'); - }); - }); - describe('#slow(ms)', function() { var run; @@ -314,7 +274,7 @@ describe('Runnable(title, fn)', function() { }, 2); }); runnable.timeout(1); - runnable.enableTimeouts(false); + runnable.timeout(0); runnable.run(function(err) { expect(err, 'to be falsy'); done(); @@ -721,7 +681,7 @@ describe('Runnable(title, fn)', function() { var runnable = new Runnable('foo', function() {}); runnable.timeout(10); runnable.resetTimeout(); - runnable.enableTimeouts(false); + runnable.timeout(0); setTimeout(function() { expect(runnable.timedOut, 'to be', false); done(); diff --git a/test/unit/test.spec.js b/test/unit/test.spec.js index 7bf739d47e..4ccd891bac 100644 --- a/test/unit/test.spec.js +++ b/test/unit/test.spec.js @@ -10,7 +10,6 @@ describe('Test', function() { this._test = new Test('To be cloned', function() {}); this._test._timeout = 3043; this._test._slow = 101; - this._test._enableTimeouts = true; this._test._retries = 3; this._test._currentRetry = 1; this._test._allowedGlobals = ['foo']; @@ -30,10 +29,6 @@ describe('Test', function() { expect(this._test.clone().slow(), 'to be', 101); }); - it('should copy the enableTimeouts value', function() { - expect(this._test.clone().enableTimeouts(), 'to be', true); - }); - it('should copy the retries value', function() { expect(this._test.clone().retries(), 'to be', 3); }); diff --git a/test/unit/timeout.spec.js b/test/unit/timeout.spec.js index 7725bfe87b..5cf3dce3b7 100644 --- a/test/unit/timeout.spec.js +++ b/test/unit/timeout.spec.js @@ -46,13 +46,13 @@ describe('timeouts', function() { }); }); - describe('using enableTimeouts(false)', function() { + describe('using timeout(0)', function() { this.timeout(4); it('should suppress timeout(4)', function(done) { this.slow(100); // The test is in the before() call. - this.enableTimeouts(false); + this.timeout(0); setTimeout(done, 50); }); }); From a00ea5541f606ca3ca5ea8e7597927289e672622 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Fri, 1 May 2020 17:59:48 +0100 Subject: [PATCH 05/14] Defensive check for 0 --- lib/runnable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runnable.js b/lib/runnable.js index 2c668b5391..8fbdcdf46a 100644 --- a/lib/runnable.js +++ b/lib/runnable.js @@ -208,7 +208,7 @@ Runnable.prototype.clearTimeout = function() { */ Runnable.prototype.resetTimeout = function() { var self = this; - var ms = this.timeout() || 1e9; + var ms = this.timeout() >= 0 ? this.timeout() : 1e9; var timeoutIsDisabled = function() { return ms === 0; From 1b1b26fddbe05a261f2b9a0c8ac6d5a9c1583084 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Fri, 1 May 2020 18:09:01 +0100 Subject: [PATCH 06/14] Use correct timeout value --- lib/runnable.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/runnable.js b/lib/runnable.js index 8fbdcdf46a..2b39b24b2c 100644 --- a/lib/runnable.js +++ b/lib/runnable.js @@ -210,16 +210,12 @@ Runnable.prototype.resetTimeout = function() { var self = this; var ms = this.timeout() >= 0 ? this.timeout() : 1e9; - var timeoutIsDisabled = function() { - return ms === 0; - }; - - if (timeoutIsDisabled()) { + if (ms === 0) { return; } this.clearTimeout(); this.timer = setTimeout(function() { - if (timeoutIsDisabled()) { + if (self.timeout() === 0) { return; } self.callback(self._timeoutError(ms)); From 0805157d37ab5e780285f6c7d9d94c6a4af1e24f Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Fri, 1 May 2020 18:12:29 +0100 Subject: [PATCH 07/14] Remove superfluous logic. --- lib/runnable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runnable.js b/lib/runnable.js index 2b39b24b2c..ced40be753 100644 --- a/lib/runnable.js +++ b/lib/runnable.js @@ -208,7 +208,7 @@ Runnable.prototype.clearTimeout = function() { */ Runnable.prototype.resetTimeout = function() { var self = this; - var ms = this.timeout() >= 0 ? this.timeout() : 1e9; + var ms = this.timeout(); if (ms === 0) { return; From 2b75cf14bcd874b2c15e154f350a85ee04bf0c02 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Sat, 2 May 2020 21:19:23 +0100 Subject: [PATCH 08/14] Add note about `enableTimeouts` to docs --- docs/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/index.md b/docs/index.md index 6c66053d8c..1a734012e3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -810,6 +810,8 @@ Again, use `this.timeout(0)` to disable the timeout for a hook. > In v3.0.0 or newer, a parameter passed to `this.timeout()` greater than the [maximum delay value][mdn-settimeout-maxdelay] will cause the timeout to be disabled. +> As of v8.0.0, `enableTimeouts()` has been removed. + ## Diffs Mocha supports the `err.expected` and `err.actual` properties of any thrown `AssertionError`s from an assertion library. Mocha will attempt to display the difference between what was expected, and what the assertion actually saw. Here's an example of a "string" diff using `--inline-diffs`: From 89ddfc79d22574c6f213f572b287444dcd36444f Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Sat, 2 May 2020 21:20:27 +0100 Subject: [PATCH 09/14] Update comment --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 1a734012e3..ffdd1fccef 100644 --- a/docs/index.md +++ b/docs/index.md @@ -810,7 +810,7 @@ Again, use `this.timeout(0)` to disable the timeout for a hook. > In v3.0.0 or newer, a parameter passed to `this.timeout()` greater than the [maximum delay value][mdn-settimeout-maxdelay] will cause the timeout to be disabled. -> As of v8.0.0, `enableTimeouts()` has been removed. +> As of v8.0.0, `this.enableTimeouts()` has been removed. ## Diffs From c3e2c85bc6ed51e6ff395f1dbaaa826a9e09e51d Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Sat, 2 May 2020 21:34:54 +0100 Subject: [PATCH 10/14] Lint fix --- docs/index.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index ffdd1fccef..492bf21351 100644 --- a/docs/index.md +++ b/docs/index.md @@ -809,8 +809,7 @@ describe('a suite of tests', function() { Again, use `this.timeout(0)` to disable the timeout for a hook. > In v3.0.0 or newer, a parameter passed to `this.timeout()` greater than the [maximum delay value][mdn-settimeout-maxdelay] will cause the timeout to be disabled. - -> As of v8.0.0, `this.enableTimeouts()` has been removed. +> In v8.0.0 or newer, `this.enableTimeouts()` has been removed. ## Diffs From 95162a983c2cdbbee647e93e8aaa7f922c40f8a7 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Sun, 3 May 2020 13:18:49 +0100 Subject: [PATCH 11/14] Disable if setting == or grtr to upper --- lib/runnable.js | 10 ++++++++-- test/unit/runnable.spec.js | 20 ++++---------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/lib/runnable.js b/lib/runnable.js index ced40be753..ed585eb93f 100644 --- a/lib/runnable.js +++ b/lib/runnable.js @@ -80,8 +80,14 @@ Runnable.prototype.timeout = function(ms) { var range = [0, INT_MAX]; ms = utils.clamp(ms, range); - debug('timeout %d', ms); - this._timeout = ms; + // see #1652 for reasoning + if (ms === range[0] || ms === range[1]) { + this._timeout = 0; + } else { + this._timeout = ms; + } + debug('timeout %d', this._timeout); + if (this.timer) { this.resetTimeout(); } diff --git a/test/unit/runnable.spec.js b/test/unit/runnable.spec.js index 417b3039c9..fa328441ca 100644 --- a/test/unit/runnable.spec.js +++ b/test/unit/runnable.spec.js @@ -74,14 +74,8 @@ describe('Runnable(title, fn)', function() { run.timeout(MAX_TIMEOUT); }); describe('given numeric value', function() { - it('should set the timeout value', function() { - expect(run.timeout(), 'to be', MAX_TIMEOUT); - }); - }); - - describe('given string timestamp', function() { - it('should set the timeout value', function() { - expect(run.timeout(), 'to be', MAX_TIMEOUT); + it('should set the disabled timeout value', function() { + expect(run.timeout(), 'to be', 0); }); }); }); @@ -96,14 +90,8 @@ describe('Runnable(title, fn)', function() { }); describe('given numeric value', function() { - it('should clamp the value to max timeout', function() { - expect(run.timeout(), 'to be', MAX_TIMEOUT); - }); - }); - - describe('given string timestamp', function() { - it('should clamp the value to max timeout', function() { - expect(run.timeout(), 'to be', MAX_TIMEOUT); + it('should set the disabled timeout value', function() { + expect(run.timeout(), 'to be', 0); }); }); }); From 5abd67dd3bb13b4dc87a3c1f27c9b8ea8c384d19 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Sun, 3 May 2020 13:34:22 +0100 Subject: [PATCH 12/14] Swap asser to expect --- test/integration/timeout.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/timeout.spec.js b/test/integration/timeout.spec.js index afe5f0f629..0f98467acc 100644 --- a/test/integration/timeout.spec.js +++ b/test/integration/timeout.spec.js @@ -25,7 +25,7 @@ describe('this.timeout()', function() { done(err); return; } - assert.strictEqual(res.stats.failures, 1); + expect(res.stats.failures, 'to be', 1); done(); }); }); From f2e1b2a5624e59919e15e7c150aa05c8c8e822c3 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Tue, 5 May 2020 12:27:08 +0100 Subject: [PATCH 13/14] Excl docs in coverage + clamp in suite. --- .nycrc | 1 + lib/suite.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/.nycrc b/.nycrc index d4091b1a0f..aac56b8030 100644 --- a/.nycrc +++ b/.nycrc @@ -5,6 +5,7 @@ ], "exclude": [ "coverage/**", + "docs/**", "packages/*/test{,s}/**", "**/*.d.ts", "test{,s}/**", diff --git a/lib/suite.js b/lib/suite.js index d564d8e515..2a64e2db8f 100644 --- a/lib/suite.js +++ b/lib/suite.js @@ -124,6 +124,12 @@ Suite.prototype.timeout = function(ms) { if (typeof ms === 'string') { ms = milliseconds(ms); } + + // Clamp to range + var INT_MAX = Math.pow(2, 31) - 1; + var range = [0, INT_MAX]; + ms = utils.clamp(ms, range); + debug('timeout %d', ms); this._timeout = parseInt(ms, 10); return this; From d01b4b773ebf814b08bfdc2ea391f9bc8a3c6a99 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Wed, 6 May 2020 11:07:58 +0100 Subject: [PATCH 14/14] Add note about async tests --- docs/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/index.md b/docs/index.md index 492bf21351..415430a3d4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -810,6 +810,7 @@ Again, use `this.timeout(0)` to disable the timeout for a hook. > In v3.0.0 or newer, a parameter passed to `this.timeout()` greater than the [maximum delay value][mdn-settimeout-maxdelay] will cause the timeout to be disabled. > In v8.0.0 or newer, `this.enableTimeouts()` has been removed. +> **Warning:** With async tests if you disable timeouts via `this.timeout(0)` and then do not call `done()`, your test will exit silently. ## Diffs