Files
vercel__workflow/packages/web-shared/test/format-duration-precise.test.ts
Mitul Shah 8a766884cf change timing markers to be precise on the timeline (#2775)
* doen

* Fix: Old test file `test/format-duration-precise.test.ts` still asserts two-decimal output ("45.20s", "1m 0.00s") that no longer matches the trimmed-zero output of `formatDurationPrecise`, so `pnpm test`/CI fails.

This commit fixes the issue reported at packages/web-shared/test/format-duration-precise.test.ts:15

## Bug

The PR changed `formatDurationPrecise` (in `packages/web-shared/src/lib/utils.ts`) to trim trailing zeros by wrapping the fractional value in `Number(x.toFixed(fractionDigits))`:

```ts
if (normalizedMs < MS_IN_MINUTE) {
  return `${Number((normalizedMs / MS_IN_SECOND).toFixed(fractionDigits))}s`;
}
...
parts.push(`${Number(seconds.toFixed(fractionDigits))}s`);
```

`Number("45.20")` → `45.2`, `Number("0.00")` → `0`, so whole/half seconds now render without padding.

A new test file `packages/web-shared/src/lib/utils.test.ts` reflects this behavior, but the pre-existing `packages/web-shared/test/format-duration-precise.test.ts` was left untouched and still asserts the **old** padded output.

## Concrete trigger

Reproduced the actual function output (integer decomposition + trimmed zeros):

| Input | Old assertion | New actual output |
|-------|---------------|-------------------|
| `45200` | `45.20s` | `45.2s` |
| `999.6` | `1.00s` | `1s` |
| `999.5` | `1.00s` | `1s` |
| `59999` | `1m 0.00s` | `1m 0s` |
| `59995` | `1m 0.00s` | `1m 0s` |
| `119999` | `2m 0.00s` | `2m 0s` |
| `3659999` | `1h 1m 0.00s` | `1h 1m 0s` |
| `86459999` | `1d 1m 0.00s` | `1d 1m 0s` |

The root `vitest.config.ts` uses default include globs, so `test/*.test.ts` runs and these assertions fail, breaking CI. (I couldn't run vitest directly in the sandbox because dev deps weren't installed / `vitest/config` unresolved, so I reproduced the exact function logic in a standalone Node script to confirm the outputs.)

## Fix

Updated the stale assertions in `test/format-duration-precise.test.ts` to the trimmed-zero outputs, and adjusted the file-level doc comment (which referenced `"1m 0.00s"` / `"60.00s"`) to describe the current behavior.

Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: mitul-s <mitulxshah@gmail.com>

---------

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
2026-07-06 18:27:10 -04:00

31 lines
1.4 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 0s") instead of rendering an
* impossible component like "60s". Trailing zeros are trimmed, so whole
* seconds read cleanly ("1m 0s" rather than "1m 0.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.2s');
expect(formatDurationPrecise(73450)).toBe('1m 13.45s');
});
it('re-buckets values that carry across unit boundaries', () => {
expect(formatDurationPrecise(999.6)).toBe('1s');
expect(formatDurationPrecise(999.5)).toBe('1s');
expect(formatDurationPrecise(59999)).toBe('1m 0s');
expect(formatDurationPrecise(59995)).toBe('1m 0s');
expect(formatDurationPrecise(119999)).toBe('2m 0s');
expect(formatDurationPrecise(3659999)).toBe('1h 1m 0s');
expect(formatDurationPrecise(86459999)).toBe('1d 1m 0s');
});
});