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

@@ -15,57 +15,16 @@
(function() {
const env = jasmine.getEnv();
/**
* ## Runner Parameters
*
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
*/
const queryString = new jasmine.QueryString({
getWindowLocation: function() {
return window.location;
}
});
const filterSpecs = !!queryString.getParam('spec');
const config = {
stopOnSpecFailure: queryString.getParam('stopOnSpecFailure'),
stopSpecOnExpectationFailure: queryString.getParam(
'stopSpecOnExpectationFailure'
),
hideDisabled: queryString.getParam('hideDisabled')
};
const random = queryString.getParam('random');
if (random !== undefined && random !== '') {
config.random = random;
}
const seed = queryString.getParam('seed');
if (seed) {
config.seed = seed;
}
const urls = new jasmine.HtmlReporterV2Urls();
/**
* ## Reporters
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
*/
const htmlReporter = new jasmine.HtmlReporterV2({
env: env,
navigateWithNewParam: function(key, value) {
return queryString.navigateWithNewParam(key, value);
},
addToExistingQueryString: function(key, value) {
return queryString.fullStringWithNewParam(key, value);
},
getContainer: function() {
return document.body;
},
timer: new jasmine.Timer(),
filterSpecs: filterSpecs
env,
urls,
container: document.body
});
/**
@@ -73,21 +32,7 @@
*/
env.addReporter(jsApiReporter);
env.addReporter(htmlReporter);
/**
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
*/
const specFilter = new jasmine.HtmlSpecFilterV2({
filterString: function() {
return queryString.getParam('spec');
}
});
config.specFilter = function(spec) {
return specFilter.matches(spec.getFullName());
};
env.configure(config);
env.configure(urls.configFromCurrentUrl());
/**
* ## Execution

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();
};