Allow custom timeout for beforeEach, afterEach, beforeAll, afterAll and it
Fix #483
This commit is contained in:
@@ -873,6 +873,98 @@ describe("Env integration", function() {
|
|||||||
env.execute();
|
env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should wait a custom interval before reporting async functions that fail to call done', function(done) {
|
||||||
|
var env = new j$.Env(),
|
||||||
|
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone', 'suiteDone', 'specDone']);
|
||||||
|
|
||||||
|
reporter.jasmineDone.and.callFake(function() {
|
||||||
|
expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||||
|
fullName: 'suite beforeAll times out',
|
||||||
|
failedExpectations: [jasmine.objectContaining({
|
||||||
|
message: 'Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.'
|
||||||
|
})]
|
||||||
|
}));
|
||||||
|
|
||||||
|
expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||||
|
fullName: 'suite afterAll',
|
||||||
|
failedExpectations: [jasmine.objectContaining({
|
||||||
|
message: 'Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.'
|
||||||
|
})]
|
||||||
|
}));
|
||||||
|
|
||||||
|
expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||||
|
fullName: 'suite beforeEach times out',
|
||||||
|
failedExpectations: [jasmine.objectContaining({
|
||||||
|
message: 'Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.'
|
||||||
|
})]
|
||||||
|
}));
|
||||||
|
|
||||||
|
expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||||
|
fullName: 'suite afterEach times out',
|
||||||
|
failedExpectations: [jasmine.objectContaining({
|
||||||
|
message: 'Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.'
|
||||||
|
})]
|
||||||
|
}));
|
||||||
|
|
||||||
|
expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||||
|
fullName: 'suite it times out',
|
||||||
|
failedExpectations: [jasmine.objectContaining({
|
||||||
|
message: 'Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.'
|
||||||
|
})]
|
||||||
|
}));
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
env.addReporter(reporter);
|
||||||
|
j$.DEFAULT_TIMEOUT_INTERVAL = 10000;
|
||||||
|
|
||||||
|
env.describe('suite', function() {
|
||||||
|
env.describe('beforeAll', function() {
|
||||||
|
env.beforeAll(function(innerDone) {
|
||||||
|
jasmine.clock().tick(5001);
|
||||||
|
innerDone();
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
env.it('times out', function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
env.describe('afterAll', function() {
|
||||||
|
env.afterAll(function(innerDone) {
|
||||||
|
jasmine.clock().tick(2001);
|
||||||
|
innerDone();
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
|
env.it('times out', function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
env.describe('beforeEach', function() {
|
||||||
|
env.beforeEach(function(innerDone) {
|
||||||
|
jasmine.clock().tick(1001);
|
||||||
|
innerDone();
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
env.it('times out', function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
env.describe('afterEach', function() {
|
||||||
|
env.afterEach(function(innerDone) {
|
||||||
|
jasmine.clock().tick(4001);
|
||||||
|
innerDone();
|
||||||
|
}, 4000);
|
||||||
|
|
||||||
|
env.it('times out', function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
env.it('it times out', function(innerDone) {
|
||||||
|
jasmine.clock().tick(6001);
|
||||||
|
innerDone();
|
||||||
|
}, 6000);
|
||||||
|
});
|
||||||
|
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
|
||||||
it('explicitly fails an async spec', function(done) {
|
it('explicitly fails an async spec', function(done) {
|
||||||
var env = new j$.Env(),
|
var env = new j$.Env(),
|
||||||
specDone = jasmine.createSpy('specDone');
|
specDone = jasmine.createSpy('specDone');
|
||||||
|
|||||||
@@ -333,7 +333,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
return runnablesExplictlySet;
|
return runnablesExplictlySet;
|
||||||
};
|
};
|
||||||
|
|
||||||
var specFactory = function(description, fn, suite) {
|
var specFactory = function(description, fn, suite, timeout) {
|
||||||
totalSpecsDefined++;
|
totalSpecsDefined++;
|
||||||
var spec = new j$.Spec({
|
var spec = new j$.Spec({
|
||||||
id: getNextSpecId(),
|
id: getNextSpecId(),
|
||||||
@@ -348,7 +348,11 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
expectationResultFactory: expectationResultFactory,
|
expectationResultFactory: expectationResultFactory,
|
||||||
queueRunnerFactory: queueRunnerFactory,
|
queueRunnerFactory: queueRunnerFactory,
|
||||||
userContext: function() { return suite.clonedSharedUserContext(); },
|
userContext: function() { return suite.clonedSharedUserContext(); },
|
||||||
queueableFn: { fn: fn, type: 'it', timeout: function() { return j$.DEFAULT_TIMEOUT_INTERVAL; } }
|
queueableFn: {
|
||||||
|
fn: fn,
|
||||||
|
type: 'it',
|
||||||
|
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
runnableLookupTable[spec.id] = spec;
|
runnableLookupTable[spec.id] = spec;
|
||||||
@@ -372,20 +376,20 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.it = function(description, fn) {
|
this.it = function(description, fn, timeout) {
|
||||||
var spec = specFactory(description, fn, currentDeclarationSuite);
|
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
|
||||||
currentDeclarationSuite.addChild(spec);
|
currentDeclarationSuite.addChild(spec);
|
||||||
return spec;
|
return spec;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.xit = function(description, fn) {
|
this.xit = function() {
|
||||||
var spec = this.it(description, fn);
|
var spec = this.it.apply(this, arguments);
|
||||||
spec.pend();
|
spec.pend();
|
||||||
return spec;
|
return spec;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.fit = function(description, fn ){
|
this.fit = function(){
|
||||||
var spec = this.it(description, fn);
|
var spec = this.it.apply(this, arguments);
|
||||||
|
|
||||||
focusedRunnables.push(spec.id);
|
focusedRunnables.push(spec.id);
|
||||||
unfocusAncestor();
|
unfocusAncestor();
|
||||||
@@ -400,20 +404,36 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
return currentRunnable().expect(actual);
|
return currentRunnable().expect(actual);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.beforeEach = function(beforeEachFunction) {
|
this.beforeEach = function(beforeEachFunction, timeout) {
|
||||||
currentDeclarationSuite.beforeEach({ fn: beforeEachFunction, type: 'beforeEach', timeout: function() { return j$.DEFAULT_TIMEOUT_INTERVAL; } });
|
currentDeclarationSuite.beforeEach({
|
||||||
|
fn: beforeEachFunction,
|
||||||
|
type: 'beforeEach',
|
||||||
|
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.beforeAll = function(beforeAllFunction) {
|
this.beforeAll = function(beforeAllFunction, timeout) {
|
||||||
currentDeclarationSuite.beforeAll({ fn: beforeAllFunction, type: 'beforeAll', timeout: function() { return j$.DEFAULT_TIMEOUT_INTERVAL; } });
|
currentDeclarationSuite.beforeAll({
|
||||||
|
fn: beforeAllFunction,
|
||||||
|
type: 'beforeAll',
|
||||||
|
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.afterEach = function(afterEachFunction) {
|
this.afterEach = function(afterEachFunction, timeout) {
|
||||||
currentDeclarationSuite.afterEach({ fn: afterEachFunction, type: 'afterEach', timeout: function() { return j$.DEFAULT_TIMEOUT_INTERVAL; } });
|
currentDeclarationSuite.afterEach({
|
||||||
|
fn: afterEachFunction,
|
||||||
|
type: 'afterEach',
|
||||||
|
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.afterAll = function(afterAllFunction) {
|
this.afterAll = function(afterAllFunction, timeout) {
|
||||||
currentDeclarationSuite.afterAll({ fn: afterAllFunction, type: 'afterAll', timeout: function() { return j$.DEFAULT_TIMEOUT_INTERVAL; } });
|
currentDeclarationSuite.afterAll({
|
||||||
|
fn: afterAllFunction,
|
||||||
|
type: 'afterAll',
|
||||||
|
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.pending = function() {
|
this.pending = function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user