import assert from 'node:assert/strict' import test from 'node:test' import { renderAppPage } from './page.ts' import { serviceWorkerScript } from './sw-script.ts' test('inline app script resolves API URLs against location.origin', () => { const html = renderAppPage({ appBasePath: '/packages/lineage', hostedUrl: 'https://kentcdodds.kody.run/packages/lineage', repoLabel: 'kentcdodds/kody', }) assert.match(html, /data-base="\/packages\/lineage\/"/) assert.match(html, /new URL\(base \|\| '\/', location\.origin\)/) assert.ok( !html.includes("base.endsWith('/') ? base : base + '/'"), 'must not use a relative path as the URL constructor base', ) const refreshAt = html.indexOf('refresh();') const swAt = html.indexOf("navigator.serviceWorker.register") assert.ok(refreshAt > 0 && swAt > 0 && swAt < refreshAt, 'service worker must register before first refresh') assert.match(html, /data-dual-range/) assert.match(html, /data-story/) assert.match(html, /class="swatch"/) assert.doesNotMatch(html, /data-loading/) assert.match(html, /data-status-mark/) assert.match(html, /data-status-text/) assert.match(html, /class="title-row"/) assert.match(html, /

Lineage<\/h1>\s*\s*Install\s*]*hidden/) assert.match(html, /shouldCanonicalizeClientPath/) assert.match(html, /location\.replace\(location\.pathname \+ '\/'/) assert.match(html, /apple-touch-icon\.png/) assert.match(html, /og-image\.jpg/) assert.match(html, /apple-mobile-web-app-status-bar-style/) assert.match(html, /beforeinstallprompt/) assert.match(html, /promptEvent\.prompt/) assert.doesNotMatch(html, /waitForInstallPrompt/) assert.match(html, /navigator\.install/) assert.match(html, /serviceWorkerScope/) assert.doesNotMatch(html, /Use your browser install \/ Add to Home Screen control to install Lineage/) const promptAt = html.indexOf("addEventListener('beforeinstallprompt'") assert.ok(promptAt > 0 && promptAt < swAt, 'install prompt must be captured before the service worker registers') const chartAt = html.indexOf('class="chart-wrap"') const controlsAt = html.indexOf('class="controls"') const storyAt = html.indexOf('class="story"') assert.ok( chartAt > 0 && controlsAt > chartAt && storyAt > controlsAt, 'graph must come before filters, story after filters', ) assert.match(html, /svg\.chart \{ width: 100%; height: auto;/) assert.doesNotMatch(html, /data-loading-title/) assert.doesNotMatch(html, /svg\.chart \{[^}]*height: min\(58vw/) assert.match(html, /visibilitychange/) assert.match(html, /pageshow/) assert.match(html, /onAppOpened/) assert.match(html, /shouldRunUpdateCheck/) assert.match(html, /class="mark"/) assert.match(html, /class="brand"/) assert.match(html, /pwa-192\.png" width="40"/) assert.doesNotMatch(html, /Filter language and type/) assert.doesNotMatch(html, /Kent C\. Dodds ·/) assert.match(html, /commits · /) assert.match(html, /timeAxisTicks/) assert.match(html, /axis-x/) }) test('service worker waits for the user before taking over an update', () => { const source = serviceWorkerScript('/packages/lineage') assert.match(source, /lineage-v9/) assert.match(source, /staleWhileRevalidate/) assert.match(source, /cacheFirst && cached/) assert.match(source, /SKIP_WAITING/) assert.match(source, /\/packages\/lineage\/manifest\.webmanifest/) assert.match(source, /\/packages\/lineage\/apple-touch-icon\.png/) assert.doesNotMatch(source, /new URL\('app\.js'/) assert.match(source, /if \(!self\.registration\.active\) return self\.skipWaiting/) })