Clone HtmlSpecFilter and HtmlReporter in preparation for backward-incompatible changes

This commit is contained in:
Steve Gravrock
2025-10-07 20:38:01 -07:00
parent bd89ef66c8
commit 77c3b8b07e
12 changed files with 2143 additions and 95 deletions

View File

@@ -32,7 +32,7 @@ jasmineRequire.HtmlReporter = function(j$) {
this.#getContainer = options.getContainer;
this.#navigateWithNewParam =
options.navigateWithNewParam || function() {};
this.#urlBuilder = new j$.private.UrlBuilder(
this.#urlBuilder = new UrlBuilder(
options.addToExistingQueryString || defaultQueryString
);
this.#filterSpecs = options.filterSpecs;
@@ -169,6 +169,42 @@ jasmineRequire.HtmlReporter = function(j$) {
}
}
class UrlBuilder {
#addToExistingQueryString;
constructor(addToExistingQueryString) {
this.#addToExistingQueryString = function(k, v) {
// 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(k, v)
);
};
}
suiteHref(suite) {
const els = [];
while (suite && suite.parent) {
els.unshift(suite.result.description);
suite = suite.parent;
}
return this.#addToExistingQueryString('spec', els.join(' '));
}
specHref(result) {
return this.#addToExistingQueryString('spec', result.fullName);
}
runAllHref() {
return this.#addToExistingQueryString('spec', '');
}
seedHref(seed) {
return this.#addToExistingQueryString('seed', seed);
}
}
function defaultQueryString(key, value) {
return '?' + key + '=' + value;
}