Simplify boot1.js

This commit is contained in:
Steve Gravrock
2025-10-08 20:25:53 -07:00
parent fb814b5f94
commit a457cf1b81
10 changed files with 298 additions and 235 deletions

View File

@@ -12,8 +12,8 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
*/
class HtmlReporterV2 {
#env;
#getContainer;
#navigateWithNewParam;
#container;
#queryString;
#urlBuilder;
#filterSpecs;
#stateBuilder;
@@ -29,13 +29,16 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
constructor(options) {
this.#env = options.env;
this.#getContainer = options.getContainer;
this.#navigateWithNewParam =
options.navigateWithNewParam || function() {};
this.#urlBuilder = new UrlBuilder(
options.addToExistingQueryString || defaultQueryString
);
this.#filterSpecs = options.filterSpecs;
this.#container = options.container;
this.#queryString =
options.queryString ||
new j$.QueryString({
getWindowLocation() {
return window.location;
}
});
this.#urlBuilder = new UrlBuilder(this.#queryString);
this.#filterSpecs = options.urls.filteringSpecs();
}
/**
@@ -51,7 +54,9 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
this.#alerts = new j$.private.AlertsView(this.#urlBuilder);
this.#symbols = new j$.private.SymbolsView();
this.#banner = new j$.private.Banner(this.#navigateWithNewParam);
this.#banner = new j$.private.Banner(
this.#queryString.navigateWithNewParam.bind(this.#queryString)
);
this.#failures = new j$.private.FailuresView(this.#urlBuilder);
this.#htmlReporterMain = createDom(
'div',
@@ -61,7 +66,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
this.#alerts.rootEl,
this.#failures.rootEl
);
this.#getContainer().appendChild(this.#htmlReporterMain);
this.#container.appendChild(this.#htmlReporterMain);
}
jasmineStarted(options) {
@@ -148,7 +153,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
}
#find(selector) {
return this.#getContainer().querySelector(
return this.#container.querySelector(
'.jasmine_html-reporter ' + selector
);
}
@@ -157,7 +162,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
const oldReporter = this.#find('');
if (oldReporter) {
this.#getContainer().removeChild(oldReporter);
this.#container.removeChild(oldReporter);
}
}
@@ -170,15 +175,10 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
}
class UrlBuilder {
#addToExistingQueryString;
#queryString;
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)
);
};
constructor(queryString) {
this.#queryString = queryString;
}
suiteHref(suite) {
@@ -203,10 +203,14 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
seedHref(seed) {
return this.#addToExistingQueryString('seed', seed);
}
}
function defaultQueryString(key, value) {
return '?' + key + '=' + value;
#addToExistingQueryString(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 || '') +
this.#queryString.fullStringWithNewParam(k, v)
);
}
}
return HtmlReporterV2;

View File

@@ -0,0 +1,58 @@
jasmineRequire.HtmlReporterV2Urls = function(j$) {
'use strict';
// TODO jsdoc
class HtmlReporterV2Urls {
constructor(options = {}) {
// queryString is injectable for use in our own tests, but user code will
// not pass any options.
this.queryString =
options.queryString ||
new jasmine.QueryString({
getWindowLocation: function() {
return window.location;
}
});
}
// TODO jsdoc. This is public.
configFromCurrentUrl() {
const config = {
stopOnSpecFailure: this.queryString.getParam('stopOnSpecFailure'),
stopSpecOnExpectationFailure: this.queryString.getParam(
'stopSpecOnExpectationFailure'
),
hideDisabled: this.queryString.getParam('hideDisabled')
};
const random = this.queryString.getParam('random');
if (random !== undefined && random !== '') {
config.random = random;
}
const seed = this.queryString.getParam('seed');
if (seed) {
config.seed = seed;
}
const specFilter = new j$.private.HtmlSpecFilterV2({
filterString: () => {
return this.queryString.getParam('spec');
}
});
config.specFilter = function(spec) {
return specFilter.matches(spec.getFullName());
};
return config;
}
filteringSpecs() {
return !!this.queryString.getParam('spec');
}
}
return HtmlReporterV2Urls;
};

View File

@@ -11,8 +11,9 @@ jasmineRequire.html = function(j$) {
j$.private.SummaryTreeView = jasmineRequire.SummaryTreeView(j$);
j$.private.FailuresView = jasmineRequire.FailuresView(j$);
j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
j$.HtmlReporterV2Urls = jasmineRequire.HtmlReporterV2Urls(j$);
j$.HtmlReporterV2 = jasmineRequire.HtmlReporterV2(j$);
j$.QueryString = jasmineRequire.QueryString();
j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
j$.HtmlSpecFilterV2 = jasmineRequire.HtmlSpecFilterV2();
j$.private.HtmlSpecFilterV2 = jasmineRequire.HtmlSpecFilterV2();
};