Converted integration specs to async/await

This commit is contained in:
Steve Gravrock
2022-06-11 13:40:29 -07:00
parent 96000220b1
commit c7ca3b0101
5 changed files with 1172 additions and 1329 deletions

View File

@@ -494,7 +494,7 @@ describe('Env', function() {
}); });
}); });
it('creates an expectationFactory that uses the current custom equality testers and object formatters', function(done) { it('creates an expectationFactory that uses the current custom equality testers and object formatters', async function() {
function customEqualityTester() {} function customEqualityTester() {}
function customObjectFormatter() {} function customObjectFormatter() {}
function prettyPrinter() {} function prettyPrinter() {}
@@ -515,7 +515,7 @@ describe('Env', function() {
expectationFactory('actual', specInstance); expectationFactory('actual', specInstance);
}); });
env.execute(null, function() { await env.execute();
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([ expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
customObjectFormatter customObjectFormatter
]); ]);
@@ -523,11 +523,9 @@ describe('Env', function() {
customTesters: [customEqualityTester], customTesters: [customEqualityTester],
pp: prettyPrinter pp: prettyPrinter
}); });
done();
});
}); });
it('creates an asyncExpectationFactory that uses the current custom equality testers and object formatters', function(done) { it('creates an asyncExpectationFactory that uses the current custom equality testers and object formatters', async function() {
function customEqualityTester() {} function customEqualityTester() {}
function customObjectFormatter() {} function customObjectFormatter() {}
function prettyPrinter() {} function prettyPrinter() {}
@@ -548,7 +546,8 @@ describe('Env', function() {
asyncExpectationFactory('actual', specInstance); asyncExpectationFactory('actual', specInstance);
}); });
env.execute(null, function() { await env.execute();
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([ expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
customObjectFormatter customObjectFormatter
]); ]);
@@ -556,8 +555,6 @@ describe('Env', function() {
customTesters: [customEqualityTester], customTesters: [customEqualityTester],
pp: prettyPrinter pp: prettyPrinter
}); });
done();
});
}); });
it("does not expose the suite as 'this'", function() { it("does not expose the suite as 'this'", function() {

View File

@@ -9,7 +9,7 @@ describe('Exceptions:', function() {
env.cleanup_(); env.cleanup_();
}); });
it('should handle exceptions thrown, but continue', function(done) { it('should handle exceptions thrown, but continue', async function() {
const secondTest = jasmine.createSpy('second test'); const secondTest = jasmine.createSpy('second test');
env.describe('Suite for handles exceptions', function() { env.describe('Suite for handles exceptions', function() {
env.it( env.it(
@@ -24,15 +24,12 @@ describe('Exceptions:', function() {
); );
}); });
const expectations = function() { await env.execute();
expect(secondTest).toHaveBeenCalled();
done();
};
env.execute(null, expectations); expect(secondTest).toHaveBeenCalled();
}); });
it('should handle exceptions thrown directly in top-level describe blocks and continue', function(done) { it('should handle exceptions thrown directly in top-level describe blocks and continue', async function() {
const secondDescribe = jasmine const secondDescribe = jasmine
.createSpy('second describe') .createSpy('second describe')
.and.callFake(function() { .and.callFake(function() {
@@ -47,11 +44,8 @@ describe('Exceptions:', function() {
}); });
env.describe("a suite that doesn't throw an exception", secondDescribe); env.describe("a suite that doesn't throw an exception", secondDescribe);
const expectations = function() { await env.execute();
expect(secondDescribe).toHaveBeenCalled();
done();
};
env.execute(null, expectations); expect(secondDescribe).toHaveBeenCalled();
}); });
}); });

View File

@@ -10,7 +10,7 @@ describe('Custom Async Matchers (Integration)', function() {
env.cleanup_(); env.cleanup_();
}); });
it('passes the spec if the custom async matcher passes', function(done) { it('passes the spec if the custom async matcher passes', async function() {
env.it('spec using custom async matcher', function() { env.it('spec using custom async matcher', function() {
env.addAsyncMatchers({ env.addAsyncMatchers({
toBeReal: function() { toBeReal: function() {
@@ -30,10 +30,10 @@ describe('Custom Async Matchers (Integration)', function() {
}; };
env.addReporter({ specDone: specExpectations }); env.addReporter({ specDone: specExpectations });
env.execute(null, done); await env.execute();
}); });
it('uses the negative compare function for a negative comparison, if provided', function(done) { it('uses the negative compare function for a negative comparison, if provided', async function() {
env.it('spec with custom negative comparison matcher', function() { env.it('spec with custom negative comparison matcher', function() {
env.addAsyncMatchers({ env.addAsyncMatchers({
toBeReal: function() { toBeReal: function() {
@@ -56,10 +56,10 @@ describe('Custom Async Matchers (Integration)', function() {
}; };
env.addReporter({ specDone: specExpectations }); env.addReporter({ specDone: specExpectations });
env.execute(null, done); await env.execute();
}); });
it('generates messages with the same rules as built in matchers absent a custom message', function(done) { it('generates messages with the same rules as built in matchers absent a custom message', async function() {
env.it('spec with an expectation', function() { env.it('spec with an expectation', function() {
env.addAsyncMatchers({ env.addAsyncMatchers({
toBeReal: function() { toBeReal: function() {
@@ -81,10 +81,10 @@ describe('Custom Async Matchers (Integration)', function() {
}; };
env.addReporter({ specDone: specExpectations }); env.addReporter({ specDone: specExpectations });
env.execute(null, done); await env.execute();
}); });
it('passes the jasmine utility to the matcher factory', function(done) { it('passes the jasmine utility to the matcher factory', async function() {
const matcherFactory = function() { const matcherFactory = function() {
return { return {
compare: function() { compare: function() {
@@ -112,10 +112,10 @@ describe('Custom Async Matchers (Integration)', function() {
}; };
env.addReporter({ specDone: specExpectations }); env.addReporter({ specDone: specExpectations });
env.execute(null, done); await env.execute();
}); });
it('provides custom equality testers to the matcher factory via matchersUtil', function(done) { it('provides custom equality testers to the matcher factory via matchersUtil', async function() {
const matcherFactory = function(matchersUtil) { const matcherFactory = function(matchersUtil) {
return { return {
compare: function(actual, expected) { compare: function(actual, expected) {
@@ -146,6 +146,6 @@ describe('Custom Async Matchers (Integration)', function() {
}; };
env.addReporter({ specDone: specExpectations }); env.addReporter({ specDone: specExpectations });
env.execute(null, done); await env.execute();
}); });
}); });

File diff suppressed because it is too large Load Diff

View File

@@ -30,7 +30,7 @@ describe('spec running', function() {
expect(it4.id).toEqual('spec4'); expect(it4.id).toEqual('spec4');
}); });
it('nested suites', function(done) { it('nested suites', async function() {
let foo = 0; let foo = 0;
let bar = 0; let bar = 0;
let baz = 0; let baz = 0;
@@ -61,16 +61,15 @@ describe('spec running', function() {
expect(baz).toEqual(0); expect(baz).toEqual(0);
expect(quux).toEqual(0); expect(quux).toEqual(0);
env.execute(null, function() { await env.execute();
expect(foo).toEqual(1); expect(foo).toEqual(1);
expect(bar).toEqual(1); expect(bar).toEqual(1);
expect(baz).toEqual(1); expect(baz).toEqual(1);
expect(quux).toEqual(1); expect(quux).toEqual(1);
done();
});
}); });
it('should permit nested describes', function(done) { it('should permit nested describes', async function() {
const actions = []; const actions = [];
env.beforeEach(function() { env.beforeEach(function() {
@@ -127,7 +126,8 @@ describe('spec running', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
const expected = [ const expected = [
'topSuite beforeEach', 'topSuite beforeEach',
'outer beforeEach', 'outer beforeEach',
@@ -158,11 +158,9 @@ describe('spec running', function() {
'topSuite afterEach' 'topSuite afterEach'
]; ];
expect(actions).toEqual(expected); expect(actions).toEqual(expected);
done();
});
}); });
it('should run multiple befores and afters ordered so functions declared later are treated as more specific', function(done) { it('should run multiple befores and afters ordered so functions declared later are treated as more specific', async function() {
const actions = []; const actions = [];
env.beforeAll(function() { env.beforeAll(function() {
@@ -219,7 +217,8 @@ describe('spec running', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
const expected = [ const expected = [
'runner beforeAll1', 'runner beforeAll1',
'runner beforeAll2', 'runner beforeAll2',
@@ -236,11 +235,9 @@ describe('spec running', function() {
'runner afterAll1' 'runner afterAll1'
]; ];
expect(actions).toEqual(expected); expect(actions).toEqual(expected);
done();
});
}); });
it('should run beforeAlls before beforeEachs and afterAlls after afterEachs', function(done) { it('should run beforeAlls before beforeEachs and afterAlls after afterEachs', async function() {
const actions = []; const actions = [];
env.beforeAll(function() { env.beforeAll(function() {
@@ -281,7 +278,8 @@ describe('spec running', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
const expected = [ const expected = [
'runner beforeAll', 'runner beforeAll',
'inner beforeAll', 'inner beforeAll',
@@ -294,11 +292,9 @@ describe('spec running', function() {
'runner afterAll' 'runner afterAll'
]; ];
expect(actions).toEqual(expected); expect(actions).toEqual(expected);
done();
});
}); });
it('should run beforeAlls and afterAlls in the order declared when runnablesToRun is provided', function(done) { it('should run beforeAlls and afterAlls in the order declared when runnablesToRun is provided', async function() {
const actions = []; const actions = [];
let spec; let spec;
let spec2; let spec2;
@@ -345,7 +341,8 @@ describe('spec running', function() {
}); });
}); });
env.execute([spec2.id, spec.id], function() { await env.execute([spec2.id, spec.id]);
const expected = [ const expected = [
'runner beforeAll', 'runner beforeAll',
'inner beforeAll', 'inner beforeAll',
@@ -364,11 +361,9 @@ describe('spec running', function() {
'runner afterAll' 'runner afterAll'
]; ];
expect(actions).toEqual(expected); expect(actions).toEqual(expected);
done();
});
}); });
it('only runs *Alls once in a focused suite', function(done) { it('only runs *Alls once in a focused suite', async function() {
const actions = []; const actions = [];
env.fdescribe('Suite', function() { env.fdescribe('Suite', function() {
@@ -383,14 +378,13 @@ describe('spec running', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
expect(actions).toEqual(['beforeAll', 'spec', 'afterAll']); expect(actions).toEqual(['beforeAll', 'spec', 'afterAll']);
done();
});
}); });
describe('focused runnables', function() { describe('focused runnables', function() {
it('runs the relevant alls and eachs for each runnable', function(done) { it('runs the relevant alls and eachs for each runnable', async function() {
const actions = []; const actions = [];
env.beforeAll(function() { env.beforeAll(function() {
actions.push('beforeAll'); actions.push('beforeAll');
@@ -417,7 +411,8 @@ describe('spec running', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
const expected = [ const expected = [
'beforeAll', 'beforeAll',
'beforeEach', 'beforeEach',
@@ -430,11 +425,9 @@ describe('spec running', function() {
'afterAll' 'afterAll'
]; ];
expect(actions).toEqual(expected); expect(actions).toEqual(expected);
done();
});
}); });
it('focused specs in focused suites cause non-focused siblings to not run', function(done) { it('focused specs in focused suites cause non-focused siblings to not run', async function() {
const actions = []; const actions = [];
env.fdescribe('focused suite', function() { env.fdescribe('focused suite', function() {
@@ -446,14 +439,13 @@ describe('spec running', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
const expected = ['focused spec']; const expected = ['focused spec'];
expect(actions).toEqual(expected); expect(actions).toEqual(expected);
done();
});
}); });
it('focused suites in focused suites cause non-focused siblings to not run', function(done) { it('focused suites in focused suites cause non-focused siblings to not run', async function() {
const actions = []; const actions = [];
env.fdescribe('focused suite', function() { env.fdescribe('focused suite', function() {
@@ -467,14 +459,13 @@ describe('spec running', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
const expected = ['inner spec']; const expected = ['inner spec'];
expect(actions).toEqual(expected); expect(actions).toEqual(expected);
done();
});
}); });
it('focused runnables unfocus ancestor focused suites', function(done) { it('focused runnables unfocus ancestor focused suites', async function() {
const actions = []; const actions = [];
env.fdescribe('focused suite', function() { env.fdescribe('focused suite', function() {
@@ -488,15 +479,14 @@ describe('spec running', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
const expected = ['focused spec']; const expected = ['focused spec'];
expect(actions).toEqual(expected); expect(actions).toEqual(expected);
done();
});
}); });
}); });
it("shouldn't run disabled suites", function(done) { it("shouldn't run disabled suites", async function() {
const specInADisabledSuite = jasmine.createSpy('specInADisabledSuite'); const specInADisabledSuite = jasmine.createSpy('specInADisabledSuite');
env.describe('A Suite', function() { env.describe('A Suite', function() {
env.xdescribe('with a disabled suite', function() { env.xdescribe('with a disabled suite', function() {
@@ -504,13 +494,12 @@ describe('spec running', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
expect(specInADisabledSuite).not.toHaveBeenCalled(); expect(specInADisabledSuite).not.toHaveBeenCalled();
done();
});
}); });
it("shouldn't run before/after functions in disabled suites", function(done) { it("shouldn't run before/after functions in disabled suites", async function() {
const shouldNotRun = jasmine.createSpy('shouldNotRun'); const shouldNotRun = jasmine.createSpy('shouldNotRun');
env.xdescribe('A disabled Suite', function() { env.xdescribe('A disabled Suite', function() {
// None of the before/after functions should run. // None of the before/after functions should run.
@@ -522,13 +511,12 @@ describe('spec running', function() {
env.it('spec inside a disabled suite', shouldNotRun); env.it('spec inside a disabled suite', shouldNotRun);
}); });
env.execute(null, function() { await env.execute();
expect(shouldNotRun).not.toHaveBeenCalled(); expect(shouldNotRun).not.toHaveBeenCalled();
done();
});
}); });
it('should allow top level suites to be disabled', function(done) { it('should allow top level suites to be disabled', async function() {
const specInADisabledSuite = jasmine.createSpy('specInADisabledSuite'), const specInADisabledSuite = jasmine.createSpy('specInADisabledSuite'),
otherSpec = jasmine.createSpy('otherSpec'); otherSpec = jasmine.createSpy('otherSpec');
@@ -539,14 +527,13 @@ describe('spec running', function() {
env.it('another spec', otherSpec); env.it('another spec', otherSpec);
}); });
env.execute(null, function() { await env.execute();
expect(specInADisabledSuite).not.toHaveBeenCalled(); expect(specInADisabledSuite).not.toHaveBeenCalled();
expect(otherSpec).toHaveBeenCalled(); expect(otherSpec).toHaveBeenCalled();
done();
});
}); });
it('should set all pending specs to pending when a suite is run', function(done) { it('should set all pending specs to pending when a suite is run', async function() {
env.describe('default current suite', function() { env.describe('default current suite', function() {
env.it('I am a pending spec'); env.it('I am a pending spec');
}); });
@@ -554,17 +541,16 @@ describe('spec running', function() {
env.addReporter(reporter); env.addReporter(reporter);
env.execute(null, function() { await env.execute();
expect(reporter.specDone).toHaveBeenCalledWith( expect(reporter.specDone).toHaveBeenCalledWith(
jasmine.objectContaining({ jasmine.objectContaining({
status: 'pending' status: 'pending'
}) })
); );
done();
});
}); });
it('should recover gracefully when there are errors in describe functions', function(done) { it('should recover gracefully when there are errors in describe functions', async function() {
const specs = [], const specs = [],
reporter = jasmine.createSpyObj(['specDone', 'suiteDone']); reporter = jasmine.createSpyObj(['specDone', 'suiteDone']);
@@ -599,7 +585,8 @@ describe('spec running', function() {
}); });
env.addReporter(reporter); env.addReporter(reporter);
env.execute(null, function() { await env.execute();
expect(specs).toEqual([ expect(specs).toEqual([
'outer1 inner1 should thingy', 'outer1 inner1 should thingy',
'outer1 inner2 should other thingy', 'outer1 inner2 should other thingy',
@@ -612,11 +599,9 @@ describe('spec running', function() {
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1', [ expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1', [
/outer error/ /outer error/
]); ]);
done();
});
}); });
it('re-enters suites that have no *Alls', function(done) { it('re-enters suites that have no *Alls', async function() {
const actions = []; const actions = [];
let spec1; let spec1;
let spec2; let spec2;
@@ -636,10 +621,9 @@ describe('spec running', function() {
actions.push('spec3'); actions.push('spec3');
}); });
env.execute([spec2.id, spec3.id, spec1.id], function() { await env.execute([spec2.id, spec3.id, spec1.id]);
expect(actions).toEqual(['spec2', 'spec3', 'spec1']); expect(actions).toEqual(['spec2', 'spec3', 'spec1']);
done();
});
}); });
it('refuses to re-enter suites with a beforeAll', function() { it('refuses to re-enter suites with a beforeAll', function() {
@@ -698,7 +682,7 @@ describe('spec running', function() {
expect(actions).toEqual([]); expect(actions).toEqual([]);
}); });
it('should run the tests in a consistent order when a seed is supplied', function(done) { it('should run the tests in a consistent order when a seed is supplied', async function() {
const actions = []; const actions = [];
env.configure({ random: true, seed: '123456' }); env.configure({ random: true, seed: '123456' });
@@ -756,7 +740,8 @@ describe('spec running', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
const expected = [ const expected = [
'topSuite beforeEach', 'topSuite beforeEach',
'outer beforeEach', 'outer beforeEach',
@@ -787,8 +772,6 @@ describe('spec running', function() {
'topSuite afterEach' 'topSuite afterEach'
]; ];
expect(actions).toEqual(expected); expect(actions).toEqual(expected);
done();
});
}); });
function hasStandardErrorHandlingBehavior() { function hasStandardErrorHandlingBehavior() {
@@ -1298,7 +1281,7 @@ describe('spec running', function() {
}); });
describe('when stopOnSpecFailure is on', function() { describe('when stopOnSpecFailure is on', function() {
it('does not run further specs when one fails', function(done) { it('does not run further specs when one fails', async function() {
const actions = []; const actions = [];
env.describe('wrapper', function() { env.describe('wrapper', function() {
@@ -1317,10 +1300,9 @@ describe('spec running', function() {
env.configure({ random: false }); env.configure({ random: false });
env.configure({ stopOnSpecFailure: true }); env.configure({ stopOnSpecFailure: true });
env.execute(null, function() { await env.execute();
expect(actions).toEqual(['fails']); expect(actions).toEqual(['fails']);
done();
});
}); });
it('runs afterAll functions', async function() { it('runs afterAll functions', async function() {
@@ -1364,7 +1346,7 @@ describe('spec running', function() {
env.configure({ autoCleanClosures: false, random: false }); env.configure({ autoCleanClosures: false, random: false });
}); });
it('should be able to run multiple times', function(done) { it('should be able to run multiple times', async function() {
const actions = []; const actions = [];
env.describe('Suite', function() { env.describe('Suite', function() {
@@ -1378,16 +1360,14 @@ describe('spec running', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
expect(actions).toEqual(['spec1', 'spec2']); expect(actions).toEqual(['spec1', 'spec2']);
env.execute(null, function() {
await env.execute();
expect(actions).toEqual(['spec1', 'spec2', 'spec1', 'spec2']); expect(actions).toEqual(['spec1', 'spec2', 'spec1', 'spec2']);
done();
});
});
}); });
it('should reset results between runs', function(done) { it('should reset results between runs', async function() {
const specResults = {}; const specResults = {};
const suiteResults = {}; const suiteResults = {};
let firstExecution = true; let firstExecution = true;
@@ -1440,7 +1420,7 @@ describe('spec running', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
expect(specResults).toEqual({ expect(specResults).toEqual({
spec1: 'failed', spec1: 'failed',
spec2: 'pending', spec2: 'pending',
@@ -1458,7 +1438,8 @@ describe('spec running', function() {
suite4: 'pending', suite4: 'pending',
suite5: 'passed' suite5: 'passed'
}); });
env.execute(null, function() {
await env.execute();
expect(specResults).toEqual({ expect(specResults).toEqual({
spec1: 'passed', spec1: 'passed',
spec2: 'passed', spec2: 'passed',
@@ -1476,12 +1457,9 @@ describe('spec running', function() {
suite4: 'pending', suite4: 'pending',
suite5: 'passed' suite5: 'passed'
}); });
done();
});
});
}); });
it('should execute before and after hooks per run', function(done) { it('should execute before and after hooks per run', async function() {
let timeline = []; let timeline = [];
const timelineFn = function(hookName) { const timelineFn = function(hookName) {
return function() { return function() {
@@ -1507,17 +1485,15 @@ describe('spec running', function() {
env.it('spec1', timelineFn('spec1')); env.it('spec1', timelineFn('spec1'));
env.it('spec2', timelineFn('spec2')); env.it('spec2', timelineFn('spec2'));
}); });
env.execute(null, function() { await env.execute();
expect(timeline).toEqual(expectedTimeLine); expect(timeline).toEqual(expectedTimeLine);
timeline = []; timeline = [];
env.execute(null, function() { await env.execute();
expect(timeline).toEqual(expectedTimeLine); expect(timeline).toEqual(expectedTimeLine);
done();
});
});
}); });
it('should be able to filter out different tests in subsequent runs', function(done) { it('should be able to filter out different tests in subsequent runs', async function() {
const specResults = {}; const specResults = {};
let focussedSpec = 'spec1'; let focussedSpec = 'spec1';
@@ -1539,30 +1515,28 @@ describe('spec running', function() {
env.it('spec3', function() {}); env.it('spec3', function() {});
}); });
env.execute(null, function() { await env.execute();
expect(specResults).toEqual({ expect(specResults).toEqual({
spec1: 'passed', spec1: 'passed',
spec2: 'excluded', spec2: 'excluded',
spec3: 'excluded' spec3: 'excluded'
}); });
focussedSpec = 'spec2'; focussedSpec = 'spec2';
env.execute(null, function() { await env.execute();
expect(specResults).toEqual({ expect(specResults).toEqual({
spec1: 'excluded', spec1: 'excluded',
spec2: 'passed', spec2: 'passed',
spec3: 'excluded' spec3: 'excluded'
}); });
focussedSpec = 'spec3'; focussedSpec = 'spec3';
env.execute(null, function() { await env.execute();
expect(specResults).toEqual({ expect(specResults).toEqual({
spec1: 'excluded', spec1: 'excluded',
spec2: 'excluded', spec2: 'excluded',
spec3: 'passed' spec3: 'passed'
}); });
done();
});
});
});
}); });
}); });
}); });