🎭 Frontend Tests Overview (Playwright)
LibreFolio's frontend tests use Playwright to drive a real browser and interact with the application exactly as a user would.
🧰 Tools & Framework
| Tool | Role |
|---|---|
| Playwright | Browser automation engine (Chromium, headless by default) |
@playwright/test |
Test runner with test(), expect(), fixtures |
page |
Playwright's page fixture — represents a browser tab |
expect |
Assertion library with auto-retry and web-first semantics |
⚙️ How Tests Work
Each test file (.spec.ts) contains scenarios that:
- Navigate to a URL (
page.goto('/fx')) - Interact with elements (
page.click(),page.fill(),page.getByRole()) - Assert outcomes (
expect(page.getByText('EUR/USD')).toBeVisible())
Playwright automatically waits for elements and retries assertions, making tests resilient to timing issues.
// Example: verify broker creation
test('create a new broker', async ({ page }) => {
await page.goto('/brokers');
await page.getByRole('button', { name: 'New Broker' }).click();
await page.getByLabel('Name').fill('My Broker');
await page.getByRole('button', { name: 'Save' }).click();
await expect(page.getByText('My Broker')).toBeVisible();
});
🤖 Automated Setup
When you run a frontend test category, everything the Playwright specs need is prepared for you (the category's Vitest files need none of it):
- Builds the frontend, when needed —
front build, which syncs the API client before building, runs only when there is no build yet, when the frontend sources, its static files, its configuration or the Tool codegen inputs changed since the last build (frontend/src/, andfrontend/static/, which adapter-static copies into the build:sw.js,offline.html, the icons, the fonts; under both, the same rule: hidden files and folders, such as the macOS Finder's.DS_Storeor the font cache's.cache_manifest.json, do not count, nor do*.test.*/*.spec.*files and the__tests__//__mocks__/folders, which only the tests use), or when the existing build is not of the kind needed: instrumented for JS coverage or plain, and a debug build fordev.py server --test. The Tool codegen inputs, among them the.pyfiles ofbackend/app/schemas/,backend/app/services/tools/andbackend/app/services/tool_plugins/, and the files offrontend/src/andfrontend/static/that count (the generated translation catalogues aside), are also checked against the fingerprint of their listing that the last successfulfront buildrecorded infrontend/build/.tool-contract-inputs: an input added, removed or renamed counts even with an old date, while a.DS_Store, an editor's hidden file or a__pycache__/next to them does not. For a build without that record (one made before the record existed, or bynpm run buildalone), the check reads the dates of the Tool codegen folders instead (for the frontend's files, only their own dates), which a.DS_Storeor a__pycache__/moves too: one rebuild too many at worst, after which the record exists. The runner checks before the specs, and for the shared test backend before starting it:dev.py server --test --build-onlyruns in the foreground (the frontend build, and the documentation site when it is missing or stale), outside the backend's startup timeout. With--no-shared-server, the server that Playwright'swebServerstarts makes that check itself, inside the webServer's startup wait. - Uses a test backend —
dev.py server --test, serving the API and the built frontend on the run's test port. By default it is the shared backend the runner starts once for the whole invocation; with--no-shared-server, Playwright'swebServerstarts its own for each Playwright run. It runs with the popups that would interrupt the specs switched off: the donation prompt (LIBREFOLIO_DISABLE_DONATION_POPUP=1), since the specs sign in again and again with the same users, and the «What's new» window (LIBREFOLIO_DISABLE_WHATS_NEW=1, lot C-54), since the lanes' accounts predate it, so theirGET /auth/meanswersuser.whats_new: null. Both switches are hidden: no.env.exampleline, no admin page. A spec that needs the window gives its own page a value instead, aslayout/whats-new.spec.tsdoes (What's new). It always runs atDEBUG(dev.py server --testsetsLIBREFOLIO_LOG_LEVEL=DEBUG), so the lane publishesclient_log_level: "debug"and the browser console gets a line for every failed API call, a4xxincluded; no spec fails on a console line (The Browser Console). - Prepares the test data — repopulates the test database with mock data and creates the E2E users, in the runner or in Playwright's
globalSetup. - Runs Playwright — executes the specs against the live application at
http://localhost:<test port>:6041unless--test-portorTEST_PORTsays otherwise. - Tears down — stops the backend it started: the shared one at the end of the invocation, Playwright's own at the end of its run.
Test isolation
The test backend works on the run's test data root: backend/data/test/ in the checkout unless
--data-dir or LIBREFOLIO_TEST_DATA_DIR says otherwise, with the database in sqlite/app.db
under it. The runner refuses a test data root that overlaps the production data, so your
production data is never touched. See Isolated Runtime Lanes.
🏁 Flags
Every frontend test category — front-utility, front-broker, front-user, front-fx,
front-asset, front-transaction, front-portfolio, front-ai-export, front-designer-lab — supports these flags.
--headed, --debug, --ui and --list follow the category (./dev.py test front-fx all --headed);
--coverage belongs to ./dev.py test and comes before it (./dev.py test --coverage js front-fx all).
| Flag | Effect | When to Use |
|---|---|---|
--headed |
Opens a visible browser window instead of headless | Watch the test flow visually, debug layout issues |
--debug |
Runs headed with the Playwright Inspector (PWDEBUG=1), which pauses the test so you can step through its actions |
Step through actions one by one, inspect selectors, set breakpoints |
--ui |
Opens Playwright UI Mode — a full interactive test runner | Explore tests interactively, view timeline/trace, re-run selectively |
--list |
Lists the category's Playwright spec files and the test titles they declare, without running anything (all for the whole category, an action name for its specs only) |
Discover tests, verify naming, plan what to run |
--coverage [py\|js\|all] |
Tracks Python and/or JS coverage: the backend's Python while the E2E tests drive it, the frontend's JS in the browser and in the category's Vitest files | py → htmlcov-backend-e2e/, js → frontend/coverage-js/ (e2e/, unit-combined/, and combined/ when both ran), all (default) → both |
E2E runs are the only ones that measure both languages
A Playwright run exercises the frontend in the browser and the backend over
HTTP, so it is the only suite where --coverage all produces two reports. See
Coverage Model.
🎨 Playwright UI Mode (--ui)
The UI mode provides a rich interactive experience:
- Timeline view — See every action (click, fill, navigate) on a visual timeline
- DOM snapshot — Inspect the page state at any point during the test
- Network tab — Monitor API calls and responses
- Re-run — Click to re-run a single test or a filtered subset
- Filter — Filter by file name, test title, or
describeblock
📋 Test Categories
| Category | Command | What's Tested |
|---|---|---|
| Front-Utility | ./dev.py test front-utility all |
Auth, settings, files, select, image crop, onboarding, layout, scheduler (Playwright) + core and component units (Vitest) |
| Front-Broker | ./dev.py test front-broker all |
Broker list, CRUD, detail page, deletion recovery (Playwright) + broker helpers (Vitest) |
| Front-User | ./dev.py test front-user all |
Multi-user isolation, broker sharing (Playwright) + auth and client-session stores (Vitest) |
| Front-FX | ./dev.py test front-fx all |
FX list, detail, add-pair, editor, CSV import, sync, bulk actions (Playwright) + EditBuffer, TimeSeriesStore, fxStoreRegistry (Vitest) |
| Front-Asset | ./dev.py test front-asset all |
Asset list, detail, modal, data editor, merge, classification (Playwright) + price store, chart aggregation (Vitest) |
| Front-Transaction | ./dev.py test front-transaction all |
Transaction modals, table, bulk operations, WAC, import wizard (Playwright) + payload and commit helpers (Vitest) |
| Front-Portfolio | ./dev.py test front-portfolio all |
Dashboard charts, banners, page cache, privacy masking, risk analysis (Playwright) + portfolio and risk stores (Vitest) |
| Front-AI-Export | ./dev.py test front-ai-export all |
AI Export panel, catalog, session memory, contracts (Playwright) + AI Export and signal units (Vitest) |
| Front-Designer-Lab | ./dev.py test front-designer-lab all |
Designer Lab: live preview in another tab, element picker, neutrality (Playwright) + Lab units (Vitest) |
The categories without a walkthrough page list their actions with ./dev.py test <category> -h.