This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user