PL
apps/jumphp-ide-remote / ui / js / texts.test.mjs · commit b81e652
// Every text of the page goes through IdeRemote.t: the keys used in app.js (EN table) and views (L('key', 'English')) exist in config/lang.yaml with the same English.// Run: docker run --rm -v $PWD:/w -w /w node:22-alpine node --test ui/js/texts.test.mjs   (from apps/jumphp-ide-remote)import test from 'node:test';import assert from 'node:assert/strict';import { readFileSync, readdirSync } from 'node:fs';import { dirname, join } from 'node:path';import { fileURLToPath } from 'node:url';const here = dirname(fileURLToPath(import.meta.url));const yaml = readFileSync(join(here, '../../config/lang.yaml'), 'utf8');const section = (lang) => {  const body = yaml.split(new RegExp(`^${lang}:\\n`, 'm'))[1].split(/^[a-z]{2}:\n/m)[0];  return Object.fromEntries([...body.matchAll(/^  (\w+): '((?:[^']|'')*)'$/gm)].map((m) => [m[1], m[2].replace(/''/g, "'")]));};const en = section('en');test('every L(key, english) of the views is in lang.yaml with the same English', () => {  for (const f of readdirSync(join(here, 'views')).filter((n) => n.endsWith('.js') && !n.includes('test'))) {    const src = readFileSync(join(here, 'views', f), 'utf8');    for (const m of src.matchAll(/\bL\('(\w+)',\s*'((?:[^'\\]|\\.)*)'/g)) {      assert.equal(en[m[1]], m[2].replace(/\\'/g, "'"), `${f}: ${m[1]}`);    }  }});test('every key of the EN table of app.js is in lang.yaml', () => {  const src = readFileSync(join(here, 'app.js'), 'utf8');  const table = src.match(/const EN = \{([\s\S]*?)\n\};/)[1];  for (const m of table.matchAll(/(\w+): '((?:[^'\\]|\\.)*)'/g)) assert.equal(en[m[1]], m[2].replace(/\\'/g, "'"), m[1]);});test('the 14 languages have the keys of English', () => {  for (const lang of ['fr', 'es', 'de', 'it', 'pt', 'nl', 'pl', 'ru', 'uk', 'tr', 'ja', 'zh', 'ko']) {    assert.deepEqual(Object.keys(section(lang)).sort(), Object.keys(en).sort(), lang);  }});