From 2e053576cfbf450d5e4e3bf722ae69a0c88cfcdd Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 18 Apr 2022 17:15:43 +0100 Subject: [PATCH] Core: Fix event "runtime" data to be rounded to milliseconds Follows-up b70af72489, 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 https://github.com/qunitjs/qunit/issues/1678. --- src/core/processing-queue.js | 2 +- src/html-reporter/html.js | 8 ++++---- src/reports/suite.js | 2 +- src/reports/test.js | 2 +- src/test.js | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/core/processing-queue.js b/src/core/processing-queue.js index 947464536..bf23da93d 100644 --- a/src/core/processing-queue.js +++ b/src/core/processing-queue.js @@ -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; diff --git a/src/html-reporter/html.js b/src/html-reporter/html.js index 5ddc64cfe..c2cbc4eab 100644 --- a/src/html-reporter/html.js +++ b/src/html-reporter/html.js @@ -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, ', @@ -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]; @@ -882,7 +882,7 @@ export function escapeText (str) { let message = escapeText(details.message) || (details.result ? 'okay' : 'failed'); message = "" + message + ''; - message += "@ " + Math.round(details.runtime) + ' ms'; + message += "@ " + details.runtime + ' ms'; let expected; let actual; @@ -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); } diff --git a/src/reports/suite.js b/src/reports/suite.js index ebb2ff26a..a2b72289f 100644 --- a/src/reports/suite.js +++ b/src/reports/suite.js @@ -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 }) { diff --git a/src/reports/test.js b/src/reports/test.js index aab7f28e3..980207dd6 100644 --- a/src/reports/test.js +++ b/src/reports/test.js @@ -61,7 +61,7 @@ export default class TestReport { } getRuntime () { - return this._endTime - this._startTime; + return Math.round(this._endTime - this._startTime); } getStatus () { diff --git a/src/test.js b/src/test.js index 327fd4a79..75f642a0d 100644 --- a/src/test.js +++ b/src/test.js @@ -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; @@ -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) }); } }, @@ -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 };