98939877db
* feat: comprehensive Playwright E2E test rewrite Rewrite all E2E tests with correct CSS selectors, add new spec files, and implement robust auth handling to work within backend rate limits. Changes: - Rewrite fixtures/index.ts with JWT-based /auth/me mock to avoid 10 req/min rate limit on /auth/me during test runs - Rewrite auth.setup.ts with offline JWT validity check to reuse existing auth state across runs (saves login rate-limit budget) - Rewrite auth.spec.ts (6 tests) - login page, fields, submit, redirect guard, invalid credentials, login/register toggle - Rewrite dashboard.spec.ts (8 tests) - header, nav tabs, navigation, overview/schedules sections, days selector, redirect - Rewrite medications.spec.ts (8 tests) - form fields, stock inventory, package type toggle, intake schedule, save/cancel, unsaved changes guard - Rewrite settings.spec.ts (12 tests) - language, notification matrix, thresholds, calculation mode, toggle switch, export/import, user menu navigation - Create planner.spec.ts (9 tests) - form, date inputs, calculate, reset, checkbox, submit, tab state, eyebrow heading - Create schedule.spec.ts (12 tests) - timeline, days selector, past/future toggles, day blocks, today highlight, collapse/expand, overview table, share button - Update playwright.config.ts: remove mobile projects, enable webServer section for CI - Add .github/workflows/e2e.yml CI workflow for Playwright tests Total: 57 E2E tests across 6 spec files, all passing consistently across 5+ consecutive runs without backend restart. Closes #154 * feat: add comprehensive E2E data tests with medication CRUD, dashboard, planner, schedule Add 48 new Playwright E2E tests covering real medication data scenarios: - medication-crud: 14 tests for create/edit/delete/list via UI form - dashboard-data: 13 tests for overview table, timeline, dose tracking - planner-data: 9 tests for demand calculator with results/status chips - schedule-data: 11 tests for timeline, collapse/expand, dose mark/undo Infrastructure improvements: - Add API helpers (createMedicationViaAPI, deleteMedicationViaAPI, deleteAllMedicationsViaAPI) with retry logic for rate-limit resilience - Configure chromium-data project for serial execution with retry:1 - Add /auth/me mock to avoid rate-limit exhaustion on auth endpoint - Increase navigateTo reliability with networkidle waits - Increase auth token validity threshold from 2 to 10 minutes - Make backend rate limit configurable via RATE_LIMIT_MAX env var - Set RATE_LIMIT_MAX=300 in dev docker-compose for E2E test support Total suite: 57 empty-state + 48 data tests = 105 tests (chromium) * test: add E2E tests for medication editing, stock status, and share schedule - medication-edit.spec.ts: 10 tests covering generic name, notes, taken-by add/remove, expiry date, refill, intake schedule editing, adding intake rows, reminder toggle, and package type changes - stock-status.spec.ts: 12 tests verifying dashboard shows correct status chips (High/Normal/Warning/Danger) for different stock levels, overview table, reorder card, detail modal, and planner integration - share-schedule.spec.ts: 10 tests for taken-by badges, share button, share dialog, link generation, shared schedule page navigation, dose tracking on shared page, and notes display - fixtures/index.ts: add createShareTokenViaAPI, updateSettingsViaAPI helpers; expand createMedicationViaAPI with takenBy, notes, expiryDate - playwright.config.ts: update testMatch/testIgnore for new test files - docker-compose.dev.yml: increase RATE_LIMIT_MAX to 1000 for E2E tests * docs: refine release-manager instructions for CLI safety and commit-linked release notes * fix: resolve PR155 CI failures for frontend lint and e2e proxy * fix: stabilize auth-related e2e checks in CI
154 lines
3.9 KiB
TypeScript
154 lines
3.9 KiB
TypeScript
import { defineConfig, devices } from "@playwright/test";
|
|
|
|
/**
|
|
* Playwright E2E Testing Configuration
|
|
*
|
|
* Run E2E tests with:
|
|
* npm run test:e2e - Run tests in headless mode
|
|
* npm run test:e2e:ui - Run tests with Playwright UI
|
|
* npm run test:e2e:headed - Run tests in headed mode
|
|
*
|
|
* Before running tests, ensure both backend and frontend are running:
|
|
* docker compose -f docker-compose.dev.yml up
|
|
*
|
|
* Or run them separately:
|
|
* cd backend && npm run dev
|
|
* cd frontend && npm run dev
|
|
*/
|
|
|
|
// Base URL for the frontend dev server
|
|
const baseURL = process.env.PLAYWRIGHT_BASE_URL || "http://localhost:5173";
|
|
|
|
export default defineConfig({
|
|
// Directory containing test files
|
|
testDir: "./e2e",
|
|
|
|
// Test file pattern
|
|
testMatch: "**/*.spec.ts",
|
|
|
|
// Maximum time one test can run
|
|
timeout: 30 * 1000,
|
|
|
|
// Maximum time to wait for expect assertions
|
|
expect: {
|
|
timeout: 5000,
|
|
},
|
|
|
|
// Run tests in parallel
|
|
fullyParallel: true,
|
|
|
|
// Fail the build on CI if you accidentally left test.only in the source code
|
|
forbidOnly: !!process.env.CI,
|
|
|
|
// Retry failed tests (more retries on CI)
|
|
retries: process.env.CI ? 2 : 0,
|
|
|
|
// Opt out of parallel tests on CI
|
|
workers: process.env.CI ? 1 : undefined,
|
|
|
|
// Reporter configuration
|
|
reporter: process.env.CI
|
|
? [["html", { outputFolder: "playwright-report" }], ["github"]]
|
|
: [["html", { outputFolder: "playwright-report" }], ["list"]],
|
|
|
|
// Shared settings for all projects
|
|
use: {
|
|
// Base URL for page.goto() calls
|
|
baseURL,
|
|
|
|
// Collect trace on first retry
|
|
trace: "on-first-retry",
|
|
|
|
// Capture screenshot on failure
|
|
screenshot: "only-on-failure",
|
|
|
|
// Record video for every test so runs can be reviewed
|
|
video: "on",
|
|
|
|
// Default viewport size
|
|
viewport: { width: 1280, height: 720 },
|
|
|
|
// Wait for network idle before considering navigation complete
|
|
navigationTimeout: 30000,
|
|
|
|
// Accept cookies and local storage
|
|
actionTimeout: 5000,
|
|
},
|
|
|
|
// Configure projects for multiple browsers
|
|
projects: [
|
|
// Setup project for authentication state
|
|
{
|
|
name: "setup",
|
|
testMatch: /.*\.setup\.ts/,
|
|
},
|
|
|
|
// Desktop Chrome — primary test browser, always runs
|
|
// Excludes data/crud tests (those run in chromium-data to avoid DB conflicts)
|
|
{
|
|
name: "chromium",
|
|
use: {
|
|
...devices["Desktop Chrome"],
|
|
},
|
|
testIgnore: /.*-(?:data|crud|edit|status|schedule)\.spec\.ts/,
|
|
dependencies: ["setup"],
|
|
retries: 1,
|
|
},
|
|
|
|
// Desktop Firefox — runs locally and optionally in CI
|
|
// Excludes data/crud/edit/status/schedule tests (those run in chromium-data to avoid DB conflicts)
|
|
{
|
|
name: "firefox",
|
|
use: {
|
|
...devices["Desktop Firefox"],
|
|
},
|
|
testIgnore: /.*-(?:data|crud|edit|status|schedule)\.spec\.ts/,
|
|
dependencies: ["setup"],
|
|
},
|
|
|
|
// Desktop Safari — runs locally and optionally in CI
|
|
// Excludes data/crud/edit/status/schedule tests (those run in chromium-data to avoid DB conflicts)
|
|
{
|
|
name: "webkit",
|
|
use: {
|
|
...devices["Desktop Safari"],
|
|
},
|
|
testIgnore: /.*-(?:data|crud|edit|status|schedule)\.spec\.ts/,
|
|
dependencies: ["setup"],
|
|
},
|
|
|
|
// Data tests — only Chromium, run serially to avoid DB conflicts
|
|
// These tests create/edit/delete medications and must not run concurrently
|
|
// across browsers since all share the same backend database.
|
|
{
|
|
name: "chromium-data",
|
|
testMatch: /.*-(?:data|crud|edit|status|schedule)\.spec\.ts/,
|
|
use: {
|
|
...devices["Desktop Chrome"],
|
|
},
|
|
dependencies: ["setup"],
|
|
fullyParallel: false,
|
|
retries: 1,
|
|
},
|
|
],
|
|
|
|
// Directory for test output files (screenshots, traces, videos)
|
|
outputDir: "test-results/",
|
|
|
|
// Web server configuration — automatically start dev servers in CI
|
|
webServer: [
|
|
{
|
|
command: "cd ../backend && npm run dev",
|
|
url: "http://localhost:3000/health",
|
|
reuseExistingServer: !process.env.CI,
|
|
timeout: 120 * 1000,
|
|
},
|
|
{
|
|
command: "npm run dev",
|
|
url: "http://localhost:5173",
|
|
reuseExistingServer: !process.env.CI,
|
|
timeout: 120 * 1000,
|
|
},
|
|
],
|
|
});
|