Consistently identify clenaup fns by a type tag, not position

This was already done for everything except spec cleanup fns, since the
various skip policies need to know the difference between afterEach and
afterAll.
This commit is contained in:
Steve Gravrock
2021-10-11 17:58:40 -07:00
parent 25c3f06839
commit 41f5c53959
13 changed files with 182 additions and 184 deletions

View File

@@ -13,10 +13,9 @@ describe('CompleteOnFirstErrorSkipPolicy', function() {
describe('After something has errored', function() {
it('skips non cleanup fns', function() {
const fns = arrayOfArbitraryFns(4);
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
fns,
2
);
fns[2].type = arbitraryCleanupType();
fns[3].type = arbitraryCleanupType();
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(fns);
policy.fnErrored(0);
expect(policy.skipTo(0)).toEqual(2);
@@ -24,6 +23,19 @@ describe('CompleteOnFirstErrorSkipPolicy', function() {
expect(policy.skipTo(3)).toEqual(4);
});
for (const type of ['afterEach', 'specCleanup', 'afterAll']) {
it(`does not skip ${type} fns`, function() {
const fns = arrayOfArbitraryFns(2);
fns[1].type = type;
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
fns
);
policy.fnErrored(0);
expect(policy.skipTo(0)).toEqual(1);
});
}
describe('When the error was in a beforeEach fn', function() {
it('runs cleanup fns defined by the current and containing suites', function() {
const parentSuite = { description: 'parentSuite' };
@@ -37,16 +49,17 @@ describe('CompleteOnFirstErrorSkipPolicy', function() {
},
{
fn: () => {},
suite: suite
suite: suite,
type: arbitraryCleanupType()
},
{
fn: () => {},
suite: parentSuite
suite: parentSuite,
type: arbitraryCleanupType()
}
];
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
fns,
2
fns
);
policy.fnErrored(0);
@@ -68,16 +81,17 @@ describe('CompleteOnFirstErrorSkipPolicy', function() {
},
{
fn: () => {},
suite: suite
suite: suite,
type: arbitraryCleanupType()
},
{
fn: () => {},
suite: parentSuite
suite: parentSuite,
type: arbitraryCleanupType()
}
];
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
fns,
2
fns
);
policy.fnErrored(0);
@@ -86,42 +100,32 @@ describe('CompleteOnFirstErrorSkipPolicy', function() {
});
it('does not skip cleanup fns that have no suite, such as the spec complete fn', function() {
const fns = [{ fn: () => {} }, { fn: () => {} }];
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
fns,
1
);
policy.fnErrored(0);
expect(policy.skipTo(0)).toEqual(1);
});
it('does not skip afterAll fns, even if before the first cleanup fn index', function() {
const fns = [
{ fn: () => {} },
{
fn: () => {},
type: 'afterAll'
type: arbitraryCleanupType()
}
];
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
fns,
2
);
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(fns);
policy.fnErrored(0);
expect(policy.skipTo(0)).toEqual(1);
});
});
});
});
function arrayOfArbitraryFns(n) {
const result = [];
function arrayOfArbitraryFns(n) {
const result = [];
for (let i = 0; i < n; i++) {
result.push({ fn: () => {} });
for (let i = 0; i < n; i++) {
result.push({ fn: () => {} });
}
return result;
}
return result;
}
function arbitraryCleanupType() {
return 'specCleanup';
}
});