mirror of https://github.com/openclaw/openclaw.git
fix: tighten duration formatter coverage
This commit is contained in:
parent
71a3dd80e7
commit
fa05947225
|
|
@ -32,7 +32,7 @@ export function formatDurationPrecise(
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
if (ms < 1000) {
|
if (ms < 1000) {
|
||||||
return `${ms}ms`;
|
return `${Math.max(0, Math.round(ms))}ms`;
|
||||||
}
|
}
|
||||||
return formatDurationSeconds(ms, {
|
return formatDurationSeconds(ms, {
|
||||||
decimals: options.decimals ?? 2,
|
decimals: options.decimals ?? 2,
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,12 @@ describe("format-duration", () => {
|
||||||
expect(formatDurationPrecise(999)).toBe("999ms");
|
expect(formatDurationPrecise(999)).toBe("999ms");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("clamps negative and fractional sub-second values to non-negative milliseconds", () => {
|
||||||
|
expect(formatDurationPrecise(-1)).toBe("0ms");
|
||||||
|
expect(formatDurationPrecise(-500)).toBe("0ms");
|
||||||
|
expect(formatDurationPrecise(999.6)).toBe("1000ms");
|
||||||
|
});
|
||||||
|
|
||||||
it("shows decimal seconds for >=1s", () => {
|
it("shows decimal seconds for >=1s", () => {
|
||||||
expect(formatDurationPrecise(1000)).toBe("1s");
|
expect(formatDurationPrecise(1000)).toBe("1s");
|
||||||
expect(formatDurationPrecise(1500)).toBe("1.5s");
|
expect(formatDurationPrecise(1500)).toBe("1.5s");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue