fix: round durations and sizes before picking the unit
Merged
WA
8d ago+130+130+012345678901234567890123456789-14-14-01234567890123456789
What and why
formatDurationinmarkdown-text.tspicked the unit before rounding, so 999.6ms showed as1000msand 59.96s as60.0sin the markdown report (and the GitHub PR comment built from it), trace pages, and failure details.- It now rounds first, as #1829 did for the HTML report. Anything that rounds to a minute or more still goes through
formatMinutes, which already rounds first, so 119.6s stays2m 0s. - I checked the other unit formatters in the repo. Four more had the same bug and are fixed here too:
formatMs(--debugtimings),formatBytes(e2e cache stats),formatSize(the HTML reporter's embedded page note), anddurationinscripts/bench-ab/markdown.ts. The two size helpers moved into their own small modules so their tests use the production code. - Apart from
formatTimeinreport/format.ts, none are left. It prints1000msfor 999.6ms, but it copies vitest's format, which prints1000msfor exactly 1000 too, so I left it.
Issue
Fixes #2090
Verified
Ran it locally: yes
| formatter | input | main | this branch |
|---|---|---|---|
formatDuration | 999.6ms | 1000ms | 1.0s |
formatDuration | 59_949ms (unchanged) | 59.9s | 59.9s |
formatDuration | 59_960ms | 60.0s | 1m 0s |
formatDuration | 119_600ms (unchanged) | 2m 0s | 2m 0s |
formatMs | 9_999.6ms | 10000ms | 10.0s |
formatBytes | 1_048_575 B | 1024.0 KiB | 1.0 MiB |
formatSize | 1_047_553 B | 1024 KB | 1.0 MB |
bench-ab duration | 999.6ms | 1000 ms | 1.00 s |
- Each fix has a test that fails on main and passes here.
- The repro from #2090, run against this branch's build, prints
1.0sand1m 0s.
Checklist
- Changeset added (
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only. - Breaking change: title carries
!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md). - Docs updated in the same PR: the
docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.