feat: enhance Playwright testing setup with E2E tests, new skills, and improved documentation
Some checks failed
Chore App Build, Test, and Push Docker Images / build-and-push (push) Failing after 1m44s
Some checks failed
Chore App Build, Test, and Push Docker Images / build-and-push (push) Failing after 1m44s
- Added E2E test setup in `auth_api.py` with `/e2e-seed` endpoint for database reset and test user creation. - Integrated Playwright for end-to-end testing in the frontend with necessary dependencies in `package.json` and `package-lock.json`. - Created Playwright configuration in `playwright.config.ts` to manage test execution and server setup. - Developed new skills for Playwright best practices, visual regression, smoke test generation, and self-healing tests. - Implemented new test cases for chore creation in `chores-create.smoke.spec.ts` and `chores-create.spec.ts`. - Added page object models for `ChildEditPage` and `LandingPage` to streamline test interactions. - Updated `.gitignore` to exclude Playwright reports and test results. - Enhanced documentation in `copilot-instructions.md` for testing and E2E setup.
This commit is contained in:
44
frontend/vue-app/tests/global-setup.ts
Normal file
44
frontend/vue-app/tests/global-setup.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { chromium } from '@playwright/test'
|
||||
|
||||
const BACKEND_URL = 'http://localhost:5000'
|
||||
const BASE_URL = 'https://localhost:5173'
|
||||
|
||||
export const E2E_EMAIL = 'e2e@test.com'
|
||||
export const E2E_PASSWORD = 'E2eTestPass1!'
|
||||
export const E2E_PIN = '1234'
|
||||
export const STORAGE_STATE = 'tests/.auth/user.json'
|
||||
|
||||
// Matches PARENT_AUTH_KEY and PARENT_AUTH_EXPIRY_PERSISTENT in src/stores/auth.ts
|
||||
const PARENT_AUTH_KEY = 'parentAuth'
|
||||
const TWO_DAYS_MS = 172_800_000
|
||||
|
||||
export default async function globalSetup() {
|
||||
// Reset all tables and insert a verified test user directly via the backend
|
||||
const seedRes = await fetch(`${BACKEND_URL}/auth/e2e-seed`, { method: 'POST' })
|
||||
if (!seedRes.ok) {
|
||||
throw new Error(`e2e-seed failed: ${seedRes.status} ${await seedRes.text()}`)
|
||||
}
|
||||
|
||||
// Use a real browser to log in so that HttpOnly auth cookies are captured correctly
|
||||
const browser = await chromium.launch()
|
||||
const context = await browser.newContext({ ignoreHTTPSErrors: true })
|
||||
const page = await context.newPage()
|
||||
|
||||
await page.goto(`${BASE_URL}/auth/login`)
|
||||
await page.fill('#email', E2E_EMAIL)
|
||||
await page.fill('#password', E2E_PASSWORD)
|
||||
await page.click('button[type="submit"]')
|
||||
|
||||
// After login the router redirects away from /auth — wait for that navigation
|
||||
await page.waitForURL(/\/(child|parent)/)
|
||||
|
||||
// Inject persistent parent auth into localStorage so tests can access /parent routes
|
||||
// without navigating through the PIN prompt UI
|
||||
await page.evaluate(
|
||||
({ key, expiresAt }) => localStorage.setItem(key, JSON.stringify({ expiresAt })),
|
||||
{ key: PARENT_AUTH_KEY, expiresAt: Date.now() + TWO_DAYS_MS },
|
||||
)
|
||||
|
||||
await context.storageState({ path: STORAGE_STATE })
|
||||
await browser.close()
|
||||
}
|
||||
Reference in New Issue
Block a user