import { test } from 'node:test' import assert from 'node:assert/strict' import { readFileSync, statSync } from 'node:fs' import vm from 'node:vm' // Statische Pruefung des Einbau-Skripts public/embed/unterkunft.js (Task 16; Muster test/shopEmbedStatic.test.js). const QUELLE = readFileSync(new URL('../public/embed/unterkunft.js', import.meta.url), 'utf8') const OHNE_KOMMENTARE = QUELLE.replace(/\/\*[\s\S]*?\*\//g, '').replace(/(^|\s)\/\/.*$/gm, '$1') test('gueltiges JavaScript, unter 40 KB, IIFE mit use strict', () => { assert.doesNotThrow(() => new vm.Script(QUELLE, { filename: 'unterkunft.js' })) assert.ok(statSync(new URL('../public/embed/unterkunft.js', import.meta.url)).size < 40 * 1024) assert.match(OHNE_KOMMENTARE, /^\s*\(function \(\) \{\s*'use strict'/) }) test('kein innerHTML, outerHTML, insertAdjacentHTML, document.write, eval, new Function', () => { assert.doesNotMatch(OHNE_KOMMENTARE, /innerHTML|outerHTML|insertAdjacentHTML|document\.write|\beval\s*\(|new Function/) }) test('API-Pfad, Praefix .wku-, @layer wku, Style-Id, kein Storage, keine Cookies, keine Fremdadressen', () => { assert.ok(OHNE_KOMMENTARE.includes('/api/public/unterkunft/v1/')) assert.ok(OHNE_KOMMENTARE.includes('@layer wku')) assert.ok(OHNE_KOMMENTARE.includes('wku-style')) assert.match(OHNE_KOMMENTARE, /\.wku-root/) assert.doesNotMatch(OHNE_KOMMENTARE, /localStorage|sessionStorage|document\.cookie|https?:\/\//) }) test('Pflichttexte und Honeypot', () => { for (const t of ['Anfragen gerne per Telefon oder E-Mail.', 'Bitte wählen Sie Anreise und Abreise im Kalender.', 'Anfrage senden', 'kontakt_url', 'formToken']) assert.ok(QUELLE.includes(t), t) assert.match(QUELLE, /Danke! Ihre Anfrage/) })