Files
anki/playwright.config.ts
Fernando Lins a140d39329 chore(e2e): add Playwright end-to-end test infrastructure (#4864)
## Linked issue

Closes #4863

## Summary / motivation

Adds Playwright as the e2e test framework so contributors can write
browser-based tests against a real headless Anki instance. There was no
automated way to exercise mediasrv pages, SvelteKit routes, or the
`/_anki/` RPC surface from a browser, this PR establishes that harness.

Key pieces:
- `qt/tests/launch_anki_for_e2e.py` — spawns a throwaway Anki instance
(temp `ANKI_BASE`, `QT_QPA_PLATFORM=offscreen`). Pre-seeds `prefs21.db`
so Anki skips the language picker and profile chooser and goes straight
  to serving mediasrv.
- `playwright.config.ts` — points `webServer` at the launcher; polls
  `/favicon.ico` as the readiness probe.
- `ts/tests/e2e/` — `fixtures.ts` base and a sanity spec that verifies
  mediasrv is reachable and a SvelteKit page hydrates.
- `justfile` — `just test-e2e` recipe; Chromium installed to
  `out/playwright-browsers/`.
- CI — e2e step in `check-linux`; failed-run artifacts uploaded for 7
days.
- `docs/e2e-testing.md` — contributor guide covering setup, managed vs
  reuse-server modes, and writing new tests.

## How to test

Build the project once, then run the e2e suite in managed mode (no
separate `./run` needed — the launcher is started automatically):

```shell
just build
just test-e2e
```

## Before / after behavior (optional)
Before: no browser-level test harness existed.
After: `just test-e2e` drives a real headless Anki instance via
Playwright.

## Risk / compatibility / migration
No production code changed. New dev-only files and CI step only.
Chromium is installed to `out/playwright-browsers/` (gitignored) and
does not affect the regular build.

---------

Co-authored-by: Abdo <abdo@abdnh.net>
2026-05-22 15:59:42 -03:00

37 lines
1.2 KiB
TypeScript

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { defineConfig } from "@playwright/test";
const MEDIASRV_PORT = process.env.ANKI_API_PORT ?? "40000";
const PYENV_PYTHON = process.platform === "win32"
? "out\\pyenv\\Scripts\\python.exe"
: "out/pyenv/bin/python";
export default defineConfig({
testDir: "./ts/tests/e2e",
outputDir: "./out/e2e-report/",
fullyParallel: false,
workers: 1,
forbidOnly: !!process.env.CI,
retries: 0,
reporter: process.env.CI
? [["github"], ["html", { open: "never", outputFolder: "out/e2e-report" }]]
: "list",
use: {
baseURL: `http://127.0.0.1:${MEDIASRV_PORT}`,
trace: "retain-on-failure",
screenshot: "only-on-failure",
},
webServer: {
command: `${PYENV_PYTHON} qt/tests/launch_anki_for_e2e.py`,
url: `http://127.0.0.1:${MEDIASRV_PORT}/favicon.ico`,
timeout: 60_000,
reuseExistingServer: process.env.ANKI_E2E_REUSE_SERVER === "1",
stdout: "pipe",
stderr: "pipe",
env: { ANKI_API_PORT: MEDIASRV_PORT },
},
});