diff --git a/src/features/run/testing/parsers.test.ts b/src/features/run/testing/parsers.test.ts index 0d0ee0977..d57e6a83c 100644 --- a/src/features/run/testing/parsers.test.ts +++ b/src/features/run/testing/parsers.test.ts @@ -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 diff --git a/src/features/run/testing/types.ts b/src/features/run/testing/types.ts index e62dcadcc..f770bc180 100644 --- a/src/features/run/testing/types.ts +++ b/src/features/run/testing/types.ts @@ -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`; } /**