jasmine-node
Advanced tools
Comparing version 1.0.17 to 1.0.18
@@ -1,260 +0,272 @@ | ||
// | ||
// Imports | ||
// | ||
var util; | ||
try { | ||
util = require('util') | ||
} catch(e) { | ||
util = require('sys') | ||
} | ||
(function() { | ||
// | ||
// Imports | ||
// | ||
var util; | ||
try { | ||
util = require('util') | ||
} catch(e) { | ||
util = require('sys') | ||
} | ||
// | ||
// Helpers | ||
// | ||
function noop() {} | ||
if (! jasmineNode) { | ||
var jasmineNode = {}; | ||
} | ||
ANSIColors = { | ||
pass: function() { return '\033[32m'; }, // Green | ||
fail: function() { return '\033[31m'; }, // Red | ||
neutral: function() { return '\033[0m'; } // Normal | ||
}; | ||
// | ||
// Helpers | ||
// | ||
function noop() {} | ||
NoColors = { | ||
pass: function() { return ''; }, | ||
fail: function() { return ''; }, | ||
neutral: function() { return ''; } | ||
}; | ||
jasmineNode.ANSIColors = { | ||
pass: function() { return '\033[32m'; }, // Green | ||
fail: function() { return '\033[31m'; }, // Red | ||
neutral: function() { return '\033[0m'; } // Normal | ||
}; | ||
var jasmineNode = {}; | ||
jasmineNode.NoColors = { | ||
pass: function() { return ''; }, | ||
fail: function() { return ''; }, | ||
neutral: function() { return ''; } | ||
}; | ||
jasmineNode.TerminalReporter = function(config) { | ||
this.print_ = config.print || util.print; | ||
this.color_ = config.color ? ANSIColors : NoColors; | ||
jasmineNode.TerminalReporter = function(config) { | ||
this.print_ = config.print || util.print; | ||
this.color_ = config.color ? jasmineNode.ANSIColors : jasmineNode.NoColors; | ||
this.started_ = false; | ||
this.finished_ = false; | ||
this.started_ = false; | ||
this.finished_ = false; | ||
this.suites_ = []; | ||
this.specResults_ = {}; | ||
this.failures_ = []; | ||
} | ||
jasmineNode.TerminalReporter.prototype.reportRunnerStarting = function(runner) { | ||
this.started_ = true; | ||
this.startedAt = new Date(); | ||
var suites = runner.topLevelSuites(); | ||
for (var i = 0; i < suites.length; i++) { | ||
var suite = suites[i]; | ||
this.suites_.push(this.summarize_(suite)); | ||
this.suites_ = []; | ||
this.specResults_ = {}; | ||
this.failures_ = []; | ||
} | ||
}; | ||
jasmineNode.TerminalReporter.prototype.summarize_ = function(suiteOrSpec) { | ||
var isSuite = suiteOrSpec instanceof jasmine.Suite; | ||
jasmineNode.TerminalReporter.prototype = { | ||
reportRunnerStarting: function(runner) { | ||
this.started_ = true; | ||
this.startedAt = new Date(); | ||
var suites = runner.topLevelSuites(); | ||
for (var i = 0; i < suites.length; i++) { | ||
var suite = suites[i]; | ||
this.suites_.push(this.summarize_(suite)); | ||
} | ||
}, | ||
// We could use a separate object for suite and spec | ||
var summary = { | ||
id: suiteOrSpec.id, | ||
name: suiteOrSpec.description, | ||
type: isSuite? 'suite' : 'spec', | ||
suiteNestingLevel: 0, | ||
children: [] | ||
}; | ||
summarize_: function(suiteOrSpec) { | ||
var isSuite = suiteOrSpec instanceof jasmine.Suite; | ||
// We could use a separate object for suite and spec | ||
var summary = { | ||
id: suiteOrSpec.id, | ||
name: suiteOrSpec.description, | ||
type: isSuite? 'suite' : 'spec', | ||
suiteNestingLevel: 0, | ||
children: [] | ||
}; | ||
if (isSuite) { | ||
var calculateNestingLevel = function(examinedSuite) { | ||
var nestingLevel = 0; | ||
while (examinedSuite.parentSuite !== null) { | ||
nestingLevel += 1; | ||
examinedSuite = examinedSuite.parentSuite; | ||
if (isSuite) { | ||
var calculateNestingLevel = function(examinedSuite) { | ||
var nestingLevel = 0; | ||
while (examinedSuite.parentSuite !== null) { | ||
nestingLevel += 1; | ||
examinedSuite = examinedSuite.parentSuite; | ||
} | ||
return nestingLevel; | ||
}; | ||
summary.suiteNestingLevel = calculateNestingLevel(suiteOrSpec); | ||
var children = suiteOrSpec.children(); | ||
for (var i = 0; i < children.length; i++) { | ||
summary.children.push(this.summarize_(children[i])); | ||
} | ||
} | ||
return nestingLevel; | ||
}; | ||
summary.suiteNestingLevel = calculateNestingLevel(suiteOrSpec); | ||
return summary; | ||
}, | ||
var children = suiteOrSpec.children(); | ||
for (var i = 0; i < children.length; i++) { | ||
summary.children.push(this.summarize_(children[i])); | ||
} | ||
} | ||
// This is heavily influenced by Jasmine's Html/Trivial Reporter | ||
reportRunnerResults: function(runner) { | ||
this.reportFailures_(); | ||
return summary; | ||
}; | ||
var results = runner.results(); | ||
var resultColor = (results.failedCount > 0) ? this.color_.fail() : this.color_.pass(); | ||
// This is heavily influenced by Jasmine's Html/Trivial Reporter | ||
jasmineNode.TerminalReporter.prototype.reportRunnerResults = function(runner) { | ||
this.reportFailures_(); | ||
var specs = runner.specs(); | ||
var specCount = specs.length; | ||
var results = runner.results(); | ||
var resultColor = (results.failedCount > 0) ? this.color_.fail() : this.color_.pass(); | ||
var message = "\n\nFinished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + " seconds"; | ||
this.printLine_(message); | ||
var specs = runner.specs(); | ||
var specCount = specs.length; | ||
// This is what jasmine-html.js has | ||
//message = "" + specCount + " spec" + ( specCount === 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount === 1) ? "" : "s"); | ||
var message = "\n\nFinished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + " seconds"; | ||
this.printLine_(message); | ||
this.printLine_(this.stringWithColor_(this.printRunnerResults_(runner), resultColor)); | ||
// This is what jasmine-html.js has | ||
//message = "" + specCount + " spec" + ( specCount === 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount === 1) ? "" : "s"); | ||
this.finished_ = true; | ||
}, | ||
this.printLine_(this.stringWithColor_(this.printRunnerResults_(runner), resultColor)); | ||
reportFailures_: function() { | ||
if (this.failures_.length === 0) { | ||
return; | ||
} | ||
this.finished_ = true; | ||
}; | ||
var indent = ' ', failure; | ||
this.printLine_('\n'); | ||
jasmineNode.TerminalReporter.prototype.reportFailures_ = function() { | ||
if (this.failures_.length == 0) { | ||
return; | ||
} | ||
var indent = ' ', failure; | ||
this.printLine_('\n'); | ||
this.print_('Failures:'); | ||
this.print_('Failures:'); | ||
for (var i = 0; i < this.failures_.length; i++) { | ||
failure = this.failures_[i]; | ||
this.printLine_('\n'); | ||
this.printLine_(' ' + (i + 1) + ') ' + failure.spec); | ||
this.printLine_(' Message:'); | ||
this.printLine_(' ' + this.stringWithColor_(failure.message, this.color_.fail())); | ||
this.printLine_(' Stacktrace:'); | ||
this.print_(' ' + failure.stackTrace); | ||
} | ||
}, | ||
for (var i = 0; i < this.failures_.length; i++) { | ||
failure = this.failures_[i]; | ||
this.printLine_('\n'); | ||
this.printLine_(' ' + (i + 1) + ') ' + failure.spec); | ||
this.printLine_(' Message:'); | ||
this.printLine_(' ' + this.stringWithColor_(failure.message, this.color_.fail())); | ||
this.printLine_(' Stacktrace:'); | ||
this.print_(' ' + failure.stackTrace); | ||
} | ||
}; | ||
reportSuiteResults: function(suite) { | ||
// Not used in this context | ||
}, | ||
jasmineNode.TerminalReporter.prototype.reportSuiteResults = function(suite) { | ||
// Not used in this context | ||
}; | ||
reportSpecResults: function(spec) { | ||
var result = spec.results(); | ||
var msg = ''; | ||
if (result.passed()) { | ||
msg = this.stringWithColor_('.', this.color_.pass()); | ||
// } else if (result.skipped) { TODO: Research why "result.skipped" returns false when "xit" is called on a spec? | ||
// msg = (colors) ? (ansi.yellow + '*' + ansi.none) : '*'; | ||
} else { | ||
msg = this.stringWithColor_('F', this.color_.fail()); | ||
this.addFailureToFailures_(spec); | ||
} | ||
this.spec_results += msg; | ||
this.print_(msg); | ||
}, | ||
jasmineNode.TerminalReporter.prototype.reportSpecResults = function(spec) { | ||
var result = spec.results(); | ||
var msg = ''; | ||
if (result.passed()) { | ||
msg = this.stringWithColor_('.', this.color_.pass()); | ||
// } else if (result.skipped) { TODO: Research why "result.skipped" returns false when "xit" is called on a spec? | ||
// msg = (colors) ? (ansi.yellow + '*' + ansi.none) : '*'; | ||
} else { | ||
msg = this.stringWithColor_('F', this.color_.fail()); | ||
this.addFailureToFailures_(spec); | ||
} | ||
this.spec_results += msg; | ||
this.print_(msg); | ||
}; | ||
addFailureToFailures_: function(spec) { | ||
var result = spec.results(); | ||
var failureItem = null; | ||
jasmineNode.TerminalReporter.prototype.addFailureToFailures_ = function(spec) { | ||
var result = spec.results(); | ||
var failureItem = null; | ||
var items_length = result.items_.length; | ||
for (var i = 0; i < items_length; i++) { | ||
if (result.items_[i].passed_ === false) { | ||
failureItem = result.items_[i]; | ||
var failure = { | ||
spec: spec.description, | ||
message: failureItem.message, | ||
stackTrace: failureItem.trace.stack | ||
} | ||
for (var i = 0; i < result.items_.length; i++) { | ||
if (result.items_[i].passed_ == false) { | ||
failureItem = result.items_[i]; | ||
var failure = { | ||
spec: spec.description, | ||
message: failureItem.message, | ||
stackTrace: failureItem.trace.stack | ||
this.failures_.push(failure); | ||
} | ||
} | ||
}, | ||
this.failures_.push(failure); | ||
printRunnerResults_: function(runner){ | ||
var results = runner.results(); | ||
var specs = runner.specs(); | ||
var msg = ''; | ||
msg += specs.length + ' test' + ((specs.length === 1) ? '' : 's') + ', '; | ||
msg += results.totalCount + ' assertion' + ((results.totalCount === 1) ? '' : 's') + ', '; | ||
msg += results.failedCount + ' failure' + ((results.failedCount === 1) ? '' : 's') + '\n'; | ||
return msg; | ||
}, | ||
// Helper Methods // | ||
stringWithColor_: function(stringValue, color) { | ||
return (color || this.color_.neutral()) + stringValue + this.color_.neutral(); | ||
}, | ||
printLine_: function(stringValue) { | ||
this.print_(stringValue); | ||
this.print_('\n'); | ||
} | ||
}; | ||
// *************************************************************** | ||
// TerminalVerboseReporter uses the TerminalReporter's constructor | ||
// *************************************************************** | ||
jasmineNode.TerminalVerboseReporter = function(config) { | ||
jasmineNode.TerminalReporter.call(this, config); | ||
// The extra field in this object | ||
this.indent_ = 0; | ||
} | ||
}; | ||
jasmineNode.TerminalReporter.prototype.printRunnerResults_ = function(runner){ | ||
var results = runner.results(); | ||
var specs = runner.specs(); | ||
var msg = ''; | ||
msg += specs.length + ' test' + ((specs.length === 1) ? '' : 's') + ', '; | ||
msg += results.totalCount + ' assertion' + ((results.totalCount === 1) ? '' : 's') + ', '; | ||
msg += results.failedCount + ' failure' + ((results.failedCount === 1) ? '' : 's') + '\n'; | ||
return msg; | ||
}; | ||
// Helper Methods // | ||
jasmineNode.TerminalReporter.prototype.stringWithColor_ = function(stringValue, color) { | ||
return (color || this.color_.neutral()) + stringValue + this.color_.neutral(); | ||
}; | ||
jasmineNode.TerminalVerboseReporter.prototype = { | ||
reportSpecResults: function(spec) { | ||
if (spec.results().failedCount > 0) { | ||
this.addFailureToFailures_(spec); | ||
} | ||
jasmineNode.TerminalReporter.prototype.printLine_ = function(stringValue) { | ||
this.print_(stringValue); | ||
this.print_('\n'); | ||
}; | ||
this.specResults_[spec.id] = { | ||
messages: spec.results().getItems(), | ||
result: spec.results().failedCount > 0 ? 'failed' : 'passed' | ||
}; | ||
}, | ||
// *************************************************************** | ||
// TerminalVerboseReporter uses the TerminalReporter's constructor | ||
// *************************************************************** | ||
jasmineNode.TerminalVerboseReporter = function(config) { | ||
jasmineNode.TerminalReporter.call(this, config); | ||
// The extra field in this object | ||
this.indent_ = 0; | ||
} | ||
reportRunnerResults: function(runner) { | ||
var messages = new Array(); | ||
this.buildMessagesFromResults_(messages, this.suites_); | ||
// Inherit from TerminalReporter | ||
jasmineNode.TerminalVerboseReporter.prototype.__proto__ = jasmineNode.TerminalReporter.prototype; | ||
var messages_length = messages.length; | ||
for (var i = 0; i < messages_length-1; i++) { | ||
this.printLine_(messages[i]); | ||
} | ||
jasmineNode.TerminalVerboseReporter.prototype.reportSpecResults = function(spec) { | ||
if (spec.results().failedCount > 0) { | ||
this.addFailureToFailures_(spec); | ||
} | ||
this.print_(messages[messages_length-1]); | ||
this.specResults_[spec.id] = { | ||
messages: spec.results().getItems(), | ||
result: spec.results().failedCount > 0 ? 'failed' : 'passed' | ||
}; | ||
}; | ||
// Call the parent object's method | ||
jasmineNode.TerminalReporter.prototype.reportRunnerResults.call(this, runner); | ||
}, | ||
jasmineNode.TerminalVerboseReporter.prototype.reportRunnerResults = function(runner) { | ||
var messages = new Array(); | ||
this.buildMessagesFromResults_(messages, this.suites_); | ||
buildMessagesFromResults_: function(messages, results) { | ||
var element, specResult, specIndentSpaces, msg = ''; | ||
for (var i=0; i<messages.length-1; i++) { | ||
this.printLine_(messages[i]); | ||
} | ||
var results_length = results.length; | ||
for (var i = 0; i < results_length; i++) { | ||
element = results[i]; | ||
this.print_(messages[messages.length-1]); | ||
if (element.type === 'spec') { | ||
specResult = this.specResults_[element.id.toString()]; | ||
// Call the parent object's method | ||
jasmineNode.TerminalReporter.prototype.reportRunnerResults.call(this, runner); | ||
}; | ||
specIndentSpaces = this.indent_ + 2; | ||
if (specResult.result === 'passed') { | ||
msg = this.stringWithColor_(this.indentMessage_(element.name, specIndentSpaces), this.color_.pass()); | ||
} else { | ||
msg = this.stringWithColor_(this.indentMessage_(element.name, specIndentSpaces), this.color_.fail()); | ||
} | ||
jasmineNode.TerminalVerboseReporter.prototype.buildMessagesFromResults_ = function(messages, results) { | ||
var element, specResult, specIndentSpaces, msg = ''; | ||
messages.push(msg); | ||
} else { | ||
this.indent_ = element.suiteNestingLevel * 2; | ||
for (var i = 0; i < results.length; i++) { | ||
element = results[i]; | ||
messages.push(''); | ||
messages.push(this.indentMessage_(element.name, this.indent_)); | ||
} | ||
if (element.type === 'spec') { | ||
specResult = this.specResults_[element.id.toString()]; | ||
this.buildMessagesFromResults_(messages, element.children); | ||
} | ||
}, | ||
specIndentSpaces = this.indent_ + 2; | ||
if (specResult.result === 'passed') { | ||
msg = this.stringWithColor_(this.indentMessage_(element.name, specIndentSpaces), this.color_.pass()); | ||
} else { | ||
msg = this.stringWithColor_(this.indentMessage_(element.name, specIndentSpaces), this.color_.fail()); | ||
indentMessage_: function(message, indentCount) { | ||
var _indent = ''; | ||
for (var i = 0; i < indentCount; i++) { | ||
_indent += ' '; | ||
} | ||
messages.push(msg); | ||
} else { | ||
this.indent_ = element.suiteNestingLevel * 2; | ||
messages.push(''); | ||
messages.push(this.indentMessage_(element.name, this.indent_)); | ||
return (_indent + message); | ||
} | ||
}; | ||
this.buildMessagesFromResults_(messages, element.children); | ||
} | ||
}; | ||
// Inherit from TerminalReporter | ||
jasmineNode.TerminalVerboseReporter.prototype.__proto__ = jasmineNode.TerminalReporter.prototype; | ||
jasmineNode.TerminalVerboseReporter.prototype.indentMessage_ = function(message, indentCount) { | ||
var _indent = ''; | ||
for (var i = 0; i < indentCount; i++) { | ||
_indent += ' '; | ||
} | ||
return (_indent + message); | ||
}; | ||
// | ||
// Exports | ||
// | ||
exports.jasmineNode = jasmineNode; | ||
// | ||
// Exports | ||
// | ||
exports.jasmineNode = jasmineNode; | ||
})(); |
@@ -30,3 +30,3 @@ exports.executeJsRunner = function(specCollection, done, jasmineEnv) { | ||
for(var i = 0; i < colonMatches.length; i++){ | ||
for(var i = 0; i < (colonMatches && colonMatches.length) || 0; i++){ | ||
thisDir = thisDir.replace(colonMatches[i], '\\' + colonMatches[i].substring(0,1)); | ||
@@ -60,3 +60,3 @@ } | ||
for(var i = 0; i < colonMatches.length; i++){ | ||
for(var i = 0; i < (colonMatches && colonMatches.length) || 0; i++){ | ||
dir = dir.replace(colonMatches[i], '/' + colonMatches[i].substring(0,1)); | ||
@@ -63,0 +63,0 @@ } |
{ | ||
"name" : "jasmine-node" | ||
, "version" : "1.0.17" | ||
, "version" : "1.0.18" | ||
, "description" : "DOM-less simple JavaScript BDD testing framework for Node" | ||
@@ -5,0 +5,0 @@ , "homepage" : [ "http://pivotal.github.com/jasmine" |
@@ -40,1 +40,16 @@ jasmine-node | ||
Checkout spec/SampleSpecs.js to see how to use it. | ||
development | ||
----------- | ||
Install the dependent packages by running: | ||
npm install | ||
Run the specs before you send your pull request: | ||
scripts/specs | ||
or | ||
scripts/specs --verbose |
@@ -19,3 +19,3 @@ var jasmineNode = require(__dirname + "/../lib/jasmine-node/reporter").jasmineNode; | ||
this.reporter = new jasmineNode.TerminalReporter(config); | ||
expect(this.reporter.color_).toEqual(ANSIColors); | ||
expect(this.reporter.color_).toEqual(jasmineNode.ANSIColors); | ||
}); | ||
@@ -22,0 +22,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
139362
36
3422
55