// The browser e2e gate (TESTING 10.3 "Browser e2e"; #66 first slice). `playwright-core` drives the // devbox `chromium` against the real server through the TLS/HTTP2 test nginx: the one proof that // matters before a phone is asked to measure is that real browsers negotiate h2 over the vhost and // execute the built client from `/`. // // The app's own e2e (join, fog pixels, drag, reconnect, traffic audit) lands with the client in T4+ // on this same harness. Here the page is the fixture `dist` of tools/distfixture.mjs, so the gate // exists and is green before the client package does. import test from 'node:test' import assert from 'node:assert/strict' import fs from 'node:fs' import { chromium } from 'playwright-core' import { freePort, httpsBaseUrl } from '../tools/lib.mjs' import { makeStateDir, startServer, stopServer } from '../tools/withserver.mjs' import { startTestNginx, stopTestNginx } from '../tools/nginx.mjs' import { writeClientDist } from '../tools/distfixture.mjs' // Nix's chromium is a wrapper around the real binary; playwright-core launches it by path (the // perf prototype does the same). SwiftShader is enough for correctness, never for a perf number. const CHROMIUM = process.env.CHROMIUM ?? 'chromium' const LAUNCH_ARGS = ['--no-sandbox', '--use-angle=swiftshader', '--enable-unsafe-swiftshader', '--ignore-gpu-blocklist'] async function stack(fn) { const stateDir = makeStateDir() const dist = writeClientDist(`${stateDir}/dist`) const nginxPort = await freePort() const server = await startServer({ stateDir, publicOrigin: httpsBaseUrl(nginxPort) }) let nginx try { nginx = await startTestNginx({ backendPort: server.port, stateDir, port: nginxPort, distDir: dist.dir }) return await fn({ stateDir, server, nginx, dist, origin: nginx.origin }) } finally { await stopTestNginx(nginx) await stopServer(server) fs.rmSync(stateDir, { recursive: true, force: true }) } } test('e2e: headless chromium loads the client dist and the page reports h2', async () => { await stack(async ({ origin, dist }) => { const browser = await chromium.launch({ executablePath: CHROMIUM, args: LAUNCH_ARGS }) try { // The certificate is a generated self-signed one (tools/tlsdev.mjs); a browser must be told // to accept it. Every other security property of the page is the real thing. const context = await browser.newContext({ ignoreHTTPSErrors: true }) const page = await context.newPage() const loaded = [] page.on('response', r => loaded.push({ url: r.url(), status: r.status() })) const errors = [] page.on('pageerror', e => errors.push(e.message)) page.on('console', m => { if (m.type() === 'error') errors.push(m.text()) }) await page.goto(`${origin}/`, { waitUntil: 'load' }) assert.equal(await page.title(), 'fff-vtt client fixture') assert.equal(await page.textContent('#fixture'), 'client dist fixture') // The hashed asset was fetched and executed by the vhost's immutable-cache location. assert.equal(await page.evaluate(() => document.documentElement.dataset.fixture), 'loaded') assert.deepEqual(errors, []) const assetResponse = loaded.find(r => r.url.endsWith(dist.assetPath)) assert.ok(assetResponse, `the page loaded ${dist.assetPath}: ${JSON.stringify(loaded)}`) assert.equal(assetResponse.status, 200) // The acceptance criterion: the browser's own view of the connection is h2 over TLS. const proto = await page.evaluate(() => { const nav = performance.getEntriesByType('navigation')[0] const resources = performance.getEntriesByType('resource') .map(e => ({ name: e.name, protocol: e.nextHopProtocol })) return { scheme: location.protocol, navigation: nav.nextHopProtocol, resources } }) assert.equal(proto.scheme, 'https:') assert.equal(proto.navigation, 'h2', 'the document came over HTTP/2') assert.ok(proto.resources.some(r => r.protocol === 'h2' && r.name.endsWith('.js')), `subresources are h2 too: ${JSON.stringify(proto.resources)}`) } finally { await browser.close() } }) })