From 5b409b56177646bc1143b3b0d86255a9e8369b59 Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Sun, 31 May 2026 10:40:27 +0100 Subject: [PATCH] fix(html-report): normalise per-test trace timeline to earliest span The Trace tab plotted spans against an axis starting at 0, but span start values are absolute offsets from the run start. Tests starting partway through a run had all their bars pushed to the right with empty lead-in space, making the trace look erroneously sparse. Normalise span positions to the earliest span start (minStart), mirroring the logic already used by the other timeline renderer in the template. Co-Authored-By: Claude Opus 4.8 --- TUnit.Engine/Reporters/Html/TestReport.template.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/TUnit.Engine/Reporters/Html/TestReport.template.html b/TUnit.Engine/Reporters/Html/TestReport.template.html index 84a79967d5..5971ba850c 100644 --- a/TUnit.Engine/Reporters/Html/TestReport.template.html +++ b/TUnit.Engine/Reporters/Html/TestReport.template.html @@ -2655,14 +2655,18 @@

Select a test

const byId = new Map(spans.map(s => [s.id, s])); spans.forEach(s => { s._children = []; }); spans.forEach(s => { if (s.parent && byId.has(s.parent)) byId.get(s.parent)._children.push(s); }); - const totalDur = Math.max(...spans.map(s => s.start + s.dur)); + // Span starts are absolute offsets from the run start, so normalise to the + // earliest span — otherwise the axis begins at 0 and all bars are pushed to + // the right, leaving the lead-in time before the test empty. + const minStart = Math.min(...spans.map(s => s.start)); + const totalDur = (Math.max(...spans.map(s => s.start + s.dur)) - minStart) || 1; const ticks = 6, axisHtml = []; for (let i = 0; i <= ticks; i++) axisHtml.push(`${fmtDur((i/ticks)*totalDur)}`); const rows = []; function walk(span, depth) { const color = SERVICE_COLORS[span.service] || 'var(--text-muted)'; - const left = (span.start / totalDur) * 100; + const left = ((span.start - minStart) / totalDur) * 100; const width = Math.max(0.2, (span.dur / totalDur) * 100); const err = (span.attrs && span.attrs['http.status_code'] >= 500) ? ' err' : ''; rows.push(`