Convert what's left of HtmlReporter to an ES6 class
This commit is contained in:
@@ -118,72 +118,86 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
* @param options Options object. See lib/jasmine-core/boot1.js for details.
|
||||
* @since 1.2.0
|
||||
*/
|
||||
function HtmlReporter(options) {
|
||||
function config() {
|
||||
return (options.env && options.env.configuration()) || {};
|
||||
}
|
||||
class HtmlReporter {
|
||||
#env;
|
||||
#getContainer;
|
||||
#domContext;
|
||||
#navigateWithNewParam;
|
||||
#urlBuilder;
|
||||
#filterSpecs;
|
||||
#stateBuilder;
|
||||
#htmlReporterMain;
|
||||
|
||||
const getContainer = options.getContainer;
|
||||
const domContext = new j$.private.DomContext({
|
||||
createElement: options.createElement,
|
||||
createTextNode: options.createTextNode
|
||||
});
|
||||
const navigateWithNewParam = options.navigateWithNewParam || function() {};
|
||||
const addToExistingQueryString =
|
||||
options.addToExistingQueryString || defaultQueryString;
|
||||
const urlBuilder = new UrlBuilder(addToExistingQueryString);
|
||||
const filterSpecs = options.filterSpecs;
|
||||
let htmlReporterMain;
|
||||
let alerts;
|
||||
let symbols;
|
||||
let banner;
|
||||
let failures;
|
||||
// Sub-views
|
||||
#alerts;
|
||||
#symbols;
|
||||
#banner;
|
||||
#failures;
|
||||
|
||||
constructor(options) {
|
||||
this.#env = options.env;
|
||||
|
||||
this.#getContainer = options.getContainer;
|
||||
this.#domContext = new j$.private.DomContext({
|
||||
createElement: options.createElement,
|
||||
createTextNode: options.createTextNode
|
||||
});
|
||||
this.#navigateWithNewParam =
|
||||
options.navigateWithNewParam || function() {};
|
||||
this.#urlBuilder = new UrlBuilder(
|
||||
options.addToExistingQueryString || defaultQueryString
|
||||
);
|
||||
this.#filterSpecs = options.filterSpecs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the reporter. Should be called before {@link Env#execute}.
|
||||
* @function
|
||||
* @name HtmlReporter#initialize
|
||||
*/
|
||||
this.initialize = function() {
|
||||
clearPrior();
|
||||
alerts = new AlertsView(domContext, urlBuilder);
|
||||
symbols = new SymbolsView(domContext, config);
|
||||
banner = new Banner(domContext, navigateWithNewParam);
|
||||
failures = new FailuresView(domContext, urlBuilder);
|
||||
htmlReporterMain = domContext.create(
|
||||
initialize() {
|
||||
this.#clearPrior();
|
||||
this.#stateBuilder = new ResultsStateBuilder();
|
||||
|
||||
this.#alerts = new AlertsView(this.#domContext, this.#urlBuilder);
|
||||
this.#symbols = new SymbolsView(
|
||||
this.#domContext,
|
||||
this.#config.bind(this)
|
||||
);
|
||||
this.#banner = new Banner(this.#domContext, this.#navigateWithNewParam);
|
||||
this.#failures = new FailuresView(this.#domContext, this.#urlBuilder);
|
||||
this.#htmlReporterMain = this.#domContext.create(
|
||||
'div',
|
||||
{ className: 'jasmine_html-reporter' },
|
||||
banner.rootEl,
|
||||
symbols.rootEl,
|
||||
alerts.rootEl,
|
||||
failures.rootEl
|
||||
this.#banner.rootEl,
|
||||
this.#symbols.rootEl,
|
||||
this.#alerts.rootEl,
|
||||
this.#failures.rootEl
|
||||
);
|
||||
getContainer().appendChild(htmlReporterMain);
|
||||
};
|
||||
this.#getContainer().appendChild(this.#htmlReporterMain);
|
||||
}
|
||||
|
||||
this.jasmineStarted = function(options) {
|
||||
stateBuilder.jasmineStarted(options);
|
||||
};
|
||||
jasmineStarted(options) {
|
||||
this.#stateBuilder.jasmineStarted(options);
|
||||
}
|
||||
|
||||
const stateBuilder = new ResultsStateBuilder();
|
||||
suiteStarted(result) {
|
||||
this.#stateBuilder.suiteStarted(result);
|
||||
}
|
||||
|
||||
this.suiteStarted = function(result) {
|
||||
stateBuilder.suiteStarted(result);
|
||||
};
|
||||
|
||||
this.suiteDone = function(result) {
|
||||
stateBuilder.suiteDone(result);
|
||||
suiteDone(result) {
|
||||
this.#stateBuilder.suiteDone(result);
|
||||
|
||||
if (result.status === 'failed') {
|
||||
failures.append(result, stateBuilder.currentParent);
|
||||
this.#failures.append(result, this.#stateBuilder.currentParent);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
this.specStarted = function(result) {};
|
||||
specStarted() {}
|
||||
|
||||
this.specDone = function(result) {
|
||||
stateBuilder.specDone(result);
|
||||
symbols.append(result, config());
|
||||
specDone(result) {
|
||||
this.#stateBuilder.specDone(result);
|
||||
this.#symbols.append(result, this.#config());
|
||||
|
||||
if (noExpectations(result)) {
|
||||
const noSpecMsg = "Spec '" + result.fullName + "' has no expectations.";
|
||||
@@ -197,70 +211,79 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
if (result.status === 'failed') {
|
||||
failures.append(result, stateBuilder.currentParent);
|
||||
this.#failures.append(result, this.#stateBuilder.currentParent);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
this.jasmineDone = function(doneResult) {
|
||||
stateBuilder.jasmineDone(doneResult);
|
||||
alerts.addDuration(doneResult.totalTime);
|
||||
banner.showOptionsMenu(config());
|
||||
jasmineDone(doneResult) {
|
||||
this.#stateBuilder.jasmineDone(doneResult);
|
||||
this.#alerts.addDuration(doneResult.totalTime);
|
||||
this.#banner.showOptionsMenu(this.#config());
|
||||
|
||||
if (stateBuilder.specsExecuted < stateBuilder.totalSpecsDefined) {
|
||||
alerts.addSkipped(
|
||||
stateBuilder.specsExecuted,
|
||||
stateBuilder.totalSpecsDefined
|
||||
if (
|
||||
this.#stateBuilder.specsExecuted < this.#stateBuilder.totalSpecsDefined
|
||||
) {
|
||||
this.#alerts.addSkipped(
|
||||
this.#stateBuilder.specsExecuted,
|
||||
this.#stateBuilder.totalSpecsDefined
|
||||
);
|
||||
}
|
||||
|
||||
alerts.addSeedBar(doneResult, stateBuilder, doneResult.order);
|
||||
this.#alerts.addSeedBar(doneResult, this.#stateBuilder, doneResult.order);
|
||||
|
||||
if (doneResult.failedExpectations) {
|
||||
for (const f of doneResult.failedExpectations) {
|
||||
alerts.addGlobalFailure(f);
|
||||
this.#alerts.addGlobalFailure(f);
|
||||
}
|
||||
}
|
||||
|
||||
for (const dw of stateBuilder.deprecationWarnings) {
|
||||
alerts.addDeprecationWarning(dw);
|
||||
for (const dw of this.#stateBuilder.deprecationWarnings) {
|
||||
this.#alerts.addDeprecationWarning(dw);
|
||||
}
|
||||
|
||||
const results = find('.jasmine-results');
|
||||
const summary = new SummaryTreeView(domContext, urlBuilder, filterSpecs);
|
||||
summary.addResults(stateBuilder.topResults);
|
||||
const results = this.#find('.jasmine-results');
|
||||
const summary = new SummaryTreeView(
|
||||
this.#domContext,
|
||||
this.#urlBuilder,
|
||||
this.#filterSpecs
|
||||
);
|
||||
summary.addResults(this.#stateBuilder.topResults);
|
||||
results.appendChild(summary.rootEl);
|
||||
|
||||
if (failures.any()) {
|
||||
alerts.addFailureToggle(
|
||||
function() {
|
||||
setMenuModeTo('jasmine-failure-list');
|
||||
},
|
||||
function() {
|
||||
setMenuModeTo('jasmine-spec-list');
|
||||
}
|
||||
if (this.#failures.any()) {
|
||||
this.#alerts.addFailureToggle(
|
||||
() => this.#setMenuModeTo('jasmine-failure-list'),
|
||||
() => this.#setMenuModeTo('jasmine-spec-list')
|
||||
);
|
||||
|
||||
setMenuModeTo('jasmine-failure-list');
|
||||
failures.show();
|
||||
this.#setMenuModeTo('jasmine-failure-list');
|
||||
this.#failures.show();
|
||||
}
|
||||
};
|
||||
|
||||
return this;
|
||||
|
||||
function find(selector) {
|
||||
return getContainer().querySelector('.jasmine_html-reporter ' + selector);
|
||||
}
|
||||
|
||||
function clearPrior() {
|
||||
const oldReporter = find('');
|
||||
#config() {
|
||||
return (this.#env && this.#env.configuration()) || {};
|
||||
}
|
||||
|
||||
#find(selector) {
|
||||
return this.#getContainer().querySelector(
|
||||
'.jasmine_html-reporter ' + selector
|
||||
);
|
||||
}
|
||||
|
||||
#clearPrior() {
|
||||
const oldReporter = this.#find('');
|
||||
|
||||
if (oldReporter) {
|
||||
getContainer().removeChild(oldReporter);
|
||||
this.#getContainer().removeChild(oldReporter);
|
||||
}
|
||||
}
|
||||
|
||||
function setMenuModeTo(mode) {
|
||||
htmlReporterMain.setAttribute('class', 'jasmine_html-reporter ' + mode);
|
||||
#setMenuModeTo(mode) {
|
||||
this.#htmlReporterMain.setAttribute(
|
||||
'class',
|
||||
'jasmine_html-reporter ' + mode
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,72 +83,86 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
* @param options Options object. See lib/jasmine-core/boot1.js for details.
|
||||
* @since 1.2.0
|
||||
*/
|
||||
function HtmlReporter(options) {
|
||||
function config() {
|
||||
return (options.env && options.env.configuration()) || {};
|
||||
}
|
||||
class HtmlReporter {
|
||||
#env;
|
||||
#getContainer;
|
||||
#domContext;
|
||||
#navigateWithNewParam;
|
||||
#urlBuilder;
|
||||
#filterSpecs;
|
||||
#stateBuilder;
|
||||
#htmlReporterMain;
|
||||
|
||||
const getContainer = options.getContainer;
|
||||
const domContext = new j$.private.DomContext({
|
||||
createElement: options.createElement,
|
||||
createTextNode: options.createTextNode
|
||||
});
|
||||
const navigateWithNewParam = options.navigateWithNewParam || function() {};
|
||||
const addToExistingQueryString =
|
||||
options.addToExistingQueryString || defaultQueryString;
|
||||
const urlBuilder = new UrlBuilder(addToExistingQueryString);
|
||||
const filterSpecs = options.filterSpecs;
|
||||
let htmlReporterMain;
|
||||
let alerts;
|
||||
let symbols;
|
||||
let banner;
|
||||
let failures;
|
||||
// Sub-views
|
||||
#alerts;
|
||||
#symbols;
|
||||
#banner;
|
||||
#failures;
|
||||
|
||||
constructor(options) {
|
||||
this.#env = options.env;
|
||||
|
||||
this.#getContainer = options.getContainer;
|
||||
this.#domContext = new j$.private.DomContext({
|
||||
createElement: options.createElement,
|
||||
createTextNode: options.createTextNode
|
||||
});
|
||||
this.#navigateWithNewParam =
|
||||
options.navigateWithNewParam || function() {};
|
||||
this.#urlBuilder = new UrlBuilder(
|
||||
options.addToExistingQueryString || defaultQueryString
|
||||
);
|
||||
this.#filterSpecs = options.filterSpecs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the reporter. Should be called before {@link Env#execute}.
|
||||
* @function
|
||||
* @name HtmlReporter#initialize
|
||||
*/
|
||||
this.initialize = function() {
|
||||
clearPrior();
|
||||
alerts = new AlertsView(domContext, urlBuilder);
|
||||
symbols = new SymbolsView(domContext, config);
|
||||
banner = new Banner(domContext, navigateWithNewParam);
|
||||
failures = new FailuresView(domContext, urlBuilder);
|
||||
htmlReporterMain = domContext.create(
|
||||
initialize() {
|
||||
this.#clearPrior();
|
||||
this.#stateBuilder = new ResultsStateBuilder();
|
||||
|
||||
this.#alerts = new AlertsView(this.#domContext, this.#urlBuilder);
|
||||
this.#symbols = new SymbolsView(
|
||||
this.#domContext,
|
||||
this.#config.bind(this)
|
||||
);
|
||||
this.#banner = new Banner(this.#domContext, this.#navigateWithNewParam);
|
||||
this.#failures = new FailuresView(this.#domContext, this.#urlBuilder);
|
||||
this.#htmlReporterMain = this.#domContext.create(
|
||||
'div',
|
||||
{ className: 'jasmine_html-reporter' },
|
||||
banner.rootEl,
|
||||
symbols.rootEl,
|
||||
alerts.rootEl,
|
||||
failures.rootEl
|
||||
this.#banner.rootEl,
|
||||
this.#symbols.rootEl,
|
||||
this.#alerts.rootEl,
|
||||
this.#failures.rootEl
|
||||
);
|
||||
getContainer().appendChild(htmlReporterMain);
|
||||
};
|
||||
this.#getContainer().appendChild(this.#htmlReporterMain);
|
||||
}
|
||||
|
||||
this.jasmineStarted = function(options) {
|
||||
stateBuilder.jasmineStarted(options);
|
||||
};
|
||||
jasmineStarted(options) {
|
||||
this.#stateBuilder.jasmineStarted(options);
|
||||
}
|
||||
|
||||
const stateBuilder = new ResultsStateBuilder();
|
||||
suiteStarted(result) {
|
||||
this.#stateBuilder.suiteStarted(result);
|
||||
}
|
||||
|
||||
this.suiteStarted = function(result) {
|
||||
stateBuilder.suiteStarted(result);
|
||||
};
|
||||
|
||||
this.suiteDone = function(result) {
|
||||
stateBuilder.suiteDone(result);
|
||||
suiteDone(result) {
|
||||
this.#stateBuilder.suiteDone(result);
|
||||
|
||||
if (result.status === 'failed') {
|
||||
failures.append(result, stateBuilder.currentParent);
|
||||
this.#failures.append(result, this.#stateBuilder.currentParent);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
this.specStarted = function(result) {};
|
||||
specStarted() {}
|
||||
|
||||
this.specDone = function(result) {
|
||||
stateBuilder.specDone(result);
|
||||
symbols.append(result, config());
|
||||
specDone(result) {
|
||||
this.#stateBuilder.specDone(result);
|
||||
this.#symbols.append(result, this.#config());
|
||||
|
||||
if (noExpectations(result)) {
|
||||
const noSpecMsg = "Spec '" + result.fullName + "' has no expectations.";
|
||||
@@ -162,70 +176,79 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
if (result.status === 'failed') {
|
||||
failures.append(result, stateBuilder.currentParent);
|
||||
this.#failures.append(result, this.#stateBuilder.currentParent);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
this.jasmineDone = function(doneResult) {
|
||||
stateBuilder.jasmineDone(doneResult);
|
||||
alerts.addDuration(doneResult.totalTime);
|
||||
banner.showOptionsMenu(config());
|
||||
jasmineDone(doneResult) {
|
||||
this.#stateBuilder.jasmineDone(doneResult);
|
||||
this.#alerts.addDuration(doneResult.totalTime);
|
||||
this.#banner.showOptionsMenu(this.#config());
|
||||
|
||||
if (stateBuilder.specsExecuted < stateBuilder.totalSpecsDefined) {
|
||||
alerts.addSkipped(
|
||||
stateBuilder.specsExecuted,
|
||||
stateBuilder.totalSpecsDefined
|
||||
if (
|
||||
this.#stateBuilder.specsExecuted < this.#stateBuilder.totalSpecsDefined
|
||||
) {
|
||||
this.#alerts.addSkipped(
|
||||
this.#stateBuilder.specsExecuted,
|
||||
this.#stateBuilder.totalSpecsDefined
|
||||
);
|
||||
}
|
||||
|
||||
alerts.addSeedBar(doneResult, stateBuilder, doneResult.order);
|
||||
this.#alerts.addSeedBar(doneResult, this.#stateBuilder, doneResult.order);
|
||||
|
||||
if (doneResult.failedExpectations) {
|
||||
for (const f of doneResult.failedExpectations) {
|
||||
alerts.addGlobalFailure(f);
|
||||
this.#alerts.addGlobalFailure(f);
|
||||
}
|
||||
}
|
||||
|
||||
for (const dw of stateBuilder.deprecationWarnings) {
|
||||
alerts.addDeprecationWarning(dw);
|
||||
for (const dw of this.#stateBuilder.deprecationWarnings) {
|
||||
this.#alerts.addDeprecationWarning(dw);
|
||||
}
|
||||
|
||||
const results = find('.jasmine-results');
|
||||
const summary = new SummaryTreeView(domContext, urlBuilder, filterSpecs);
|
||||
summary.addResults(stateBuilder.topResults);
|
||||
const results = this.#find('.jasmine-results');
|
||||
const summary = new SummaryTreeView(
|
||||
this.#domContext,
|
||||
this.#urlBuilder,
|
||||
this.#filterSpecs
|
||||
);
|
||||
summary.addResults(this.#stateBuilder.topResults);
|
||||
results.appendChild(summary.rootEl);
|
||||
|
||||
if (failures.any()) {
|
||||
alerts.addFailureToggle(
|
||||
function() {
|
||||
setMenuModeTo('jasmine-failure-list');
|
||||
},
|
||||
function() {
|
||||
setMenuModeTo('jasmine-spec-list');
|
||||
}
|
||||
if (this.#failures.any()) {
|
||||
this.#alerts.addFailureToggle(
|
||||
() => this.#setMenuModeTo('jasmine-failure-list'),
|
||||
() => this.#setMenuModeTo('jasmine-spec-list')
|
||||
);
|
||||
|
||||
setMenuModeTo('jasmine-failure-list');
|
||||
failures.show();
|
||||
this.#setMenuModeTo('jasmine-failure-list');
|
||||
this.#failures.show();
|
||||
}
|
||||
};
|
||||
|
||||
return this;
|
||||
|
||||
function find(selector) {
|
||||
return getContainer().querySelector('.jasmine_html-reporter ' + selector);
|
||||
}
|
||||
|
||||
function clearPrior() {
|
||||
const oldReporter = find('');
|
||||
#config() {
|
||||
return (this.#env && this.#env.configuration()) || {};
|
||||
}
|
||||
|
||||
#find(selector) {
|
||||
return this.#getContainer().querySelector(
|
||||
'.jasmine_html-reporter ' + selector
|
||||
);
|
||||
}
|
||||
|
||||
#clearPrior() {
|
||||
const oldReporter = this.#find('');
|
||||
|
||||
if (oldReporter) {
|
||||
getContainer().removeChild(oldReporter);
|
||||
this.#getContainer().removeChild(oldReporter);
|
||||
}
|
||||
}
|
||||
|
||||
function setMenuModeTo(mode) {
|
||||
htmlReporterMain.setAttribute('class', 'jasmine_html-reporter ' + mode);
|
||||
#setMenuModeTo(mode) {
|
||||
this.#htmlReporterMain.setAttribute(
|
||||
'class',
|
||||
'jasmine_html-reporter ' + mode
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user