jest.mock("@fastify/http-proxy", () => { const mock = jest.fn(async () => {}); return { __esModule: true, default: mock }; }); import Fastify from "fastify"; import proxyPlugin from "../../src/dev-server/proxy"; const getHttpProxyMock = () => require("@fastify/http-proxy").default as jest.Mock; async function registerProxy(opts: Record) { const server = Fastify(); await server.register(proxyPlugin as any, opts); await server.ready(); return server; } describe("proxy plugin undici configuration", () => { beforeEach(() => jest.clearAllMocks()); test("passes undici: false when httpProxy is not set", async () => { await registerProxy({ proxy: [{ from: "/api", to: "http://upstream.example.com" }], silent: true, }); expect(getHttpProxyMock()).toHaveBeenCalledWith( expect.any(Object), expect.objectContaining({ undici: false }), expect.any(Function), ); }); test("passes undici: { proxy } when httpProxy is set", async () => { await registerProxy({ proxy: [{ from: "/api", to: "http://upstream.example.com" }], silent: true, httpProxy: "http://proxy.corp.example.com:8080", }); expect(getHttpProxyMock()).toHaveBeenCalledWith( expect.any(Object), expect.objectContaining({ undici: { proxy: "http://proxy.corp.example.com:8080" }, }), expect.any(Function), ); }); test("per-entry opts.undici overrides global httpProxy", async () => { await registerProxy({ proxy: [ { from: "/api", to: "http://upstream.example.com", opts: { undici: false }, }, ], silent: true, httpProxy: "http://proxy.corp.example.com:8080", }); expect(getHttpProxyMock()).toHaveBeenCalledWith( expect.any(Object), expect.objectContaining({ undici: false }), expect.any(Function), ); }); });