From 1771ec3c633fdc91ae8a32890cb352f5a79bc471 Mon Sep 17 00:00:00 2001 From: Alex Kwiatkowski Date: Sun, 15 Apr 2012 17:45:50 -0400 Subject: [PATCH] Add checkbox to test runner which toggles catching of exceptions during tests --- lib/jasmine-core/jasmine-html.js | 89 ++++++++++++++++++++++++++----- lib/jasmine-core/jasmine.css | 1 + lib/jasmine-core/jasmine.js | 2 +- src/html/HtmlReporter.js | 70 ++++++++++++++++++++++-- src/html/ReporterView.js | 6 +-- src/html/SpecView.js | 10 ++-- src/html/SuiteView.js | 2 +- src/html/_HTMLReporter.scss | 91 +++++++++++++++++--------------- src/html/jasmine.css | 1 + 9 files changed, 205 insertions(+), 67 deletions(-) diff --git a/lib/jasmine-core/jasmine-html.js b/lib/jasmine-core/jasmine-html.js index a0b06394..157f7e85 100644 --- a/lib/jasmine-core/jasmine-html.js +++ b/lib/jasmine-core/jasmine-html.js @@ -78,6 +78,7 @@ jasmine.HtmlReporter = function(_doc) { createReporterDom(runner.env.versionString()); doc.body.appendChild(dom.reporter); + setExceptionHandling(); reporterView = new jasmine.HtmlReporter.ReporterView(dom); reporterView.addSpecs(specs, self.specFilter); @@ -131,7 +132,7 @@ jasmine.HtmlReporter = function(_doc) { } var paramMap = []; - var params = doc.location.search.substring(1).split('&'); + var params = jasmine.HtmlReporter.parameters(doc); for (var i = 0; i < params.length; i++) { var p = params[i].split('='); @@ -151,14 +152,78 @@ jasmine.HtmlReporter = function(_doc) { self.createDom('span', { className: 'version' }, version)), dom.symbolSummary = self.createDom('ul', {className: 'symbolSummary'}), - dom.alert = self.createDom('div', {className: 'alert'}), + dom.alert = self.createDom('div', {className: 'alert'}, + self.createDom('span', { className: 'exceptions' }, + self.createDom('label', { className: 'label', for: 'no_try_catch' }, 'No try/catch'), + self.createDom('input', { id: 'no_try_catch', type: 'checkbox' }))), dom.results = self.createDom('div', {className: 'results'}, dom.summary = self.createDom('div', { className: 'summary' }), dom.details = self.createDom('div', { id: 'details' })) ); } + + function noTryCatch() { + return window.location.search.match(/catch=false/); + } + + function searchWithCatch() { + var params = jasmine.HtmlReporter.parameters(window.document); + var removed = false; + var i = 0; + + while (!removed && i < params.length) { + if (params[i].match(/catch=/)) { + params.splice(i, 1); + removed = true; + } + i++; + } + if (jasmine.CATCH_EXCEPTIONS) { + params.push("catch=false"); + } + + return params.join("&"); + } + + function setExceptionHandling() { + var chxCatch = document.getElementById('no_try_catch'); + + if (noTryCatch()) { + chxCatch.setAttribute('checked', true); + jasmine.CATCH_EXCEPTIONS = false; + } + chxCatch.onclick = function() { + window.location.search = searchWithCatch(); + }; + } }; -jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);jasmine.HtmlReporter.ReporterView = function(dom) { +jasmine.HtmlReporter.parameters = function(doc) { + var paramStr = doc.location.search.substring(1); + var params = []; + + if (paramStr.length > 0) { + params = paramStr.split('&'); + } + return params; +} +jasmine.HtmlReporter.sectionLink = function(sectionName) { + var link = '?'; + var params = []; + + if (sectionName) { + params.push('spec=' + encodeURIComponent(sectionName)); + } + if (!jasmine.CATCH_EXCEPTIONS) { + params.push("catch=false"); + } + if (params.length > 0) { + link += params.join("&"); + } + + return link; +}; +jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter); +jasmine.HtmlReporter.ReporterView = function(dom) { this.startedAt = new Date(); this.runningSpecCount = 0; this.completeSpecCount = 0; @@ -241,14 +306,14 @@ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);jasmine.HtmlReporte // currently running UI if (isUndefined(this.runningAlert)) { - this.runningAlert = this.createDom('a', {href: "?", className: "runningAlert bar"}); + this.runningAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "runningAlert bar" }); dom.alert.appendChild(this.runningAlert); } this.runningAlert.innerHTML = "Running " + this.completeSpecCount + " of " + specPluralizedFor(this.totalSpecCount); // skipped specs UI if (isUndefined(this.skippedAlert)) { - this.skippedAlert = this.createDom('a', {href: "?", className: "skippedAlert bar"}); + this.skippedAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "skippedAlert bar" }); } this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all"; @@ -259,7 +324,7 @@ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);jasmine.HtmlReporte // passing specs UI if (isUndefined(this.passedAlert)) { - this.passedAlert = this.createDom('span', {href: "?", className: "passingAlert bar"}); + this.passedAlert = this.createDom('span', { href: jasmine.HtmlReporter.sectionLink(), className: "passingAlert bar" }); } this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount); @@ -331,11 +396,11 @@ jasmine.HtmlReporter.SpecView = function(spec, dom, views) { this.dom.symbolSummary.appendChild(this.symbol); this.summary = this.createDom('div', { className: 'specSummary' }, - this.createDom('a', { - className: 'description', - href: '?spec=' + encodeURIComponent(this.spec.getFullName()), - title: this.spec.getFullName() - }, this.spec.description) + this.createDom('a', { + className: 'description', + href: jasmine.HtmlReporter.sectionLink(this.spec.getFullName()), + title: this.spec.getFullName() + }, this.spec.description) ); this.detail = this.createDom('div', { className: 'specDetail' }, @@ -406,7 +471,7 @@ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView);jasmine.Ht this.views = views; this.element = this.createDom('div', { className: 'suite' }, - this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(this.suite.getFullName()) }, this.suite.description) + this.createDom('a', { className: 'description', href: jasmine.HtmlReporter.sectionLink(this.suite.getFullName()) }, this.suite.description) ); this.appendToSummary(this.suite, this.element); diff --git a/lib/jasmine-core/jasmine.css b/lib/jasmine-core/jasmine.css index 826e5753..8c008dc7 100644 --- a/lib/jasmine-core/jasmine.css +++ b/lib/jasmine-core/jasmine.css @@ -19,6 +19,7 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; } #HTMLReporter .symbolSummary li.skipped:before { color: #bababa; content: "\02022"; } #HTMLReporter .symbolSummary li.pending { line-height: 11px; } #HTMLReporter .symbolSummary li.pending:before { color: #aaaaaa; content: "-"; } +#HTMLReporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; } #HTMLReporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; } #HTMLReporter .runningAlert { background-color: #666666; } #HTMLReporter .skippedAlert { background-color: #aaaaaa; } diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index c7d4eb55..6bac2236 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -2537,5 +2537,5 @@ jasmine.version_= { "major": 1, "minor": 2, "build": 0, - "revision": 1337005947 + "revision": 1337006083 }; diff --git a/src/html/HtmlReporter.js b/src/html/HtmlReporter.js index b69fc9d1..b5d062b8 100644 --- a/src/html/HtmlReporter.js +++ b/src/html/HtmlReporter.js @@ -18,6 +18,7 @@ jasmine.HtmlReporter = function(_doc) { createReporterDom(runner.env.versionString()); doc.body.appendChild(dom.reporter); + setExceptionHandling(); reporterView = new jasmine.HtmlReporter.ReporterView(dom); reporterView.addSpecs(specs, self.specFilter); @@ -71,7 +72,7 @@ jasmine.HtmlReporter = function(_doc) { } var paramMap = []; - var params = doc.location.search.substring(1).split('&'); + var params = jasmine.HtmlReporter.parameters(doc); for (var i = 0; i < params.length; i++) { var p = params[i].split('='); @@ -91,11 +92,74 @@ jasmine.HtmlReporter = function(_doc) { self.createDom('span', { className: 'version' }, version)), dom.symbolSummary = self.createDom('ul', {className: 'symbolSummary'}), - dom.alert = self.createDom('div', {className: 'alert'}), + dom.alert = self.createDom('div', {className: 'alert'}, + self.createDom('span', { className: 'exceptions' }, + self.createDom('label', { className: 'label', for: 'no_try_catch' }, 'No try/catch'), + self.createDom('input', { id: 'no_try_catch', type: 'checkbox' }))), dom.results = self.createDom('div', {className: 'results'}, dom.summary = self.createDom('div', { className: 'summary' }), dom.details = self.createDom('div', { id: 'details' })) ); } + + function noTryCatch() { + return window.location.search.match(/catch=false/); + } + + function searchWithCatch() { + var params = jasmine.HtmlReporter.parameters(window.document); + var removed = false; + var i = 0; + + while (!removed && i < params.length) { + if (params[i].match(/catch=/)) { + params.splice(i, 1); + removed = true; + } + i++; + } + if (jasmine.CATCH_EXCEPTIONS) { + params.push("catch=false"); + } + + return params.join("&"); + } + + function setExceptionHandling() { + var chxCatch = document.getElementById('no_try_catch'); + + if (noTryCatch()) { + chxCatch.setAttribute('checked', true); + jasmine.CATCH_EXCEPTIONS = false; + } + chxCatch.onclick = function() { + window.location.search = searchWithCatch(); + }; + } }; -jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter); \ No newline at end of file +jasmine.HtmlReporter.parameters = function(doc) { + var paramStr = doc.location.search.substring(1); + var params = []; + + if (paramStr.length > 0) { + params = paramStr.split('&'); + } + return params; +} +jasmine.HtmlReporter.sectionLink = function(sectionName) { + var link = '?'; + var params = []; + + if (sectionName) { + params.push('spec=' + encodeURIComponent(sectionName)); + } + if (!jasmine.CATCH_EXCEPTIONS) { + params.push("catch=false"); + } + if (params.length > 0) { + link += params.join("&"); + } + + return link; +}; +jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter); diff --git a/src/html/ReporterView.js b/src/html/ReporterView.js index 6a6d0056..419accec 100644 --- a/src/html/ReporterView.js +++ b/src/html/ReporterView.js @@ -81,14 +81,14 @@ jasmine.HtmlReporter.ReporterView = function(dom) { // currently running UI if (isUndefined(this.runningAlert)) { - this.runningAlert = this.createDom('a', {href: "?", className: "runningAlert bar"}); + this.runningAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "runningAlert bar" }); dom.alert.appendChild(this.runningAlert); } this.runningAlert.innerHTML = "Running " + this.completeSpecCount + " of " + specPluralizedFor(this.totalSpecCount); // skipped specs UI if (isUndefined(this.skippedAlert)) { - this.skippedAlert = this.createDom('a', {href: "?", className: "skippedAlert bar"}); + this.skippedAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "skippedAlert bar" }); } this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all"; @@ -99,7 +99,7 @@ jasmine.HtmlReporter.ReporterView = function(dom) { // passing specs UI if (isUndefined(this.passedAlert)) { - this.passedAlert = this.createDom('span', {href: "?", className: "passingAlert bar"}); + this.passedAlert = this.createDom('span', { href: jasmine.HtmlReporter.sectionLink(), className: "passingAlert bar" }); } this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount); diff --git a/src/html/SpecView.js b/src/html/SpecView.js index 8769bb84..b9bcf08a 100644 --- a/src/html/SpecView.js +++ b/src/html/SpecView.js @@ -7,11 +7,11 @@ jasmine.HtmlReporter.SpecView = function(spec, dom, views) { this.dom.symbolSummary.appendChild(this.symbol); this.summary = this.createDom('div', { className: 'specSummary' }, - this.createDom('a', { - className: 'description', - href: '?spec=' + encodeURIComponent(this.spec.getFullName()), - title: this.spec.getFullName() - }, this.spec.description) + this.createDom('a', { + className: 'description', + href: jasmine.HtmlReporter.sectionLink(this.spec.getFullName()), + title: this.spec.getFullName() + }, this.spec.description) ); this.detail = this.createDom('div', { className: 'specDetail' }, diff --git a/src/html/SuiteView.js b/src/html/SuiteView.js index 19a1efaf..a7f433f5 100644 --- a/src/html/SuiteView.js +++ b/src/html/SuiteView.js @@ -4,7 +4,7 @@ jasmine.HtmlReporter.SuiteView = function(suite, dom, views) { this.views = views; this.element = this.createDom('div', { className: 'suite' }, - this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(this.suite.getFullName()) }, this.suite.description) + this.createDom('a', { className: 'description', href: jasmine.HtmlReporter.sectionLink(this.suite.getFullName()) }, this.suite.description) ); this.appendToSummary(this.suite, this.element); diff --git a/src/html/_HTMLReporter.scss b/src/html/_HTMLReporter.scss index 8abbddf2..04f42cca 100644 --- a/src/html/_HTMLReporter.scss +++ b/src/html/_HTMLReporter.scss @@ -136,167 +136,174 @@ body { } } } - + + .exceptions { + color: #fff; + float: right; + margin-top: 5px; + margin-right: 5px; + } + //--- Alert ---// - + .bar { line-height: $line-height * 2; font-size: $large-font-size; - + display: block; color: #eee; } - + .runningAlert { background-color: $light-text-color; } - + .skippedAlert { background-color: $feint-text-color; - + &:first-child { background-color: $text-color; } - + &:hover { text-decoration: none; color: white; text-decoration: underline; } } - + .passingAlert { background-color: $light-passing-color; - + &:first-child { background-color: $passing-color; } } - + .failingAlert { background-color: $light-failing-color; - + &:first-child { background-color: $failing-color } } //--- Results ---// - + .results { margin-top: $line-height; } //--- Results menu ---// - + #details { display: none; } - + .resultsMenu, .resultsMenu a { background-color: #fff; color: $text-color; } - + &.showDetails { - + .summaryMenuItem { font-weight: normal; text-decoration: inherit; - + &:hover { text-decoration: underline; } } - + .detailsMenuItem { font-weight: bold; - text-decoration: underline; + text-decoration: underline; } - + .summary { display: none; } - + #details { display: block; } } - - .summaryMenuItem { + + .summaryMenuItem { font-weight: bold; text-decoration: underline; } - + //--- Results summary ---// - + .summary { margin-top: $margin-unit; - + .suite .suite, .specSummary { margin-left: $margin-unit; } - + .specSummary { &.passed a { - color: $passing-color; + color: $passing-color; } &.failed a { color: $failing-color; } } } - + .description+.suite { margin-top: 0; } - + .suite { margin-top: $margin-unit; - + a { color: $text-color; } } - + //--- Results details ---// - + #details { .specDetail { margin-bottom: $line-height * 2; - + .description { //line-height: $line-height * 2; display: block; - + color: white; background-color: $failing-color; - + //font-size: $large-font-size; } } } - + .resultMessage { padding-top: $line-height; - + color: $text-color; } - + .resultMessage span.result { display: block; } - + .stackTrace { margin: 5px 0 0 0; max-height: $line-height * 16; overflow: auto; line-height: 18px; - + color: $light-text-color; border: 1px solid #ddd; background: white; white-space: pre; } -} \ No newline at end of file +} diff --git a/src/html/jasmine.css b/src/html/jasmine.css index 826e5753..8c008dc7 100644 --- a/src/html/jasmine.css +++ b/src/html/jasmine.css @@ -19,6 +19,7 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; } #HTMLReporter .symbolSummary li.skipped:before { color: #bababa; content: "\02022"; } #HTMLReporter .symbolSummary li.pending { line-height: 11px; } #HTMLReporter .symbolSummary li.pending:before { color: #aaaaaa; content: "-"; } +#HTMLReporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; } #HTMLReporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; } #HTMLReporter .runningAlert { background-color: #666666; } #HTMLReporter .skippedAlert { background-color: #aaaaaa; }