HtmlReporterV2: Show a non-color indication of status while running

This commit is contained in:
Steve Gravrock
2025-10-16 19:20:56 -07:00
parent 4cc605756a
commit ea882c2f1e
6 changed files with 123 additions and 9 deletions

View File

@@ -978,6 +978,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
// Sub-views // Sub-views
#alerts; #alerts;
#statusBar;
#progress; #progress;
#banner; #banner;
#failures; #failures;
@@ -1012,6 +1013,9 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
this.#stateBuilder = new j$.private.ResultsStateBuilder(); this.#stateBuilder = new j$.private.ResultsStateBuilder();
this.#alerts = new j$.private.AlertsView(this.#urlBuilder); this.#alerts = new j$.private.AlertsView(this.#urlBuilder);
this.#statusBar = new j$.private.OverallStatusBar(this.#urlBuilder);
this.#statusBar.showRunning();
this.#alerts.addBar(this.#statusBar.rootEl);
this.#progress = new ProgressView(); this.#progress = new ProgressView();
this.#banner = new j$.private.Banner( this.#banner = new j$.private.Banner(
this.#queryString.navigateWithNewParam.bind(this.#queryString), this.#queryString.navigateWithNewParam.bind(this.#queryString),
@@ -1044,6 +1048,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
if (result.status === 'failed') { if (result.status === 'failed') {
this.#failures.append(result, this.#stateBuilder.currentParent); this.#failures.append(result, this.#stateBuilder.currentParent);
this.#statusBar.showFailing();
} }
} }
@@ -1064,6 +1069,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
if (result.status === 'failed') { if (result.status === 'failed') {
this.#failures.append(result, this.#stateBuilder.currentParent); this.#failures.append(result, this.#stateBuilder.currentParent);
this.#statusBar.showFailing();
} }
} }
@@ -1082,9 +1088,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
); );
} }
const statusBar = new j$.private.OverallStatusBar(this.#urlBuilder); this.#statusBar.showDone(doneResult, this.#stateBuilder);
statusBar.showDone(doneResult, this.#stateBuilder);
this.#alerts.addBar(statusBar.rootEl);
if (doneResult.failedExpectations) { if (doneResult.failedExpectations) {
for (const f of doneResult.failedExpectations) { for (const f of doneResult.failedExpectations) {
@@ -1327,6 +1331,7 @@ jasmineRequire.OverallStatusBar = function(j$) {
'use strict'; 'use strict';
const { createDom } = j$.private.htmlReporterUtils; const { createDom } = j$.private.htmlReporterUtils;
const staticClassNames = 'jasmine-overall-result jasmine-bar';
class OverallStatusBar { class OverallStatusBar {
#urlBuilder; #urlBuilder;
@@ -1334,11 +1339,25 @@ jasmineRequire.OverallStatusBar = function(j$) {
constructor(urlBuilder) { constructor(urlBuilder) {
this.#urlBuilder = urlBuilder; this.#urlBuilder = urlBuilder;
this.rootEl = createDom('span', { this.rootEl = createDom('span', {
className: 'jasmine-overall-result jasmine-bar' className: staticClassNames,
'aria-live': 'polite'
}); });
} }
showRunning() {
this.rootEl.textContent = 'Running...';
this.rootEl.classList.add('jasmine-in-progress');
}
showFailing() {
this.rootEl.textContent = 'Failing...';
this.rootEl.classList.add('jasmine-failed');
}
showDone(doneResult, stateBuilder) { showDone(doneResult, stateBuilder) {
// Clear any classes added to represent in-progress state
this.rootEl.className = staticClassNames;
let statusBarMessage = ''; let statusBarMessage = '';
const globalFailures = const globalFailures =
(doneResult && doneResult.failedExpectations) || []; (doneResult && doneResult.failedExpectations) || [];

View File

@@ -162,8 +162,12 @@ body {
display: block; display: block;
color: #eee; color: #eee;
} }
.jasmine_html-reporter .jasmine-bar.jasmine-in-progress {
color: #333;
}
.jasmine_html-reporter .jasmine-bar.jasmine-failed, .jasmine_html-reporter .jasmine-bar.jasmine-errored { .jasmine_html-reporter .jasmine-bar.jasmine-failed, .jasmine_html-reporter .jasmine-bar.jasmine-errored {
background-color: #ca3a11; background-color: #ca3a11;
color: #eee;
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;
} }
.jasmine_html-reporter .jasmine-bar.jasmine-passed { .jasmine_html-reporter .jasmine-bar.jasmine-passed {

View File

@@ -1132,7 +1132,74 @@ describe('HtmlReporterV2', function() {
}); });
}); });
describe('The overall result bar', function() { describe('The overall status bar', function() {
describe('Before the jasmineDone event fires', function() {
describe('When nothing has failed', function() {
it('shows "Running..." and the has class jasmine-in-progress', function() {
const reporter = setup();
reporter.initialize();
const alertBar = container.querySelector('.jasmine-overall-result');
expect(alertBar.textContent).toEqual('Running...');
expect(alertBar).not.toHaveClass('jasmine-passed');
expect(alertBar).not.toHaveClass('jasmine-failed');
expect(alertBar).toHaveClass('jasmine-in-progress');
for (const status of ['passed', 'excluded', 'pending']) {
reporter.specDone({
status,
fullName: `Some ${status} spec`,
passedExpectations: [],
failedExpectations: []
});
}
expect(alertBar.textContent).toEqual('Running...');
expect(alertBar).not.toHaveClass('jasmine-passed');
expect(alertBar).not.toHaveClass('jasmine-failed');
expect(alertBar).toHaveClass('jasmine-in-progress');
});
});
describe('When a spec has failed', function() {
it('shows "Failing..." and the has class jasmine-failed', function() {
const reporter = setup();
reporter.initialize();
const alertBar = container.querySelector('.jasmine-overall-result');
reporter.specDone({
status: 'failed',
fullName: 'Some failed spec',
passedExpectations: [],
failedExpectations: []
});
expect(alertBar.textContent).toEqual('Failing...');
expect(alertBar).toHaveClass('jasmine-failed');
expect(alertBar).not.toHaveClass('jasmine-passed');
});
});
describe('When a suite has failed', function() {
it('shows "Failing..." and the has class jasmine-failed', function() {
const reporter = setup();
reporter.initialize();
const alertBar = container.querySelector('.jasmine-overall-result');
reporter.suiteDone({
status: 'failed',
fullName: 'Some failed suite',
passedExpectations: [],
failedExpectations: []
});
expect(alertBar.textContent).toEqual('Failing...');
expect(alertBar).toHaveClass('jasmine-failed');
expect(alertBar).not.toHaveClass('jasmine-passed');
});
});
});
describe("When the jasmineDone event's overallStatus is 'passed'", function() { describe("When the jasmineDone event's overallStatus is 'passed'", function() {
it('has class jasmine-passed', function() { it('has class jasmine-passed', function() {
const reporter = setup(); const reporter = setup();

View File

@@ -30,6 +30,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
// Sub-views // Sub-views
#alerts; #alerts;
#statusBar;
#progress; #progress;
#banner; #banner;
#failures; #failures;
@@ -64,6 +65,9 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
this.#stateBuilder = new j$.private.ResultsStateBuilder(); this.#stateBuilder = new j$.private.ResultsStateBuilder();
this.#alerts = new j$.private.AlertsView(this.#urlBuilder); this.#alerts = new j$.private.AlertsView(this.#urlBuilder);
this.#statusBar = new j$.private.OverallStatusBar(this.#urlBuilder);
this.#statusBar.showRunning();
this.#alerts.addBar(this.#statusBar.rootEl);
this.#progress = new ProgressView(); this.#progress = new ProgressView();
this.#banner = new j$.private.Banner( this.#banner = new j$.private.Banner(
this.#queryString.navigateWithNewParam.bind(this.#queryString), this.#queryString.navigateWithNewParam.bind(this.#queryString),
@@ -96,6 +100,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
if (result.status === 'failed') { if (result.status === 'failed') {
this.#failures.append(result, this.#stateBuilder.currentParent); this.#failures.append(result, this.#stateBuilder.currentParent);
this.#statusBar.showFailing();
} }
} }
@@ -116,6 +121,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
if (result.status === 'failed') { if (result.status === 'failed') {
this.#failures.append(result, this.#stateBuilder.currentParent); this.#failures.append(result, this.#stateBuilder.currentParent);
this.#statusBar.showFailing();
} }
} }
@@ -134,9 +140,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
); );
} }
const statusBar = new j$.private.OverallStatusBar(this.#urlBuilder); this.#statusBar.showDone(doneResult, this.#stateBuilder);
statusBar.showDone(doneResult, this.#stateBuilder);
this.#alerts.addBar(statusBar.rootEl);
if (doneResult.failedExpectations) { if (doneResult.failedExpectations) {
for (const f of doneResult.failedExpectations) { for (const f of doneResult.failedExpectations) {

View File

@@ -2,6 +2,7 @@ jasmineRequire.OverallStatusBar = function(j$) {
'use strict'; 'use strict';
const { createDom } = j$.private.htmlReporterUtils; const { createDom } = j$.private.htmlReporterUtils;
const staticClassNames = 'jasmine-overall-result jasmine-bar';
class OverallStatusBar { class OverallStatusBar {
#urlBuilder; #urlBuilder;
@@ -9,11 +10,25 @@ jasmineRequire.OverallStatusBar = function(j$) {
constructor(urlBuilder) { constructor(urlBuilder) {
this.#urlBuilder = urlBuilder; this.#urlBuilder = urlBuilder;
this.rootEl = createDom('span', { this.rootEl = createDom('span', {
className: 'jasmine-overall-result jasmine-bar' className: staticClassNames,
'aria-live': 'polite'
}); });
} }
showRunning() {
this.rootEl.textContent = 'Running...';
this.rootEl.classList.add('jasmine-in-progress');
}
showFailing() {
this.rootEl.textContent = 'Failing...';
this.rootEl.classList.add('jasmine-failed');
}
showDone(doneResult, stateBuilder) { showDone(doneResult, stateBuilder) {
// Clear any classes added to represent in-progress state
this.rootEl.className = staticClassNames;
let statusBarMessage = ''; let statusBarMessage = '';
const globalFailures = const globalFailures =
(doneResult && doneResult.failedExpectations) || []; (doneResult && doneResult.failedExpectations) || [];

View File

@@ -233,8 +233,13 @@ body {
display: block; display: block;
color: #eee; color: #eee;
&.jasmine-in-progress {
color: $text-color;
}
&.jasmine-failed, &.jasmine-errored { &.jasmine-failed, &.jasmine-errored {
background-color: $failing-color; background-color: $failing-color;
color: #eee; // Override jasmine-in-progress
border-bottom: 1px solid $page-background-color; border-bottom: 1px solid $page-background-color;
} }