Skip to content

Commit

Permalink
HTML Reporter: Report time as seconds in qunit-testresult-display
Browse files Browse the repository at this point in the history
QUnit 2.21.0:
> 254 tests completed in 912 milliseconds, with 0 failed, 7 skipped, and 4 todo.
> 819 assertions of 823 passed, 4 failed.

New:
> 254 tests completed in 0.9 seconds, with 0 failed, 7 skipped, and 4 todo.

This is a more human-scale number. Rounding is opionated. I went with 1 digit
of precision, and thus reporting 123ms as 0.1s. For number smaller than 100ms,
I opted for a longer format with at always 1 significant digit, so reporting
20ms as 0.02s, instead of e.g. forcefully rounding either down to a confusing
0.0s or a deceptively high 0.1s. It allows for a little pride/recognition of
small numbers. As a GUI, this is not meant to be machine readable either way.
In practice, numbers below 0.1s are rare.

The `runEnd` event data is unchanged, and continues to report in milliseconds.
  • Loading branch information
Krinkle committed Jun 11, 2024
1 parent dbeab48 commit 170acc0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/html-reporter/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,15 +721,24 @@ const stats = {
].join('');
}

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

QUnit.on('runEnd', function (runEnd) {
const banner = id('qunit-banner');
const tests = id('qunit-tests');
const abortButton = id('qunit-abort-tests-button');
let html = [
runEnd.testCounts.total,
' tests completed in ',
runEnd.runtime,
' milliseconds, with ',
msToSec(runEnd.runtime),
', with ',
runEnd.testCounts.failed,
' failed, ',
runEnd.testCounts.skipped,
Expand All @@ -744,7 +753,7 @@ const stats = {

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

for (let i = 0; i < tests.children.length; i++) {
test = tests.children[i];
Expand Down

0 comments on commit 170acc0

Please sign in to comment.