rake tasks use console reporter

This commit is contained in:
Corey Johnson 2012-03-15 10:15:06 -07:00
parent ef9673a145
commit 80641636f9
2 changed files with 20 additions and 148 deletions

View File

@ -1,6 +1,7 @@
{$$} = require 'space-pen'
nakedLoad 'jasmine'
nakedLoad 'jasmine-atom-reporter'
nakedLoad 'jasmine-console-reporter'
nakedLoad 'jasmine-focused'
$ = require 'jquery'
@ -13,13 +14,14 @@ $('head').append $$ ->
$('body').append $$ ->
@div id: 'jasmine-content'
jasmineEnv = jasmine.getEnv()
atomReporter = new jasmine.AtomReporter(document)
jasmineEnv.addReporter(atomReporter)
jasmineEnv.specFilter = (spec) -> atomReporter.specFilter(spec)
reporter = if atom.exitAfterSpecs
new jasmine.ConsoleReporter(document)
else
new jasmine.AtomReporter(document)
require 'spec-suite'
jasmineEnv = jasmine.getEnv()
jasmineEnv.addReporter(reporter)
jasmineEnv.specFilter = (spec) -> reporter.specFilter(spec)
jasmineEnv.execute()

View File

@ -1,175 +1,45 @@
jasmine.AtomReporter = function(doc, logRunningSpecs) {
this.document = doc || document;
this.suiteDivs = {};
this.logRunningSpecs = logRunningSpecs == false ? false : true;
jasmine.ConsoleReporter = function(doc) {
};
jasmine.AtomReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
var el = document.createElement(type);
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child === 'string') {
el.appendChild(document.createTextNode(child));
} else {
if (child) { el.appendChild(child); }
}
}
for (var attr in attrs) {
if (attr == "className") {
el[attr] = attrs[attr];
} else {
el.setAttribute(attr, attrs[attr]);
}
}
return el;
};
jasmine.AtomReporter.prototype.reportRunnerStarting = function(runner) {
jasmine.ConsoleReporter.prototype.reportRunnerStarting = function(runner) {
var showPassed, showSkipped;
this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
this.createDom('div', { className: 'banner' },
this.createDom('div', { className: 'logo' },
this.createDom('span', { className: 'title' }, "Jasmine"),
this.createDom('span', { className: 'version' }, runner.env.versionString())),
this.createDom('div', { className: 'options' },
"Show ",
showPassed = this.createDom('input', { id: "__jasmine_AtomReporter_showPassed__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_AtomReporter_showPassed__" }, " passed "),
showSkipped = this.createDom('input', { id: "__jasmine_AtomReporter_showSkipped__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_AtomReporter_showSkipped__" }, " skipped")
)
),
this.runnerDiv = this.createDom('div', { className: 'runner running' },
this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
);
this.document.body.appendChild(this.outerDiv);
var suites = runner.suites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
var suiteDiv = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
this.suiteDivs[suite.id] = suiteDiv;
var parentDiv = this.outerDiv;
if (suite.parentSuite) {
parentDiv = this.suiteDivs[suite.parentSuite.id];
}
parentDiv.appendChild(suiteDiv);
}
this.startedAt = new Date();
var self = this;
showPassed.onclick = function(evt) {
if (showPassed.checked) {
self.outerDiv.className += ' show-passed';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
}
};
showSkipped.onclick = function(evt) {
if (showSkipped.checked) {
self.outerDiv.className += ' show-skipped';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
}
};
};
jasmine.AtomReporter.prototype.reportRunnerResults = function(runner) {
jasmine.ConsoleReporter.prototype.reportRunnerResults = function(runner) {
var results = runner.results();
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
this.runnerDiv.setAttribute("class", className);
var specs = runner.specs();
var specCount = 0;
for (var i = 0; i < specs.length; i++) {
if (this.specFilter(specs[i])) {
specCount++;
}
}
var specCount = specs.legnth;
var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
if (atom.exitAfterSpecs) $native.exit(results.failedCount > 0 ? 1 : 0)
$native.exit(results.failedCount > 0 ? 1 : 0)
};
jasmine.AtomReporter.prototype.reportSuiteResults = function(suite) {
var results = suite.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.totalCount === 0) { // todo: change this to check results.skipped
status = 'skipped';
}
this.suiteDivs[suite.id].className += " " + status;
jasmine.ConsoleReporter.prototype.reportSuiteResults = function(suite) {
};
jasmine.AtomReporter.prototype.reportSpecResults = function(spec) {
jasmine.ConsoleReporter.prototype.reportSpecResults = function(spec) {
var results = spec.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';
}
var specDiv = this.createDom('div', { className: 'spec ' + status },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(spec.getFullName()),
title: spec.getFullName()
}, spec.description));
var resultItems = results.getItems();
var messagesDiv = this.createDom('div', { className: 'messages' });
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'log') {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
} else if (result.type == 'expect' && result.passed && !result.passed()) {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
if (this.logRunningSpecs) console.log(spec.getFullName())
if (result.type == 'expect' && result.passed && !result.passed()) {
console.log(spec.getFullName())
if (result.trace.stack) {
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
if (this.logRunningSpecs) console.log(result.trace.stack)
console.log(result.trace.stack)
}
}
}
if (messagesDiv.childNodes.length > 0) {
specDiv.appendChild(messagesDiv);
}
this.suiteDivs[spec.suite.id].appendChild(specDiv);
};
jasmine.AtomReporter.prototype.getLocation = function() {
return this.document.location;
};
jasmine.AtomReporter.prototype.specFilter = function(spec) {
var paramMap = {};
var params = this.getLocation().search.substring(1).split('&');
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
if (!paramMap.spec) {
return true;
}
return spec.getFullName().indexOf(paramMap.spec) === 0;
jasmine.ConsoleReporter.prototype.specFilter = function(spec) {
return true;
};