Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970// The request/response exchange a guest server observes. Expected lines are what// Node v24 logs for tests/fixtures/guests/http-exchange.cjs under curl, except// remoteAddress (Node saw curl's ::1; the virtual socket reports 127.0.0.1) and the// destroyed exchange, which Node shows the client as an empty reply and the bridge// as a 502.import { test, expect, type Page } from "@playwright/test";
async function bootExchange(page: Page): Promise<string> { const source = await (await page.request.get("/tests/fixtures/guests/http-exchange.cjs")).text(); await page.goto("/demo/fixture.html"); await page.waitForFunction(() => window.__runtime !== undefined, undefined, { timeout: 20_000 }); return await page.evaluate(async (source) => { const runtime = window.__runtime!; runtime.writeTree({ "/app/http-exchange.cjs": source }); runtime.exec("/app/http-exchange.cjs"); return await runtime.waitForPort(3101); }, source);}
test("a 'data' listener attached after a timer still receives the body", async ({ page }) => { const base = await bootExchange(page); const text = await page.evaluate(async (base) => (await fetch(base + "late", { method: "POST", body: "payload" })).text(), base); expect(text).toBe("late:payload");});
test("a buffered body carries the content-length a browser sends but hides from the SW", async ({ page }) => { const base = await bootExchange(page); const lines = await page.evaluate(async (base) => Promise.all([ fetch(base + "length", { method: "POST", body: "payload" }).then((r) => r.text()), fetch(base + "length", { method: "POST" }).then((r) => r.text()), fetch(base + "length", { method: "PUT", body: "" }).then((r) => r.text()), fetch(base + "length").then((r) => r.text()), fetch(base + "length", { method: "DELETE" }).then((r) => r.text()), ]), base); expect(lines).toEqual(["POST 7 undefined", "POST 0 undefined", "PUT 0 undefined", "GET undefined undefined", "DELETE undefined undefined"]);});
test("socket facts, write callbacks and finish/close order match Node", async ({ page }) => { const base = await bootExchange(page); const res = await page.evaluate(async (base) => { const body = await (await fetch(base + "events")).text(); await new Promise((r) => setTimeout(r, 50)); return { body, log: await (await fetch(base + "log")).text() }; }, base); expect(res.body).toBe("ab"); expect(res.log.split("\n")).toEqual([ "socket:true false 127.0.0.1 number localhost:3101", "before:true false false false", "write:true", "after:true true true true", "write-cb", "finish:true", "end-cb", "close:true true", ]);});
test("destroying the response before end() closes it and answers 502", async ({ page }) => { const base = await bootExchange(page); const res = await page.evaluate(async (base) => { const r = await fetch(base + "destroy"); const text = await r.text(); await new Promise((resolve) => setTimeout(resolve, 50)); return { status: r.status, text, log: await (await fetch(base + "log")).text() }; }, base); expect(res.status).toBe(502); expect(res.text).toBe("ERR_NIB_SOCKET_DESTROYED: the server closed the connection without responding\n"); expect(res.log).toBe("destroyed:false true true");});