Skip to content

Commit

Permalink
Merge branch 'fix_defaultreporter' of https://github.com/cnishina/jas…
Browse files Browse the repository at this point in the history
…mine-npm into cnishina-fix_defaultreporter

- Merges #98 from @cnishina
- See also #95
  • Loading branch information
Gregg Van Hove committed Dec 2, 2016
2 parents e0d502f + 1d51773 commit f5d1d09
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/reporters/console_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 f5d1d09

Please sign in to comment.