pp-planer/tests/e2e/auth.setup.ts
Thorsten Bus f313e7be8c test(e2e): add Playwright infrastructure with auth setup
- Install @playwright/test and chromium browser
- Create playwright.config.ts (baseURL, workers:1, no webServer)
- Create tests/e2e/auth.setup.ts (dummy login via POST /dev-login)
- Add test:e2e npm script
- Update .gitignore for tests/e2e/.auth/ and test-results/
- Auth setup uses page.request.post() to bypass ZiggyVue dependency
- storageState pattern for reusing login across tests
2026-03-01 22:45:19 +01:00

28 lines
1,017 B
TypeScript

import { test as setup, expect } from '@playwright/test';
const authFile = 'tests/e2e/.auth/user.json';
setup('authenticate', async ({ page }) => {
// Navigate to login page to establish session cookies (incl. XSRF-TOKEN)
await page.goto('http://cts-work.test/login');
// Get XSRF token from cookies for CSRF protection
const cookies = await page.context().cookies('http://cts-work.test');
const xsrfCookie = cookies.find((c) => c.name === 'XSRF-TOKEN');
const xsrfToken = decodeURIComponent(xsrfCookie?.value || '');
// POST to dev-login route directly (bypasses Vue rendering dependency)
await page.request.post('http://cts-work.test/dev-login', {
headers: {
'X-XSRF-TOKEN': xsrfToken,
},
});
// Navigate to dashboard to confirm login and load session
await page.goto('http://cts-work.test/dashboard');
await page.waitForURL('**/dashboard');
// Save signed-in state
await page.context().storageState({ path: authFile });
});