Fix test failures and workload/websocket behavior
This commit is contained in:
43
frontend/e2e/global-setup.ts
Normal file
43
frontend/e2e/global-setup.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { chromium, FullConfig } from 'playwright/test'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
const storageStatePath = path.join(__dirname, '.auth', 'admin.json')
|
||||
const baseUrl = process.env.E2E_BASE_URL || 'http://localhost:3000'
|
||||
|
||||
const requireEnv = (name: string) => {
|
||||
const value = process.env[name]
|
||||
if (!value) {
|
||||
throw new Error(`Missing required env var: ${name}`)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
async function globalSetup(_config: FullConfig) {
|
||||
fs.mkdirSync(path.dirname(storageStatePath), { recursive: true })
|
||||
|
||||
const browser = await chromium.launch()
|
||||
const context = await browser.newContext()
|
||||
const page = await context.newPage()
|
||||
|
||||
await page.addInitScript(() => {
|
||||
localStorage.setItem('i18nextLng', 'en')
|
||||
})
|
||||
|
||||
const email = requireEnv('E2E_EMAIL')
|
||||
const password = requireEnv('E2E_PASSWORD')
|
||||
|
||||
await page.goto(`${baseUrl}/login`)
|
||||
await page.getByLabel('Email').fill(email)
|
||||
await page.getByLabel('Password').fill(password)
|
||||
await page.getByRole('button', { name: 'Sign in' }).click()
|
||||
await page.getByRole('button', { name: 'Logout' }).waitFor()
|
||||
|
||||
await context.storageState({ path: storageStatePath })
|
||||
await browser.close()
|
||||
}
|
||||
|
||||
export default globalSetup
|
||||
Reference in New Issue
Block a user