From deb2cacd01f08ca37e3512ec08e6d8508542a88d Mon Sep 17 00:00:00 2001 From: CodeWithMaBot <310216433+CodeWithMaBot@users.noreply.github.com> Date: Sun, 22 Nov 2026 18:10:52 +0100 Subject: [PATCH 1/2] test(e2e): add a headless browser journey against the production build One Playwright test adds a series, reloads, marks an episode watched, checks the history, and deletes the series. It covers what the jsdom specs cannot: the production bundle, its CSP, real clicks, and real IndexedDB. CI runs it against the nginx preview container. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/ci.yml | 7 +++++ .gitignore | 2 ++ AGENTS.md | 1 + README.md | 9 ++++++ angular.json | 4 ++- bun.lock | 7 +++++ e2e/journey.e2e.ts | 60 ++++++++++++++++++++++++++++++++++++++++ e2e/serve.mjs | 23 +++++++++++++++ e2e/tsconfig.json | 8 ++++++ package.json | 10 ++++--- playwright.config.ts | 31 +++++++++++++++++++++ prek.toml | 9 ++++++ 12 files changed, 166 insertions(+), 5 deletions(-) create mode 100644 e2e/journey.e2e.ts create mode 100644 e2e/serve.mjs create mode 100644 e2e/tsconfig.json create mode 100644 playwright.config.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6cf130ad..158ef537 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,6 +78,13 @@ jobs: run: bun run container:preview - name: Smoke-test production preview run: bun containers/smoke-test.mjs + - run: bun install --frozen-lockfile + - name: Install Chromium + run: bunx playwright install --with-deps chromium + - name: Browser journey against the production preview + run: bun run e2e + env: + E2E_BASE_URL: http://localhost:4200 - name: Show container logs if: always() run: podman-compose -f containers/compose.prod.yml logs diff --git a/.gitignore b/.gitignore index eb3a11be..3043e4eb 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,8 @@ yarn-error.log testem.log /typings __screenshots__/ +/test-results +/playwright-report # System files .DS_Store diff --git a/AGENTS.md b/AGENTS.md index 77df3b35..3661443d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,3 +14,4 @@ The main function is to show me what tv series or movie I should watch next. - Run a single spec file: `bun run test -- --include="src/app/utils/form.utils.spec.ts" --no-watch` - Run a single test by name (regex): `bun run test -- --filter="toPositiveNumber" --no-watch` - To get test code coverage run: `bun run test -- --coverage --no-watch` +- Browser test (one journey against the production build, slow): `bun run e2e`. On NixOS point it at a system browser: `E2E_CHROMIUM_PATH=$(which chromium) bun run e2e`. Keep it to this single journey; cover everything else with Vitest specs. diff --git a/README.md b/README.md index 6b299190..90f03da2 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,15 @@ bunx prek install bunx prek install -t commit-msg ``` +One browser test drives the production build through a real headless Chromium: + +```shell +bunx playwright install chromium # once +bun run e2e +``` + +Set `E2E_CHROMIUM_PATH` to use a system browser, or `E2E_BASE_URL` to test a running deployment. + ## Privacy Watch-list data is stored locally in your browser using IndexedDB. Nothing is ever sent to a server. Your watch history stays on your device. Export your data before upgrading from versions that used localStorage if you want to keep it. diff --git a/angular.json b/angular.json index 095d54b1..8601e7a7 100644 --- a/angular.json +++ b/angular.json @@ -124,7 +124,9 @@ "options": { "lintFilePatterns": [ "src/**/*.ts", - "src/**/*.html" + "src/**/*.html", + "e2e/**/*.ts", + "playwright.config.ts" ] } } diff --git a/bun.lock b/bun.lock index 21146104..e0644d6a 100644 --- a/bun.lock +++ b/bun.lock @@ -25,6 +25,7 @@ "@commitlint/config-conventional": "^21.2.3", "@eslint/js": "^10.0.1", "@j178/prek": "^0.5.5", + "@playwright/test": "^1.65.1", "@tailwindcss/postcss": "^4.3.5", "@types/node": "^22.0.0", "@vitest/coverage-v8": "^5.1.0", @@ -573,6 +574,8 @@ "@pkgjs/parseargs": ["@pkgjs/parseargs@0.11.0", "", {}, "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg=="], + "@playwright/test": ["@playwright/test@1.65.1", "", { "dependencies": { "playwright": "1.65.1" }, "bin": { "playwright": "cli.js" } }, "sha512-y+NCIRm2LvY4slUVWvGh1nujJ8RF/hEisIsq2mtUPgdQC4L701bq5hZGMhrpeXjACvwvO9tj5dJqhvM6TP9lbw=="], + "@rolldown/binding-android-arm-eabi": ["@rolldown/binding-android-arm-eabi@1.2.16", "", { "os": "android", "cpu": "arm" }, "sha512-ia3DwAs0OsMGS7+IConptSiyk9pEXkOx/AbJ2n/lAGxH3QkWQus1t8d7gnAT38FCU2sQu8lUbeR6AiZFv4JxaA=="], "@rolldown/binding-android-arm64": ["@rolldown/binding-android-arm64@1.2.16", "", { "os": "android", "cpu": "arm64" }, "sha512-kx5wBiMB6E7TEvpl2B9gjLU004BkvEm2Dr941BFjx/SontPwSzNuQUIoVKxHHoSjpFIfHMmcguyLOtyn0hObRg=="], @@ -1453,6 +1456,10 @@ "pkijs": ["pkijs@3.4.1", "", { "dependencies": { "@noble/hashes": "1.8.0", "asn1js": "^3.0.6", "bytestreamjs": "^2.0.1", "pvtsutils": "^1.3.6", "pvutils": "^1.1.3", "tslib": "^2.8.1" } }, "sha512-Oo/NZcSWccq8KyoG7gLE9fnltgHns+pNCjCAp/WmjsUySi+sX7y4z4Xqu4fVb42CDHzRPl33fjzT15V1wvcyhA=="], + "playwright": ["playwright@1.65.1", "", { "dependencies": { "playwright-core": "1.65.1" }, "bin": { "playwright": "cli.js" } }, "sha512-vJ1FuoOrNwOKHUIVEvSt3jT1L+wjjDpwhwIstKtfvTh8XIG4FG4bIFuvNdMxi81LGfAhUgUZleVFaOLY4RIUUw=="], + + "playwright-core": ["playwright-core@1.65.1", "", { "bin": { "playwright-core": "cli.js" } }, "sha512-hqPpz7blSMPxWVdoeE1yiBSzXsKiVOd2k+kjCvmUywD2GPO2Dd9HfcWnq9NN0GHbNZDFgZ9JfBFr+X5/BLo0qw=="], + "plist": ["plist@3.1.0", "", { "dependencies": { "@xmldom/xmldom": "^0.8.8", "base64-js": "^1.5.1", "xmlbuilder": "^15.1.1" } }, "sha512-uysumyrvkUX0rX/dEVqt8gC3sTBzd4zoWfLeS29nb53imdaXVvLINYXTI2GNqzaMuvacNx4uJQ8+b3zXR0pkgQ=="], "postcss": ["postcss@8.5.29", "", { "dependencies": { "nanoid": "^3.3.19", "picocolors": "^1.1.1", "source-map-js": "^1.2.2" } }, "sha512-49cGhUbXj8Qenv0iTMxA1cFBzxXoctpC9Ujd77t1WcbJIr6nF/eI7g/8MgxrYldFRuAXvja7xQRwavoW7kgrxQ=="], diff --git a/e2e/journey.e2e.ts b/e2e/journey.e2e.ts new file mode 100644 index 00000000..e9154ca0 --- /dev/null +++ b/e2e/journey.e2e.ts @@ -0,0 +1,60 @@ +import { expect, test } from '@playwright/test'; + +// The one browser test. Component and service behaviour is covered by the +// Vitest specs; this proves what they cannot: the production bundle boots under +// its Content-Security-Policy, real clicks reach the controls, and the +// collection persists in the browser's own IndexedDB. +test('add a series, watch an episode, and delete the series', async ({ page }) => { + const title = 'Browser Journey Series'; + const problems: string[] = []; + page.on('pageerror', (error) => problems.push(`page error: ${error.message}`)); + page.on('console', (message) => { + // index.html's policy mirrors the nginx header, including a + // directive browsers only honour as a header and report on every load. + const expected = message.text().includes("'frame-ancestors' is ignored"); + if (message.type() === 'error' && !expected) { + problems.push(`console error: ${message.text()}`); + } + }); + + const nav = page.getByRole('navigation'); + const card = page.getByRole('link', { name: title }); + + await page.goto('/'); + await nav.getByRole('link', { name: 'Items' }).click(); + await expect(page.getByText('No items found')).toBeVisible(); + + await page.getByRole('link', { name: 'Add Item' }).click(); + await page.getByLabel('Title *').fill(title); + await page.getByRole('button', { name: 'Add Season' }).click(); + await page.getByLabel('Episodes', { exact: true }).fill('3'); + await page.getByRole('button', { name: 'Add Item' }).click(); + + await expect(page).toHaveURL(/\/items$/); + await expect(card.first()).toBeVisible(); + + await page.reload(); + await expect(card.first()).toBeVisible(); + + await card.first().click(); + await expect(page.getByRole('heading', { name: title })).toBeVisible(); + await page.getByRole('button', { name: 'Mark Watched' }).click(); + await expect(page.getByRole('listitem').filter({ hasText: 'S1E1' })).toBeVisible(); + + await nav.getByRole('link', { name: 'History' }).click(); + await expect(page.getByRole('heading', { name: 'Watch History' })).toBeVisible(); + await expect(page.getByText('S1E1')).toBeVisible(); + await page.getByRole('link', { name: title }).click(); + + await page.getByRole('link', { name: 'Edit' }).click(); + await page.getByRole('button', { name: 'Delete', exact: true }).click(); + await page.getByRole('button', { name: 'Confirm Delete?' }).click(); + + await expect(page).toHaveURL(/\/items$/); + await expect(page.getByText('No items found')).toBeVisible(); + await nav.getByRole('link', { name: 'History' }).click(); + // History outlives its item by design. + await expect(page.getByText(`${title} (deleted)`)).toBeVisible(); + + expect(problems).toEqual([]); +}); diff --git a/e2e/serve.mjs b/e2e/serve.mjs new file mode 100644 index 00000000..de1f76db --- /dev/null +++ b/e2e/serve.mjs @@ -0,0 +1,23 @@ +// Serves the production build for the browser tests, with the same SPA +// fallback as containers/nginx.conf. +import { join, normalize } from 'node:path'; + +const root = join(import.meta.dirname, '../dist/watch-list/browser'); +const port = Number(process.argv[2] ?? 4300); + +if (!(await Bun.file(join(root, 'index.html')).exists())) { + throw new Error(`No production build in ${root}. Run "bun run build" first.`); +} + +Bun.serve({ + port, + hostname: 'localhost', + async fetch(request) { + const path = normalize(decodeURIComponent(new URL(request.url).pathname)); + const file = Bun.file(join(root, path)); + const isFile = path !== '/' && (await file.exists()); + return new Response(isFile ? file : Bun.file(join(root, 'index.html'))); + }, +}); + +console.log(`Serving ${root} on http://localhost:${port}`); diff --git a/e2e/tsconfig.json b/e2e/tsconfig.json new file mode 100644 index 00000000..da2eda9c --- /dev/null +++ b/e2e/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "noEmit": true, + "types": ["node"] + }, + "include": ["**/*.ts", "../playwright.config.ts"] +} diff --git a/package.json b/package.json index 4ac25158..69e94040 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "container:down": "podman-compose -f containers/compose.prod.yml down", "container:logs": "podman-compose -f containers/compose.prod.yml logs -f", "test": "ng test", + "e2e": "playwright test", "electron": "electron .", "electron:dev": "tsc -p electron/tsconfig.json && concurrently -k \"bun start:electron\" \"wait-on http://localhost:4200 && electron ./dist-electron/main.js\"", "electron:build": "bun run build:electron && tsc -p electron/tsconfig.json && electron-builder", @@ -60,14 +61,14 @@ "@commitlint/config-conventional": "^21.2.3", "@eslint/js": "^10.0.1", "@j178/prek": "^0.5.5", + "@playwright/test": "^1.65.1", "@tailwindcss/postcss": "^4.3.5", "@types/node": "^22.0.0", + "@vitest/coverage-v8": "^5.1.0", + "angular-eslint": "^22.6.0", "concurrently": "^10.0.7", "electron": "^44.7.0", "electron-builder": "^26.18.0", - "wait-on": "^9.5.1", - "@vitest/coverage-v8": "^5.1.0", - "angular-eslint": "^22.6.0", "eslint": "^10.15.0", "fake-indexeddb": "^6.2.4", "jsdom": "^30.1.2", @@ -77,6 +78,7 @@ "tailwindcss": "^4.3.5", "typescript": "~6.0.3", "typescript-eslint": "^8.72.2", - "vitest": "^5.1.0" + "vitest": "^5.1.0", + "wait-on": "^9.5.1" } } diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 00000000..bdfc82c3 --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,31 @@ +import { defineConfig, devices } from '@playwright/test'; + +// Set E2E_BASE_URL to test an already running deployment (CI points it at the +// nginx container, the only place the real security headers exist). Without it +// the production build is created and served locally. +const externalBaseUrl = process.env['E2E_BASE_URL']; +const localPort = 4300; +// Playwright's downloaded Chromium cannot start on every OS (NixOS, for one). +// Set E2E_CHROMIUM_PATH to use a system browser instead. +const executablePath = process.env['E2E_CHROMIUM_PATH']; + +export default defineConfig({ + testDir: 'e2e', + testMatch: '**/*.e2e.ts', + forbidOnly: !!process.env['CI'], + reporter: 'list', + use: { + baseURL: externalBaseUrl ?? `http://localhost:${localPort}`, + trace: 'retain-on-failure', + launchOptions: executablePath ? { executablePath } : {}, + }, + projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }], + webServer: externalBaseUrl + ? undefined + : { + command: `bun run build && bun e2e/serve.mjs ${localPort}`, + url: `http://localhost:${localPort}`, + timeout: 180_000, + reuseExistingServer: false, + }, +}); diff --git a/prek.toml b/prek.toml index cf5a0359..767cabd6 100644 --- a/prek.toml +++ b/prek.toml @@ -53,6 +53,15 @@ hooks = [ pass_filenames = false, stages = ["pre-commit"], }, + { + id = "tsc-e2e", + name = "TypeScript (e2e)", + language = "system", + entry = "bunx tsc -p e2e/tsconfig.json", + files = "\\.ts$", + pass_filenames = false, + stages = ["pre-commit"], + }, { id = "knip", name = "Knip (dead code)", From 97869e7bc3411b626cebd3425cf54cb5eadd2282 Mon Sep 17 00:00:00 2001 From: CodeWithMaBot <310216433+CodeWithMaBot@users.noreply.github.com> Date: Sun, 22 Nov 2026 18:14:14 +0100 Subject: [PATCH 2/2] fix(csp): drop frame-ancestors from the meta policy Browsers ignore frame-ancestors in a tag and log a console error on every page load. The nginx header keeps it; the browser test no longer needs to excuse the error. Co-Authored-By: Claude Fable 5.2 --- containers/nginx.conf | 2 ++ e2e/journey.e2e.ts | 7 +------ src/index.html | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/containers/nginx.conf b/containers/nginx.conf index 573bbdc5..52bcd978 100644 --- a/containers/nginx.conf +++ b/containers/nginx.conf @@ -5,6 +5,8 @@ # in src/index.html (GitHub Pages cannot send custom HTTP headers, so the meta # tag is its only enforcement). If the inline theme script in index.html # changes, recompute its sha256 and update script-src in both places. +# The one intended difference: frame-ancestors exists only here, because +# browsers ignore it in a tag and log an error on every page load. # # Policy notes: # - img-src allows blob:/data:/https: (IndexedDB posters via object URLs, diff --git a/e2e/journey.e2e.ts b/e2e/journey.e2e.ts index e9154ca0..d4031fd6 100644 --- a/e2e/journey.e2e.ts +++ b/e2e/journey.e2e.ts @@ -9,12 +9,7 @@ test('add a series, watch an episode, and delete the series', async ({ page }) = const problems: string[] = []; page.on('pageerror', (error) => problems.push(`page error: ${error.message}`)); page.on('console', (message) => { - // index.html's policy mirrors the nginx header, including a - // directive browsers only honour as a header and report on every load. - const expected = message.text().includes("'frame-ancestors' is ignored"); - if (message.type() === 'error' && !expected) { - problems.push(`console error: ${message.text()}`); - } + if (message.type() === 'error') problems.push(`console error: ${message.text()}`); }); const nav = page.getByRole('navigation'); diff --git a/src/index.html b/src/index.html index 29e899c1..88c7132c 100644 --- a/src/index.html +++ b/src/index.html @@ -8,7 +8,7 @@ and update script-src here and in nginx.conf. --> WatchList