HtmlReporterV2: show median and mean spec run time
This commit is contained in:
@@ -1509,14 +1509,17 @@ jasmineRequire.PerformanceView = function(j$) {
|
||||
const MAX_SLOW_SPECS = 20;
|
||||
|
||||
class PerformanceView {
|
||||
#summary;
|
||||
#tbody;
|
||||
|
||||
constructor() {
|
||||
this.#tbody = document.createElement('tbody');
|
||||
this.#summary = document.createElement('div');
|
||||
this.rootEl = createDom(
|
||||
'div',
|
||||
{ className: 'jasmine-performance-view' },
|
||||
createDom('h2', {}, 'Performance'),
|
||||
this.#summary,
|
||||
createDom('h3', {}, 'Slowest Specs'),
|
||||
createDom(
|
||||
'table',
|
||||
@@ -1537,9 +1540,13 @@ jasmineRequire.PerformanceView = function(j$) {
|
||||
}
|
||||
|
||||
addResults(resultsTree) {
|
||||
let specResults = [];
|
||||
const specResults = [];
|
||||
getSpecResults(resultsTree, specResults);
|
||||
|
||||
if (specResults.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
specResults.sort(function(a, b) {
|
||||
if (a.duration < b.duration) {
|
||||
return 1;
|
||||
@@ -1549,6 +1556,25 @@ jasmineRequire.PerformanceView = function(j$) {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
this.#populateSumary(specResults);
|
||||
this.#populateTable(specResults);
|
||||
}
|
||||
|
||||
#populateSumary(specResults) {
|
||||
const total = specResults.map(r => r.duration).reduce((a, b) => a + b, 0);
|
||||
const mean = total / specResults.length;
|
||||
const median = specResults[Math.floor(specResults.length / 2)].duration;
|
||||
this.#summary.appendChild(
|
||||
document.createTextNode(`Mean spec run time: ${mean.toFixed(0)}ms`)
|
||||
);
|
||||
this.#summary.appendChild(document.createElement('br'));
|
||||
this.#summary.appendChild(
|
||||
document.createTextNode(`Median spec run time: ${median}ms`)
|
||||
);
|
||||
}
|
||||
|
||||
#populateTable(specResults) {
|
||||
specResults = specResults.slice(0, MAX_SLOW_SPECS);
|
||||
|
||||
for (const r of specResults) {
|
||||
|
||||
@@ -337,4 +337,15 @@ body {
|
||||
|
||||
.jasmine-tab + .jasmine-tab:before {
|
||||
content: " | ";
|
||||
}
|
||||
|
||||
.jasmine-performance-view h2, .jasmine-performance-view h3 {
|
||||
margin-top: 1em;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
.jasmine-performance-view table {
|
||||
border-spacing: 5px;
|
||||
}
|
||||
.jasmine-performance-view th, .jasmine-performance-view td {
|
||||
text-align: left;
|
||||
}
|
||||
Reference in New Issue
Block a user