mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
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 54299a9412).
This commit is contained in:
@@ -8,12 +8,33 @@ afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
type RuntimeDurationFormat = new (
|
||||
locale: string,
|
||||
options: Record<string, string>
|
||||
) => { format: (duration: Record<string, number>) => string }
|
||||
|
||||
function runtimeNarrowDuration(locale: string, duration: Record<string, number>): 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', () => {
|
||||
|
||||
Reference in New Issue
Block a user