Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added specLink method and changed href: "?" to href: window.location.search in reporter #177

Closed
wants to merge 1 commit into from

3 participants

@wheresrhys

Fixes bug where any query strings specified by the user (Example use case: specifying a jQuery version to include using a url query string) are overwritten when clicking on links.

@wheresrhys wheresrhys Added specLink method in order to correctly generate hrefs for report…
…er's links. Fixes bug where any query strings specified by the user (Example use case: specifying a jQuery version to include using a url query string) are overwritten when clicking on these links.
fec9084
@infews
Owner

What is the use case for this? And do you have tests that demonstrate the problem?

@wheresrhys

If you go to https://github.com/wheresrhys/jQuery-flickbook/tests/testSuite.php you'll see that a get parameter is passed in to the test page in order to specify the version of jQuery to include. At present clicking on any individual test/subsuite link replaces the entire GET query string, thus leading to jQuery not being included when the page reloads.

So that was the problem I had, but in general the links break if the user, for whatever reason, accesses the test page using a query srtring in the URL.

@ragaskar
Owner

It seems OK to preserve the query params. We'll need to rewrite this for the HTML reporter and get some spec coverage around it.

@infews
Owner
@stas stas referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@stas stas referenced this pull request from a commit in stas/jasmine
@stas stas Introducing `pageURI` method to handle test cases links with custom l…
…ocation.

Basically this should solve issues like #177.
Developer should be able to customize `pageURI` method for the reporter he's using.
Ex.:

```javascript
var jasmineEnv = jasmine.getEnv();
var reporter = new jasmine.TrivialReporter();
reporter.pageURI = function(path){ return window.location.pathname + path };
jasmineEnv.addReporter(reporter);
jasmineEnv.execute();
```
13cd56a
@ragaskar
Owner

Closing in favor of #197

@ragaskar ragaskar closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 15, 2012
  1. @wheresrhys

    Added specLink method in order to correctly generate hrefs for report…

    wheresrhys authored
    …er's links. Fixes bug where any query strings specified by the user (Example use case: specifying a jQuery version to include using a url query string) are overwritten when clicking on these links.
This page is out of date. Refresh to see the latest.
Showing with 46 additions and 12 deletions.
  1. +46 −12 lib/jasmine-core/jasmine-html.js
View
58 lib/jasmine-core/jasmine-html.js
@@ -301,14 +301,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: window.location.search, 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: window.location.search, className: "skippedAlert bar"});
}
this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
@@ -319,13 +319,13 @@ 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: window.location.search, className: "passingAlert bar"});
}
this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount);
// failing specs UI
if (isUndefined(this.failedAlert)) {
- this.failedAlert = this.createDom('span', {href: "?", className: "failingAlert bar"});
+ this.failedAlert = this.createDom('span', {href: window.location.search, className: "failingAlert bar"});
}
this.failedAlert.innerHTML = "Failing " + specPluralizedFor(this.failedCount);
@@ -393,7 +393,7 @@ jasmine.HtmlReporter.SpecView = function(spec, dom, views) {
this.summary = this.createDom('div', { className: 'specSummary' },
this.createDom('a', {
className: 'description',
- href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
+ href: this.specLink(this.spec),
title: this.spec.getFullName()
}, this.spec.description)
);
@@ -401,7 +401,7 @@ jasmine.HtmlReporter.SpecView = function(spec, dom, views) {
this.detail = this.createDom('div', { className: 'specDetail' },
this.createDom('a', {
className: 'description',
- href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
+ href: this.specLink(this.spec),
title: this.spec.getFullName()
}, this.spec.getFullName())
);
@@ -466,7 +466,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: this.specLink(this.suite) }, this.suite.description)
);
this.appendToSummary(this.suite, this.element);
@@ -482,6 +482,22 @@ jasmine.HtmlReporter.SuiteView.prototype.refresh = function() {
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SuiteView);
+jasmine.HtmlReporter.prototype.specLink = function (spec) {
+ var query = window.location.search;
+ if(query) {
+ if (query.match(new RegExp("([\?&])spec="))) {
+ query = query.replace(new RegExp("([\?&]spec=)[^&]+"), function ($0, $1) {
+ return $1 + encodeURIComponent(spec.getFullName());
+ });
+ } else {
+ query += "&spec=" + encodeURIComponent(spec.getFullName());
+ }
+ } else {
+ query = "?spec=" + encodeURIComponent(spec.getFullName());
+ }
+ return query;
+}
+
/* @deprecated Use jasmine.HtmlReporter instead
*/
jasmine.TrivialReporter = function(doc) {
@@ -532,7 +548,7 @@ jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
),
this.runnerDiv = this.createDom('div', { className: 'runner running' },
- this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
+ this.createDom('a', { className: 'run_spec', href: window.location.search }, "run all"),
this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
);
@@ -543,8 +559,8 @@ jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
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.createDom('a', { className: 'run_spec', href: this.specLink(suite) }, "run"),
+ this.createDom('a', { className: 'description', href: this.specLink(suite) }, suite.description));
this.suiteDivs[suite.id] = suiteDiv;
var parentDiv = this.outerDiv;
if (suite.parentSuite) {
@@ -588,9 +604,10 @@ jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
}
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.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: window.location.search}, message), this.runnerMessageSpan.firstChild);
this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
+
};
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
@@ -608,6 +625,22 @@ jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
}
};
+jasmine.TrivialReporter.prototype.specLink = function (spec) {
+ var query = window.location.search;
+ if(query) {
+ if (query.match(new RegExp("([\?&])spec="))) {
+ query = query.replace(new RegExp("([\?&]spec=)[^&]+"), function ($0, $1) {
+ return $1 + encodeURIComponent(spec.getFullName());
+ });
+ } else {
+ query += "&spec=" + encodeURIComponent(spec.getFullName());
+ }
+ } else {
+ query = "?spec=" + encodeURIComponent(spec.getFullName());
+ }
+ return query;
+}
+
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
var results = spec.results();
var status = results.passed() ? 'passed' : 'failed';
@@ -618,7 +651,8 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
this.createDom('a', {
className: 'description',
- href: '?spec=' + encodeURIComponent(spec.getFullName()),
+ href: this.specLink(spec),
+
title: spec.getFullName()
}, spec.description));
Something went wrong with that request. Please try again.