import assert from 'node:assert/strict'; import { execFileSync } from 'node:child_process'; import { existsSync, readFileSync, readdirSync } from 'node:fs'; import path from 'node:path'; import vm from 'node:vm'; import { fileURLToPath } from 'node:url'; const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const PUBLIC = path.join(ROOT, 'public'); const requested = new Set(process.argv.slice(2)); const wants = (suite) => requested.size === 0 || requested.has('all') || requested.has(suite); const failures = []; function read(relativePath) { return readFileSync(path.join(ROOT, relativePath), 'utf8'); } function loadConfig() { const context = { window: {} }; vm.createContext(context); vm.runInContext(read('public/custom/seo-config.js'), context); return context.window.SEO_CONFIG; } function count(text, pattern) { return (text.match(pattern) || []).length; } function htmlEscape(value) { return String(value) .replace(/&/g, '&') .replace(/"/g, '"') .replace(//g, '>'); } function check(name, fn) { try { fn(); console.log(`PASS ${name}`); } catch (error) { failures.push(`${name}: ${error.message}`); console.error(`FAIL ${name}: ${error.message}`); } } function bakeSeo() { execFileSync(process.execPath, ['scripts/bake-seo.mjs'], { cwd: ROOT, stdio: 'pipe' }); } if (wants('core')) { const config = loadConfig(); const cities = ['Hamburg', 'Hannover', 'Wolfsburg', 'Uelzen', 'Celle', 'Lüneburg']; check('Geschäftsort ist Ebstorf', () => { assert.equal(config.BUSINESS.addressLocality, 'Ebstorf'); }); check('alle sechs Sportregionen sind zentral gepflegt', () => { assert.deepEqual(Array.from(config.BUSINESS.areaServed), cities); }); check('Sportseite hat seitenspezifische Service-Daten', () => { const page = config.PAGES['/sportfotografie']; assert.equal(page.service.serviceType, 'Sportfotografie'); assert.deepEqual( Array.from(page.service.areaServed, (place) => place.name), cities ); assert.ok(page.jsonld.includes('service')); }); check('Eventseite hat Hamburg und Deutschland als Einsatzgebiet', () => { const page = config.PAGES['/eventfotografie']; assert.deepEqual( JSON.parse(JSON.stringify(page.service.areaServed)), [ { type: 'City', name: 'Hamburg' }, { type: 'Country', name: 'Deutschland' } ] ); assert.ok(page.jsonld.includes('service')); }); check('gebackener Event-Head entspricht der Konfiguration', () => { const page = config.PAGES['/eventfotografie']; const html = read('public/eventfotografie.html'); assert.equal(count(html, //g), 1); assert.equal(count(html, /<meta name="description"/g), 1); assert.ok(html.includes(`<title>${htmlEscape(page.title)}`)); assert.ok(html.includes(`content="${htmlEscape(page.desc)}"`)); assert.ok(html.includes('"serviceType":"Eventfotografie"')); assert.ok(html.includes('"@type":"Country","name":"Deutschland"')); }); check('erneutes SEO-Backen verändert den Event-Head nicht', () => { const before = read('public/eventfotografie.html'); bakeSeo(); assert.equal(read('public/eventfotografie.html'), before); }); } if (failures.length) { console.error(`\n${failures.length} Prüfung(en) fehlgeschlagen.`); process.exit(1); } console.log('\nAlle angeforderten SEO-Prüfungen sind grün.');