-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathplaywright-global-setup.ts
More file actions
32 lines (27 loc) · 945 Bytes
/
playwright-global-setup.ts
File metadata and controls
32 lines (27 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { logger } from '@repo/utils/logger/server'
const pollTimeoutMs = 60_000
const pollIntervalMs = 500
const apiUrl =
process.env.PLAYWRIGHT_API_URL ?? process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:3001'
async function waitForUrl(url: string, timeoutMs: number): Promise<boolean> {
const start = Date.now()
while (Date.now() - start < timeoutMs) {
try {
const res = await fetch(url, { signal: AbortSignal.timeout(2000) })
if (res.ok || res.status === 307) return true
} catch {
// continue polling
}
await new Promise(r => setTimeout(r, pollIntervalMs))
}
return false
}
async function globalSetup() {
const apiOk = await waitForUrl(`${apiUrl}/health`, pollTimeoutMs)
if (!apiOk) {
logger.error(`E2E setup: API unreachable at ${apiUrl}/health after ${pollTimeoutMs}ms`)
process.exit(1)
}
}
// Playwright requires default export for globalSetup
export default globalSetup