Skip to content

Commit

Permalink
Only call the completion callback once per call to execute()
Browse files Browse the repository at this point in the history
  • Loading branch information
sgravrock committed Oct 13, 2021
1 parent 6b3c747 commit 4a1178e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/jasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,11 @@ Jasmine.prototype.execute = async function(files, filterString) {

await this.loadSpecs();

this.addReporter(this.completionReporter);
if (!this.completionReporterInstalled_) {
this.addReporter(this.completionReporter);
this.completionReporterInstalled_ = true;
}

let overallResult;
this.addReporter({
jasmineDone: r => overallResult = r
Expand Down
8 changes: 7 additions & 1 deletion spec/jasmine_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ describe('Jasmine', function() {
expect(this.testJasmine.env.configure).toHaveBeenCalledWith({specFilter: jasmine.any(Function)});
});

it('adds an exit code reporter', async function() {
it('adds an exit code reporter the first time execute is called', async function() {
const completionReporterSpy = jasmine.createSpyObj('reporter', ['onComplete']);
this.testJasmine.completionReporter = completionReporterSpy;
spyOn(this.testJasmine, 'addReporter');
Expand All @@ -506,6 +506,12 @@ describe('Jasmine', function() {

expect(this.testJasmine.addReporter).toHaveBeenCalledWith(completionReporterSpy);
expect(this.testJasmine.completionReporter.exitHandler).toBe(this.testJasmine.checkExit);
this.testJasmine.addReporter.calls.reset();

await this.testJasmine.execute();
expect(this.testJasmine.addReporter).not.toHaveBeenCalledWith(
completionReporterSpy
);
});

describe('when exit is called prematurely', function() {
Expand Down

0 comments on commit 4a1178e

Please sign in to comment.