Incognito-Wiki/tests/rendered-output.test.mjs
msa46 bcb8dcfe2a
Some checks are pending
Deploy to GitHub Pages / build (push) Waiting to run
Deploy to GitHub Pages / deploy (push) Blocked by required conditions
fix: resolve final Starlight migration review
2026-08-02 18:59:28 +02:00

46 lines
1.8 KiB
JavaScript

import assert from 'node:assert/strict';
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import test from 'node:test';
import { checkRenderedOutput } from '../scripts/lib/rendered-output.mjs';
async function withRenderedSite(run) {
const root = await mkdtemp(join(tmpdir(), 'incognito-rendered-'));
try {
await run(root);
} finally {
await rm(root, { recursive: true, force: true });
}
}
test('reports every published HTML page that does not contain exactly one H1', async () => {
await withRenderedSite(async (root) => {
await mkdir(join(root, 'about'), { recursive: true });
await mkdir(join(root, 'empty'), { recursive: true });
await writeFile(join(root, 'index.html'), '<main><h1>Home</h1></main>');
await writeFile(join(root, 'about/index.html'), '<main><h1>About</h1><h1>Duplicate</h1></main>');
await writeFile(join(root, 'empty/index.html'), '<main><p>No heading</p></main>');
await writeFile(join(root, '404.html'), '<main><p>Generated error page</p></main>');
const result = await checkRenderedOutput({ distRoot: root });
assert.equal(result.htmlFilesChecked, 3);
assert.deepEqual(result.headingIssues, [
{ file: 'about/index.html', h1Count: 2 },
{ file: 'empty/index.html', h1Count: 0 },
]);
});
});
test('reports any to-be-studied path that reaches built output', async () => {
await withRenderedSite(async (root) => {
await writeFile(join(root, 'index.html'), '<main><h1>Home</h1></main>');
await mkdir(join(root, 'to-be-studied'), { recursive: true });
await writeFile(join(root, 'to-be-studied/leak.txt'), 'unpublished');
const result = await checkRenderedOutput({ distRoot: root });
assert.deepEqual(result.unpublishedPaths, ['to-be-studied/leak.txt']);
});
});