Skip to content

Commit

Permalink
Using the jasmineNode namespace for the reporters
Browse files Browse the repository at this point in the history
  • Loading branch information
adomokos committed Dec 23, 2011
1 parent 4c8cf12 commit 7ac94e0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 37 deletions.
6 changes: 3 additions & 3 deletions lib/jasmine-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ delete global.window;
require("./async-callback");
require("jasmine-reporters");

var TerminalReporter = require('./reporter').TerminalReporter;
var jasmineNode = require('./reporter').jasmineNode;

jasmine.loadHelpersInFolder=function(folder, matcher)
{
Expand Down Expand Up @@ -89,12 +89,12 @@ jasmine.executeSpecsInFolder = function(folder,
if(teamcity){
jasmineEnv.addReporter(new jasmine.TeamcityReporter());
} else if(isVerbose) {
jasmineEnv.addReporter(new TerminalVerboseReporter({ print: util.print,
jasmineEnv.addReporter(new jasmineNode.TerminalVerboseReporter({ print: util.print,
color: showColors,
onComplete: done,
stackFilter: removeJasmineFrames}));
} else {
jasmineEnv.addReporter(new TerminalReporter({print: util.print,
jasmineEnv.addReporter(new jasmineNode.TerminalReporter({print: util.print,
color: showColors,
onComplete: done,
stackFilter: removeJasmineFrames}));
Expand Down
52 changes: 27 additions & 25 deletions lib/jasmine-node/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ NoColors = {
neutral: function() { return ''; }
};

TerminalReporter = function(config) {
var jasmineNode = {};

jasmineNode.TerminalReporter = function(config) {
this.print_ = config.print || util.print;
this.color_ = config.color ? ANSIColors : NoColors;

Expand All @@ -37,7 +39,7 @@ TerminalReporter = function(config) {
this.failures_ = [];
}

TerminalReporter.prototype.reportRunnerStarting = function(runner) {
jasmineNode.TerminalReporter.prototype.reportRunnerStarting = function(runner) {
this.started_ = true;
this.startedAt = new Date();
var suites = runner.topLevelSuites();
Expand All @@ -47,7 +49,7 @@ TerminalReporter.prototype.reportRunnerStarting = function(runner) {
}
};

TerminalReporter.prototype.summarize_ = function(suiteOrSpec) {
jasmineNode.TerminalReporter.prototype.summarize_ = function(suiteOrSpec) {
var isSuite = suiteOrSpec instanceof jasmine.Suite;

var summary = {
Expand All @@ -68,7 +70,7 @@ TerminalReporter.prototype.summarize_ = function(suiteOrSpec) {
};

// This is heavily influenced by Jasmine's Html/Trivial Reporter
TerminalReporter.prototype.reportRunnerResults = function(runner) {
jasmineNode.TerminalReporter.prototype.reportRunnerResults = function(runner) {
this.reportFailures_();

var results = runner.results();
Expand All @@ -88,7 +90,7 @@ TerminalReporter.prototype.reportRunnerResults = function(runner) {
this.finished_ = true;
};

TerminalReporter.prototype.reportFailures_ = function() {
jasmineNode.TerminalReporter.prototype.reportFailures_ = function() {
if (this.failures_.length == 0) {
return;
}
Expand All @@ -109,11 +111,11 @@ TerminalReporter.prototype.reportFailures_ = function() {
}
};

TerminalReporter.prototype.reportSuiteResults = function(suite) {
jasmineNode.TerminalReporter.prototype.reportSuiteResults = function(suite) {
// Not used in this context
};

TerminalReporter.prototype.reportSpecResults = function(spec) {
jasmineNode.TerminalReporter.prototype.reportSpecResults = function(spec) {
var result = spec.results();
var msg = '';
if (result.passed()) {
Expand All @@ -128,7 +130,7 @@ TerminalReporter.prototype.reportSpecResults = function(spec) {
this.print_(msg);
};

TerminalReporter.prototype.addFailureToFailures_ = function(spec) {
jasmineNode.TerminalReporter.prototype.addFailureToFailures_ = function(spec) {
var result = spec.results();
var failureItem = null;

Expand All @@ -146,7 +148,7 @@ TerminalReporter.prototype.addFailureToFailures_ = function(spec) {
}
};

TerminalReporter.prototype.printRunnerResults_ = function(runner){
jasmineNode.TerminalReporter.prototype.printRunnerResults_ = function(runner){
var results = runner.results();
var specs = runner.specs();
var msg = '';
Expand All @@ -157,28 +159,28 @@ TerminalReporter.prototype.printRunnerResults_ = function(runner){
};

// Helper Methods //
TerminalReporter.prototype.stringWithColor_ = function(stringValue, color) {
jasmineNode.TerminalReporter.prototype.stringWithColor_ = function(stringValue, color) {
return (color || this.color_.neutral()) + stringValue + this.color_.neutral();
};

TerminalReporter.prototype.printLine_ = function(stringValue) {
jasmineNode.TerminalReporter.prototype.printLine_ = function(stringValue) {
this.print_(stringValue);
this.print_('\n');
};

// ***************************************************************
// TerminalVerboseReporter uses the TerminalReporter's constructor
// ***************************************************************
TerminalVerboseReporter = function(config) {
TerminalReporter.call(this, config);
jasmineNode.TerminalVerboseReporter = function(config) {
jasmineNode.TerminalReporter.call(this, config);
// The extra field in this object
this.indent_ = [];
}

// Inherit from TerminalReporter
TerminalVerboseReporter.prototype.__proto__ = TerminalReporter.prototype;
jasmineNode.TerminalVerboseReporter.prototype.__proto__ = jasmineNode.TerminalReporter.prototype;

TerminalVerboseReporter.prototype.reportSpecResults = function(spec) {
jasmineNode.TerminalVerboseReporter.prototype.reportSpecResults = function(spec) {
if (spec.results().failedCount > 0) {
this.addFailureToFailures_(spec);
}
Expand All @@ -189,25 +191,25 @@ TerminalVerboseReporter.prototype.reportSpecResults = function(spec) {
};
};

TerminalVerboseReporter.prototype.reportRunnerResults = function(runner) {
jasmineNode.TerminalVerboseReporter.prototype.reportRunnerResults = function(runner) {
var messages = new Array();
this.constructMessagesFromResult_(messages, this.suites_);
this.buildMessagesFromResult_(messages, this.suites_);

for (var i=0; i<messages.length; i++) {
this.printLine_(messages[i]);
}

// Call the super class' method
TerminalReporter.prototype.reportRunnerResults.call(this, runner);
// Call the parent object's method
jasmineNode.TerminalReporter.prototype.reportRunnerResults.call(this, runner);
}

TerminalVerboseReporter.prototype.constructMessagesFromResult_ = function(messages, result) {
jasmineNode.TerminalVerboseReporter.prototype.buildMessagesFromResult_ = function(messages, results) {
var element = undefined,
specResult = undefined,
msg = '';

for (var i = 0; i < result.length; i++) {
element = result[i];
for (var i = 0; i < results.length; i++) {
element = results[i];

if (element.type === 'spec') {
this.indent_ = 2;
Expand All @@ -226,11 +228,11 @@ TerminalVerboseReporter.prototype.constructMessagesFromResult_ = function(messag
messages.push(this.indentMessage_(element.name));
}

this.constructMessagesFromResult_(messages, element.children);
this.buildMessagesFromResult_(messages, element.children);
}
};

TerminalVerboseReporter.prototype.indentMessage_ = function(message) {
jasmineNode.TerminalVerboseReporter.prototype.indentMessage_ = function(message) {
var _indent = '';
for (var i = 0; i < this.indent_; i++) {
_indent += ' ';
Expand All @@ -241,4 +243,4 @@ TerminalVerboseReporter.prototype.indentMessage_ = function(message) {
//
// Exports
//
exports.TerminalReporter = TerminalReporter;
exports.jasmineNode = jasmineNode;
34 changes: 25 additions & 9 deletions spec/reporter_spec.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
var reporter = require(__dirname + "/../lib/jasmine-node/reporter");
var jasmineNode = require(__dirname + "/../lib/jasmine-node/reporter").jasmineNode;

describe('TerminalReporter', function() {
beforeEach(function() {
var config = {}
this.reporter = new reporter.TerminalReporter(config);
this.reporter = new jasmineNode.TerminalReporter(config);
});

describe("initialize", function() {
it('initializes print_ from config', function() {
var config = { print: true };
this.reporter = new reporter.TerminalReporter(config);
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.print_).toBeTruthy();
});

it('initializes color_ from config', function() {
var config = { color: true }
this.reporter = new reporter.TerminalReporter(config);
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.color_).toEqual(ANSIColors);
});

it('sets the started_ flag to false', function() {
var config = {}
this.reporter = new reporter.TerminalReporter(config);
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.started_).toBeFalsy();
});

it('sets the finished_ flag to false', function() {
var config = {}
this.reporter = new reporter.TerminalReporter(config);
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.finished_).toBeFalsy();
});

it('initializes the suites_ array', function() {
var config = {}
this.reporter = new reporter.TerminalReporter(config);
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.suites_.length).toEqual(0);
});

it('initializes the specResults_ to an Object', function() {
var config = {}
this.reporter = new reporter.TerminalReporter(config);
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.specResults_).toBeDefined();
});

it('initializes the failures_ array', function() {
var config = {}
this.reporter = new reporter.TerminalReporter(config);
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.failures_.length).toEqual(0);
});
});
Expand Down Expand Up @@ -278,3 +278,19 @@ describe('TerminalReporter', function() {
});
});
});

describe('TerminalVerboseReporter', function() {
beforeEach(function() {
var config = {}
this.verboseReporter = new jasmineNode.TerminalVerboseReporter(config);
});

it('does not build anything when the results collection is empty', function() {
var results = [],
messages = [];

this.verboseReporter.buildMessagesFromResult_(messages, results);

expect(messages.length).toEqual(0);
});
});

0 comments on commit 7ac94e0

Please sign in to comment.