Skip everything except afterAll fns when a beforeAll fn errors
* Fixes #1533
This commit is contained in:
@@ -1,24 +1,25 @@
|
||||
describe('CompleteOnFirstErrorSkipPolicy', function() {
|
||||
describe('#skipTo', function() {
|
||||
describe('When errored is false', function() {
|
||||
describe('Before anything has errored', function() {
|
||||
it('returns the next index', function() {
|
||||
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
|
||||
arrayOfArbitraryFns(4),
|
||||
4
|
||||
);
|
||||
expect(policy.skipTo(1, false)).toEqual(2);
|
||||
expect(policy.skipTo(1)).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When errored is true', function() {
|
||||
describe('After something has errored', function() {
|
||||
it('returns the first cleanup fn when called with a non cleanup fn', function() {
|
||||
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
|
||||
arrayOfArbitraryFns(4),
|
||||
2
|
||||
);
|
||||
|
||||
expect(policy.skipTo(0, true)).toEqual(2);
|
||||
expect(policy.skipTo(1, true)).toEqual(2);
|
||||
policy.fnErrored(0);
|
||||
expect(policy.skipTo(0)).toEqual(2);
|
||||
expect(policy.skipTo(1)).toEqual(2);
|
||||
});
|
||||
|
||||
it('returns the next index when called with a cleanup fn', function() {
|
||||
@@ -27,8 +28,9 @@ describe('CompleteOnFirstErrorSkipPolicy', function() {
|
||||
1
|
||||
);
|
||||
|
||||
expect(policy.skipTo(1, true)).toEqual(2);
|
||||
expect(policy.skipTo(2, true)).toEqual(3);
|
||||
policy.fnErrored(0);
|
||||
expect(policy.skipTo(1)).toEqual(2);
|
||||
expect(policy.skipTo(2)).toEqual(3);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -674,7 +674,10 @@ describe('QueueRunner', function() {
|
||||
{ fn: jasmine.createSpy('fn2').and.throwError(new Error('nope')) },
|
||||
{ fn: jasmine.createSpy('fn3') }
|
||||
];
|
||||
const skipPolicy = jasmine.createSpyObj('skipPolicy', ['skipTo']);
|
||||
const skipPolicy = jasmine.createSpyObj('skipPolicy', [
|
||||
'skipTo',
|
||||
'fnErrored'
|
||||
]);
|
||||
skipPolicy.skipTo.and.callFake(function(lastRanIx) {
|
||||
return lastRanIx === 0 ? 2 : lastRanIx + 1;
|
||||
});
|
||||
@@ -687,8 +690,9 @@ describe('QueueRunner', function() {
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
expect(skipPolicy.skipTo).toHaveBeenCalledWith(0, false);
|
||||
expect(skipPolicy.skipTo).toHaveBeenCalledWith(2, true);
|
||||
expect(skipPolicy.skipTo).toHaveBeenCalledWith(0);
|
||||
expect(skipPolicy.skipTo).toHaveBeenCalledWith(2);
|
||||
expect(skipPolicy.fnErrored).toHaveBeenCalledWith(2);
|
||||
expect(queueableFns[0].fn).toHaveBeenCalled();
|
||||
expect(queueableFns[1].fn).not.toHaveBeenCalled();
|
||||
expect(queueableFns[2].fn).toHaveBeenCalled();
|
||||
|
||||
65
spec/core/SkipAfterBeforeAllErrorPolicySpec.js
Normal file
65
spec/core/SkipAfterBeforeAllErrorPolicySpec.js
Normal file
@@ -0,0 +1,65 @@
|
||||
describe('SkipAfterBeforeAllErrorPolicy', function() {
|
||||
describe('#skipTo', function() {
|
||||
describe('When nothing has errored', function() {
|
||||
it('does not skip anything', function() {
|
||||
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(
|
||||
arrayOfArbitraryFns(4),
|
||||
2
|
||||
);
|
||||
|
||||
expect(policy.skipTo(0)).toEqual(1);
|
||||
expect(policy.skipTo(1)).toEqual(2);
|
||||
expect(policy.skipTo(2)).toEqual(3);
|
||||
expect(policy.skipTo(3)).toEqual(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When anything but a beforeAll has errored', function() {
|
||||
it('does not skip anything', function() {
|
||||
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(
|
||||
arrayOfArbitraryFns(4),
|
||||
2
|
||||
);
|
||||
|
||||
policy.fnErrored(0);
|
||||
expect(policy.skipTo(0)).toEqual(1);
|
||||
policy.fnErrored(1);
|
||||
expect(policy.skipTo(1)).toEqual(2);
|
||||
policy.fnErrored(2);
|
||||
expect(policy.skipTo(2)).toEqual(3);
|
||||
policy.fnErrored(3);
|
||||
expect(policy.skipTo(3)).toEqual(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When a beforeAll has errored', function() {
|
||||
it('skips subsequent functions other than afterAll', function() {
|
||||
const fns = [
|
||||
{ type: 'beforeAll', fn: () => {} },
|
||||
{ fn: () => {} },
|
||||
{ fn: () => {} },
|
||||
{ type: 'afterAll', fn: () => {} },
|
||||
{ type: 'afterAll', fn: () => {} }
|
||||
];
|
||||
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(
|
||||
fns,
|
||||
2
|
||||
);
|
||||
|
||||
policy.fnErrored(0);
|
||||
expect(policy.skipTo(0)).toEqual(3);
|
||||
expect(policy.skipTo(3)).toEqual(4);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function arrayOfArbitraryFns(n) {
|
||||
const result = [];
|
||||
|
||||
for (let i = 0; i < n; i++) {
|
||||
result.push({ fn: () => {} });
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -482,7 +482,10 @@ describe('TreeProcessor', function() {
|
||||
var leaf = new Leaf(),
|
||||
node = new Node({
|
||||
children: [leaf],
|
||||
beforeAllFns: ['beforeAll1', 'beforeAll2']
|
||||
beforeAllFns: [
|
||||
{ fn: 'beforeAll1', timeout: 1 },
|
||||
{ fn: 'beforeAll2', timeout: 2 }
|
||||
]
|
||||
}),
|
||||
root = new Node({ children: [node] }),
|
||||
queueRunner = jasmine.createSpy('queueRunner'),
|
||||
@@ -502,8 +505,8 @@ describe('TreeProcessor', function() {
|
||||
|
||||
expect(queueableFns).toEqual([
|
||||
{ fn: jasmine.any(Function) },
|
||||
'beforeAll1',
|
||||
'beforeAll2',
|
||||
{ type: 'beforeAll', fn: 'beforeAll1', timeout: 1 },
|
||||
{ type: 'beforeAll', fn: 'beforeAll2', timeout: 2 },
|
||||
{ fn: jasmine.any(Function) }
|
||||
]);
|
||||
});
|
||||
@@ -512,7 +515,7 @@ describe('TreeProcessor', function() {
|
||||
var leaf = new Leaf(),
|
||||
node = new Node({
|
||||
children: [leaf],
|
||||
afterAllFns: ['afterAll1', 'afterAll2']
|
||||
afterAllFns: [{ fn: 'afterAll1' }, { fn: 'afterAll2' }]
|
||||
}),
|
||||
root = new Node({ children: [node] }),
|
||||
queueRunner = jasmine.createSpy('queueRunner'),
|
||||
@@ -533,15 +536,15 @@ describe('TreeProcessor', function() {
|
||||
expect(queueableFns).toEqual([
|
||||
{ fn: jasmine.any(Function) },
|
||||
{ fn: jasmine.any(Function) },
|
||||
'afterAll1',
|
||||
'afterAll2'
|
||||
{ type: 'afterAll', fn: 'afterAll1' },
|
||||
{ type: 'afterAll', fn: 'afterAll2' }
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not run beforeAlls or afterAlls for a node with no children', function() {
|
||||
var node = new Node({
|
||||
beforeAllFns: ['before'],
|
||||
afterAllFns: ['after']
|
||||
beforeAllFns: [{ fn: 'before' }],
|
||||
afterAllFns: [{ fn: 'after' }]
|
||||
}),
|
||||
root = new Node({ children: [node] }),
|
||||
queueRunner = jasmine.createSpy('queueRunner'),
|
||||
@@ -566,8 +569,8 @@ describe('TreeProcessor', function() {
|
||||
var leaf = new Leaf({ markedPending: true }),
|
||||
node = new Node({
|
||||
children: [leaf],
|
||||
beforeAllFns: ['before'],
|
||||
afterAllFns: ['after'],
|
||||
beforeAllFns: [{ fn: 'before' }],
|
||||
afterAllFns: [{ fn: 'after' }],
|
||||
markedPending: false
|
||||
}),
|
||||
root = new Node({ children: [node] }),
|
||||
|
||||
@@ -1158,6 +1158,68 @@ describe('spec running', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('When a beforeAll function fails', function() {
|
||||
it('skips contained specs and suites', async function() {
|
||||
const outerBeforeEach = jasmine.createSpy('outerBeforeEach');
|
||||
const nestedBeforeEach = jasmine.createSpy('nestedBeforeEach');
|
||||
const outerAfterEach = jasmine.createSpy('outerAfterEach');
|
||||
const nestedAfterEach = jasmine.createSpy('nestedAfterEach');
|
||||
const outerIt = jasmine.createSpy('outerIt');
|
||||
const nestedIt = jasmine.createSpy('nestedIt');
|
||||
const nestedBeforeAll = jasmine.createSpy('nestedBeforeAll');
|
||||
|
||||
env.beforeAll(function() {
|
||||
throw new Error('nope');
|
||||
});
|
||||
|
||||
env.beforeEach(outerBeforeEach);
|
||||
env.it('a spec', outerIt);
|
||||
env.describe('a nested suite', function() {
|
||||
env.beforeAll(nestedBeforeAll);
|
||||
env.beforeEach(nestedBeforeEach);
|
||||
env.it('a nested spec', nestedIt);
|
||||
env.afterEach(nestedAfterEach);
|
||||
});
|
||||
env.afterEach(outerAfterEach);
|
||||
|
||||
await env.execute();
|
||||
|
||||
expect(outerBeforeEach).not.toHaveBeenCalled();
|
||||
expect(outerIt).not.toHaveBeenCalled();
|
||||
expect(nestedBeforeAll).not.toHaveBeenCalled();
|
||||
expect(nestedBeforeEach).not.toHaveBeenCalled();
|
||||
expect(nestedIt).not.toHaveBeenCalled();
|
||||
expect(nestedAfterEach).not.toHaveBeenCalled();
|
||||
expect(outerAfterEach).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('runs afterAll functions in the current suite and outer scopes', async function() {
|
||||
const outerAfterAll = jasmine.createSpy('outerAfterAll');
|
||||
const nestedAfterAll = jasmine.createSpy('nestedAfterAll');
|
||||
const secondNestedAfterAll = jasmine.createSpy('secondNestedAfterAll');
|
||||
|
||||
env.describe('a nested suite', function() {
|
||||
env.beforeAll(function() {
|
||||
throw new Error('nope');
|
||||
});
|
||||
|
||||
env.describe('more nesting', function() {
|
||||
env.it('a nested spec', function() {});
|
||||
env.afterAll(secondNestedAfterAll);
|
||||
});
|
||||
|
||||
env.afterAll(nestedAfterAll);
|
||||
});
|
||||
env.afterAll(outerAfterAll);
|
||||
|
||||
await env.execute();
|
||||
|
||||
expect(secondNestedAfterAll).not.toHaveBeenCalled();
|
||||
expect(nestedAfterAll).toHaveBeenCalled();
|
||||
expect(outerAfterAll).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when stopOnSpecFailure is on', function() {
|
||||
it('does not run further specs when one fails', function(done) {
|
||||
var actions = [],
|
||||
|
||||
Reference in New Issue
Block a user