Asper Header  1.0.22
The header injector extension
Loading...
Searching...
No Matches
messageReference.test.ts
Go to the documentation of this file.
1
15import * as assert from 'assert';
16import { messages } from '../modules/messageReference';
17
18suite('MessageReference Hardening', () => {
19 const locales = Object.keys(messages).sort();
20 const expectedLocales = ['cs', 'de', 'en', 'es', 'fr', 'hu', 'it', 'ja', 'ko', 'pl', 'pt-br', 'ru', 'tr', 'zh-cn', 'zh-tw'].sort();
21 const enKeys = Object.keys(messages.en).sort();
22
23 test('should expose exactly 15 locales', () => {
24 assert.deepStrictEqual(locales, expectedLocales, `Locales mismatch: got ${locales.join(',')}`);
25 });
26
27 test('en should have at least 140 keys (currently 148)', () => {
28 // Guard against accidental deletion; allow growth but not shrink below known baseline
29 assert.ok(enKeys.length >= 140, `en has ${enKeys.length} keys, expected >=140`);
30 assert.ok(enKeys.length < 300, `en has ${enKeys.length} keys, suspicious growth`);
31 });
32
33 test('every locale should have exactly the same keys as en', () => {
34 for (const locale of locales) {
35 const keys = Object.keys(messages[locale]).sort();
36 const missing = enKeys.filter(k => !keys.includes(k));
37 const extra = keys.filter(k => !enKeys.includes(k));
38 assert.strictEqual(missing.length, 0, `Locale ${locale} missing keys: ${missing.join(', ')}`);
39 assert.strictEqual(extra.length, 0, `Locale ${locale} has extra keys: ${extra.join(', ')}`);
40 }
41 });
42
43 test('every message value should be a function returning string', () => {
44 for (const locale of locales) {
45 for (const key of enKeys) {
46 const fn = (messages[locale] as any)[key];
47 assert.strictEqual(typeof fn, 'function', `${locale}.${key} should be function`);
48 // spot-check arity: calling with dummy args must return string, not throw
49 let result: string;
50 try {
51 result = fn('a', 'b', 'c', 123);
52 } catch {
53 // some functions may require specific arity, try zero
54 result = fn();
55 }
56 assert.strictEqual(typeof result, 'string', `${locale}.${key}() should return string`);
57 assert.ok(result.length >= 0, `${locale}.${key}() should not be empty check`);
58 }
59 }
60 });
61
62 test('new 1.0.21/1.0.22 keys should exist in every locale', () => {
63 const newKeys = ['headerLogoReference', 'headerLogoReferenceNotFound', 'headerLogoReferenceNotFoundGUI', 'headerLogoVersionDisabled'];
64 for (const k of newKeys) {
65 assert.ok(k in messages.en, `en missing ${k}`);
66 for (const locale of locales) {
67 assert.ok(k in messages[locale], `${locale} missing ${k}`);
68 }
69 }
70 });
71});
export const export const string[]
Definition constants.ts:203
import *as assert from assert
export const messages
Complete message dictionary for all supported languages with type-safe function interfaces @export Ex...