From 640b4d879cc552cab99cfa3ea7d506fc3c08c708 Mon Sep 17 00:00:00 2001 From: Neil Date: Wed, 11 Nov 2026 05:43:38 -0800 Subject: [PATCH] test(cloud): REG-4 the clock's German format matches the runtime's CLDR, not one engine's string run-vitest.mjs now runs this folder under Bun, whose Intl.DurationFormat (JSC) formats de narrow as '2min 5s' where V8/Electron says '2 Min., 5 Sek.'. Both are the runtime's own locale data; the code correctly uses Intl in either. The test now checks German goes through the runtime's DurationFormat and isn't the English fallback, instead of pinning V8's words (added in 54299a9412b). --- .../worktree-creation-clock.test.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/components/worktree-creation/worktree-creation-clock.test.ts b/src/renderer/src/components/worktree-creation/worktree-creation-clock.test.ts index 675bbe909ba..03703a9b4a4 100644 --- a/src/renderer/src/components/worktree-creation/worktree-creation-clock.test.ts +++ b/src/renderer/src/components/worktree-creation/worktree-creation-clock.test.ts @@ -8,12 +8,33 @@ afterEach(() => { vi.unstubAllGlobals() }) +type RuntimeDurationFormat = new ( + locale: string, + options: Record +) => { format: (duration: Record) => string } + +function runtimeNarrowDuration(locale: string, duration: Record): string { + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the TS lib lacks Intl.DurationFormat; every runtime these tests run on has it. + const DurationFormat = (Intl as unknown as { DurationFormat: RuntimeDurationFormat }) + .DurationFormat + return new DurationFormat(locale, { + style: 'narrow', + secondsDisplay: 'always', + minutesDisplay: 'auto' + }).format({ hours: 0, ...duration }) +} + describe('formatElapsedTime', () => { it('formats with Intl in the given locale and keeps minutes once past an hour', () => { expect(formatElapsedTime(5_000, 'en')).toBe('5s') expect(formatElapsedTime(125_000, 'en')).toBe('2m 5s') expect(formatElapsedTime(3_605_000, 'en')).toBe('1h 0m 5s') - expect(formatElapsedTime(125_000, 'de')).toBe('2 Min., 5 Sek.') + // German goes through the runtime's own Intl.DurationFormat, not the English fallback. The exact + // words are CLDR data and differ by engine (V8/Electron: "2 Min., 5 Sek.", Bun/JSC: "2min 5s"), + // so the test compares with the runtime instead of pinning one engine's string (REG-4). + const german = formatElapsedTime(125_000, 'de') + expect(german).toBe(runtimeNarrowDuration('de', { minutes: 2, seconds: 5 })) + expect(german).not.toBe('2m 5s') }) it('falls back to the same English shape where Intl.DurationFormat is missing', () => {