Files
vercel__workflow/packages/web-shared/test/format-duration-precise.test.ts
Mitul Shah eb2b8c988d [web-shared] Show precise durations in the new trace viewer (#2335)
* [web-shared] Show precise durations in the new trace viewer

The events list and timeline bar labels now render two-decimal seconds for
durations over 1s instead of rounding to whole seconds.

Co-authored-by: Cursor <cursoragent@cursor.com>

* [web-shared] Fix duration rounding at unit boundaries

formatDurationPrecise bucketed durations on the raw ms value but only
rounded at display time, so inputs just below a unit boundary carried
into the next unit without re-bucketing (e.g. 59999ms -> "60.00s").

Round to centisecond precision FIRST, then decompose in integer
centisecond space so the seconds component stays in [0.00, 59.99] and
carries re-bucket into the next unit (59999ms -> "1m 0.00s").

Co-authored-by: Cursor <cursoragent@cursor.com>

* [web-shared] Simplify precise duration formatting

Reuse the existing MS_IN_* constants instead of the centisecond decomposition; behavior is unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-10 20:57:29 +00:00

30 lines
1.3 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { formatDurationPrecise } from '../src/lib/utils.js';
/**
* Tests for `formatDurationPrecise`, with particular focus on unit-boundary
* carry cases. The formatter rounds to centisecond precision FIRST and then
* decomposes in integer space, so a value just below a unit boundary (e.g.
* 59999ms) re-buckets into the next unit ("1m 0.00s") instead of rendering an
* impossible component like "60.00s".
*/
describe('formatDurationPrecise', () => {
it('formats normal durations', () => {
expect(formatDurationPrecise(0)).toBe('0s');
expect(formatDurationPrecise(626)).toBe('626ms');
expect(formatDurationPrecise(1626)).toBe('1.63s');
expect(formatDurationPrecise(45200)).toBe('45.20s');
expect(formatDurationPrecise(73450)).toBe('1m 13.45s');
});
it('re-buckets values that carry across unit boundaries', () => {
expect(formatDurationPrecise(999.6)).toBe('1.00s');
expect(formatDurationPrecise(999.5)).toBe('1.00s');
expect(formatDurationPrecise(59999)).toBe('1m 0.00s');
expect(formatDurationPrecise(59995)).toBe('1m 0.00s');
expect(formatDurationPrecise(119999)).toBe('2m 0.00s');
expect(formatDurationPrecise(3659999)).toBe('1h 1m 0.00s');
expect(formatDurationPrecise(86459999)).toBe('1d 1m 0.00s');
});
});