auth.setup.ts 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. import { test as setup, expect } from '@playwright/test'
  2. /**
  3. * Signs in once and keeps the session on disk. Every other spec starts already
  4. * authenticated, which saves a login per test and keeps the sign-in flow tested
  5. * in exactly one place.
  6. */
  7. const AUTH_STATE = 'e2e/.auth/owner.json'
  8. const email = process.env.E2E_USER_EMAIL ?? 'demo@torqvoice.com'
  9. const password = process.env.E2E_USER_PASSWORD ?? 'demo-e2e-pass'
  10. setup('sign in as the workshop owner', async ({ page, context }) => {
  11. await page.goto('/auth/sign-in')
  12. await page.locator('#email').fill(email)
  13. await page.locator('#password').fill(password)
  14. await page.getByRole('button', { name: 'Sign In', exact: true }).click()
  15. // Landing anywhere outside /auth means the session cookie was accepted.
  16. await page.waitForURL((url) => !url.pathname.startsWith('/auth'), { timeout: 30_000 })
  17. await expect(page.locator('#password')).toHaveCount(0)
  18. // The app reads its language from this cookie before Accept-Language. Set
  19. // here rather than per test so the saved state carries it everywhere.
  20. const { hostname } = new URL(page.url())
  21. await context.addCookies([{ name: 'locale', value: 'en', domain: hostname, path: '/' }])
  22. await context.storageState({ path: AUTH_STATE })
  23. })