// @requirements REQ-PRODUCT-CONSENT-REHEARSAL REQ-PRODUCT-A11Y REQ-PRODUCT-MOBILE import {test} from 'node:test'; import assert from 'node:assert/strict'; import {readFile} from 'node:fs/promises'; import {build} from 'esbuild'; import {createAccessibilityAudit} from '../../scripts/accessibility-audit.mjs'; import {mountConsentRehearsal} from '@notabenda/core/setup/consent-rehearsal'; import {exampleConsentConfig} from '../../examples/static/choices-build.mjs'; import {serveHost} from '../host.mjs'; const root=new URL('../dist/public/',import.meta.url); test('rehearsal is a separate local asset and never enters the ordinary visitor bundle',async()=>{ const entry=await readFile(new URL('assets/cartridges.mjs',root),'utf8'),preview=await readFile(new URL('assets/runtime/setup-consent-rehearsal.js',root),'utf8'); assert.match(entry,/import\(["']\/assets\/runtime\/setup-consent-rehearsal\.js["']\)/);assert.doesNotMatch(entry,/Preparing your local controls/);assert.match(preview,/Preparing your local controls/);assert.match(preview,/allow-same-origin/);assert.doesNotMatch(preview,/allow-scripts|allow-forms|allow-popups|notabenda-cf|node:fs/); const graph=await build({stdin:{contents:preview},bundle:false,platform:'browser',format:'esm',write:false,metafile:true});assert.deepEqual(Object.values(graph.metafile.outputs)[0].imports,[]); for(const path of ['assets/consent.mjs','assets/consent.css'])assert.doesNotMatch(await readFile(new URL(path,root),'utf8'),/nb-rehearsal|mountConsentRehearsal|setup-consent-rehearsal/); const html=await readFile(new URL('start/index.html',root),'utf8'),env={ASSETS:{fetch:async()=>new Response(html,{headers:{'Content-Type':'text/html'}})}};const response=await serveHost(new Request('https://example.test/start/'),env);assert.equal(response.status,200);assert.match(response.headers.get('Content-Security-Policy'),/frame-src 'self'/); }); test('rehearsal shell and configured child controls retain semantic names and landmarks',async()=>{ const audit=await createAccessibilityAudit('