Simplify HtmlReporterV2 initialization and boot1.js

This commit is contained in:
Steve Gravrock
2025-11-28 09:34:25 -08:00
parent f5e9b61f73
commit 00b09a9a04
5 changed files with 36 additions and 174 deletions

View File

@@ -41,19 +41,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
const env = jasmine.getEnv();
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,
urls,
getContainer() {
return document.body;
}
});
env.addReporter(htmlReporter);
/**
* Configures Jasmine based on the current set of query parameters. This
* supports all parameters set by the HTML reporter as well as
@@ -62,18 +49,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
env.configure(urls.configFromCurrentUrl());
/**
* ## Execution
*
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
*/
const currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
htmlReporter.initialize();
window.addEventListener('load', function() {
// The HTML reporter needs to be set up here so it can access the DOM. Other
// reporters can be added at any time before env.execute() is called.
const htmlReporter = new jasmine.HtmlReporterV2({ env, urls });
env.addReporter(htmlReporter);
env.execute();
};
});
})();

View File

@@ -970,12 +970,12 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
* const reporter = new jasmine.HtmlReporterV2({
* env,
* urls,
* getContainer: () => document.body
* // container is optional and defaults to document.body.
* container: someElement
* });
*/
class HtmlReporterV2 {
#env;
#getContainer;
#container;
#queryString;
#urlBuilder;
#filterSpecs;
@@ -992,9 +992,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
#failures;
constructor(options) {
this.#env = options.env;
this.#getContainer = options.getContainer;
this.#container = options.container || document.body;
this.#queryString =
options.queryString ||
new j$.QueryString({
@@ -1007,16 +1005,8 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
getSuiteById: id => this.#stateBuilder.suitesById[id]
});
this.#filterSpecs = options.urls.filteringSpecs();
}
/**
* Initializes the reporter. Should be called before {@link Env#execute}.
* @function
* @name HtmlReporter#initialize
*/
initialize() {
this.#clearPrior();
this.#config = this.#env ? this.#env.configuration() : {};
this.#config = options.env ? options.env.configuration() : {};
this.#stateBuilder = new j$.private.ResultsStateBuilder();
@@ -1057,7 +1047,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
this.#alerts.rootEl,
this.#failures.rootEl
);
this.#getContainer().appendChild(this.#htmlReporterMain);
this.#container.appendChild(this.#htmlReporterMain);
this.#failures.show();
}
@@ -1150,19 +1140,11 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
}
#find(selector) {
return this.#getContainer().querySelector(
return this.#container.querySelector(
'.jasmine_html-reporter ' + selector
);
}
#clearPrior() {
const oldReporter = this.#find('');
if (oldReporter) {
this.#getContainer().removeChild(oldReporter);
}
}
#setMenuModeTo(mode) {
this.#htmlReporterMain.setAttribute(
'class',