| 1 |
import type { FullConfig } from '@playwright/test'; |
| 2 |
|
| 3 |
// wp-playground-cli opens its HTTP port before the blueprint finishes |
| 4 |
// applying. Playwright's webServer.url check returns 200 from that |
| 5 |
// pre-blueprint state, so tests can race past steps like installTheme + |
| 6 |
// runPHP. Poll the REST root for the blogdescription sentinel that |
| 7 |
// setup.php writes — last blueprint step, theme-agnostic, no auth needed. |
| 8 |
const READY_MARKER = 'extendify-pw-blueprint-ready'; |
| 9 |
const TIMEOUT_MS = 180_000; |
| 10 |
const POLL_MS = 1_000; |
| 11 |
|
| 12 |
const isReady = async (baseURL: string) => { |
| 13 |
try { |
| 14 |
const res = await fetch(`${baseURL}/?rest_route=/`); |
| 15 |
if (!res.ok) return false; |
| 16 |
return (await res.text()).includes(READY_MARKER); |
| 17 |
} catch { |
| 18 |
return false; |
| 19 |
} |
| 20 |
}; |
| 21 |
|
| 22 |
export default async (config: FullConfig) => { |
| 23 |
const baseURLs = Array.from( |
| 24 |
new Set( |
| 25 |
config.projects |
| 26 |
.map((p) => p.use.baseURL) |
| 27 |
.filter((u): u is string => Boolean(u)), |
| 28 |
), |
| 29 |
); |
| 30 |
await Promise.all( |
| 31 |
baseURLs.map(async (baseURL) => { |
| 32 |
const start = Date.now(); |
| 33 |
while (Date.now() - start < TIMEOUT_MS) { |
| 34 |
if (await isReady(baseURL)) return; |
| 35 |
await new Promise((r) => setTimeout(r, POLL_MS)); |
| 36 |
} |
| 37 |
throw new Error( |
| 38 |
`Playground at ${baseURL} did not reach ready state within ${TIMEOUT_MS / 1000}s`, |
| 39 |
); |
| 40 |
}), |
| 41 |
); |
| 42 |
}; |
| 43 |
|