Skip to content

Commit 28a09d7

Browse files
committed
build: test runner show total time taken to run tests in ui
1 parent b85ae69 commit 28a09d7

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

test/BootstrapReporterView.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ define(function (require, exports, module) {
3030

3131
var _ = require("thirdparty/lodash");
3232

33+
function formatMilliseconds(ms) {
34+
const hours = Math.floor(ms / (1000 * 60 * 60));
35+
const minutes = Math.floor((ms % (1000 * 60 * 60)) / (1000 * 60));
36+
const seconds = Math.floor((ms % (1000 * 60)) / 1000);
37+
38+
let result = '';
39+
40+
if (hours) {
41+
result = result + `${hours}-Hour `;
42+
}
43+
if (minutes) {
44+
result = result + `${minutes}-Minutes `;
45+
}
46+
result = `${result}${seconds}-Seconds`;
47+
48+
return result.trim();
49+
}
50+
3351
function _addPrintableContainer() {
3452
var container = $(`
3553
<div>
@@ -236,17 +254,26 @@ define(function (require, exports, module) {
236254
}
237255
};
238256

239-
BootstrapReporterView.prototype._handleRunnerEnd = function (event, reporter) {
257+
BootstrapReporterView.prototype._handleRunnerEnd = function (event, reporter, runnerResult) {
240258
if (this.$info) {
241259
this.$info.toggleClass("alert-info", false);
242260

243261
window.testResults.passed = reporter.passed;
262+
263+
// Get total time from the reporter's runInfo if available
264+
let totalTime = null;
265+
if (runnerResult && runnerResult.totalTime) {
266+
totalTime = runnerResult.totalTime;
267+
}
268+
269+
let timeText = totalTime ? ` (Done in ${formatMilliseconds(totalTime)})` : '';
270+
244271
if (reporter.passed) {
245-
this.$info.toggleClass("alert-success", true).text("Complete. No failures.");
272+
this.$info.toggleClass("alert-success", true).text("Complete. No failures." + timeText);
246273
} else {
247274
this.$info.toggleClass("alert-error", true).text(
248275
"Complete. See failures Below. If all tests have passed and no failures are seen below," +
249-
"Check the debug console for errors. (search for 'Spec Error:' , 'Suite Error:' or Runner Error: in console)");
276+
"Check the debug console for errors. (search for 'Spec Error:' , 'Suite Error:' or Runner Error: in console)" + timeText);
250277
}
251278
window.playWrightRunComplete = true;
252279
}

test/UnitTestReporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ define(function (require, exports, module) {
512512
}
513513
}
514514
}
515-
$(this).triggerHandler("runnerEnd", [this]);
515+
$(this).triggerHandler("runnerEnd", [this, runner]);
516516
activeReporter = null;
517517
};
518518

0 commit comments

Comments
 (0)