← Back to PRs

#11421: Tests: add unit tests for infra/format-duration

by PythonUser42 open 2026-02-07 19:55 View on GitHub →
stale size: S
## Summary - Add `src/infra/format-duration.test.ts` with 14 tests covering both `formatDurationSeconds()` and `formatDurationMs()` - Covers: non-finite values (NaN, Infinity), negative inputs, zero, trailing zero trimming, decimal precision options, unit labels (`s` vs `seconds`), and the ms-to-seconds threshold at 1000ms ## Test plan - [x] All 14 tests pass locally via `vitest run src/infra/format-duration.test.ts` - [x] AI-assisted (Claude Code), tested, and verified against source implementation 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds a new Vitest unit test file (`src/infra/format-duration.test.ts`) covering `formatDurationSeconds()` and `formatDurationMs()` across typical values and edge cases (non-finite numbers, negatives, zero, trailing-zero trimming, decimals option, unit label options, and the 1000ms threshold behavior). The tests align with the current implementation in `src/infra/format-duration.ts` (e.g., `formatDurationMs` returning raw `ms` strings for values `< 1000`, and delegating to `formatDurationSeconds` with a default of 2 decimals). <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk. - Changes are limited to adding a new unit test file, and the assertions match the current `format-duration` implementation (including edge-case handling and default options). No production code paths are modified. - No files require special attention <!-- greptile_other_comments_section --> <sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub> <!-- /greptile_comment -->

Most Similar PRs