diff --git a/TUnit.Engine/Reporters/Html/HtmlReportGenerator.cs b/TUnit.Engine/Reporters/Html/HtmlReportGenerator.cs index 3e3a7d9f9b..b332960955 100644 --- a/TUnit.Engine/Reporters/Html/HtmlReportGenerator.cs +++ b/TUnit.Engine/Reporters/Html/HtmlReportGenerator.cs @@ -24,6 +24,7 @@ private static void AppendHead(StringBuilder sb, ReportData data) sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); + sb.AppendLine(""); sb.Append("Test Report \u2014 "); sb.Append(WebUtility.HtmlEncode(data.AssemblyName)); sb.AppendLine(""); @@ -1204,7 +1205,7 @@ function highlight(text, query) { function sortTests(tests) { if (sortMode === 'duration') return [...tests].sort((a,b) => b.durationMs - a.durationMs); if (sortMode === 'name') return [...tests].sort((a,b) => a.displayName.localeCompare(b.displayName)); - return [...tests].sort((a,b) => (statusOrder[a.status]||9) - (statusOrder[b.status]||9)); + return [...tests].sort((a,b) => (statusOrder[a.status]??9) - (statusOrder[b.status]??9)); } function computeDisplayGroups() { @@ -1532,10 +1533,20 @@ function renderSlowestSection() { sec.innerHTML = h; } +function sortGroups(grps) { + if (sortMode === 'duration') { + const maxDur = new Map(grps.map(g => [g, g.tests.length ? Math.max(...g.tests.map(t => t.durationMs)) : 0])); + return [...grps].sort((a,b) => maxDur.get(b) - maxDur.get(a)); + } + if (sortMode === 'name') return [...grps].sort((a,b) => a.label.localeCompare(b.label)); + const minStatus = new Map(grps.map(g => [g, g.tests.length ? Math.min(...g.tests.map(t => statusOrder[t.status] ?? 9)) : 9])); + return [...grps].sort((a,b) => minStatus.get(a) - minStatus.get(b)); +} + function render() { let total = 0; let html = ''; - const displayGroups = computeDisplayGroups(); + const displayGroups = sortGroups(computeDisplayGroups()); const limited = displayGroups.slice(0, renderLimit); limited.forEach((g,gi)=>{ const ft = sortTests(g.tests.filter(matchesFilter));