diff --git a/test/harness.ts b/test/harness.ts index 1aae38b75f..8ebfdf1a7c 100644 --- a/test/harness.ts +++ b/test/harness.ts @@ -8,6 +8,8 @@ import { heapStats } from "bun:jsc"; type Awaitable = T | Promise; +export const BREAKING_CHANGES_BUN_1_2 = false; + export const isMacOS = process.platform === "darwin"; export const isLinux = process.platform === "linux"; export const isPosix = isMacOS || isLinux; @@ -1044,4 +1046,26 @@ export function rejectUnauthorizedScope(value: boolean) { }; } -export const BREAKING_CHANGES_BUN_1_2 = false; +let networkInterfaces: any; + +function isIP(type: "IPv4" | "IPv6") { + if (!networkInterfaces) { + networkInterfaces = os.networkInterfaces(); + } + for (const networkInterface of Object.values(networkInterfaces)) { + for (const { family } of networkInterface as any[]) { + if (family === type) { + return true; + } + } + } + return false; +} + +export function isIPv6() { + return isIP("IPv6"); +} + +export function isIPv4() { + return isIP("IPv4"); +} diff --git a/test/js/bun/http/serve.test.ts b/test/js/bun/http/serve.test.ts index ea3fc3941a..6a9a66dc74 100644 --- a/test/js/bun/http/serve.test.ts +++ b/test/js/bun/http/serve.test.ts @@ -2,7 +2,7 @@ import { file, gc, Serve, serve, Server } from "bun"; import { afterEach, describe, it, expect, afterAll, mock } from "bun:test"; import { readFileSync, writeFileSync } from "fs"; import { join, resolve } from "path"; -import { bunExe, bunEnv, dumpStats } from "harness"; +import { bunExe, bunEnv, dumpStats, isPosix, isIPv6, tmpdirSync, isIPv4 } from "harness"; // import { renderToReadableStream } from "react-dom/server"; // import app_jsx from "./app.jsx"; import { spawn } from "child_process"; @@ -27,7 +27,6 @@ async function runTest({ port, ...serverOptions }: Serve, test: (server: Se while (!server) { try { server = serve({ ...serverOptions, port: 0 }); - console.log(`Server: ${server.url}`); break; } catch (e: any) { console.log("catch:", e); @@ -1275,11 +1274,12 @@ it("#5859 json", async () => { }); it("#5859 arrayBuffer", async () => { - await Bun.write("/tmp/bad", new Uint8Array([0xfd])); - expect(async () => await Bun.file("/tmp/bad").json()).toThrow(); + const tmp = join(tmpdirSync(), "bad"); + await Bun.write(tmp, new Uint8Array([0xfd])); + expect(async () => await Bun.file(tmp).json()).toThrow(); }); -it("server.requestIP (v4)", async () => { +it.if(isIPv4())("server.requestIP (v4)", async () => { using server = Bun.serve({ port: 0, fetch(req, server) { @@ -1296,7 +1296,7 @@ it("server.requestIP (v4)", async () => { }); }); -it("server.requestIP (v6)", async () => { +it.if(isIPv6())("server.requestIP (v6)", async () => { using server = Bun.serve({ port: 0, fetch(req, server) { @@ -1313,8 +1313,8 @@ it("server.requestIP (v6)", async () => { }); }); -it("server.requestIP (unix)", async () => { - const unix = "/tmp/bun-serve.sock"; +it.if(isPosix)("server.requestIP (unix)", async () => { + const unix = join(tmpdirSync(), "serve.sock"); using server = Bun.serve({ unix, fetch(req, server) { diff --git a/test/regression/issue/__snapshots__/03830.test.ts.snap b/test/regression/issue/__snapshots__/03830.test.ts.snap index 4fce0aab18..867c16c5ae 100644 --- a/test/regression/issue/__snapshots__/03830.test.ts.snap +++ b/test/regression/issue/__snapshots__/03830.test.ts.snap @@ -13,3 +13,10 @@ exports[`macros should not lead to seg faults under any given input 1`] = ` error: "Cannot convert argument type to JS" error in macro at [dir]/index.ts:2:1" `; + +exports[`macros should not lead to seg faults under any given input 1`] = ` +"2 | fn(\`©${''}\`); + ^ +error: "Cannot convert argument type to JS" error in macro + at [dir]/index.ts:2:1" +`;