Skip to content

Commit

Permalink
new attempt for fixing #1906: add window.location.pathname to hrefs +…
Browse files Browse the repository at this point in the history
… comments + fixed tests
  • Loading branch information
Joris Stolwijk committed Jun 29, 2021
1 parent ee88ecc commit e4c7d8a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
8 changes: 4 additions & 4 deletions spec/html/HtmlReporterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ describe('HtmlReporter', function() {
var suiteDetail = outerSuite.childNodes[0];
var suiteLink = suiteDetail.childNodes[0];
expect(suiteLink.innerHTML).toEqual('A Suite');
expect(suiteLink.getAttribute('href')).toEqual('?foo=bar&spec=A Suite');
expect(suiteLink.getAttribute('href')).toEqual('/?foo=bar&spec=A Suite');

var specs = outerSuite.childNodes[1];
var spec = specs.childNodes[0];
Expand All @@ -494,7 +494,7 @@ describe('HtmlReporter', function() {
var specLink = spec.childNodes[0];
expect(specLink.innerHTML).toEqual('with a spec');
expect(specLink.getAttribute('href')).toEqual(
'?foo=bar&spec=A Suite with a spec'
'/?foo=bar&spec=A Suite with a spec'
);
});

Expand Down Expand Up @@ -1050,7 +1050,7 @@ describe('HtmlReporter', function() {
var seedBar = container.querySelector('.jasmine-seed-bar');
expect(seedBar.textContent).toBe(', randomized with seed 424242');
var seedLink = container.querySelector('.jasmine-seed-bar a');
expect(seedLink.getAttribute('href')).toBe('?seed=424242');
expect(seedLink.getAttribute('href')).toBe('/?seed=424242');
});

it('should not show the current seed bar if not randomizing', function() {
Expand Down Expand Up @@ -1099,7 +1099,7 @@ describe('HtmlReporter', function() {
reporter.jasmineDone({ order: { random: true } });

var skippedLink = container.querySelector('.jasmine-skipped a');
expect(skippedLink.getAttribute('href')).toEqual('?foo=bar&spec=');
expect(skippedLink.getAttribute('href')).toEqual('/?foo=bar&spec=');
});
});

Expand Down
23 changes: 19 additions & 4 deletions src/html/HtmlReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ jasmineRequire.HtmlReporter = function(j$) {
' of ' +
totalSpecsDefined +
' specs - run all';
var skippedLink = addToExistingQueryString('spec', '');
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
var skippedLink =
(window.location.pathname || '') +
addToExistingQueryString('spec', '');
alert.appendChild(
createDom(
'span',
Expand Down Expand Up @@ -604,7 +607,11 @@ jasmineRequire.HtmlReporter = function(j$) {
suite = suite.parent;
}

return addToExistingQueryString('spec', els.join(' '));
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
return (
(window.location.pathname || '') +
addToExistingQueryString('spec', els.join(' '))
);
}

function addDeprecationWarnings(result, runnableType) {
Expand Down Expand Up @@ -668,11 +675,19 @@ jasmineRequire.HtmlReporter = function(j$) {
}

function specHref(result) {
return addToExistingQueryString('spec', result.fullName);
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
return (
(window.location.pathname || '') +
addToExistingQueryString('spec', result.fullName)
);
}

function seedHref(seed) {
return addToExistingQueryString('seed', seed);
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
return (
(window.location.pathname || '') +
addToExistingQueryString('seed', seed)
);
}

function defaultQueryString(key, value) {
Expand Down

0 comments on commit e4c7d8a

Please sign in to comment.