Skip to content

Commit 27a071c

Browse files
committed
test(bun): actually run the node-compat suites under Bun
1 parent 0fbfb06 commit 27a071c

3 files changed

Lines changed: 133 additions & 89 deletions

File tree

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
"srvx": "./bin/srvx.mjs",
5757
"test": "pnpm lint && pnpm typecheck && vitest run --coverage",
5858
"test:node-compat:deno": "deno run vitest test/node.test",
59-
"test:node-compat:bun": "bun vitest test/node.test.ts",
59+
"test:node-compat:bun": "bun --bun run vitest run test/node.test.ts",
6060
"test:node-adapters:deno": "deno run vitest test/node-adapters.test",
61-
"test:node-adapters:bun": "bun vitest test/node-adapters.test.ts",
61+
"test:node-adapters:bun": "bun --bun run vitest run test/node-adapters.test.ts",
6262
"typecheck": "tsc --noEmit --skipLibCheck",
6363
"vitest": "vitest"
6464
},

‎test/_tests.ts‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export function addTests(opts: {
1212
}): void {
1313
const { url, fetch: _fetch = globalThis.fetch } = opts;
1414

15+
// srvx's Node adapter driven by Bun's `node:http` compat layer (test/node.test.ts
16+
// run under Bun). Distinct from `"bun"`, which is srvx's native Bun adapter.
17+
// Bun's `node:http` server never surfaces a client disconnect as a request
18+
// abort, so every abort-dependent expectation below is a runtime gap there.
19+
const isBunNodeCompat = opts.runtime === "bun-node-compat";
20+
1521
let fetchCount = 0;
1622
const fetch = (...args: Parameters<typeof _fetch>) => {
1723
fetchCount++;
@@ -122,7 +128,7 @@ export function addTests(opts: {
122128
expect(await response.text()).toBe("error: test error");
123129
});
124130

125-
test("abort request", async () => {
131+
test.skipIf(isBunNodeCompat)("abort request", async () => {
126132
const controller = new AbortController();
127133
const response = await fetch(url("/abort"), {
128134
signal: controller.signal,
@@ -153,13 +159,14 @@ export function addTests(opts: {
153159
const aborts = await res.json();
154160
// console.log(aborts.map((a: any) => `${a.request}`).join("\n"));
155161

156-
// Deno Node.js compat behaves differently!!!
157-
if (opts.runtime !== "deno-node-compat") {
162+
// Deno Node.js compat behaves differently!!!, and Bun's never logs an abort
163+
// at all (see `isBunNodeCompat`).
164+
if (opts.runtime !== "deno-node-compat" && !isBunNodeCompat) {
158165
expect(aborts.length).toBe(expectedAbortCount);
159166
}
160167
});
161168

162-
test("cancel reading body", async () => {
169+
test.skipIf(isBunNodeCompat)("cancel reading body", async () => {
163170
const res = await fetch(url("/body-cancel"), {
164171
method: "POST",
165172
// @ts-expect-error
@@ -193,8 +200,11 @@ export function addTests(opts: {
193200
if (done) break;
194201
}
195202
const body = Buffer.concat(chunks).toString("utf8").trim();
196-
if ("Bun" in globalThis) {
197-
// It seems a Bun bug (from fetch client-side not server-side!)
203+
if ("Bun" in globalThis && !isBunNodeCompat) {
204+
// It seems a Bun bug (from fetch client-side not server-side!) -- hence the
205+
// check on the runtime executing the fetch rather than on the adapter under
206+
// test. It does not reproduce against a `node:http` server, which is what the
207+
// Node adapter serves over under Bun node-compat.
198208
expect(body).toBe("chunk1\nchunk2\n\r\nchunk1\nchunk2");
199209
} else {
200210
expect(body).toBe("chunk1\nchunk2");
@@ -313,12 +323,13 @@ export function addTests(opts: {
313323
});
314324
});
315325

316-
// Skipped on the Bun adapter only: Bun's `util.inspect(new Headers())` prints
317-
// `Headers {}` without enumerating entries, while Node and Deno list them.
318-
// Nothing for srvx to fix -- it does not implement a custom inspect. The Node
319-
// adapter passes under Bun (node-compat) because its headers are srvx's own
320-
// class rather than a native `Headers`. Re-enable if Bun fixes util.inspect.
321-
test.skipIf(opts.runtime === "bun")("inspect objects", async () => {
326+
// Skipped on Bun: `util.inspect(new Headers())` prints `Headers {}` without
327+
// enumerating entries, while Node and Deno list them. Nothing for srvx to fix --
328+
// it does not implement a custom inspect. This applies to the Node adapter under
329+
// Bun node-compat too; the exemption previously claimed otherwise, which went
330+
// unnoticed while the Bun scripts were silently running on Node.
331+
// Re-enable if Bun fixes util.inspect.
332+
test.skipIf(opts.runtime === "bun" || isBunNodeCompat)("inspect objects", async () => {
322333
const response = await fetch(url("/node-inspect"), {
323334
headers: { "x-foo": "1" },
324335
});

0 commit comments

Comments
 (0)