diff --git a/packages/cli/test/fixture/standalone-owner.ts b/packages/cli/test/fixture/standalone-owner.ts index d34385a10e4..a5c2acb75b5 100644 --- a/packages/cli/test/fixture/standalone-owner.ts +++ b/packages/cli/test/fixture/standalone-owner.ts @@ -14,7 +14,7 @@ await Effect.runPromise( const response = yield* Effect.promise(() => fetch(new URL("/api/health", endpoint.url), { headers: Service.headers(endpoint) }), ) - console.log(`${endpoint.pid} ${endpoint.url} ${response.status}`) + console.log(`STANDALONE_READY ${endpoint.pid} ${endpoint.url} ${response.status}`) return yield* Effect.never }), ), diff --git a/packages/cli/test/standalone.test.ts b/packages/cli/test/standalone.test.ts index 3cfe25855fa..aeea5c8f14a 100644 --- a/packages/cli/test/standalone.test.ts +++ b/packages/cli/test/standalone.test.ts @@ -9,8 +9,8 @@ test("standalone server exits when its owner is killed", async () => { stdout: "pipe", stderr: "pipe", }) - const line = await Promise.race([readLine(owner.stdout), Bun.sleep(10_000).then(() => undefined)]) - const [rawPID, url, status] = line?.split(" ") ?? [] + const line = await Promise.race([readLine(owner.stdout, "STANDALONE_READY "), Bun.sleep(10_000).then(() => undefined)]) + const [, rawPID, url, status] = line?.split(" ") ?? [] const pid = Number(rawPID) try { @@ -29,7 +29,7 @@ test("standalone server exits when its owner is killed", async () => { } }) -async function readLine(stream: ReadableStream) { +async function readLine(stream: ReadableStream, prefix: string) { const reader = stream.getReader() const decoder = new TextDecoder() const chunks: string[] = [] @@ -38,14 +38,14 @@ async function readLine(stream: ReadableStream) { if (result.done) break chunks.push(decoder.decode(result.value, { stream: true })) const output = chunks.join("") - const newline = output.indexOf("\n") - if (newline !== -1) { + const line = output.split("\n").find((line) => line.startsWith(prefix)) + if (line) { reader.releaseLock() - return output.slice(0, newline) + return line } } reader.releaseLock() - return chunks.join("") + decoder.decode() + return (chunks.join("") + decoder.decode()).split("\n").find((line) => line.startsWith(prefix)) } async function waitForExit(pid: number, attempts = 100): Promise {