Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ yarn-error.log
testem.log
/typings
__screenshots__/
/test-results
/playwright-report

# System files
.DS_Store
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@
"options": {
"lintFilePatterns": [
"src/**/*.ts",
"src/**/*.html"
"src/**/*.html",
"e2e/**/*.ts",
"playwright.config.ts"
]
}
}
Expand Down
7 changes: 7 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions containers/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 <meta> tag and log an error on every page load.
#
# Policy notes:
# - img-src allows blob:/data:/https: (IndexedDB posters via object URLs,
Expand Down
55 changes: 55 additions & 0 deletions e2e/journey.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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) => {
if (message.type() === 'error') 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([]);
});
23 changes: 23 additions & 0 deletions e2e/serve.mjs
Original file line number Diff line number Diff line change
@@ -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}`);
8 changes: 8 additions & 0 deletions e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": true,
"types": ["node"]
},
"include": ["**/*.ts", "../playwright.config.ts"]
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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"
}
}
31 changes: 31 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -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,
},
});
9 changes: 9 additions & 0 deletions prek.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
and update script-src here and in nginx.conf. -->
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self'; base-uri 'self'; form-action 'self'; object-src 'none'; frame-ancestors 'none'; script-src 'self' 'sha256-Hq3FIAQiTPolQXnEfi9wb+iJcaXWvqDZulbwr3WX+IE='; style-src 'self' 'unsafe-inline'; img-src 'self' blob: data: https:; connect-src 'self' https://api.themoviedb.org https://api.jikan.moe https://graphql.anilist.co https://image.tmdb.org https://cdn.myanimelist.net https://s4.anilist.co; font-src 'self' data:; manifest-src 'self'; worker-src 'self'"
content="default-src 'self'; base-uri 'self'; form-action 'self'; object-src 'none'; script-src 'self' 'sha256-Hq3FIAQiTPolQXnEfi9wb+iJcaXWvqDZulbwr3WX+IE='; style-src 'self' 'unsafe-inline'; img-src 'self' blob: data: https:; connect-src 'self' https://api.themoviedb.org https://api.jikan.moe https://graphql.anilist.co https://image.tmdb.org https://cdn.myanimelist.net https://s4.anilist.co; font-src 'self' data:; manifest-src 'self'; worker-src 'self'"
/>
<meta name="referrer" content="no-referrer" />
<title>WatchList</title>
Expand Down