Report start and end events for specs/suites that are skipped due to a beforeAll error

This is noisier, but it maintains compatibility with reporters that assume
(quite reasonably) that all specs and suites are either filtered out or
reported.
This commit is contained in:
Steve Gravrock
2021-12-11 12:34:23 -08:00
parent f1cf6ee419
commit 0b1385c3d3
7 changed files with 397 additions and 95 deletions

View File

@@ -3,8 +3,7 @@ describe('SkipAfterBeforeAllErrorPolicy', function() {
describe('When nothing has errored', function() {
it('does not skip anything', function() {
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(
arrayOfArbitraryFns(4),
2
arrayOfArbitraryFns(4)
);
expect(policy.skipTo(0)).toEqual(1);
@@ -17,8 +16,7 @@ describe('SkipAfterBeforeAllErrorPolicy', function() {
describe('When anything but a beforeAll has errored', function() {
it('does not skip anything', function() {
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(
arrayOfArbitraryFns(4),
2
arrayOfArbitraryFns(4)
);
policy.fnErrored(0);
@@ -34,17 +32,15 @@ describe('SkipAfterBeforeAllErrorPolicy', function() {
describe('When a beforeAll has errored', function() {
it('skips subsequent functions other than afterAll', function() {
const suite = {};
const fns = [
{ type: 'beforeAll', fn: () => {} },
{ type: 'beforeAll', fn: () => {}, suite },
{ fn: () => {} },
{ fn: () => {} },
{ type: 'afterAll', fn: () => {} },
{ type: 'afterAll', fn: () => {} }
];
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(
fns,
2
);
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(fns);
policy.fnErrored(0);
expect(policy.skipTo(0)).toEqual(3);
@@ -52,6 +48,29 @@ describe('SkipAfterBeforeAllErrorPolicy', function() {
});
});
});
describe('#fnErrored', function() {
describe('When the fn is a beforeAll', function() {
it("sets the suite's hadBeforeAllFailure property to true", function() {
const suite = {};
const fns = [{ type: 'beforeAll', fn: () => {}, suite }];
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(fns);
policy.fnErrored(0);
expect(suite.hadBeforeAllFailure).toBeTrue();
});
});
describe('When the fn is not a beforeAll', function() {
it('does not try to access the suite, which is probably not there', function() {
const fns = [{ fn: () => {} /* no suite */ }];
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(fns);
expect(() => policy.fnErrored(0)).not.toThrow();
});
});
});
});
function arrayOfArbitraryFns(n) {