Skip to content

Commit bfa2b65

Browse files
committed
fix: sort groups in HTML report when sort mode is changed
The sort toggle in the HTML report only sorted tests within each group but never reordered the groups themselves. Added sortGroups() to also sort groups by duration (slowest first) or name (alphabetical). Also added an empty favicon link to prevent 404 errors when the report is served from a remote host.
1 parent 4e5b663 commit bfa2b65

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

TUnit.Engine/Reporters/Html/HtmlReportGenerator.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private static void AppendHead(StringBuilder sb, ReportData data)
2424
sb.AppendLine("<head>");
2525
sb.AppendLine("<meta charset=\"UTF-8\">");
2626
sb.AppendLine("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">");
27+
sb.AppendLine("<link rel=\"icon\" href=\"data:,\">");
2728
sb.Append("<title>Test Report \u2014 ");
2829
sb.Append(WebUtility.HtmlEncode(data.AssemblyName));
2930
sb.AppendLine("</title>");
@@ -1532,10 +1533,20 @@ function renderSlowestSection() {
15321533
sec.innerHTML = h;
15331534
}
15341535
1536+
function sortGroups(grps) {
1537+
if (sortMode === 'duration') return [...grps].sort((a,b) => {
1538+
const aMax = Math.max.apply(null, a.tests.map(function(t){return t.durationMs}));
1539+
const bMax = Math.max.apply(null, b.tests.map(function(t){return t.durationMs}));
1540+
return bMax - aMax;
1541+
});
1542+
if (sortMode === 'name') return [...grps].sort((a,b) => a.label.localeCompare(b.label));
1543+
return grps;
1544+
}
1545+
15351546
function render() {
15361547
let total = 0;
15371548
let html = '';
1538-
const displayGroups = computeDisplayGroups();
1549+
const displayGroups = sortGroups(computeDisplayGroups());
15391550
const limited = displayGroups.slice(0, renderLimit);
15401551
limited.forEach((g,gi)=>{
15411552
const ft = sortTests(g.tests.filter(matchesFilter));

0 commit comments

Comments
 (0)