|
| 1 | +<!-- SPDX-FileCopyrightText: © 2025 StreamKit Contributors --> |
| 2 | +<!-- SPDX-License-Identifier: MPL-2.0 --> |
| 3 | + |
| 4 | +# StreamKit E2E Tests |
| 5 | + |
| 6 | +End-to-end tests for StreamKit using Playwright. |
| 7 | + |
| 8 | +## Prerequisites |
| 9 | + |
| 10 | +- Bun 1.3.5+ |
| 11 | +- Rust 1.92.0+ (for building skit) |
| 12 | +- Built UI (`cd ui && bun install && bun run build` or `just build-ui`) |
| 13 | +- Built skit binary (`cargo build -p streamkit-server --bin skit`) |
| 14 | + |
| 15 | +## Quick Start |
| 16 | + |
| 17 | +```bash |
| 18 | +# Install dependencies and Playwright browsers |
| 19 | +just install-e2e |
| 20 | +just install-playwright |
| 21 | + |
| 22 | +# Run tests (automatically starts server) |
| 23 | +just e2e |
| 24 | + |
| 25 | +# Or run directly from e2e directory |
| 26 | +cd e2e |
| 27 | +bun install |
| 28 | +bunx playwright install chromium |
| 29 | +bun run test |
| 30 | +``` |
| 31 | + |
| 32 | +## Running Against External Server |
| 33 | + |
| 34 | +If you already have a StreamKit server running: |
| 35 | + |
| 36 | +```bash |
| 37 | +E2E_BASE_URL=http://localhost:4545 bun run test:only |
| 38 | + |
| 39 | +# Or via justfile |
| 40 | +just e2e-external http://localhost:4545 |
| 41 | +``` |
| 42 | + |
| 43 | +## Running Against Vite Dev Server |
| 44 | + |
| 45 | +To test against the Vite development server (useful for debugging UI changes): |
| 46 | + |
| 47 | +```bash |
| 48 | +# Terminal 1: Start skit backend |
| 49 | +cargo run -p streamkit-server --bin skit -- serve |
| 50 | + |
| 51 | +# Terminal 2: Start Vite dev server |
| 52 | +cd ui && bun run dev |
| 53 | + |
| 54 | +# Terminal 3: Run E2E tests against Vite |
| 55 | +just e2e-external http://localhost:3045 |
| 56 | +``` |
| 57 | + |
| 58 | +The Vite dev server proxies `/api/*` and `/healthz` requests to the skit backend |
| 59 | +(default `127.0.0.1:4545`). This is primarily for Playwright’s direct API calls when |
| 60 | +`E2E_BASE_URL` points at the Vite server; the UI itself still talks directly to the backend |
| 61 | +in development (via `import.meta.env.VITE_API_BASE`). |
| 62 | + |
| 63 | +Both servers must be running for tests to pass. |
| 64 | + |
| 65 | +## Test Structure |
| 66 | + |
| 67 | +- `tests/design.spec.ts` - Design view tests (canvas, samples, YAML editor) |
| 68 | +- `tests/monitor.spec.ts` - Monitor view tests (session lifecycle) |
| 69 | + |
| 70 | +## Server Harness |
| 71 | + |
| 72 | +When `E2E_BASE_URL` is not set, the test harness (`src/harness/run.ts`): |
| 73 | + |
| 74 | +1. Finds a free port |
| 75 | +2. Starts `target/debug/skit serve` with `SK_SERVER__ADDRESS=127.0.0.1:<port>` |
| 76 | +3. Polls `/healthz` until server is ready (30s timeout) |
| 77 | +4. Runs all Playwright tests |
| 78 | +5. Stops the server |
| 79 | + |
| 80 | +Environment variables set by harness: |
| 81 | + |
| 82 | +- `SK_SERVER__ADDRESS` - Bind address |
| 83 | +- `SK_LOG__FILE_ENABLE=false` - Disable file logging |
| 84 | +- `RUST_LOG=warn` - Reduce log noise |
| 85 | + |
| 86 | +## Scripts |
| 87 | + |
| 88 | +| Script | Description | |
| 89 | +| --------------------- | -------------------------------------------- | |
| 90 | +| `bun run test` | Run tests with auto server management | |
| 91 | +| `bun run test:only` | Run tests directly (requires `E2E_BASE_URL`) | |
| 92 | +| `bun run test:headed` | Run tests with visible browser | |
| 93 | +| `bun run test:ui` | Run tests with Playwright UI | |
| 94 | +| `bun run report` | Show HTML test report | |
| 95 | + |
| 96 | +## Debugging |
| 97 | + |
| 98 | +```bash |
| 99 | +# Run with debug mode (shows server output) |
| 100 | +DEBUG=1 bun run test |
| 101 | + |
| 102 | +# Run single test file |
| 103 | +bun run test -- tests/design.spec.ts |
| 104 | + |
| 105 | +# Run with trace viewer on failure |
| 106 | +bun run test -- --trace on |
| 107 | + |
| 108 | +# Run specific test by name |
| 109 | +bun run test -- -g "loads with all main panes" |
| 110 | +``` |
| 111 | + |
| 112 | +## CI |
| 113 | + |
| 114 | +Tests run automatically in CI via `.github/workflows/e2e.yml`. |
| 115 | +On failure, `playwright-report/` and `test-results/` are uploaded as artifacts. |
| 116 | + |
| 117 | +## Adding New Tests |
| 118 | + |
| 119 | +1. Create a new spec file in `tests/` directory |
| 120 | +2. Use `data-testid` attributes for stable element selection |
| 121 | +3. Prefer role/name selectors for accessible elements |
| 122 | +4. Avoid arbitrary waits; use Playwright's built-in assertions |
| 123 | + |
| 124 | +Example: |
| 125 | + |
| 126 | +```typescript |
| 127 | +import { test, expect } from '@playwright/test'; |
| 128 | + |
| 129 | +test('my new test', async ({ page }) => { |
| 130 | + await page.goto('/my-route'); |
| 131 | + await expect(page.getByTestId('my-element')).toBeVisible(); |
| 132 | +}); |
| 133 | +``` |
0 commit comments