Merge pull request #14945 from roidelapluie/submillis

fix(web): properly format sub-millisecond durations in target status page
This commit is contained in:
Julius Volz 2024-09-20 21:27:16 +02:00 committed by GitHub
commit dfc6f4b5bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View file

@ -57,6 +57,12 @@ describe("humanizeDuration", () => {
expect(humanizeDuration(0)).toBe("0s"); expect(humanizeDuration(0)).toBe("0s");
}); });
test("formats submilliseconds correctly", () => {
expect(humanizeDuration(0.1)).toBe("0ms");
expect(humanizeDuration(0.6)).toBe("1ms");
expect(humanizeDuration(0.000001)).toBe("0ms");
});
test("formats milliseconds correctly", () => { test("formats milliseconds correctly", () => {
expect(humanizeDuration(1)).toBe("1ms"); expect(humanizeDuration(1)).toBe("1ms");
expect(humanizeDuration(999)).toBe("999ms"); expect(humanizeDuration(999)).toBe("999ms");

View file

@ -86,6 +86,9 @@ const formatDuration = (
r.push(`${v}${unit}`); r.push(`${v}${unit}`);
} }
} }
if (r.length == 0 && unit == "ms") {
r.push(`${Math.round(ms)}ms`)
}
} }
return sign + r.join(componentSeparator || ""); return sign + r.join(componentSeparator || "");