From 5989948cafa5479f7bde23ddced2b8a3604d003a Mon Sep 17 00:00:00 2001 From: Mauricio Borges Silva Date: Wed, 30 Dec 2015 15:43:04 -0200 Subject: [PATCH 1/3] Replace method to add default report only when no custom reports are provided. Now uses fallback method --- lib/jasmine.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/jasmine.js b/lib/jasmine.js index b1aed93f..a4b4a4fc 100644 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -18,7 +18,6 @@ function Jasmine(options) { this.specFiles = []; this.helperFiles = []; this.env = this.jasmine.getEnv(); - this.reportersCount = 0; this.exitCodeReporter = new ExitCodeReporter(); this.onCompleteCallbackAdded = false; this.exit = exit; @@ -43,7 +42,10 @@ Jasmine.prototype.addSpecFile = function(filePath) { Jasmine.prototype.addReporter = function(reporter) { this.env.addReporter(reporter); - this.reportersCount++; +}; + +Jasmine.prototype.provideFallbackReporter = function(reporter) { + this.env.provideFallbackReporter(reporter); }; Jasmine.prototype.configureDefaultReporter = function(options) { @@ -58,7 +60,7 @@ Jasmine.prototype.configureDefaultReporter = function(options) { this.printDeprecation('Passing in an onComplete function to configureDefaultReporter is deprecated.'); } var consoleReporter = new module.exports.ConsoleReporter(options); - this.addReporter(consoleReporter); + this.provideFallbackReporter(consoleReporter); this.defaultReporterAdded = true; }; @@ -131,10 +133,7 @@ Jasmine.prototype.stopSpecOnExpectationFailure = function(value) { Jasmine.prototype.execute = function(files, filterString) { this.loadHelpers(); - - if(this.reportersCount === 0) { - this.configureDefaultReporter({ showColors: this.showingColors }); - } + this.configureDefaultReporter({ showColors: this.showingColors }); if(filterString) { var specFilter = new ConsoleSpecFilter({ From 085fa31c622924ed67adbf4e36e80b48b1025fd0 Mon Sep 17 00:00:00 2001 From: Mauricio Borges Silva Date: Wed, 30 Dec 2015 16:50:29 -0200 Subject: [PATCH 2/3] Fix specifications regarding the fallback approach --- spec/jasmine_spec.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spec/jasmine_spec.js b/spec/jasmine_spec.js index 41693c23..9928abd5 100644 --- a/spec/jasmine_spec.js +++ b/spec/jasmine_spec.js @@ -7,6 +7,7 @@ describe('Jasmine', function() { this.bootedJasmine = { getEnv: jasmine.createSpy('getEnv').and.returnValue({ addReporter: jasmine.createSpy('addReporter'), + provideFallbackReporter: jasmine.createSpy('provideFallbackReporter'), execute: jasmine.createSpy('execute'), throwOnExpectationFailure: jasmine.createSpy('throwOnExpectationFailure'), randomizeTests: jasmine.createSpy('randomizeTests') @@ -60,7 +61,7 @@ describe('Jasmine', function() { this.testJasmine.configureDefaultReporter(reporterOptions); expect(Jasmine.ConsoleReporter).toHaveBeenCalledWith(expectedReporterOptions); - expect(this.testJasmine.env.addReporter).toHaveBeenCalledWith({someProperty: 'some value'}); + expect(this.testJasmine.env.provideFallbackReporter).toHaveBeenCalledWith({someProperty: 'some value'}); }); it('creates a reporter with a default option if an option is not specified', function() { @@ -76,7 +77,7 @@ describe('Jasmine', function() { }; expect(Jasmine.ConsoleReporter).toHaveBeenCalledWith(expectedReporterOptions); - expect(this.testJasmine.env.addReporter).toHaveBeenCalledWith({someProperty: 'some value'}); + expect(this.testJasmine.env.provideFallbackReporter).toHaveBeenCalledWith({someProperty: 'some value'}); }); it('sets the defaultReporterAdded flag', function() { @@ -269,15 +270,16 @@ describe('Jasmine', function() { expect(this.testJasmine.env.execute).toHaveBeenCalled(); }); - it('does not add a default reporter if a reporter was already added', function() { + it('adds a default reporter as a fallback reporter', function() { this.testJasmine.addReporter(new Jasmine.ConsoleReporter({})); - spyOn(this.testJasmine, 'configureDefaultReporter'); + //spyOn(this.testJasmine, 'configureDefaultReporter'); spyOn(this.testJasmine, 'loadSpecs'); this.testJasmine.execute(); - expect(this.testJasmine.configureDefaultReporter).not.toHaveBeenCalled(); + expect(this.testJasmine.env.provideFallbackReporter).toHaveBeenCalled(); + expect(this.testJasmine.env.addReporter).toHaveBeenCalled(); expect(this.testJasmine.loadSpecs).toHaveBeenCalled(); expect(this.testJasmine.env.execute).toHaveBeenCalled(); }); From 01421057ae055be6086cc23cd99b6df519625576 Mon Sep 17 00:00:00 2001 From: Mauricio Borges Silva Date: Wed, 30 Dec 2015 17:16:33 -0200 Subject: [PATCH 3/3] Add custom helper to configure report --- spec/helpers/console_reporter.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 spec/helpers/console_reporter.js diff --git a/spec/helpers/console_reporter.js b/spec/helpers/console_reporter.js new file mode 100644 index 00000000..ccdb40f6 --- /dev/null +++ b/spec/helpers/console_reporter.js @@ -0,0 +1,9 @@ +var util = require('util'); +var options = { + showColors: true, + print: function() { + process.stdout.write(util.format.apply(this, arguments)); + } +}; + +jasmine.getEnv().addReporter(new jasmine.ConsoleReporter(options));