Skip to content

Commit

Permalink
Fix setOptions to the ConsoleReporter if it exists on the options param
Browse files Browse the repository at this point in the history
- setOptions to the ConsoleReporter if it exists on the options param
- test setOptions should not override existing options if set multiple times

closes #95
  • Loading branch information
cnishina committed Nov 8, 2016
1 parent 6f58487 commit 2ae4cb6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lib/reporters/console_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function ConsoleReporter() {
showColors = false,
timer = noopTimer,
jasmineCorePath = null,
printDeprecation = function() {},
printDeprecation = require('../printDeprecation'),
specCount,
executableSpecCount,
failureCount,
Expand All @@ -27,17 +27,27 @@ function ConsoleReporter() {
onComplete = function() {};

this.setOptions = function(options) {
print = options.print;
if (options.print) {
print = options.print;
}
showColors = options.showColors || false;
timer = options.timer || noopTimer;
jasmineCorePath = options.jasmineCorePath;
printDeprecation = options.printDeprecation || require('../printDeprecation');
stackFilter = options.stackFilter || defaultStackFilter;
if (options.timer) {
timer = options.timer;
}
if (options.jasmineCorePath) {
jasmineCorePath = options.jasmineCorePath;
}
if (options.printDeprecation) {
printDeprecation = options.printDeprecation;
}
if (options.stackFilter) {
stackFilter = options.stackFilter;
}

if(options.onComplete) {
printDeprecation('Passing in an onComplete function to the ConsoleReporter is deprecated.');
onComplete = options.onComplete;
}
onComplete = options.onComplete || function() {};
};

this.jasmineStarted = function() {
Expand Down
28 changes: 28 additions & 0 deletions spec/reporters/console_reporter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,34 @@ describe("ConsoleReporter", function() {
expect(this.out.getOutput()).toEqual("Started\n");
});

it("setOptions should not override existing options if set multiple times", function() {
var timerSpy = jasmine.createSpyObj('timer', ['start']),
reporter = new ConsoleReporter();

reporter.setOptions({
print: this.out.print,
timer: timerSpy
});

reporter.jasmineStarted();
expect(timerSpy.start).toHaveBeenCalled();
expect(this.out.getOutput()).toEqual("Started\n");

// clean up this.out.output
this.out.clear();
expect(this.out.getOutput()).toEqual("");

// set options that does not include print, should still print with this.out.print
reporter.setOptions({
timer: timerSpy
});

reporter.jasmineStarted();
expect(timerSpy.start).toHaveBeenCalled();
expect(this.out.getOutput()).toEqual("Started\n");
});


it("starts the provided timer when jasmine starts", function() {
var timerSpy = jasmine.createSpyObj('timer', ['start']),
reporter = new ConsoleReporter();
Expand Down

0 comments on commit 2ae4cb6

Please sign in to comment.