|
1 | 1 | import { connect as tlsConnect } from "node:tls"; |
| 2 | +import { mkdtemp, rm } from "node:fs/promises"; |
| 3 | +import { tmpdir } from "node:os"; |
| 4 | +import { join } from "node:path"; |
2 | 5 | import { describe, beforeAll, afterAll, expect, test } from "vitest"; |
3 | 6 | import { fetch, Agent } from "undici"; |
4 | 7 | import { addTests } from "./_tests.ts"; |
@@ -141,6 +144,30 @@ describe.skipIf(isDeno || isBun)(`${runtime} (absolute-form over TLS)`, () => { |
141 | 144 | }); |
142 | 145 | }); |
143 | 146 |
|
| 147 | +// `node.path` must win over the default `port` (https://github.com/h3js/srvx/issues/315) |
| 148 | +describe.skipIf(isDeno || isBun || process.platform === "win32")(`${runtime} (unix socket)`, () => { |
| 149 | + test("listens on node.path instead of the default port", async () => { |
| 150 | + const dir = await mkdtemp(join(tmpdir(), "srvx-")); |
| 151 | + const path = join(dir, "app.sock"); |
| 152 | + const server = serve({ |
| 153 | + node: { path }, |
| 154 | + fetch: () => new Response("ok"), |
| 155 | + }); |
| 156 | + try { |
| 157 | + await server.ready(); |
| 158 | + expect(server.url).toBe(path); |
| 159 | + expect(server.node!.server!.address()).toBe(path); |
| 160 | + const body = await fetch("http://localhost/", { |
| 161 | + dispatcher: new Agent({ connect: { socketPath: path } }), |
| 162 | + }).then((r) => r.text()); |
| 163 | + expect(body).toBe("ok"); |
| 164 | + } finally { |
| 165 | + await server.close(true); |
| 166 | + await rm(dir, { recursive: true, force: true }); |
| 167 | + } |
| 168 | + }); |
| 169 | +}); |
| 170 | + |
144 | 171 | function getHttpClient(h2?: boolean) { |
145 | 172 | if (!h2) { |
146 | 173 | return { |
|
0 commit comments