Skip to content

Commit

Permalink
Provide a more coherent display of specs, fails, and skipped.
Browse files Browse the repository at this point in the history
  • Loading branch information
emackey committed Jan 23, 2013
1 parent 32a48f6 commit 676b68c
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 21 deletions.
99 changes: 79 additions & 20 deletions ThirdParty/jasmine-1.3.1/jasmine-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ jasmine.HtmlReporterHelpers.appendToSummary = function(child, childElement) {
parentDiv.appendChild(childElement);
};

jasmine.HtmlReporterHelpers.appendToSkipped = function(child, childElement) {
var parentDiv = this.dom.skipped;
var parentSuite = (typeof child.parentSuite == 'undefined') ? 'suite' : 'parentSuite';
var parent = child[parentSuite];

if (parent) {
if (typeof this.views.suites[parent.id] == 'undefined') {
this.views.suites[parent.id] = new jasmine.HtmlReporter.SuiteView(parent, this.dom, this.views, 'skipped');
}
parentDiv = this.views.suites[parent.id].element;
}

parentDiv.appendChild(childElement);
};


jasmine.HtmlReporterHelpers.addHelpers = function(ctor) {
for(var fn in jasmine.HtmlReporterHelpers) {
Expand Down Expand Up @@ -368,7 +383,8 @@ jasmine.HtmlReporter = function(_doc) {
self.createDom('input', { type: 'button', value: 'run with coverage', id: 'runCoverageButton' }, 'run with coverage'))),
dom.results = self.createDom('div', {className: 'results'},
dom.summary = self.createDom('div', { className: 'summary' }),
dom.details = self.createDom('div', { id: 'details' }))
dom.details = self.createDom('div', { id: 'details' }),
dom.skipped = self.createDom('div', { id: 'skipped' }))
);
}

Expand Down Expand Up @@ -440,16 +456,26 @@ jasmine.HtmlReporter.ReporterView = function(dom) {

this.createResultsMenu = function() {
this.resultsMenu = this.createDom('span', {className: 'resultsMenu bar'},
'View: ',
this.summaryMenuItem = this.createDom('a', {className: 'summaryMenuItem', href: "#"}, '0 specs'),
' | ',
this.detailsMenuItem = this.createDom('a', {className: 'detailsMenuItem', href: "#"}, '0 failing'));
this.detailsMenuItem = this.createDom('a', {className: 'detailsMenuItem', href: "#"}, '0 failing'),
' | ',
this.skippedMenuItem = this.createDom('a', {className: 'skippedMenuItem', href: "#"}, '0 skipped'));

this.summaryMenuItem.onclick = function() {
dom.reporter.className = dom.reporter.className.replace(/ showDetails/g, '');
showSpecs();
return false; // Don't append a # to the URL in the address bar.
};

this.detailsMenuItem.onclick = function() {
showDetails();
return false; // Don't append a # to the URL in the address bar.
};

this.skippedMenuItem.onclick = function() {
showSkipped();
return false; // Don't append a # to the URL in the address bar.
};
};

Expand Down Expand Up @@ -547,16 +573,24 @@ jasmine.HtmlReporter.ReporterView = function(dom) {
}

var specView = this.views.specs[spec.id];
var name = encodeURIComponent(spec.getFullName());
var name = encodeURIComponent(spec.getFullName());

var runTime = '', status = specView.status();
if (isDefined(spec.runTime)) {
runTime = ' (' + (spec.runTime / 1000) + 's)';
}
if (status === 'skipped') {
runTime += ' (skipped)';
}

specView.summary.appendChild(this.createDom('span', {className: 'specTime'},
this.createDom('a', {className: 'run_spec', href: '?spec=' + name}, 'run'),
this.createDom('a', {className: 'run_spec', href: '../Instrumented/jscoverage.html?../Specs/SpecRunner.html' +
specView.summary.appendChild(this.createDom('span', {className: 'specTime'},
this.createDom('a', {className: 'run_spec', href: '?spec=' + name}, 'run'),
this.createDom('a', {className: 'run_spec', href: '../Instrumented/jscoverage.html?../Specs/SpecRunner.html' +
window.encodeURIComponent('?baseUrl=../Instrumented&spec=' + name), target: '_top' }, "coverage"),
this.createDom('a', {className: 'run_spec', href: '?spec=' + name + '&debug=' + name}, 'debug'),
' (' + (spec.runTime / 1000) + 's)'));
this.createDom('a', {className: 'run_spec', href: '?spec=' + name + '&debug=' + name}, 'debug'),
runTime));

switch (specView.status()) {
switch (status) {
case 'passed':
this.passedCount++;
break;
Expand Down Expand Up @@ -586,12 +620,17 @@ jasmine.HtmlReporter.ReporterView = function(dom) {
return;
}

var runTime = '';
if (isDefined(suite.runTime)) {
runTime = ' (' + (suite.runTime / 1000) + 's)';
}

var name = encodeURIComponent(suite.getFullName());
suiteView.element.insertBefore(this.createDom('span', {className: 'suiteTime'},
this.createDom('a', {className: 'run_spec', href: '?spec=' + name, target: '_top'}, 'run'),
this.createDom('a', {className: 'run_spec', href: '../Instrumented/jscoverage.html?../Specs/SpecRunner.html' +
window.encodeURIComponent('?baseUrl=../Instrumented&spec=' + name), target: '_top' }, "coverage"),
' (' + (suite.runTime / 1000) + 's)'), suiteView.element.getElementsByTagName('a')[2].nextSibling);
runTime), suiteView.element.getElementsByTagName('a')[2].nextSibling);


suiteView.refresh();
Expand All @@ -601,6 +640,7 @@ jasmine.HtmlReporter.ReporterView = function(dom) {

if (isUndefined(this.resultsMenu)) {
this.createResultsMenu();
dom.reporter.insertBefore(this.resultsMenu, dom.results);
}

if (isUndefined(this.categoryMenu)) {
Expand Down Expand Up @@ -643,20 +683,22 @@ jasmine.HtmlReporter.ReporterView = function(dom) {

if (this.failedCount === 1 && isDefined(dom.alert)) {
dom.alert.appendChild(this.failedAlert);
dom.alert.appendChild(this.resultsMenu);
}

// summary info
this.summaryMenuItem.innerHTML = "" + specPluralizedFor(this.runningSpecCount) + " (view summary)";
this.detailsMenuItem.innerHTML = "" + this.failedCount + " failing (view detail)";
this.summaryMenuItem.innerHTML = "" + specPluralizedFor(this.runningSpecCount);
this.detailsMenuItem.innerHTML = "" + this.failedCount + ' failing';
this.skippedMenuItem.innerHTML = "" + this.skippedCount + ' skipped';
};

this.complete = function() {
dom.alert.removeChild(this.runningAlert);

this.skippedAlert.innerHTML = "Ran " + this.runningSpecCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";

if (this.failedCount === 0) {
if (this.failedCount === 0 && this.passedCount === 0) {
showSkipped();
} else if (this.failedCount === 0) {
dom.alert.appendChild(this.createDom('span', {className: 'passingAlert bar'}, "Passing " + specPluralizedFor(this.passedCount)));
} else {
showDetails();
Expand All @@ -667,11 +709,23 @@ jasmine.HtmlReporter.ReporterView = function(dom) {

return this;

function showSpecs() {
dom.reporter.className = dom.reporter.className.replace(/ showDetails/g, '').replace(/ showSkipped/g, '');
}

function showDetails() {
if (dom.reporter.className.search(/showDetails/) === -1) {
dom.reporter.className += " showDetails";
if (dom.reporter.className.search(/showDetails/) === -1) {
dom.reporter.className = dom.reporter.className.replace(/ showSkipped/g, '');
dom.reporter.className += " showDetails";
}
}

function showSkipped() {
if (dom.reporter.className.search(/showSkipped/) === -1) {
dom.reporter.className = dom.reporter.className.replace(/ showDetails/g, '');
dom.reporter.className += " showSkipped";
}
}
}

function isUndefined(obj) {
return typeof obj === 'undefined';
Expand Down Expand Up @@ -728,6 +782,7 @@ jasmine.HtmlReporter.SpecView.prototype.refresh = function() {

switch (this.status()) {
case 'skipped':
this.appendToSkipped(this.spec, this.summary);
break;

case 'passed':
Expand Down Expand Up @@ -774,7 +829,7 @@ jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() {

jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView);

jasmine.HtmlReporter.SuiteView = function(suite, dom, views) {
jasmine.HtmlReporter.SuiteView = function(suite, dom, views, skipped) {
this.suite = suite;
this.dom = dom;
this.views = views;
Expand Down Expand Up @@ -805,7 +860,11 @@ jasmine.HtmlReporter.SuiteView = function(suite, dom, views) {
};
}(this.element));

this.appendToSummary(this.suite, this.element);
if (typeof skipped !== 'undefined') {
this.appendToSkipped(this.suite, this.element);
} else {
this.appendToSummary(this.suite, this.element);
}
};

jasmine.HtmlReporter.SuiteView.prototype.status = function() {
Expand Down
8 changes: 7 additions & 1 deletion ThirdParty/jasmine-1.3.1/jasmine.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
#HTMLReporter a { text-decoration: none; }
#HTMLReporter a:hover { text-decoration: underline; }
#HTMLReporter p, #HTMLReporter h1, #HTMLReporter h2, #HTMLReporter h3, #HTMLReporter h4, #HTMLReporter h5, #HTMLReporter h6 { margin: 0; line-height: 14px; }
#HTMLReporter .banner, #HTMLReporter .symbolSummary, #HTMLReporter .summary, #HTMLReporter .resultMessage, #HTMLReporter .specDetail .description, #HTMLReporter .alert .bar, #HTMLReporter .stackTrace { padding-left: 9px; padding-right: 9px; }
#HTMLReporter .banner, #HTMLReporter .symbolSummary, #HTMLReporter .summary, #HTMLReporter .resultMessage, #HTMLReporter .specDetail .description, #HTMLReporter .alert .bar, #HTMLReporter .resultsMenu, #HTMLReporter .stackTrace { padding-left: 9px; padding-right: 9px; }
#HTMLReporter #jasmine_content { position: fixed; right: 100%; }
#HTMLReporter .version { color: #aaaaaa; }
#HTMLReporter .banner { margin-top: 14px; }
Expand All @@ -104,12 +104,18 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
#HTMLReporter .failingAlert:first-child { background-color: #b03911; }
#HTMLReporter .results { margin-top: 14px; }
#HTMLReporter #details { display: none; }
#HTMLReporter #skipped { display: none; }
#HTMLReporter .resultsMenu, #HTMLReporter .resultsMenu a { background-color: #fff; color: #333333; }
#HTMLReporter.showDetails .summaryMenuItem { font-weight: normal; text-decoration: inherit; }
#HTMLReporter.showDetails .summaryMenuItem:hover { text-decoration: underline; }
#HTMLReporter.showDetails .detailsMenuItem { font-weight: bold; text-decoration: underline; }
#HTMLReporter.showDetails .summary { display: none; }
#HTMLReporter.showDetails #details { display: block; }
#HTMLReporter.showSkipped .summaryMenuItem { font-weight: normal; text-decoration: inherit; }
#HTMLReporter.showSkipped .summaryMenuItem:hover { text-decoration: underline; }
#HTMLReporter.showSkipped .skippedMenuItem { font-weight: bold; text-decoration: underline; }
#HTMLReporter.showSkipped .summary { display: none; }
#HTMLReporter.showSkipped #skipped { display: block; }
#HTMLReporter .summaryMenuItem { font-weight: bold; text-decoration: underline; }
#HTMLReporter .summary { margin-top: 14px; }
#HTMLReporter .summary .suite .suite, #HTMLReporter .summary .specSummary { margin-left: 14px; }
Expand Down

0 comments on commit 676b68c

Please sign in to comment.