test(web): the parity test names the keys in fault in its messages (#205)
A failure of parity.test.ts now carries the keys in the message of the
assertion itself ("keys of fr.json missing in en.json: ..."), not only in
the diff the default reporter prints.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
732784ac59
commit
d81bd18a2c
2 changed files with 10 additions and 10 deletions
|
|
@ -3,8 +3,8 @@ import fr from './fr.json';
|
|||
import en from './en.json';
|
||||
|
||||
// The texts of the site (#205): fr.json and en.json hold the same keys, and
|
||||
// no key is left without a text. Every failure names the keys in fault: each
|
||||
// assertion compares a list of them with the empty list.
|
||||
// no key is left without a text. Every failure names the keys in fault, in
|
||||
// the message of its assertion.
|
||||
|
||||
// Every leaf of a file, by its dotted key (`assistants.tokens.heading`).
|
||||
function leaves(node: unknown, prefix = ''): [key: string, value: unknown][] {
|
||||
|
|
@ -22,10 +22,10 @@ const FILES = { fr: new Map(leaves(fr)), en: new Map(leaves(en)) };
|
|||
|
||||
describe('fr.json and en.json', () => {
|
||||
it('hold the same keys', () => {
|
||||
expect({
|
||||
'in fr.json only': [...FILES.fr.keys()].filter((key) => !FILES.en.has(key)),
|
||||
'in en.json only': [...FILES.en.keys()].filter((key) => !FILES.fr.has(key)),
|
||||
}).toEqual({ 'in fr.json only': [], 'in en.json only': [] });
|
||||
const frOnly = [...FILES.fr.keys()].filter((key) => !FILES.en.has(key));
|
||||
const enOnly = [...FILES.en.keys()].filter((key) => !FILES.fr.has(key));
|
||||
expect(frOnly, `keys of fr.json missing in en.json: ${frOnly.join(', ')}`).toEqual([]);
|
||||
expect(enOnly, `keys of en.json missing in fr.json: ${enOnly.join(', ')}`).toEqual([]);
|
||||
// Control: the comparison had something to read.
|
||||
expect(FILES.fr.size).toBeGreaterThan(50);
|
||||
});
|
||||
|
|
@ -35,14 +35,14 @@ describe('fr.json and en.json', () => {
|
|||
[...texts]
|
||||
.filter(([, value]) => typeof value !== 'string' || value.trim() === '')
|
||||
.map(([key]) => `${file}.json: ${key}`));
|
||||
expect(empty).toEqual([]);
|
||||
expect(empty, `keys without a text: ${empty.join(', ')}`).toEqual([]);
|
||||
});
|
||||
|
||||
it('use the same interpolation variables in both languages', () => {
|
||||
const different = [...FILES.fr]
|
||||
.filter(([key, text]) => variables(text).join() !== variables(FILES.en.get(key)).join())
|
||||
.map(([key, text]) => `${key}: fr {${variables(text)}} en {${variables(FILES.en.get(key))}}`);
|
||||
expect(different).toEqual([]);
|
||||
.map(([key, text]) => `${key} (fr: ${variables(text)}; en: ${variables(FILES.en.get(key))})`);
|
||||
expect(different, `keys whose variables differ: ${different.join(', ')}`).toEqual([]);
|
||||
// Control: some texts do carry a variable.
|
||||
expect([...FILES.fr.values()].filter((text) => variables(text).length > 0).length).toBeGreaterThan(10);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -530,7 +530,7 @@ describe('texts of the page', () => {
|
|||
|
||||
it('every key the page asks for has a text in both languages', () => {
|
||||
// Control: the five component files and the keys were found.
|
||||
expect(sources).toHaveLength(7);
|
||||
expect(sources.length).toBeGreaterThanOrEqual(7);
|
||||
expect(used.size).toBeGreaterThan(60);
|
||||
expect([...used].filter((key) => typeof textOf(fr, key) !== 'string' || typeof textOf(en, key) !== 'string')).toEqual([]);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue