@@ -212,7 +212,16 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
* @default 5000
|
* @default 5000
|
||||||
* @since 1.3.0
|
* @since 1.3.0
|
||||||
*/
|
*/
|
||||||
j$.DEFAULT_TIMEOUT_INTERVAL = 5000;
|
var DEFAULT_TIMEOUT_INTERVAL = 5000;
|
||||||
|
Object.defineProperty(j$, 'DEFAULT_TIMEOUT_INTERVAL', {
|
||||||
|
get: function() {
|
||||||
|
return DEFAULT_TIMEOUT_INTERVAL;
|
||||||
|
},
|
||||||
|
set: function(newValue) {
|
||||||
|
j$.util.validateTimeout(newValue, 'jasmine.DEFAULT_TIMEOUT_INTERVAL');
|
||||||
|
DEFAULT_TIMEOUT_INTERVAL = newValue;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
j$.getGlobal = function() {
|
j$.getGlobal = function() {
|
||||||
return jasmineGlobal;
|
return jasmineGlobal;
|
||||||
@@ -726,6 +735,21 @@ getJasmineRequireObj().util = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
util.validateTimeout = function(timeout, msgPrefix) {
|
||||||
|
// Timeouts are implemented with setTimeout, which only supports a limited
|
||||||
|
// range of values. The limit is unspecified, as is the behavior when it's
|
||||||
|
// exceeded. But on all currently supported JS runtimes, setTimeout calls
|
||||||
|
// the callback immediately when the timeout is greater than 2147483647
|
||||||
|
// (the maximum value of a signed 32 bit integer).
|
||||||
|
var max = 2147483647;
|
||||||
|
|
||||||
|
if (timeout > max) {
|
||||||
|
throw new Error(
|
||||||
|
(msgPrefix || 'Timeout value') + ' cannot be greater than ' + max
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return util;
|
return util;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2286,6 +2310,11 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
if (arguments.length > 1 && typeof fn !== 'undefined') {
|
if (arguments.length > 1 && typeof fn !== 'undefined') {
|
||||||
ensureIsFunctionOrAsync(fn, 'it');
|
ensureIsFunctionOrAsync(fn, 'it');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
|
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
|
||||||
if (currentDeclarationSuite.markedPending) {
|
if (currentDeclarationSuite.markedPending) {
|
||||||
spec.pend();
|
spec.pend();
|
||||||
@@ -2309,6 +2338,10 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
this.fit = function(description, fn, timeout) {
|
this.fit = function(description, fn, timeout) {
|
||||||
ensureIsNotNested('fit');
|
ensureIsNotNested('fit');
|
||||||
ensureIsFunctionOrAsync(fn, 'fit');
|
ensureIsFunctionOrAsync(fn, 'fit');
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
|
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
|
||||||
currentDeclarationSuite.addChild(spec);
|
currentDeclarationSuite.addChild(spec);
|
||||||
focusedRunnables.push(spec.id);
|
focusedRunnables.push(spec.id);
|
||||||
@@ -2373,6 +2406,11 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
this.beforeEach = function(beforeEachFunction, timeout) {
|
this.beforeEach = function(beforeEachFunction, timeout) {
|
||||||
ensureIsNotNested('beforeEach');
|
ensureIsNotNested('beforeEach');
|
||||||
ensureIsFunctionOrAsync(beforeEachFunction, 'beforeEach');
|
ensureIsFunctionOrAsync(beforeEachFunction, 'beforeEach');
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
currentDeclarationSuite.beforeEach({
|
currentDeclarationSuite.beforeEach({
|
||||||
fn: beforeEachFunction,
|
fn: beforeEachFunction,
|
||||||
timeout: timeout || 0
|
timeout: timeout || 0
|
||||||
@@ -2382,6 +2420,11 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
this.beforeAll = function(beforeAllFunction, timeout) {
|
this.beforeAll = function(beforeAllFunction, timeout) {
|
||||||
ensureIsNotNested('beforeAll');
|
ensureIsNotNested('beforeAll');
|
||||||
ensureIsFunctionOrAsync(beforeAllFunction, 'beforeAll');
|
ensureIsFunctionOrAsync(beforeAllFunction, 'beforeAll');
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
currentDeclarationSuite.beforeAll({
|
currentDeclarationSuite.beforeAll({
|
||||||
fn: beforeAllFunction,
|
fn: beforeAllFunction,
|
||||||
timeout: timeout || 0
|
timeout: timeout || 0
|
||||||
@@ -2391,6 +2434,11 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
this.afterEach = function(afterEachFunction, timeout) {
|
this.afterEach = function(afterEachFunction, timeout) {
|
||||||
ensureIsNotNested('afterEach');
|
ensureIsNotNested('afterEach');
|
||||||
ensureIsFunctionOrAsync(afterEachFunction, 'afterEach');
|
ensureIsFunctionOrAsync(afterEachFunction, 'afterEach');
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
afterEachFunction.isCleanup = true;
|
afterEachFunction.isCleanup = true;
|
||||||
currentDeclarationSuite.afterEach({
|
currentDeclarationSuite.afterEach({
|
||||||
fn: afterEachFunction,
|
fn: afterEachFunction,
|
||||||
@@ -2401,6 +2449,11 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
this.afterAll = function(afterAllFunction, timeout) {
|
this.afterAll = function(afterAllFunction, timeout) {
|
||||||
ensureIsNotNested('afterAll');
|
ensureIsNotNested('afterAll');
|
||||||
ensureIsFunctionOrAsync(afterAllFunction, 'afterAll');
|
ensureIsFunctionOrAsync(afterAllFunction, 'afterAll');
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
currentDeclarationSuite.afterAll({
|
currentDeclarationSuite.afterAll({
|
||||||
fn: afterAllFunction,
|
fn: afterAllFunction,
|
||||||
timeout: timeout || 0
|
timeout: timeout || 0
|
||||||
|
|||||||
@@ -256,6 +256,12 @@ describe('Env', function() {
|
|||||||
env.it('async', jasmine.getEnv().makeAsyncAwaitFunction());
|
env.it('async', jasmine.getEnv().makeAsyncAwaitFunction());
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||||
|
expect(function() {
|
||||||
|
env.it('huge timeout', function() {}, 2147483648);
|
||||||
|
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#xit', function() {
|
describe('#xit', function() {
|
||||||
@@ -298,6 +304,12 @@ describe('Env', function() {
|
|||||||
/fit expects a function argument; received \[object (Undefined|DOMWindow|Object)\]/
|
/fit expects a function argument; received \[object (Undefined|DOMWindow|Object)\]/
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||||
|
expect(function() {
|
||||||
|
env.fit('huge timeout', function() {}, 2147483648);
|
||||||
|
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#beforeEach', function() {
|
describe('#beforeEach', function() {
|
||||||
@@ -315,6 +327,12 @@ describe('Env', function() {
|
|||||||
env.beforeEach(jasmine.getEnv().makeAsyncAwaitFunction());
|
env.beforeEach(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||||
|
expect(function() {
|
||||||
|
env.beforeEach(function() {}, 2147483648);
|
||||||
|
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#beforeAll', function() {
|
describe('#beforeAll', function() {
|
||||||
@@ -332,6 +350,12 @@ describe('Env', function() {
|
|||||||
env.beforeAll(jasmine.getEnv().makeAsyncAwaitFunction());
|
env.beforeAll(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||||
|
expect(function() {
|
||||||
|
env.beforeAll(function() {}, 2147483648);
|
||||||
|
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#afterEach', function() {
|
describe('#afterEach', function() {
|
||||||
@@ -349,6 +373,12 @@ describe('Env', function() {
|
|||||||
env.afterEach(jasmine.getEnv().makeAsyncAwaitFunction());
|
env.afterEach(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||||
|
expect(function() {
|
||||||
|
env.afterEach(function() {}, 2147483648);
|
||||||
|
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#afterAll', function() {
|
describe('#afterAll', function() {
|
||||||
@@ -366,6 +396,12 @@ describe('Env', function() {
|
|||||||
env.afterAll(jasmine.getEnv().makeAsyncAwaitFunction());
|
env.afterAll(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||||
|
expect(function() {
|
||||||
|
env.afterAll(function() {}, 2147483648);
|
||||||
|
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when not constructed with suppressLoadErrors: true', function() {
|
describe('when not constructed with suppressLoadErrors: true', function() {
|
||||||
|
|||||||
@@ -141,4 +141,49 @@ describe('base helpers', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('DEFAULT_TIMEOUT_INTERVAL setter', function() {
|
||||||
|
var max = 2147483647;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
this.initialValue = jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = this.initialValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('accepts only values <= ' + max, function() {
|
||||||
|
expect(function() {
|
||||||
|
jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = max + 1;
|
||||||
|
}).toThrowError(
|
||||||
|
'jasmine.DEFAULT_TIMEOUT_INTERVAL cannot be greater than ' + max
|
||||||
|
);
|
||||||
|
|
||||||
|
jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = max;
|
||||||
|
expect(jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL).toEqual(max);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is consistent with setTimeout in this environment', function(done) {
|
||||||
|
var f1 = jasmine.createSpy('setTimeout callback for ' + max),
|
||||||
|
f2 = jasmine.createSpy('setTimeout callback for ' + (max + 1)),
|
||||||
|
id;
|
||||||
|
|
||||||
|
// Suppress printing of TimeoutOverflowWarning in node
|
||||||
|
spyOn(console, 'error');
|
||||||
|
|
||||||
|
id = setTimeout(f1, max);
|
||||||
|
setTimeout(function() {
|
||||||
|
clearTimeout(id);
|
||||||
|
expect(f1).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
id = setTimeout(f2, max + 1);
|
||||||
|
setTimeout(function() {
|
||||||
|
clearTimeout(id);
|
||||||
|
expect(f2).toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1245,6 +1245,11 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
if (arguments.length > 1 && typeof fn !== 'undefined') {
|
if (arguments.length > 1 && typeof fn !== 'undefined') {
|
||||||
ensureIsFunctionOrAsync(fn, 'it');
|
ensureIsFunctionOrAsync(fn, 'it');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
|
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
|
||||||
if (currentDeclarationSuite.markedPending) {
|
if (currentDeclarationSuite.markedPending) {
|
||||||
spec.pend();
|
spec.pend();
|
||||||
@@ -1268,6 +1273,10 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
this.fit = function(description, fn, timeout) {
|
this.fit = function(description, fn, timeout) {
|
||||||
ensureIsNotNested('fit');
|
ensureIsNotNested('fit');
|
||||||
ensureIsFunctionOrAsync(fn, 'fit');
|
ensureIsFunctionOrAsync(fn, 'fit');
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
|
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
|
||||||
currentDeclarationSuite.addChild(spec);
|
currentDeclarationSuite.addChild(spec);
|
||||||
focusedRunnables.push(spec.id);
|
focusedRunnables.push(spec.id);
|
||||||
@@ -1332,6 +1341,11 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
this.beforeEach = function(beforeEachFunction, timeout) {
|
this.beforeEach = function(beforeEachFunction, timeout) {
|
||||||
ensureIsNotNested('beforeEach');
|
ensureIsNotNested('beforeEach');
|
||||||
ensureIsFunctionOrAsync(beforeEachFunction, 'beforeEach');
|
ensureIsFunctionOrAsync(beforeEachFunction, 'beforeEach');
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
currentDeclarationSuite.beforeEach({
|
currentDeclarationSuite.beforeEach({
|
||||||
fn: beforeEachFunction,
|
fn: beforeEachFunction,
|
||||||
timeout: timeout || 0
|
timeout: timeout || 0
|
||||||
@@ -1341,6 +1355,11 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
this.beforeAll = function(beforeAllFunction, timeout) {
|
this.beforeAll = function(beforeAllFunction, timeout) {
|
||||||
ensureIsNotNested('beforeAll');
|
ensureIsNotNested('beforeAll');
|
||||||
ensureIsFunctionOrAsync(beforeAllFunction, 'beforeAll');
|
ensureIsFunctionOrAsync(beforeAllFunction, 'beforeAll');
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
currentDeclarationSuite.beforeAll({
|
currentDeclarationSuite.beforeAll({
|
||||||
fn: beforeAllFunction,
|
fn: beforeAllFunction,
|
||||||
timeout: timeout || 0
|
timeout: timeout || 0
|
||||||
@@ -1350,6 +1369,11 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
this.afterEach = function(afterEachFunction, timeout) {
|
this.afterEach = function(afterEachFunction, timeout) {
|
||||||
ensureIsNotNested('afterEach');
|
ensureIsNotNested('afterEach');
|
||||||
ensureIsFunctionOrAsync(afterEachFunction, 'afterEach');
|
ensureIsFunctionOrAsync(afterEachFunction, 'afterEach');
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
afterEachFunction.isCleanup = true;
|
afterEachFunction.isCleanup = true;
|
||||||
currentDeclarationSuite.afterEach({
|
currentDeclarationSuite.afterEach({
|
||||||
fn: afterEachFunction,
|
fn: afterEachFunction,
|
||||||
@@ -1360,6 +1384,11 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
this.afterAll = function(afterAllFunction, timeout) {
|
this.afterAll = function(afterAllFunction, timeout) {
|
||||||
ensureIsNotNested('afterAll');
|
ensureIsNotNested('afterAll');
|
||||||
ensureIsFunctionOrAsync(afterAllFunction, 'afterAll');
|
ensureIsFunctionOrAsync(afterAllFunction, 'afterAll');
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
j$.util.validateTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
currentDeclarationSuite.afterAll({
|
currentDeclarationSuite.afterAll({
|
||||||
fn: afterAllFunction,
|
fn: afterAllFunction,
|
||||||
timeout: timeout || 0
|
timeout: timeout || 0
|
||||||
|
|||||||
@@ -43,7 +43,16 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
* @default 5000
|
* @default 5000
|
||||||
* @since 1.3.0
|
* @since 1.3.0
|
||||||
*/
|
*/
|
||||||
j$.DEFAULT_TIMEOUT_INTERVAL = 5000;
|
var DEFAULT_TIMEOUT_INTERVAL = 5000;
|
||||||
|
Object.defineProperty(j$, 'DEFAULT_TIMEOUT_INTERVAL', {
|
||||||
|
get: function() {
|
||||||
|
return DEFAULT_TIMEOUT_INTERVAL;
|
||||||
|
},
|
||||||
|
set: function(newValue) {
|
||||||
|
j$.util.validateTimeout(newValue, 'jasmine.DEFAULT_TIMEOUT_INTERVAL');
|
||||||
|
DEFAULT_TIMEOUT_INTERVAL = newValue;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
j$.getGlobal = function() {
|
j$.getGlobal = function() {
|
||||||
return jasmineGlobal;
|
return jasmineGlobal;
|
||||||
|
|||||||
@@ -142,5 +142,20 @@ getJasmineRequireObj().util = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
util.validateTimeout = function(timeout, msgPrefix) {
|
||||||
|
// Timeouts are implemented with setTimeout, which only supports a limited
|
||||||
|
// range of values. The limit is unspecified, as is the behavior when it's
|
||||||
|
// exceeded. But on all currently supported JS runtimes, setTimeout calls
|
||||||
|
// the callback immediately when the timeout is greater than 2147483647
|
||||||
|
// (the maximum value of a signed 32 bit integer).
|
||||||
|
var max = 2147483647;
|
||||||
|
|
||||||
|
if (timeout > max) {
|
||||||
|
throw new Error(
|
||||||
|
(msgPrefix || 'Timeout value') + ' cannot be greater than ' + max
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return util;
|
return util;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user