fix: vollständige SEO-Bake-Prüfung sichern

This commit is contained in:
Leon Tonhäuser committed 2026-07-30 12:01:34 +02:00
1 parent 6dbf5c2fec
commit 5eed960772
2 files changed
+38 -6

No files matched your search

+31 -5
View File
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { existsSync, readFileSync, readdirSync } from 'node:fs';
import { readFileSync, readdirSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import vm from 'node:vm';
import { fileURLToPath } from 'node:url';
@@ -45,12 +45,20 @@ function check(name, fn) {
}
function bakeSeo() {
execFileSync(process.execPath, ['scripts/bake-seo.mjs'], {
return execFileSync(process.execPath, ['scripts/bake-seo.mjs'], {
cwd: ROOT,
encoding: 'utf8',
stdio: 'pipe'
});
}
function snapshotTopLevelHtml() {
return readdirSync(PUBLIC)
.filter((name) => name.endsWith('.html'))
.sort()
.map((name) => [name, readFileSync(path.join(PUBLIC, name), 'utf8')]);
}
if (wants('core')) {
const config = loadConfig();
const cities = ['Hamburg', 'Hannover', 'Wolfsburg', 'Uelzen', 'Celle', 'Lüneburg'];
@@ -96,10 +104,28 @@ if (wants('core')) {
assert.ok(html.includes('"@type":"Country","name":"Deutschland"'));
});
check('erneutes SEO-Backen verändert den Event-Head nicht', () => {
const before = read('public/eventfotografie.html');
check('erneutes SEO-Backen verändert keine Top-Level-HTML-Seite', () => {
const before = snapshotTopLevelHtml();
bakeSeo();
assert.equal(read('public/eventfotografie.html'), before);
assert.deepEqual(snapshotTopLevelHtml(), before);
});
check('SEO-Bake meldet übersprungene HTML-Seiten als Fehler', () => {
const file = path.join(PUBLIC, 'blog.html');
const original = readFileSync(file, 'utf8');
let failure;
try {
writeFileSync(file, original.replace('</head>', ''));
try {
bakeSeo();
} catch (error) {
failure = error;
}
} finally {
writeFileSync(file, original);
}
assert.ok(failure, 'das Backen muss bei übersprungenen HTML-Seiten fehlschlagen');
assert.match(String(failure.stderr), /kein <\/head> in blog\.html/);
});
}