Skip to content

Commit

Permalink
HTML Reporter: Fix formatting of 951-999ms as plural "1 seconds"
Browse files Browse the repository at this point in the history
We only checked for 1 equality in the branch for >1000,
but toPrecision also returns "1" for numbers close but under it.

Ref #1760.
  • Loading branch information
Krinkle committed Jul 10, 2024
1 parent 3a3c898 commit 4419ce6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/reporters/HtmlReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,12 +723,12 @@ export default class HtmlReporter {

onRunEnd (runEnd) {
function msToSec (milliseconds) {
if (milliseconds < 1000) {
// Will return e.g. "0.2", "0.03" or "0.004"
return (milliseconds / 1000).toPrecision(1) + ' seconds';
}
const sec = Math.ceil(milliseconds / 1000);
return sec + (sec === 1 ? ' second' : ' seconds');
// Will return a whole number of seconds,
// or e.g. "0.2", "0.03" or "0.004".
const sec = (milliseconds > 1000)
? ('' + Math.round(milliseconds / 1000))
: (milliseconds / 1000).toPrecision(1);
return sec + (sec === '1' ? ' second' : ' seconds');
}

const abortButton = this.element.querySelector('#qunit-abort-tests-button');
Expand All @@ -742,20 +742,17 @@ export default class HtmlReporter {
'and <span class="todo">', runEnd.testCounts.todo, '</span> todo.',
this.getRerunFailedHtml(this.stats.failedTests)
].join('');
let test;
let assertLi;
let assertList;

// Update remaining tests to aborted
if (abortButton && abortButton.disabled) {
html = 'Tests aborted after ' + msToSec(runEnd.runtime) + '.';

for (let i = 0; i < this.elementTests.children.length; i++) {
test = this.elementTests.children[i];
const test = this.elementTests.children[i];
if (test.className === '' || test.className === 'running') {
test.className = 'aborted';
assertList = test.getElementsByTagName('ol')[0];
assertLi = document.createElement('li');
const assertList = test.getElementsByTagName('ol')[0];
const assertLi = document.createElement('li');
assertLi.className = 'fail';
assertLi.textContent = 'Test aborted.';
assertList.appendChild(assertLi);
Expand Down
34 changes: 34 additions & 0 deletions test/main/HtmlReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,40 @@ QUnit.test('testresult-display [testStart]', function (assert) {
);
});

QUnit.test.each('testresult-display [runEnd]', {
'3ms': [3, '0.003 seconds'],
'98ms': [98, '0.1 seconds'],
'149ms': [149, '0.1 seconds'],
'151ms': [151, '0.2 seconds'],
'850ms': [850, '0.8 seconds'],
'940ms': [940, '0.9 seconds'],
'960ms': [960, '1 second'],
'1010ms': [1010, '1 second'],
'1090ms': [1090, '1 second'],
'1590ms': [1590, '2 seconds']
}, function (assert, data) {
var element = document.createElement('div');
new QUnit.reporters.html(this.MockQUnit, {
element: element,
config: {
urlConfig: []
}
});
this.MockQUnit._do_mixed_run_half();
this.MockQUnit.emit('runEnd', {
testCounts: { total: 5, passed: 4, failed: 0, skipped: 1, todo: 0 },
status: 'passed',
runtime: data[0]
});

var display = element.querySelector('#qunit-testresult-display');
assert.equal(
display.textContent,
'5 tests completed in ' + data[1] + '.4 passed, 1 skipped, 0 failed, and 0 todo.',
'display text'
);
});

QUnit.test('test-output trace', function (assert) {
var element = document.createElement('div');
new QUnit.reporters.html(this.MockQUnit, {
Expand Down

0 comments on commit 4419ce6

Please sign in to comment.