test(app): fix e2e
This commit is contained in:
@@ -25,15 +25,21 @@ async function freePort() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function waitForHealth(url: string) {
|
async function waitForHealth(url: string) {
|
||||||
const timeout = Date.now() + 60_000
|
const timeout = Date.now() + 120_000
|
||||||
|
const errors: string[] = []
|
||||||
while (Date.now() < timeout) {
|
while (Date.now() < timeout) {
|
||||||
const ok = await fetch(url)
|
const result = await fetch(url)
|
||||||
.then((r) => r.ok)
|
.then((r) => ({ ok: r.ok, error: undefined }))
|
||||||
.catch(() => false)
|
.catch((error) => ({
|
||||||
if (ok) return
|
ok: false,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
}))
|
||||||
|
if (result.ok) return
|
||||||
|
if (result.error) errors.push(result.error)
|
||||||
await new Promise((r) => setTimeout(r, 250))
|
await new Promise((r) => setTimeout(r, 250))
|
||||||
}
|
}
|
||||||
throw new Error(`Timed out waiting for server health: ${url}`)
|
const last = errors.length ? ` (last error: ${errors[errors.length - 1]})` : ""
|
||||||
|
throw new Error(`Timed out waiting for server health: ${url}${last}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const appDir = process.cwd()
|
const appDir = process.cwd()
|
||||||
@@ -72,7 +78,7 @@ const serverEnv = {
|
|||||||
} satisfies Record<string, string>
|
} satisfies Record<string, string>
|
||||||
|
|
||||||
const runnerEnv = {
|
const runnerEnv = {
|
||||||
...process.env,
|
...serverEnv,
|
||||||
PLAYWRIGHT_SERVER_HOST: "127.0.0.1",
|
PLAYWRIGHT_SERVER_HOST: "127.0.0.1",
|
||||||
PLAYWRIGHT_SERVER_PORT: String(serverPort),
|
PLAYWRIGHT_SERVER_PORT: String(serverPort),
|
||||||
VITE_OPENCODE_SERVER_HOST: "127.0.0.1",
|
VITE_OPENCODE_SERVER_HOST: "127.0.0.1",
|
||||||
@@ -92,27 +98,21 @@ if (seedExit !== 0) {
|
|||||||
process.exit(seedExit)
|
process.exit(seedExit)
|
||||||
}
|
}
|
||||||
|
|
||||||
const server = Bun.spawn(
|
Object.assign(process.env, serverEnv)
|
||||||
[
|
process.env.AGENT = "1"
|
||||||
"bun",
|
process.env.OPENCODE = "1"
|
||||||
"dev",
|
|
||||||
"--",
|
const log = await import("../../opencode/src/util/log")
|
||||||
"--print-logs",
|
const install = await import("../../opencode/src/installation")
|
||||||
"--log-level",
|
await log.Log.init({
|
||||||
"WARN",
|
print: true,
|
||||||
"serve",
|
dev: install.Installation.isLocal(),
|
||||||
"--port",
|
level: "WARN",
|
||||||
String(serverPort),
|
})
|
||||||
"--hostname",
|
|
||||||
"127.0.0.1",
|
const servermod = await import("../../opencode/src/server/server")
|
||||||
],
|
const server = servermod.Server.listen({ port: serverPort, hostname: "127.0.0.1" })
|
||||||
{
|
console.log(`opencode server listening on http://127.0.0.1:${serverPort}`)
|
||||||
cwd: opencodeDir,
|
|
||||||
env: serverEnv,
|
|
||||||
stdout: "inherit",
|
|
||||||
stderr: "inherit",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await waitForHealth(`http://127.0.0.1:${serverPort}/global/health`)
|
await waitForHealth(`http://127.0.0.1:${serverPort}/global/health`)
|
||||||
@@ -126,5 +126,5 @@ try {
|
|||||||
|
|
||||||
process.exitCode = await runner.exited
|
process.exitCode = await runner.exited
|
||||||
} finally {
|
} finally {
|
||||||
server.kill()
|
await server.stop()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user