import { test } from 'node:test' import assert from 'node:assert/strict' import { readFileSync, existsSync } from 'node:fs' const P1 = ['dom', 'api', 'routen', 'router', 'reiter', 'etage', 'zaehler', 'fristen-streifen', 'konto', 'leiste', 'huelle'].map((n) => `${n}.js`) const pfad = (f) => new URL(`../public/neu/${f}`, import.meta.url) const ohneKommentare = (t) => t.replace(/\/\*[\s\S]*?\*\//g, '').replace(/(^|\s)\/\/.*$/gm, '') test('P1-Module: kein innerHTML, nur relative Importe, keine Verweise auf entfernte Seiten', () => { for (const f of P1.filter((d) => existsSync(pfad(d)))) { const q = ohneKommentare(readFileSync(pfad(f), 'utf8')) assert.doesNotMatch(q, /innerHTML|insertAdjacentHTML|outerHTML|document\.write|\beval\(/, f) assert.doesNotMatch(q, /admin\.html|kalkulation\.html|\/api\/portal-admin/, f) for (const m of q.matchAll(/from '([^']+)'/g)) assert.match(m[1], /^\.\//, `${f}: nur relative Importe`) } }) test('Dateiübersicht P1 ist vollständig vorhanden', () => { const soll = [...P1, 'tokens.css', 'basis.css', 'huelle.css', 'dashboard.html', 'manifest.webmanifest', 'ansichten.css', 'funktionen.css', 'module.css', ...['website', 'funktionen', 'chat', 'vertraege', 'passwort', 'gutschrift', 'wechsel', 'bestellen'].map((n) => `ansicht-${n}.js`)] for (const f of soll) assert.ok(existsSync(pfad(f)), f) })