Files
FWS-DiscordBot/tests/docs.test.js
T

51 lines
2.4 KiB
JavaScript

import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { describe, it } from 'node:test';
const read = (file) => readFileSync(new URL(`../${file}`, import.meta.url), 'utf8');
const headingCount = (text, level) => (text.match(new RegExp(`^${'#'.repeat(level)} `, 'gm')) ?? []).length;
const commandNames = (text) => new Set([...text.matchAll(/`\/([a-z]+)/g)].map((match) => match[1]));
const envTokens = (text) => new Set(text.match(/\b[A-Z][A-Z0-9]*_[A-Z0-9_]+\b/g) ?? []);
/** The organisation requires both READMEs, kept in sync (`.profile/README.md`). */
describe('bilingual documentation', () => {
it('keeps README.md and README.en.md structurally in sync', () => {
const fr = read('README.md');
const en = read('README.en.md');
assert.equal(headingCount(en, 2), headingCount(fr, 2), 'a section is missing on one side');
assert.equal(headingCount(en, 3), headingCount(fr, 3), 'a subsection is missing on one side');
});
it('documents the same commands and environment variables in both languages', () => {
const fr = read('README.md');
const en = read('README.en.md');
assert.deepEqual([...commandNames(en)].sort(), [...commandNames(fr)].sort(), 'command list differs');
assert.deepEqual([...envTokens(en)].sort(), [...envTokens(fr)].sort(), 'environment list differs');
});
it('links the two versions to each other', () => {
assert.match(read('README.md'), /README\.en\.md/, 'the French README does not link the English one');
assert.match(read('README.en.md'), /README\.md/, 'the English README does not link the French one');
});
it('ships the organisation files', () => {
assert.match(read('CHANGELOG.md'), /^# Changelog/, 'the generated changelog is missing');
assert.match(read('AGENTS.md'), /Instructions pour les agents/, 'the agent instructions are missing');
assert.match(
read('.gitea/PULL_REQUEST_TEMPLATE.md'),
/Conventional Commits/,
'the pull request template is missing',
);
assert.match(
read('.gitea/ISSUE_TEMPLATE/bug.md'),
/Étapes de reproduction/,
'the bug report template is missing',
);
assert.match(read('.gitignore'), /^\.env$/m, 'the environment files are not ignored');
assert.match(read('.gitignore'), /^\.freebuff\/$/m, 'the assistant data is not ignored');
});
});