17 lines
952 B
JavaScript
17 lines
952 B
JavaScript
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`)
|
|
}
|
|
})
|