Skip to content

Commit 3a41f74

Browse files
author
slackersoft
committed
Merge branch 'master' of https://github.com/mauricioborges/jasmine-npm into mauricioborges-master
- Merges #67 from @mauricioborges - Fixes #66
2 parents 1b716d0 + 0142105 commit 3a41f74

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

lib/jasmine.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ function Jasmine(options) {
1818
this.specFiles = [];
1919
this.helperFiles = [];
2020
this.env = this.jasmine.getEnv();
21-
this.reportersCount = 0;
2221
this.exitCodeReporter = new ExitCodeReporter();
2322
this.onCompleteCallbackAdded = false;
2423
this.exit = exit;
@@ -47,7 +46,10 @@ Jasmine.prototype.addSpecFile = function(filePath) {
4746

4847
Jasmine.prototype.addReporter = function(reporter) {
4948
this.env.addReporter(reporter);
50-
this.reportersCount++;
49+
};
50+
51+
Jasmine.prototype.provideFallbackReporter = function(reporter) {
52+
this.env.provideFallbackReporter(reporter);
5153
};
5254

5355
Jasmine.prototype.configureDefaultReporter = function(options) {
@@ -62,7 +64,7 @@ Jasmine.prototype.configureDefaultReporter = function(options) {
6264
this.printDeprecation('Passing in an onComplete function to configureDefaultReporter is deprecated.');
6365
}
6466
var consoleReporter = new module.exports.ConsoleReporter(options);
65-
this.addReporter(consoleReporter);
67+
this.provideFallbackReporter(consoleReporter);
6668
this.defaultReporterAdded = true;
6769
};
6870

@@ -139,10 +141,7 @@ Jasmine.prototype.stopSpecOnExpectationFailure = function(value) {
139141

140142
Jasmine.prototype.execute = function(files, filterString) {
141143
this.loadHelpers();
142-
143-
if(this.reportersCount === 0) {
144-
this.configureDefaultReporter({ showColors: this.showingColors });
145-
}
144+
this.configureDefaultReporter({ showColors: this.showingColors });
146145

147146
if(filterString) {
148147
var specFilter = new ConsoleSpecFilter({

spec/helpers/console_reporter.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var util = require('util');
2+
var options = {
3+
showColors: true,
4+
print: function() {
5+
process.stdout.write(util.format.apply(this, arguments));
6+
}
7+
};
8+
9+
jasmine.getEnv().addReporter(new jasmine.ConsoleReporter(options));

spec/jasmine_spec.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe('Jasmine', function() {
77
this.bootedJasmine = {
88
getEnv: jasmine.createSpy('getEnv').and.returnValue({
99
addReporter: jasmine.createSpy('addReporter'),
10+
provideFallbackReporter: jasmine.createSpy('provideFallbackReporter'),
1011
execute: jasmine.createSpy('execute'),
1112
throwOnExpectationFailure: jasmine.createSpy('throwOnExpectationFailure'),
1213
randomizeTests: jasmine.createSpy('randomizeTests')
@@ -65,7 +66,7 @@ describe('Jasmine', function() {
6566
this.testJasmine.configureDefaultReporter(reporterOptions);
6667

6768
expect(Jasmine.ConsoleReporter).toHaveBeenCalledWith(expectedReporterOptions);
68-
expect(this.testJasmine.env.addReporter).toHaveBeenCalledWith({someProperty: 'some value'});
69+
expect(this.testJasmine.env.provideFallbackReporter).toHaveBeenCalledWith({someProperty: 'some value'});
6970
});
7071

7172
it('creates a reporter with a default option if an option is not specified', function() {
@@ -81,7 +82,7 @@ describe('Jasmine', function() {
8182
};
8283

8384
expect(Jasmine.ConsoleReporter).toHaveBeenCalledWith(expectedReporterOptions);
84-
expect(this.testJasmine.env.addReporter).toHaveBeenCalledWith({someProperty: 'some value'});
85+
expect(this.testJasmine.env.provideFallbackReporter).toHaveBeenCalledWith({someProperty: 'some value'});
8586
});
8687

8788
it('sets the defaultReporterAdded flag', function() {
@@ -289,15 +290,16 @@ describe('Jasmine', function() {
289290
expect(this.testJasmine.env.execute).toHaveBeenCalled();
290291
});
291292

292-
it('does not add a default reporter if a reporter was already added', function() {
293+
it('adds a default reporter as a fallback reporter', function() {
293294
this.testJasmine.addReporter(new Jasmine.ConsoleReporter({}));
294295

295-
spyOn(this.testJasmine, 'configureDefaultReporter');
296+
//spyOn(this.testJasmine, 'configureDefaultReporter');
296297
spyOn(this.testJasmine, 'loadSpecs');
297298

298299
this.testJasmine.execute();
299300

300-
expect(this.testJasmine.configureDefaultReporter).not.toHaveBeenCalled();
301+
expect(this.testJasmine.env.provideFallbackReporter).toHaveBeenCalled();
302+
expect(this.testJasmine.env.addReporter).toHaveBeenCalled();
301303
expect(this.testJasmine.loadSpecs).toHaveBeenCalled();
302304
expect(this.testJasmine.env.execute).toHaveBeenCalled();
303305
});

0 commit comments

Comments
 (0)