
























@@ -29,9 +29,9 @@ const { ProxyAgent, EnvHttpProxyAgent, undiciFetch, proxyAgentSpy, envAgentSpy,
2929}
3030class EnvHttpProxyAgent {
3131static lastCreated: EnvHttpProxyAgent | undefined;
32-constructor() {
32+constructor(public readonly options?: Record<string, unknown>) {
3333EnvHttpProxyAgent.lastCreated = this;
34-envAgentSpy();
34+envAgentSpy(options);
3535}
3636}
3737@@ -159,7 +159,7 @@ describe("resolveProxyFetchFromEnv", () => {
159159HTTPS_PROXY: "http://proxy.test:8080",
160160});
161161expect(fetchFn).toBeDefined();
162-expect(envAgentSpy).toHaveBeenCalled();
162+expect(envAgentSpy).toHaveBeenCalledWith({ httpsProxy: "http://proxy.test:8080" });
163163164164await fetchFn!("https://api.example.com");
165165expect(undiciFetch).toHaveBeenCalledWith(
@@ -174,7 +174,10 @@ describe("resolveProxyFetchFromEnv", () => {
174174HTTP_PROXY: "http://fallback.test:3128",
175175});
176176expect(fetchFn).toBeDefined();
177-expect(envAgentSpy).toHaveBeenCalled();
177+expect(envAgentSpy).toHaveBeenCalledWith({
178+httpProxy: "http://fallback.test:3128",
179+httpsProxy: "http://fallback.test:3128",
180+});
178181});
179182180183it("returns proxy fetch when lowercase https_proxy is set", () => {
@@ -185,7 +188,7 @@ describe("resolveProxyFetchFromEnv", () => {
185188https_proxy: "http://lower.test:1080",
186189});
187190expect(fetchFn).toBeDefined();
188-expect(envAgentSpy).toHaveBeenCalled();
191+expect(envAgentSpy).toHaveBeenCalledWith({ httpsProxy: "http://lower.test:1080" });
189192});
190193191194it("returns proxy fetch when lowercase http_proxy is set", () => {
@@ -196,7 +199,25 @@ describe("resolveProxyFetchFromEnv", () => {
196199http_proxy: "http://lower-http.test:1080",
197200});
198201expect(fetchFn).toBeDefined();
199-expect(envAgentSpy).toHaveBeenCalled();
202+expect(envAgentSpy).toHaveBeenCalledWith({
203+httpProxy: "http://lower-http.test:1080",
204+httpsProxy: "http://lower-http.test:1080",
205+});
206+});
207+208+it("returns proxy fetch when ALL_PROXY is set", () => {
209+const fetchFn = resolveProxyFetchFromEnv({
210+HTTPS_PROXY: "",
211+HTTP_PROXY: "",
212+https_proxy: "",
213+http_proxy: "",
214+ALL_PROXY: "socks5://all-proxy.test:1080",
215+});
216+expect(fetchFn).toBeDefined();
217+expect(envAgentSpy).toHaveBeenCalledWith({
218+httpProxy: "socks5://all-proxy.test:1080",
219+httpsProxy: "socks5://all-proxy.test:1080",
220+});
200221});
201222202223it("returns undefined when EnvHttpProxyAgent constructor throws", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。