Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Throw an exception when timeout too large.

Callum Macraefdad1dc29f61
diff --git a/lib/runnable.js b/lib/runnable.js
index 49f52c7d..3291b28f 100644
--- a/lib/runnable.js
+++ b/lib/runnable.js
@@ -75,7 +75,8 @@ Runnable.prototype.timeout = function(ms) {
if (!arguments.length) {
return this._timeout;
}
- if (ms === 0) {
+ // see #1652 for reasoning
+ if (ms === 0 || ms > Math.pow(2, 31)) {
this._enableTimeouts = false;
}
if (typeof ms === 'string') {
diff --git a/test/runnable.js b/test/runnable.js
index a3d88add..ba1ea48f 100644
--- a/test/runnable.js
+++ b/test/runnable.js
@@ -41,6 +41,13 @@ describe('Runnable(title, fn)', function(){
})
})
+ describe('#timeout(ms) when ms>2^31', function(){
+ it('should throw an error', function () {
+ var run = new Runnable;
+ run.timeout.bind(run, 1e10).should.throw(/Timeout too large/);
+ });
+ });
+
describe('#enableTimeouts(enabled)', function(){
it('should set enabled', function(){
var run = new Runnable;