E2E Testing with Playwright
The panel ships with a Playwright test harness that gives every test a real, pre-authenticated session for a specific role — no OAuth, no login page, no browser cookies to manage manually.How It Works
NODE_ENV !== 'production' — it is never reachable in production.
Roles Available
| Role | Use For | |
|---|---|---|
superadmin | test-superadmin@test.local | Platform-level admin features |
admin | test-admin@test.local | Org admin features |
user | test-user@test.local | Standard member features |
Writing a Test
1. Create the spec file
Place all E2E specs infrontend/solidstart/tests/e2e/. Follow the naming convention:
- Single-role:
<feature>.<role>.spec.ts— e.g.dashboard.superadmin.spec.ts - Multi-role:
<feature>.multirole.spec.ts— when one test verifies permission differences across roles
You do not need any login code inside the test. The session is injected automatically by Playwright’s storageState for the project you select at run time.
2. Run the test as a specific role
--project flag selects which stored auth state (and which role) Playwright loads. No auth code is needed in the test itself.
The [data-testid="api-error-toast"] Contract
In dev mode the panel wraps globalThis.fetch and appends a visible <div data-testid="api-error-toast"> to the DOM whenever any request returns a status ≥ 400.
Every happy-path test MUST assert this element has count 0:
Before You Start: One-Time Setup
Seed test users
Set environment variables
Copy.env.test.example from the monorepo root to .env.test and fill in your local values:
Running Smoke Tests First
Before running Playwright, run the API smoke test to catch any broken endpoints early:Agent Definition of Done
Before handing off any frontend feature, complete all steps and paste terminal output as proof:- Smoke tests pass →
pnpm smoke:apiexits 0 - Playwright spec passes →
npx playwright test <spec> --project=<role>exits 0 - No API error toasts → final assertion in spec confirms count 0
Troubleshooting
Global setup fails: “Test user not found”
The test users haven’t been seeded yet. Run:Global setup fails: “Sign-in failed”
The credential account for the test user is missing or has a stale password. Re-run the seed — it deletes and recreates credential accounts:Session returns 401 on protected endpoints
The cookie set bytest-session needs to match the backend that the panel talks to. Make sure TEST_SESSION_ENDPOINT in .env.test points to the same Bun backend that the panel’s VITE_BETTER_AUTH_URL points to.
Auth state files are stale
Delete the auth directory and let global setup recreate it:Related
- Adding Features
- Build Scripts
- Backend:
backend/bun/AGENTS.md— Definition of Done for backend changes - Frontend:
frontend/solidstart/AGENTS.md— Naming convention and Definition of Done