fix(run): carry a duration's rounded seconds into its minutes (#5142)

A run or test lasting between 1 m 59.5 s and 2 m showed as `1 m 60 s` (and likewise at every minute) in the test tree, the exported test report and the run tab's "Finished in …" tooltip. `formatDuration` split off whole minutes first and rounded the remainder afterwards; it now rounds to whole seconds first and splits after.

Co-authored-by: HEOJUNFO <100739943+HEOJUNFO@users.noreply.github.com>
This commit is contained in:
HEOJUNFO
2026-11-22 14:04:54 +08:00
committed by GitHub
parent 92dbf0baa5
commit 305ff382e7
2 changed files with 19 additions and 2 deletions
+17
View File
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import {
cargoParser,
createTestParser,
formatDuration,
frameworkFor,
goParser,
jsParser,
@@ -39,6 +40,22 @@ describe("parseDuration", () => {
});
});
describe("formatDuration", () => {
it("shows milliseconds, seconds and minutes", () => {
expect(formatDuration(undefined)).toBe("");
expect(formatDuration(850)).toBe("850 ms");
expect(formatDuration(1250)).toBe("1.25 s");
expect(formatDuration(59_400)).toBe("59.4 s");
expect(formatDuration(125_000)).toBe("2 m 5 s");
});
it("carries seconds that round up to 60 into the minutes", () => {
expect(formatDuration(119_400)).toBe("1 m 59 s");
expect(formatDuration(119_600)).toBe("2 m 0 s");
expect(formatDuration(3_599_700)).toBe("60 m 0 s");
});
});
describe("cargo test", () => {
const fixture = ` Compiling app v0.1.0 (/p/app)
Finished \`test\` profile [unoptimized + debuginfo] target(s) in 0.52s
+2 -2
View File
@@ -48,8 +48,8 @@ export function formatDuration(ms: number | undefined): string {
if (ms === undefined) return "";
if (ms < 1000) return `${Math.round(ms)} ms`;
if (ms < 60_000) return `${(ms / 1000).toFixed(ms < 10_000 ? 2 : 1).replace(/\.?0+$/, "")} s`;
const m = Math.floor(ms / 60_000);
return `${m} m ${Math.round((ms % 60_000) / 1000)} s`;
const s = Math.round(ms / 1000);
return `${Math.floor(s / 60)} m ${s % 60} s`;
}
/**