alepha@docs:~/docs/framework/guides/testing$
cat 3-e2e-tests.md | pretty
1 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  use: { baseURL: "http://localhost:3000" }, 7  webServer: { 8    command: "node dist", 9    url: "http://localhost:3000",10    reuseExistingServer: false,11    env: { APP_SECRET: "e2e-test-secret" },12  },13});

The webServer option starts the production server before tests run and tears it down after. Two lines in it earn their place:

  • env.APP_SECRET: the built server runs in production mode, and SecretProvider refuses to boot on the built-in default secret in production. Without a value here the server never starts.
  • reuseExistingServer: false: Playwright's default (!process.env.CI) will happily adopt a running alepha dev server, and the suite then reports green against hot-reloaded sources and the dev database instead of the build.

#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("/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  use: { baseURL: "http://localhost:3000" }, 7  webServer: { 8    command: "bun dist", 9    url: "http://localhost:3000",10    reuseExistingServer: false,11    env: { APP_SECRET: "e2e-test-secret" },12  },13});

#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.