alepha@docs:~/docs/guides/testing$
cat 3-e2e-tests.md1 min read
Last commit:
#End-to-End Tests
End-to-end tests run against the built production version of your Alepha application. Use Playwright to drive a real browser and test the full stack.
#Setup
Install Playwright:
npm install -D @playwright/test
npx playwright install
Create a Playwright configuration:
typescript
1// playwright.config.ts 2import { defineConfig } from "@playwright/test"; 3 4export default defineConfig({ 5 testDir: "./e2e", 6 baseURL: "http://localhost:3000", 7 webServer: { 8 command: "node dist", 9 url: "http://localhost:3000",10 },11});
The webServer option starts the production server before tests run and tears it down after.
#Build and Test
Always build before running e2e tests. The tests execute against the dist/ output, not the dev server.
bash
alepha build
npx playwright test
#Writing Tests
Place test files in the e2e/ directory:
typescript
1// e2e/home.spec.ts 2import { test, expect } from "@playwright/test"; 3 4test("home page loads", async ({ page }) => { 5 await page.goto("/"); 6 await expect(page).toHaveTitle(/My App/); 7}); 8 9test("API returns data", async ({ request }) => {10 const response = await request.get("/api/health");11 expect(response.ok()).toBeTruthy();12});
#With Bun
If your production server runs on Bun, adjust the webServer command:
typescript
1// playwright.config.ts 2import { defineConfig } from "@playwright/test"; 3 4export default defineConfig({ 5 testDir: "./e2e", 6 baseURL: "http://localhost:3000", 7 webServer: { 8 command: "bun dist", 9 url: "http://localhost:3000",10 },11});
#CI Integration
In CI, run the full pipeline:
bash
alepha build
npx playwright test --reporter=html
Playwright generates an HTML report by default. Configure reporters in playwright.config.ts to match your CI system.