import { describe, expect, test } from 'bun:test'; import { readdirSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; import { findMissingKeys, findExtraKeys } from 'i18n'; import en from './en-GB.json'; /** * Parity, over whatever locales are actually ON DISK — not a list written here. * * This used to name its locales literally, and that made it a check you had to remember to update. Adding * `sv-SE` added a file no parity test looked at, so it shipped out of step and every test stayed green. * A guard that needs maintaining to keep guarding is the thing it was written to prevent. * * Both directions, too. `findMissingKeys` alone reports half of a rename: the new key is missing from the * translation and caught, while the stale one it still carries is invisible. That is exactly how sv-SE * ended up naming two keys en-GB did not have. */ const LOCALES: Record> = Object.fromEntries( readdirSync(__dirname) .filter((f) => f.endsWith('.json') && f !== 'en-GB.json') .map((f) => [f.replace(/\.json$/, ''), JSON.parse(readFileSync(join(__dirname, f), 'utf8'))]), ); describe('officer-web (app.*) locale catalogs', () => { test('there is at least one locale besides en-GB', () => { // Otherwise every assertion below passes over an empty set and says nothing. expect(Object.keys(LOCALES).length).toBeGreaterThan(0); }); test('every locale has every key en-GB has', () => { expect(findMissingKeys(en, LOCALES)).toEqual([]); }); test('no locale has a key en-GB does not', () => { expect(findExtraKeys(en, LOCALES)).toEqual([]); }); });