Skip to content

Commit

Permalink
Core: Fix event "runtime" data to be rounded to milliseconds
Browse files Browse the repository at this point in the history
Follows-up b70af72, which corrected this in the UI, but this
means any plugins and integrations reporting `details.runtime` are
still affected by the needless precision.

This affects:
* `QUnit.log`, `QUnit.testDone`, `QUnit.moduleDone` and `QUnit.done`.
* `on('testEnd')`, `on('suiteEnd')`, and `on('runEnd')`.

I was initially cautious about this as I worried that perhaps
consumers would accumulate these and then become increasingly less
accurate in large test suites where perhaps most leaf nodes round to
0ms. However I have no such case in practice. Generally, for total
times the reported totals can be, should be, and are being used.

Ref #1678.
  • Loading branch information
Krinkle committed Apr 18, 2022
1 parent 01bdab0 commit 2e05357
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/core/processing-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function done () {

const storage = config.storage;

const runtime = performance.now() - config.started;
const runtime = Math.round(performance.now() - config.started);
const passed = config.stats.all - config.stats.bad;

ProcessingQueue.finished = true;
Expand Down
8 changes: 4 additions & 4 deletions src/html-reporter/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ export function escapeText (str) {
let html = [
runEnd.testCounts.total,
' tests completed in ',
Math.round(runEnd.runtime),
runEnd.runtime,
' milliseconds, with ',
runEnd.testCounts.failed,
' failed, ',
Expand All @@ -779,7 +779,7 @@ export function escapeText (str) {

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

for (let i = 0; i < tests.children.length; i++) {
test = tests.children[i];
Expand Down Expand Up @@ -882,7 +882,7 @@ export function escapeText (str) {

let message = escapeText(details.message) || (details.result ? 'okay' : 'failed');
message = "<span class='test-message'>" + message + '</span>';
message += "<span class='runtime'>@ " + Math.round(details.runtime) + ' ms</span>';
message += "<span class='runtime'>@ " + details.runtime + ' ms</span>';

let expected;
let actual;
Expand Down Expand Up @@ -1043,7 +1043,7 @@ export function escapeText (str) {

let time = document.createElement('span');
time.className = 'runtime';
time.innerHTML = Math.round(details.runtime) + ' ms';
time.innerHTML = details.runtime + ' ms';
testItem.insertBefore(time, assertList);
}

Expand Down
2 changes: 1 addition & 1 deletion src/reports/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class SuiteReport {
}

getRuntime () {
return this._endTime - this._startTime;
return Math.round(this._endTime - this._startTime);
}

getTestCounts (counts = { passed: 0, failed: 0, skipped: 0, todo: 0, total: 0 }) {
Expand Down
2 changes: 1 addition & 1 deletion src/reports/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class TestReport {
}

getRuntime () {
return this._endTime - this._startTime;
return Math.round(this._endTime - this._startTime);
}

getStatus () {
Expand Down
6 changes: 3 additions & 3 deletions src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ Test.prototype = {
let bad = 0;
const storage = config.storage;

this.runtime = performance.now() - this.started;
this.runtime = Math.round(performance.now() - this.started);

config.stats.all += this.assertions.length;
config.stats.testCount += 1;
Expand Down Expand Up @@ -477,7 +477,7 @@ Test.prototype = {
failed: module.stats.bad,
passed: module.stats.all - module.stats.bad,
total: module.stats.all,
runtime: performance.now() - module.stats.started
runtime: Math.round(performance.now() - module.stats.started)
});
}
},
Expand Down Expand Up @@ -559,7 +559,7 @@ Test.prototype = {
actual: resultInfo.actual,
testId: this.testId,
negative: resultInfo.negative || false,
runtime: performance.now() - this.started,
runtime: Math.round(performance.now() - this.started),
todo: !!this.todo
};

Expand Down

0 comments on commit 2e05357

Please sign in to comment.