Files
DevRunbook-Public/tests/e2e/global-setup.ts
T
DevRunbook release export cfd2804e27
Managed validation / full (push) Successful in 3m18s
Publish DevRunbook source
2026-09-03 04:09:17 +02:00

29 lines
1004 B
TypeScript

import { request, type FullConfig } from '@playwright/test'
import { mkdir } from 'node:fs/promises'
export default async function globalSetup(config: FullConfig) {
const email = process.env.DEVRUNBOOK_E2E_EMAIL
const password = process.env.DEVRUNBOOK_E2E_PASSWORD
if (!email || !password) return
const baseURL = config.projects[0]?.use.baseURL
if (typeof baseURL !== 'string') {
throw new Error('PLAYWRIGHT_BASE_URL is required for authenticated setup')
}
const context = await request.newContext({
baseURL,
extraHTTPHeaders: { origin: new URL(baseURL).origin },
})
try {
const response = await context.post('/api/auth/sign-in/email', {
data: { email, password },
})
if (!response.ok()) {
throw new Error(`Browser authentication failed with ${response.status()}`)
}
await mkdir('test-results/.auth', { recursive: true })
await context.storageState({ path: 'test-results/.auth/m2.json' })
} finally {
await context.dispose()
}
}