Skip to content

Commit 8bb0e2d

Browse files
author
Gregg Van Hove
committed
Merge branch 'ikonst-set-timeout-error-message'
- Merges jasmine#1567 from @ikonst
2 parents e2895a9 + 8c1b80d commit 8bb0e2d

File tree

5 files changed

+32
-26
lines changed

5 files changed

+32
-26
lines changed

lib/jasmine-core/jasmine.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ getJasmineRequireObj().Env = function(j$) {
14531453
userContext: function() { return suite.clonedSharedUserContext(); },
14541454
queueableFn: {
14551455
fn: fn,
1456-
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
1456+
timeout: timeout || 0
14571457
},
14581458
throwOnExpectationFailure: throwOnExpectationFailure
14591459
});
@@ -1536,7 +1536,7 @@ getJasmineRequireObj().Env = function(j$) {
15361536
ensureIsFunctionOrAsync(beforeEachFunction, 'beforeEach');
15371537
currentDeclarationSuite.beforeEach({
15381538
fn: beforeEachFunction,
1539-
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
1539+
timeout: timeout || 0
15401540
});
15411541
};
15421542

@@ -1545,7 +1545,7 @@ getJasmineRequireObj().Env = function(j$) {
15451545
ensureIsFunctionOrAsync(beforeAllFunction, 'beforeAll');
15461546
currentDeclarationSuite.beforeAll({
15471547
fn: beforeAllFunction,
1548-
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
1548+
timeout: timeout || 0
15491549
});
15501550
};
15511551

@@ -1555,7 +1555,7 @@ getJasmineRequireObj().Env = function(j$) {
15551555
afterEachFunction.isCleanup = true;
15561556
currentDeclarationSuite.afterEach({
15571557
fn: afterEachFunction,
1558-
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
1558+
timeout: timeout || 0
15591559
});
15601560
};
15611561

@@ -1564,7 +1564,7 @@ getJasmineRequireObj().Env = function(j$) {
15641564
ensureIsFunctionOrAsync(afterAllFunction, 'afterAll');
15651565
currentDeclarationSuite.afterAll({
15661566
fn: afterAllFunction,
1567-
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
1567+
timeout: timeout || 0
15681568
});
15691569
};
15701570

@@ -5090,12 +5090,16 @@ getJasmineRequireObj().QueueRunner = function(j$) {
50905090

50915091
self.globalErrors.pushListener(handleError);
50925092

5093-
if (queueableFn.timeout) {
5093+
if (queueableFn.timeout !== undefined) {
5094+
var timeoutInterval = queueableFn.timeout || j$.DEFAULT_TIMEOUT_INTERVAL;
50945095
timeoutId = self.setTimeout(function() {
5095-
var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.');
5096+
var error = new Error(
5097+
'Timeout - Async callback was not invoked within ' + timeoutInterval + 'ms ' +
5098+
(queueableFn.timeout ? '(custom timeout)' : '(set by jasmine.DEFAULT_TIMEOUT_INTERVAL)')
5099+
);
50965100
onException(error);
50975101
next();
5098-
}, queueableFn.timeout());
5102+
}, timeoutInterval);
50995103
}
51005104

51015105
try {

spec/core/QueueRunnerSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ describe("QueueRunner", function() {
183183

184184
it("sets a timeout if requested for asynchronous functions so they don't go on forever", function() {
185185
var timeout = 3,
186-
beforeFn = { fn: function(done) { }, type: 'before', timeout: function() { return timeout; } },
186+
beforeFn = { fn: function(done) { }, type: 'before', timeout: timeout },
187187
queueableFn = { fn: jasmine.createSpy('fn'), type: 'queueable' },
188188
onComplete = jasmine.createSpy('onComplete'),
189189
onException = jasmine.createSpy('onException'),
@@ -304,7 +304,7 @@ describe("QueueRunner", function() {
304304
});
305305

306306
it("continues running functions when an exception is thrown in async code without timing out", function() {
307-
var queueableFn = { fn: function(done) { throwAsync(); }, timeout: function() { return 1; } },
307+
var queueableFn = { fn: function(done) { throwAsync(); }, timeout: 1 },
308308
nextQueueableFn = { fn: jasmine.createSpy("nextFunction") },
309309
onException = jasmine.createSpy('onException'),
310310
globalErrors = { pushListener: jasmine.createSpy('pushListener'), popListener: jasmine.createSpy('popListener') },

spec/core/integration/EnvSpec.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -1106,17 +1106,15 @@ describe("Env integration", function() {
11061106

11071107
it('should wait a custom interval before reporting async functions that fail to call done', function(done) {
11081108
var env = createMockedEnv(),
1109-
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone', 'suiteDone', 'specDone']),
1110-
timeoutFailure = (/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./);
1111-
1109+
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone', 'suiteDone', 'specDone']);
11121110

11131111
reporter.jasmineDone.and.callFake(function(r) {
11141112
expect(r.failedExpectations).toEqual([]);
1115-
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('suite beforeAll', [ timeoutFailure ]);
1116-
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('suite afterAll', [ timeoutFailure ]);
1117-
expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite beforeEach times out', [ timeoutFailure ]);
1118-
expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite afterEach times out', [ timeoutFailure ]);
1119-
expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite it times out', [ timeoutFailure ]);
1113+
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('suite beforeAll', [ 'Error: Timeout - Async callback was not invoked within 5000ms (custom timeout)' ]);
1114+
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('suite afterAll', [ 'Error: Timeout - Async callback was not invoked within 2000ms (custom timeout)' ]);
1115+
expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite beforeEach times out', ['Error: Timeout - Async callback was not invoked within 1000ms (custom timeout)']);
1116+
expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite afterEach times out', [ 'Error: Timeout - Async callback was not invoked within 4000ms (custom timeout)' ]);
1117+
expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite it times out', [ 'Error: Timeout - Async callback was not invoked within 6000ms (custom timeout)' ]);
11201118

11211119
jasmine.clock().tick(1);
11221120
realSetTimeout(done);

src/core/Env.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ getJasmineRequireObj().Env = function(j$) {
682682
userContext: function() { return suite.clonedSharedUserContext(); },
683683
queueableFn: {
684684
fn: fn,
685-
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
685+
timeout: timeout || 0
686686
},
687687
throwOnExpectationFailure: throwOnExpectationFailure
688688
});
@@ -765,7 +765,7 @@ getJasmineRequireObj().Env = function(j$) {
765765
ensureIsFunctionOrAsync(beforeEachFunction, 'beforeEach');
766766
currentDeclarationSuite.beforeEach({
767767
fn: beforeEachFunction,
768-
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
768+
timeout: timeout || 0
769769
});
770770
};
771771

@@ -774,7 +774,7 @@ getJasmineRequireObj().Env = function(j$) {
774774
ensureIsFunctionOrAsync(beforeAllFunction, 'beforeAll');
775775
currentDeclarationSuite.beforeAll({
776776
fn: beforeAllFunction,
777-
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
777+
timeout: timeout || 0
778778
});
779779
};
780780

@@ -784,7 +784,7 @@ getJasmineRequireObj().Env = function(j$) {
784784
afterEachFunction.isCleanup = true;
785785
currentDeclarationSuite.afterEach({
786786
fn: afterEachFunction,
787-
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
787+
timeout: timeout || 0
788788
});
789789
};
790790

@@ -793,7 +793,7 @@ getJasmineRequireObj().Env = function(j$) {
793793
ensureIsFunctionOrAsync(afterAllFunction, 'afterAll');
794794
currentDeclarationSuite.afterAll({
795795
fn: afterAllFunction,
796-
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
796+
timeout: timeout || 0
797797
});
798798
};
799799

src/core/QueueRunner.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,16 @@ getJasmineRequireObj().QueueRunner = function(j$) {
105105

106106
self.globalErrors.pushListener(handleError);
107107

108-
if (queueableFn.timeout) {
108+
if (queueableFn.timeout !== undefined) {
109+
var timeoutInterval = queueableFn.timeout || j$.DEFAULT_TIMEOUT_INTERVAL;
109110
timeoutId = self.setTimeout(function() {
110-
var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.');
111+
var error = new Error(
112+
'Timeout - Async callback was not invoked within ' + timeoutInterval + 'ms ' +
113+
(queueableFn.timeout ? '(custom timeout)' : '(set by jasmine.DEFAULT_TIMEOUT_INTERVAL)')
114+
);
111115
onException(error);
112116
next();
113-
}, queueableFn.timeout());
117+
}, timeoutInterval);
114118
}
115119

116120
try {

0 commit comments

Comments
 (0)