// Older TVs (2026-11-21): the terminal's production build has a second copy for older browsers (a TV's // built-in browser from 2021–2023), and modern browsers never load it. This suite builds the terminal // and serves the build. A modern browser must get the same files as always: no "-legacy" chunk, no // compat layer, no .compat.css. Then it plays an "older TV": the same page with the modern scripts // taken out, container units reported missing and the flex-gap fix forced. That run must load the legacy // copy and the compat layer, show the pairing screen, play the signage slide at the same sizes as // the modern browser, and space flex items itself. // A real Chrome 79 isn't driven here: syntax and missing APIs are the legacy build's job (Babel + // core-js for LEGACY_TARGETS in terminal/vite.config.js); what's checked is our layer. // node compat.mjs import { execFileSync, spawn } from 'node:child_process' import { openSync } from 'node:fs' import path from 'node:path' import { chromium } from 'playwright' import { BROWSER_CHANNEL, CS, OUT, reporter, waitFor } from './lib/env.mjs' import { killTree, startBackend, waitHttp } from './lib/proc.mjs' import { supportLogin } from './lib/support.mjs' const PORT = 5196 const DIST = path.join(OUT, 'compat-dist') const r = reporter('older TVs: the legacy build and the compat layer (terminal)') const errors = [] execFileSync('npx', ['vite', 'build', '--outDir', DIST, '--emptyOutDir'], { cwd: path.join(CS, 'terminal'), shell: process.platform === 'win32', stdio: 'ignore' }) const backend = await startBackend({ port: 8066, siteId: 'test-site-1', env: { LICENSE_MODE: 'off' } }) const log = openSync(path.join(OUT, `vite-${PORT}.log`), 'w') const preview = spawn('npx', ['vite', 'preview', '--outDir', DIST, '--port', String(PORT), '--strictPort'], { cwd: path.join(CS, 'terminal'), shell: process.platform === 'win32', detached: process.platform !== 'win32', stdio: ['ignore', log, log], env: { ...process.env, XENIA_BACKEND: backend.url }, }) const URL = `http://localhost:${PORT}` await waitHttp(URL + '/') const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {}) let failures = 0 async function api(method, url, { token, body } = {}) { const res = await fetch(backend.url + url, { method, headers: { 'content-type': 'application/json', ...(token ? { authorization: `Bearer ${token}` } : {}) }, body: body === undefined ? undefined : JSON.stringify(body), }) const text = await res.text() if (!res.ok) throw new Error(`${method} ${url} → ${res.status} ${text.slice(0, 200)}`) return JSON.parse(text) } const shown = (page, testId, timeout = 15_000) => page.getByTestId(testId).first().waitFor({ timeout }).then(() => true).catch(() => false) /** The page as an older browser runs it: no module scripts, the nomodule ones run (polyfills + SystemJS). */ function asOldBrowser(html) { return html .replace(/