-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
55 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
const { fetch } = require("undici"); | ||
const { fetch, setGlobalDispatcher, ProxyAgent } = require("undici"); | ||
|
||
const proxyServer = | ||
process.env['https_proxy'] || process.env['HTTPS_PROXY']; | ||
if (proxyServer) { | ||
setGlobalDispatcher(new ProxyAgent(proxyServer)); | ||
} | ||
|
||
if (!Object.keys(global).includes("fetch")) { | ||
Object.defineProperty(global, "fetch", { value: fetch }); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { run } from "node:test"; | ||
import { resolve, dirname } from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
const files = ["with-proxy.mjs", "with-polyfill.mjs", "without-polyfill.mjs"].map( | ||
(testFile) => resolve(__dirname, testFile) | ||
); | ||
|
||
run({ files }).pipe(process.stdout); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
import "fetch-undici-polyfill"; | ||
import { test } from "node:test"; | ||
import assert from "node:assert"; | ||
import { getGlobalDispatcher, ProxyAgent } from "undici"; | ||
|
||
// Act | ||
await import("fetch-undici-polyfill"); | ||
|
||
// Assert | ||
test("fetch exists", () => { | ||
assert(typeof fetch !== "undefined"); | ||
}); | ||
|
||
test("proxy is not set", () => { | ||
assert(!(getGlobalDispatcher() instanceof ProxyAgent)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { test } from "node:test"; | ||
import assert from "node:assert"; | ||
import { getGlobalDispatcher, ProxyAgent } from "undici"; | ||
|
||
// Arrange | ||
process.env["HTTPS_PROXY"] = "https://foo.com"; | ||
|
||
// Act | ||
await import("fetch-undici-polyfill"); | ||
|
||
// Assert | ||
test("fetch exists", () => { | ||
assert(typeof fetch !== "undefined"); | ||
}); | ||
|
||
test("proxy is set", () => { | ||
assert(getGlobalDispatcher() instanceof ProxyAgent); | ||
}); |