From ce49779cbcd2fa410cf1ac6dd9a6c0f614328c02 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 10 Jul 2023 23:08:46 +0000 Subject: [PATCH 01/21] fix(deps): update octokit monorepo --- package-lock.json | 187 ++++++++++++++++++---------------------------- package.json | 10 +-- 2 files changed, 76 insertions(+), 121 deletions(-) diff --git a/package-lock.json b/package-lock.json index d0a3c00c..f46dd6a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,11 +9,11 @@ "version": "0.0.0-development", "license": "MIT", "dependencies": { - "@octokit/auth-action": "^3.0.0", - "@octokit/core": "^4.0.0", - "@octokit/plugin-paginate-rest": "^7.0.0", - "@octokit/plugin-rest-endpoint-methods": "^8.0.0", - "@octokit/types": "^10.0.0", + "@octokit/auth-action": "^4.0.0", + "@octokit/core": "^5.0.0", + "@octokit/plugin-paginate-rest": "^8.0.0", + "@octokit/plugin-rest-endpoint-methods": "^9.0.0", + "@octokit/types": "^11.0.0", "https-proxy-agent": "^7.0.0" }, "devDependencies": { @@ -1506,12 +1506,12 @@ "dev": true }, "node_modules/@octokit/auth-action": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@octokit/auth-action/-/auth-action-3.0.2.tgz", - "integrity": "sha512-QkRAlAFqELFdzddFjDA68IN26pJ2hoTLY2vNYsmX5vwcYIWiiQA1KDFIrqpdzZo4dpPJXM9E0drXyBpZhicGTA==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@octokit/auth-action/-/auth-action-4.0.0.tgz", + "integrity": "sha512-sMm9lWZdiX6e89YFaLrgE9EFs94k58BwIkvjOtozNWUqyTmsrnWFr/M5LolaRzZ7Kmb5FbhF9hi7FEeE274SoQ==", "dependencies": { "@octokit/auth-token": "^4.0.0", - "@octokit/types": "^10.0.0" + "@octokit/types": "^11.0.0" }, "engines": { "node": ">= 18" @@ -1526,78 +1526,46 @@ } }, "node_modules/@octokit/core": { - "version": "4.2.4", - "resolved": "https://registry.npmjs.org/@octokit/core/-/core-4.2.4.tgz", - "integrity": "sha512-rYKilwgzQ7/imScn3M9/pFfUf4I1AZEH3KhyJmtPdE2zfaXAn2mFfUy4FbKewzc2We5y/LlKLj36fWJLKC2SIQ==", - "dependencies": { - "@octokit/auth-token": "^3.0.0", - "@octokit/graphql": "^5.0.0", - "@octokit/request": "^6.0.0", - "@octokit/request-error": "^3.0.0", - "@octokit/types": "^9.0.0", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-5.0.0.tgz", + "integrity": "sha512-YbAtMWIrbZ9FCXbLwT9wWB8TyLjq9mxpKdgB3dUNxQcIVTf9hJ70gRPwAcqGZdY6WdJPZ0I7jLaaNDCiloGN2A==", + "dependencies": { + "@octokit/auth-token": "^4.0.0", + "@octokit/graphql": "^7.0.0", + "@octokit/request": "^8.0.2", + "@octokit/request-error": "^5.0.0", + "@octokit/types": "^11.0.0", "before-after-hook": "^2.2.0", "universal-user-agent": "^6.0.0" }, "engines": { - "node": ">= 14" - } - }, - "node_modules/@octokit/core/node_modules/@octokit/auth-token": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-3.0.4.tgz", - "integrity": "sha512-TWFX7cZF2LXoCvdmJWY7XVPi74aSY0+FfBZNSXEXFkMpjcqsQwDSYVv5FhRFaI0V1ECnwbz4j59T/G+rXNWaIQ==", - "engines": { - "node": ">= 14" - } - }, - "node_modules/@octokit/core/node_modules/@octokit/types": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.3.2.tgz", - "integrity": "sha512-D4iHGTdAnEEVsB8fl95m1hiz7D5YiRdQ9b/OEb3BYRVwbLsGHcRVPz+u+BgRLNk0Q0/4iZCBqDN96j2XNxfXrA==", - "dependencies": { - "@octokit/openapi-types": "^18.0.0" + "node": ">= 18" } }, "node_modules/@octokit/endpoint": { - "version": "7.0.6", - "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-7.0.6.tgz", - "integrity": "sha512-5L4fseVRUsDFGR00tMWD/Trdeeihn999rTMGRMC1G/Ldi1uWlWJzI98H4Iak5DB/RVvQuyMYKqSK/R6mbSOQyg==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-9.0.0.tgz", + "integrity": "sha512-szrQhiqJ88gghWY2Htt8MqUDO6++E/EIXqJ2ZEp5ma3uGS46o7LZAzSLt49myB7rT+Hfw5Y6gO3LmOxGzHijAQ==", "dependencies": { - "@octokit/types": "^9.0.0", + "@octokit/types": "^11.0.0", "is-plain-object": "^5.0.0", "universal-user-agent": "^6.0.0" }, "engines": { - "node": ">= 14" - } - }, - "node_modules/@octokit/endpoint/node_modules/@octokit/types": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.3.2.tgz", - "integrity": "sha512-D4iHGTdAnEEVsB8fl95m1hiz7D5YiRdQ9b/OEb3BYRVwbLsGHcRVPz+u+BgRLNk0Q0/4iZCBqDN96j2XNxfXrA==", - "dependencies": { - "@octokit/openapi-types": "^18.0.0" + "node": ">= 18" } }, "node_modules/@octokit/graphql": { - "version": "5.0.6", - "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-5.0.6.tgz", - "integrity": "sha512-Fxyxdy/JH0MnIB5h+UQ3yCoh1FG4kWXfFKkpWqjZHw/p+Kc8Y44Hu/kCgNBT6nU1shNumEchmW/sUO1JuQnPcw==", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-7.0.1.tgz", + "integrity": "sha512-T5S3oZ1JOE58gom6MIcrgwZXzTaxRnxBso58xhozxHpOqSTgDS6YNeEUvZ/kRvXgPrRz/KHnZhtb7jUMRi9E6w==", "dependencies": { - "@octokit/request": "^6.0.0", - "@octokit/types": "^9.0.0", + "@octokit/request": "^8.0.1", + "@octokit/types": "^11.0.0", "universal-user-agent": "^6.0.0" }, "engines": { - "node": ">= 14" - } - }, - "node_modules/@octokit/graphql/node_modules/@octokit/types": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.3.2.tgz", - "integrity": "sha512-D4iHGTdAnEEVsB8fl95m1hiz7D5YiRdQ9b/OEb3BYRVwbLsGHcRVPz+u+BgRLNk0Q0/4iZCBqDN96j2XNxfXrA==", - "dependencies": { - "@octokit/openapi-types": "^18.0.0" + "node": ">= 18" } }, "node_modules/@octokit/openapi-types": { @@ -1606,96 +1574,71 @@ "integrity": "sha512-V8GImKs3TeQRxRtXFpG2wl19V7444NIOTDF24AWuIbmNaNYOQMWRbjcGDXV5B+0n887fgDcuMNOmlul+k+oJtw==" }, "node_modules/@octokit/plugin-paginate-rest": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-7.1.2.tgz", - "integrity": "sha512-Jx8KuKqEAVRsK6fMzZKv3h6UH9/NRDHsDRtUAROqqmZlCptM///Uef7A1ViZ/cbDplekz7VbDWdFLAZ/mpuDww==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-8.0.0.tgz", + "integrity": "sha512-2xZ+baZWUg+qudVXnnvXz7qfrTmDeYPCzangBVq/1gXxii/OiS//4shJp9dnCCvj1x+JAm9ji1Egwm1BA47lPQ==", "dependencies": { - "@octokit/tsconfig": "^2.0.0", - "@octokit/types": "^9.3.2" + "@octokit/types": "^11.0.0" }, "engines": { "node": ">= 18" }, "peerDependencies": { - "@octokit/core": ">=4" - } - }, - "node_modules/@octokit/plugin-paginate-rest/node_modules/@octokit/types": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.3.2.tgz", - "integrity": "sha512-D4iHGTdAnEEVsB8fl95m1hiz7D5YiRdQ9b/OEb3BYRVwbLsGHcRVPz+u+BgRLNk0Q0/4iZCBqDN96j2XNxfXrA==", - "dependencies": { - "@octokit/openapi-types": "^18.0.0" + "@octokit/core": ">=5" } }, "node_modules/@octokit/plugin-rest-endpoint-methods": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-8.0.0.tgz", - "integrity": "sha512-GtA8B7zkdxJv2OBVUtUeynu/OkWo272w2IpWC+QCQiUhgrRZ9Zrz2NgAiqYkVhlITGD3PcWYEjy9JR1HrzYtQA==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-9.0.0.tgz", + "integrity": "sha512-KquMF/VB1IkKNiVnzJKspY5mFgGyLd7HzdJfVEGTJFzqu9BRFNWt+nwTCMuUiWc72gLQhRWYubTwOkQj+w/1PA==", "dependencies": { - "@octokit/types": "^10.0.0" + "@octokit/types": "^11.0.0" }, "engines": { "node": ">= 18" }, "peerDependencies": { - "@octokit/core": ">=3" + "@octokit/core": ">=5" } }, "node_modules/@octokit/request": { - "version": "6.2.8", - "resolved": "https://registry.npmjs.org/@octokit/request/-/request-6.2.8.tgz", - "integrity": "sha512-ow4+pkVQ+6XVVsekSYBzJC0VTVvh/FCTUUgTsboGq+DTeWdyIFV8WSCdo0RIxk6wSkBTHqIK1mYuY7nOBXOchw==", + "version": "8.0.4", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-8.0.4.tgz", + "integrity": "sha512-YZ1XeDRil4ejHKoBP8BgROgP4auOH5A9lLZH96l39GKKEmsKOccQxKP5M7m+Punblg1bFw8LrdeKIDwIzQ8afA==", "dependencies": { - "@octokit/endpoint": "^7.0.0", - "@octokit/request-error": "^3.0.0", - "@octokit/types": "^9.0.0", + "@octokit/endpoint": "^9.0.0", + "@octokit/request-error": "^5.0.0", + "@octokit/types": "^11.0.0", "is-plain-object": "^5.0.0", - "node-fetch": "^2.6.7", "universal-user-agent": "^6.0.0" }, "engines": { - "node": ">= 14" + "node": ">= 18" } }, "node_modules/@octokit/request-error": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-3.0.3.tgz", - "integrity": "sha512-crqw3V5Iy2uOU5Np+8M/YexTlT8zxCfI+qu+LxUB7SZpje4Qmx3mub5DfEKSO8Ylyk0aogi6TYdf6kxzh2BguQ==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-5.0.0.tgz", + "integrity": "sha512-1ue0DH0Lif5iEqT52+Rf/hf0RmGO9NWFjrzmrkArpG9trFfDM/efx00BJHdLGuro4BR/gECxCU2Twf5OKrRFsQ==", "dependencies": { - "@octokit/types": "^9.0.0", + "@octokit/types": "^11.0.0", "deprecation": "^2.0.0", "once": "^1.4.0" }, "engines": { - "node": ">= 14" - } - }, - "node_modules/@octokit/request-error/node_modules/@octokit/types": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.3.2.tgz", - "integrity": "sha512-D4iHGTdAnEEVsB8fl95m1hiz7D5YiRdQ9b/OEb3BYRVwbLsGHcRVPz+u+BgRLNk0Q0/4iZCBqDN96j2XNxfXrA==", - "dependencies": { - "@octokit/openapi-types": "^18.0.0" - } - }, - "node_modules/@octokit/request/node_modules/@octokit/types": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.3.2.tgz", - "integrity": "sha512-D4iHGTdAnEEVsB8fl95m1hiz7D5YiRdQ9b/OEb3BYRVwbLsGHcRVPz+u+BgRLNk0Q0/4iZCBqDN96j2XNxfXrA==", - "dependencies": { - "@octokit/openapi-types": "^18.0.0" + "node": ">= 18" } }, "node_modules/@octokit/tsconfig": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@octokit/tsconfig/-/tsconfig-2.0.0.tgz", - "integrity": "sha512-tWnrai3quGt8+gRN2edzo9fmraWekeryXPeXDomMw2oFSpu/lH3VSWGn/q4V+rwjTRMeeXk/ci623/01Zet4VQ==" + "integrity": "sha512-tWnrai3quGt8+gRN2edzo9fmraWekeryXPeXDomMw2oFSpu/lH3VSWGn/q4V+rwjTRMeeXk/ci623/01Zet4VQ==", + "dev": true }, "node_modules/@octokit/types": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-10.0.0.tgz", - "integrity": "sha512-Vm8IddVmhCgU1fxC1eyinpwqzXPEYu0NrYzD3YZjlGjyftdLBTeqNblRC0jmJmgxbJIsQlyogVeGnrNaaMVzIg==", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-11.1.0.tgz", + "integrity": "sha512-Fz0+7GyLm/bHt8fwEqgvRBWwIV1S6wRRyq+V6exRKLVWaKGsuy6H9QFYeBVDV7rK6fO3XwHgQOPxv+cLj2zpXQ==", "dependencies": { "@octokit/openapi-types": "^18.0.0" } @@ -3955,6 +3898,9 @@ "version": "2.6.11", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz", "integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==", + "dev": true, + "optional": true, + "peer": true, "dependencies": { "whatwg-url": "^5.0.0" }, @@ -4701,7 +4647,10 @@ "node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "dev": true, + "optional": true, + "peer": true }, "node_modules/ts-jest": { "version": "29.1.0", @@ -4874,12 +4823,18 @@ "node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "dev": true, + "optional": true, + "peer": true }, "node_modules/whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dev": true, + "optional": true, + "peer": true, "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" diff --git a/package.json b/package.json index 982fa582..d9c7e2d9 100644 --- a/package.json +++ b/package.json @@ -24,11 +24,11 @@ "author": "Gregor Martynus (https://twitter.com/gr2m)", "license": "MIT", "dependencies": { - "@octokit/auth-action": "^3.0.0", - "@octokit/core": "^4.0.0", - "@octokit/plugin-paginate-rest": "^7.0.0", - "@octokit/plugin-rest-endpoint-methods": "^8.0.0", - "@octokit/types": "^10.0.0", + "@octokit/auth-action": "^4.0.0", + "@octokit/core": "^5.0.0", + "@octokit/plugin-paginate-rest": "^8.0.0", + "@octokit/plugin-rest-endpoint-methods": "^9.0.0", + "@octokit/types": "^11.0.0", "https-proxy-agent": "^7.0.0" }, "devDependencies": { From 9a984f4099083da78fd3ae5bad2e10c457bc9588 Mon Sep 17 00:00:00 2001 From: Nick Floyd <139819+nickfloyd@users.noreply.github.com> Date: Tue, 11 Jul 2023 21:53:25 +0000 Subject: [PATCH 02/21] todo fix proxy test by replacing http agent/fetch mock with custom fetch --- test/smoke.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/smoke.test.ts b/test/smoke.test.ts index 69ab5bdb..b374348e 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -178,7 +178,7 @@ describe("Smoke test", () => { expect(data).toStrictEqual({ ok: true }); }); - it.each(["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"])( + it.skip.each(["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"])( "Uses https-proxy-agent with %s env var", async (https_proxy_env) => { process.env.GITHUB_TOKEN = "secret123"; @@ -219,7 +219,7 @@ describe("Smoke test", () => { }, ); - it("Uses the explicitly provided request.agent value if it's provided", async () => { + it.skip("Uses the explicitly provided request.agent value if it's provided", async () => { process.env.GITHUB_TOKEN = "secret123"; process.env.GITHUB_ACTION = "test"; process.env.HTTPS_PROXY = "https://127.0.0.1"; From 8d6afaac5d27e86e31c98e70b92167cd6a697dfc Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Tue, 11 Jul 2023 18:20:15 -0400 Subject: [PATCH 03/21] build: switch to `@gr2m/fetch-mock` --- package-lock.json | 9 +++++---- package.json | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index f46dd6a1..a1baafb9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "@types/jest": "^29.0.0", "@types/node": "^18.0.0", "esbuild": "^0.18.0", - "fetch-mock": "^9.0.0", + "fetch-mock": "npm:@gr2m/fetch-mock@9.11.0-pull-request-644.1", "glob": "^10.2.6", "jest": "^29.0.0", "prettier": "3.0.0", @@ -2509,9 +2509,10 @@ } }, "node_modules/fetch-mock": { - "version": "9.11.0", - "resolved": "https://registry.npmjs.org/fetch-mock/-/fetch-mock-9.11.0.tgz", - "integrity": "sha512-PG1XUv+x7iag5p/iNHD4/jdpxL9FtVSqRMUQhPab4hVDt80T1MH5ehzVrL2IdXO9Q2iBggArFvPqjUbHFuI58Q==", + "name": "@gr2m/fetch-mock", + "version": "9.11.0-pull-request-644.1", + "resolved": "https://registry.npmjs.org/@gr2m/fetch-mock/-/fetch-mock-9.11.0-pull-request-644.1.tgz", + "integrity": "sha512-gTp6RCHzlOXS1qRb0APfuyz48Lw/JFPa4uiar+kEgL1STsDwth75HJZ4x30tBlXMJXV8XDTDzJ2Hz9w3RWiHJA==", "dev": true, "dependencies": { "@babel/core": "^7.0.0", diff --git a/package.json b/package.json index d9c7e2d9..54ecab51 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@types/jest": "^29.0.0", "@types/node": "^18.0.0", "esbuild": "^0.18.0", - "fetch-mock": "^9.0.0", + "fetch-mock": "npm:@gr2m/fetch-mock@9.11.0-pull-request-644.1", "glob": "^10.2.6", "jest": "^29.0.0", "prettier": "3.0.0", From b89fa45192465fe824dde76a32c06440d64e15a2 Mon Sep 17 00:00:00 2001 From: Nick Floyd <139819+nickfloyd@users.noreply.github.com> Date: Thu, 13 Jul 2023 15:29:16 +0000 Subject: [PATCH 04/21] updates the plugin to use a custom fetch as suggested --- package-lock.json | 36 +++++++++++++++++++++++++++++++++++- package.json | 3 ++- src/index.ts | 15 +++++++++++---- test/smoke.test.ts | 14 ++------------ 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index f46dd6a1..dbbbfe9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,8 @@ "prettier": "3.0.0", "semantic-release-plugin-update-version-in-files": "^1.0.0", "ts-jest": "^29.0.0", - "typescript": "^5.0.0" + "typescript": "^5.0.0", + "undici": "^5.0.0" }, "engines": { "node": ">= 18" @@ -2051,6 +2052,18 @@ "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", "dev": true }, + "node_modules/busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "dev": true, + "dependencies": { + "streamsearch": "^1.1.0" + }, + "engines": { + "node": ">=10.16.0" + } + }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -4441,6 +4454,15 @@ "node": ">=8" } }, + "node_modules/streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", + "dev": true, + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/string-length": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.2.tgz", @@ -4762,6 +4784,18 @@ "node": ">=14.17" } }, + "node_modules/undici": { + "version": "5.22.1", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.22.1.tgz", + "integrity": "sha512-Ji2IJhFXZY0x/0tVBXeQwgPlLWw13GVzpsWPQ3rV50IFMMof2I55PZZxtm4P6iNq+L5znYN9nSTAq0ZyE6lSJw==", + "dev": true, + "dependencies": { + "busboy": "^1.6.0" + }, + "engines": { + "node": ">=14.0" + } + }, "node_modules/universal-user-agent": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.0.tgz", diff --git a/package.json b/package.json index d9c7e2d9..3ba9f3be 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,8 @@ "prettier": "3.0.0", "semantic-release-plugin-update-version-in-files": "^1.0.0", "ts-jest": "^29.0.0", - "typescript": "^5.0.0" + "typescript": "^5.0.0", + "undici": "^5.0.0" }, "jest": { "transform": { diff --git a/src/index.ts b/src/index.ts index 09983983..2064c4da 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ export type { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-meth import { VERSION } from "./version"; import type { OctokitOptions } from "@octokit/core/dist-types/types"; -import { HttpsProxyAgent } from "https-proxy-agent"; +import { fetch as undiciFetch, ProxyAgent } from "undici"; const DEFAULTS = { authStrategy: createActionAuth, @@ -17,17 +17,24 @@ const DEFAULTS = { function getProxyAgent() { const httpProxy = process.env["HTTP_PROXY"] || process.env["http_proxy"]; if (httpProxy) { - return new HttpsProxyAgent(httpProxy); + return new ProxyAgent(httpProxy); } const httpsProxy = process.env["HTTPS_PROXY"] || process.env["https_proxy"]; if (httpsProxy) { - return new HttpsProxyAgent(httpsProxy); + return new ProxyAgent(httpsProxy); } return undefined; } +const customFetch = async function (url: string, opts: any) { + return await undiciFetch(url, { + dispatcher: getProxyAgent(), + ...opts, + }); +}; + export const Octokit = Core.plugin( paginateRest, legacyRestEndpointMethods, @@ -36,7 +43,7 @@ export const Octokit = Core.plugin( ...DEFAULTS, ...options, request: { - agent: getProxyAgent(), + fetch: customFetch, ...options.request, }, }; diff --git a/test/smoke.test.ts b/test/smoke.test.ts index b374348e..5eb181e8 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -1,7 +1,4 @@ import fetchMock from "fetch-mock"; -import { RequestOptions } from "https"; -import { HttpsProxyAgent } from "https-proxy-agent"; - import { Octokit } from "../src"; jest.mock("https-proxy-agent"); @@ -178,7 +175,7 @@ describe("Smoke test", () => { expect(data).toStrictEqual({ ok: true }); }); - it.skip.each(["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"])( + it.each(["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"])( "Uses https-proxy-agent with %s env var", async (https_proxy_env) => { process.env.GITHUB_TOKEN = "secret123"; @@ -209,17 +206,14 @@ describe("Smoke test", () => { title: "My test issue", }); - expect(HttpsProxyAgent).toHaveBeenCalled(); - const [call] = fetchSandbox.calls(); expect(call[0]).toEqual( "https://api.github.com/repos/octocat/hello-world/issues", ); - expect((call[1] as RequestOptions).agent).toBeInstanceOf(HttpsProxyAgent); }, ); - it.skip("Uses the explicitly provided request.agent value if it's provided", async () => { + it("Uses the explicitly provided request.agent value if it's provided", async () => { process.env.GITHUB_TOKEN = "secret123"; process.env.GITHUB_ACTION = "test"; process.env.HTTPS_PROXY = "https://127.0.0.1"; @@ -240,7 +234,6 @@ describe("Smoke test", () => { auth: "secret123", request: { fetch: mock, - agent: null, }, }); await octokit.request("POST /repos/{owner}/{repo}/issues", { @@ -249,12 +242,9 @@ describe("Smoke test", () => { title: "My test issue", }); - expect(HttpsProxyAgent).toHaveBeenCalled(); - const [call] = fetchSandbox.calls(); expect(call[0]).toEqual( "https://api.github.com/repos/octocat/hello-world/issues", ); - expect((call[1] as RequestOptions).agent).toBeNull(); }); }); From 45937ec2268f2329d3b3484925f63f0ada05b9fc Mon Sep 17 00:00:00 2001 From: Nick Floyd <139819+nickfloyd@users.noreply.github.com> Date: Thu, 13 Jul 2023 15:52:16 +0000 Subject: [PATCH 05/21] moves undici to deps and removes https-proxy-agent --- package-lock.json | 35 +++++------------------------------ package.json | 5 ++--- test/smoke.test.ts | 4 +--- 3 files changed, 8 insertions(+), 36 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8b8dcfb9..59e55380 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@octokit/plugin-paginate-rest": "^8.0.0", "@octokit/plugin-rest-endpoint-methods": "^9.0.0", "@octokit/types": "^11.0.0", - "https-proxy-agent": "^7.0.0" + "undici": "^5.0.0" }, "devDependencies": { "@octokit/tsconfig": "^2.0.0", @@ -27,8 +27,7 @@ "prettier": "3.0.0", "semantic-release-plugin-update-version-in-files": "^1.0.0", "ts-jest": "^29.0.0", - "typescript": "^5.0.0", - "undici": "^5.0.0" + "typescript": "^5.0.0" }, "engines": { "node": ">= 18" @@ -1795,17 +1794,6 @@ "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==", "dev": true }, - "node_modules/agent-base": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.0.tgz", - "integrity": "sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==", - "dependencies": { - "debug": "^4.3.4" - }, - "engines": { - "node": ">= 14" - } - }, "node_modules/ansi-escapes": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", @@ -2056,7 +2044,6 @@ "version": "1.6.0", "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", - "dev": true, "dependencies": { "streamsearch": "^1.1.0" }, @@ -2295,6 +2282,7 @@ "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, "dependencies": { "ms": "2.1.2" }, @@ -2757,18 +2745,6 @@ "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "dev": true }, - "node_modules/https-proxy-agent": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.0.tgz", - "integrity": "sha512-0euwPCRyAPSgGdzD1IVN9nJYHtBhJwb6XPfbpQcYbPCwrBidX6GzxmchnaF4sfF/jPb74Ojx5g4yTg3sixlyPw==", - "dependencies": { - "agent-base": "^7.0.2", - "debug": "4" - }, - "engines": { - "node": ">= 14" - } - }, "node_modules/human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -3900,7 +3876,8 @@ "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true }, "node_modules/natural-compare": { "version": "1.4.0", @@ -4459,7 +4436,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", - "dev": true, "engines": { "node": ">=10.0.0" } @@ -4789,7 +4765,6 @@ "version": "5.22.1", "resolved": "https://registry.npmjs.org/undici/-/undici-5.22.1.tgz", "integrity": "sha512-Ji2IJhFXZY0x/0tVBXeQwgPlLWw13GVzpsWPQ3rV50IFMMof2I55PZZxtm4P6iNq+L5znYN9nSTAq0ZyE6lSJw==", - "dev": true, "dependencies": { "busboy": "^1.6.0" }, diff --git a/package.json b/package.json index 06318d9d..ba8c72ff 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@octokit/plugin-paginate-rest": "^8.0.0", "@octokit/plugin-rest-endpoint-methods": "^9.0.0", "@octokit/types": "^11.0.0", - "https-proxy-agent": "^7.0.0" + "undici": "^5.0.0" }, "devDependencies": { "@octokit/tsconfig": "^2.0.0", @@ -42,8 +42,7 @@ "prettier": "3.0.0", "semantic-release-plugin-update-version-in-files": "^1.0.0", "ts-jest": "^29.0.0", - "typescript": "^5.0.0", - "undici": "^5.0.0" + "typescript": "^5.0.0" }, "jest": { "transform": { diff --git a/test/smoke.test.ts b/test/smoke.test.ts index 5eb181e8..d1c98d57 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -1,8 +1,6 @@ import fetchMock from "fetch-mock"; import { Octokit } from "../src"; -jest.mock("https-proxy-agent"); - describe("Smoke test", () => { beforeEach(() => { delete process.env.GITHUB_TOKEN; @@ -176,7 +174,7 @@ describe("Smoke test", () => { }); it.each(["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"])( - "Uses https-proxy-agent with %s env var", + "Uses ProxyAgent with %s env var", async (https_proxy_env) => { process.env.GITHUB_TOKEN = "secret123"; process.env.GITHUB_ACTION = "test"; From a68deda49abd50bfc334341534a8aaf703044696 Mon Sep 17 00:00:00 2001 From: Nick Floyd <139819+nickfloyd@users.noreply.github.com> Date: Thu, 13 Jul 2023 15:58:12 +0000 Subject: [PATCH 06/21] Serialization issue as seen in core --- test/smoke.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/smoke.test.ts b/test/smoke.test.ts index d1c98d57..1e4f8a71 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -170,7 +170,8 @@ describe("Smoke test", () => { title: "My test issue", }); - expect(data).toStrictEqual({ ok: true }); + // TODO: need a follow up issue to clean this up + expect(JSON.stringify(data)).toStrictEqual(JSON.stringify({ ok: true })); }); it.each(["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"])( From 9647263d2499d3e33ed4b0e20f54d1627b101a9d Mon Sep 17 00:00:00 2001 From: Nick Floyd <139819+nickfloyd@users.noreply.github.com> Date: Fri, 14 Jul 2023 20:17:18 +0000 Subject: [PATCH 07/21] adds local server for the tests to call --- test/smoke.test.ts | 52 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/test/smoke.test.ts b/test/smoke.test.ts index 1e4f8a71..67bbb0c1 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -1,7 +1,29 @@ import fetchMock from "fetch-mock"; +import { createServer } from "https"; import { Octokit } from "../src"; describe("Smoke test", () => { + let server: any; + + beforeAll((done) => { + server = createServer( + { + requestCert: false, + rejectUnauthorized: false, + }, + (request: any, response: any) => { + expect(request.method).toEqual("GET"); + expect(request.url).toEqual("/"); + + response.writeHead(200); + response.write("ok"); + response.end(); + }, + ); + + server.listen(0, done); + }); + beforeEach(() => { delete process.env.GITHUB_TOKEN; delete process.env.INPUT_GITHUB_TOKEN; @@ -9,6 +31,8 @@ describe("Smoke test", () => { delete process.env.GITHUB_API_URL; delete process.env.HTTPS_PROXY; delete process.env.https_proxy; + delete process.env.HTTP_PROXY; + delete process.env.http_proxy; }); it("happy path with GITHUB_TOKEN", () => { @@ -174,7 +198,7 @@ describe("Smoke test", () => { expect(JSON.stringify(data)).toStrictEqual(JSON.stringify({ ok: true })); }); - it.each(["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"])( + it.skip.each(["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"])( "Uses ProxyAgent with %s env var", async (https_proxy_env) => { process.env.GITHUB_TOKEN = "secret123"; @@ -212,7 +236,7 @@ describe("Smoke test", () => { }, ); - it("Uses the explicitly provided request.agent value if it's provided", async () => { + it.skip("Uses the explicitly provided request.agent value if it's provided", async () => { process.env.GITHUB_TOKEN = "secret123"; process.env.GITHUB_ACTION = "test"; process.env.HTTPS_PROXY = "https://127.0.0.1"; @@ -246,4 +270,28 @@ describe("Smoke test", () => { "https://api.github.com/repos/octocat/hello-world/issues", ); }); + + // WIP + it("test HTTPS_PROXY", async () => { + process.env.GITHUB_TOKEN = "secret123"; + process.env.GITHUB_ACTION = "test"; + process.env.HTTPS_PROXY = "https://localhost"; + + expect(Octokit).toBeInstanceOf(Function); + const octokit = new Octokit({ + auth: "secret123", + baseUrl: "https://localhost:" + server.address().port, + }); + + // await octokit.request("GET /", { + // username: "octocat", + // }); + + // expect(Agent).toHaveBeenCalled(); + expect(octokit).toHaveProperty("request"); + }); + + afterAll((done) => { + server.close(done); + }); }); From e5de68387f4cdb3a08b68a8159b28f0157e66f5c Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Mon, 17 Jul 2023 13:19:04 -0700 Subject: [PATCH 08/21] Undo skip for array of smoke tests --- test/smoke.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/smoke.test.ts b/test/smoke.test.ts index 67bbb0c1..c6ba64a5 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -198,7 +198,7 @@ describe("Smoke test", () => { expect(JSON.stringify(data)).toStrictEqual(JSON.stringify({ ok: true })); }); - it.skip.each(["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"])( + it.each(["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"])( "Uses ProxyAgent with %s env var", async (https_proxy_env) => { process.env.GITHUB_TOKEN = "secret123"; From f0cfdb9c16dafd178671a53df9e64b4e910e2e37 Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Mon, 17 Jul 2023 13:22:17 -0700 Subject: [PATCH 09/21] Undo skip on another test --- test/smoke.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/smoke.test.ts b/test/smoke.test.ts index c6ba64a5..e5331bc1 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -236,7 +236,7 @@ describe("Smoke test", () => { }, ); - it.skip("Uses the explicitly provided request.agent value if it's provided", async () => { + it("Uses the explicitly provided request.agent value if it's provided", async () => { process.env.GITHUB_TOKEN = "secret123"; process.env.GITHUB_ACTION = "test"; process.env.HTTPS_PROXY = "https://127.0.0.1"; From a23ec0d32c55dede3338b5ce54cd85aed78a1fa0 Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Mon, 17 Jul 2023 15:02:14 -0700 Subject: [PATCH 10/21] WIP checkpoint with all lines covered but one test broken --- src/index.ts | 6 +- test/smoke.test.ts | 201 ++++++++++++++++++++++++++++++++------------- 2 files changed, 148 insertions(+), 59 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2064c4da..5a736fcc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,7 +14,7 @@ const DEFAULTS = { userAgent: `octokit-action.js/${VERSION}`, }; -function getProxyAgent() { +export function getProxyAgent() { const httpProxy = process.env["HTTP_PROXY"] || process.env["http_proxy"]; if (httpProxy) { return new ProxyAgent(httpProxy); @@ -28,7 +28,9 @@ function getProxyAgent() { return undefined; } -const customFetch = async function (url: string, opts: any) { +export const customFetch = async function (url: string, opts: any) { + console.log("inside customFetch"); + console.log(opts); return await undiciFetch(url, { dispatcher: getProxyAgent(), ...opts, diff --git a/test/smoke.test.ts b/test/smoke.test.ts index e5331bc1..1384977d 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -1,6 +1,16 @@ import fetchMock from "fetch-mock"; import { createServer } from "https"; import { Octokit } from "../src"; +import * as OctokitModule from "../src"; +import { ProxyAgent /*fetch as undiciFetch*/ } from "undici"; + +jest.mock("undici", () => { + return { + fetch: jest.fn(), + ProxyAgent: jest.requireActual("undici").ProxyAgent, + }; +}); +const undici = jest.requireMock("undici"); describe("Smoke test", () => { let server: any; @@ -35,6 +45,118 @@ describe("Smoke test", () => { delete process.env.http_proxy; }); + afterAll((done) => { + server.close(done); + jest.unmock("undici"); + }); + + it("should return a ProxyAgent for the httpProxy environment variable", () => { + process.env.HTTP_PROXY = "http://example.com"; + const agent = OctokitModule.getProxyAgent(); + expect(agent).toBeInstanceOf(ProxyAgent); + }); + + it("should return a ProxyAgent for the httpsProxy environment variable", () => { + process.env.HTTPS_PROXY = "https://example.com"; + const agent = OctokitModule.getProxyAgent(); + expect(agent).toBeInstanceOf(ProxyAgent); + }); + + it("should return undefined if no proxy environment variables are set", () => { + const agent = OctokitModule.getProxyAgent(); + expect(agent).toBeUndefined(); + }); + + it("should call undiciFetch with the correct dispatcher", async () => { + process.env.HTTPS_PROXY = "https://example.com"; + const mockAgent = new ProxyAgent("https://example.com"); + // (OctokitModule.getProxyAgent as jest.Mock).mockReturnValueOnce(mockAgent); + + // Use jest.spyOn to create a mock + const spy = jest.spyOn(OctokitModule, "getProxyAgent"); + spy.mockReturnValueOnce(mockAgent); + + // Mock undici.fetch to set the 'dispatcher' option manually + let dispatcher: any; + (undici.fetch as jest.Mock).mockImplementation( + (_url: string, options: any) => { + console.log("Inside mock undici.fetch"); // add this log + console.log(options); // log the options here + + dispatcher = options.dispatcher; + + // Simulate a real fetch call + // This is your original mock implementation + return Promise.resolve(new Response()); + }, + ); + + // Add logging or assertion to check return value of getProxyAgent + console.log(OctokitModule.getProxyAgent()); + // Or + // expect(OctokitModule.getProxyAgent()).toBe(mockAgent); + + await OctokitModule.customFetch("http://api.github.com", {}); + + // Assert against the mocked 'dispatcher' value + expect(dispatcher).toBe(mockAgent); + // expect(dispatcher.uri).toBe("https://example.com"); + spy.mockRestore(); + }); + + // it("should call undiciFetch with the correct dispatcher", async () => { + // const mockAgent = new ProxyAgent("https://example.com"); + // (OctokitModule.getProxyAgent as jest.Mock).mockReturnValueOnce(mockAgent); + // // jest.spyOn(OctokitModule, "getProxyAgent").mockReturnValueOnce(mockAgent); + // // OctokitModule.getProxyAgent = jest.fn().mockReturnValueOnce(mockAgent) + + // await OctokitModule.customFetch("http://api.github.com", {}); + + // expect(undici.fetch).toHaveBeenCalledWith( + // "http://api.github.com", + // expect.objectContaining({ + // dispatcher: mockAgent, + // }), + // ); + // }); + + it("Uses the explicitly provided request.agent value if it's provided", async () => { + process.env.GITHUB_TOKEN = "secret123"; + process.env.GITHUB_ACTION = "test"; + process.env.HTTPS_PROXY = "https://127.0.0.1"; + + const fetchSandbox = fetchMock.sandbox(); + const mock = fetchSandbox.post( + "path:/repos/octocat/hello-world/issues", + { id: 1 }, + { + body: { + title: "My test issue", + }, + }, + ); + + expect(Octokit).toBeInstanceOf(Function); + const octokit = new Octokit({ + auth: "secret123", + request: { + fetch: mock, + }, + }); + await octokit.request("POST /repos/{owner}/{repo}/issues", { + owner: "octocat", + repo: "hello-world", + title: "My test issue", + }); + + const [call] = fetchSandbox.calls(); + expect(call[0]).toEqual( + "https://api.github.com/repos/octocat/hello-world/issues", + ); + + fetchMock.restore(); + }); + it("happy path with GITHUB_TOKEN", () => { process.env.GITHUB_TOKEN = "secret123"; process.env.GITHUB_ACTION = "test"; @@ -236,62 +358,27 @@ describe("Smoke test", () => { }, ); - it("Uses the explicitly provided request.agent value if it's provided", async () => { - process.env.GITHUB_TOKEN = "secret123"; - process.env.GITHUB_ACTION = "test"; - process.env.HTTPS_PROXY = "https://127.0.0.1"; - - const fetchSandbox = fetchMock.sandbox(); - const mock = fetchSandbox.post( - "path:/repos/octocat/hello-world/issues", - { id: 1 }, - { - body: { - title: "My test issue", - }, - }, - ); - - expect(Octokit).toBeInstanceOf(Function); - const octokit = new Octokit({ - auth: "secret123", - request: { - fetch: mock, - }, - }); - await octokit.request("POST /repos/{owner}/{repo}/issues", { - owner: "octocat", - repo: "hello-world", - title: "My test issue", - }); - - const [call] = fetchSandbox.calls(); - expect(call[0]).toEqual( - "https://api.github.com/repos/octocat/hello-world/issues", - ); - }); - // WIP - it("test HTTPS_PROXY", async () => { - process.env.GITHUB_TOKEN = "secret123"; - process.env.GITHUB_ACTION = "test"; - process.env.HTTPS_PROXY = "https://localhost"; - - expect(Octokit).toBeInstanceOf(Function); - const octokit = new Octokit({ - auth: "secret123", - baseUrl: "https://localhost:" + server.address().port, - }); - - // await octokit.request("GET /", { - // username: "octocat", - // }); - - // expect(Agent).toHaveBeenCalled(); - expect(octokit).toHaveProperty("request"); - }); - - afterAll((done) => { - server.close(done); - }); + // it("test HTTPS_PROXY", async () => { + // process.env.GITHUB_TOKEN = "secret123"; + // process.env.GITHUB_ACTION = "test"; + // process.env.HTTPS_PROXY = "https://localhost"; + + // expect(Octokit).toBeInstanceOf(Function); + // const octokit = new Octokit({ + // auth: "secret123", + // baseUrl: "https://localhost:" + server.address().port, + // }); + + // await octokit.request("GET /", { + // username: "octocat", + // }); + + // expect(ProxyAgent).toHaveBeenCalled(); + // expect(octokit).toHaveProperty("request"); + // }); + + // afterAll((done) => { + // server.close(done); + // }); }); From e35075d545dbdd14a8b7c46efe40abee1aa33597 Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Mon, 17 Jul 2023 15:13:06 -0700 Subject: [PATCH 11/21] WIP checkpoint with tests passing --- test/smoke.test.ts | 59 ++++------------------------------------------ 1 file changed, 5 insertions(+), 54 deletions(-) diff --git a/test/smoke.test.ts b/test/smoke.test.ts index 1384977d..b12e8717 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -70,9 +70,7 @@ describe("Smoke test", () => { it("should call undiciFetch with the correct dispatcher", async () => { process.env.HTTPS_PROXY = "https://example.com"; const mockAgent = new ProxyAgent("https://example.com"); - // (OctokitModule.getProxyAgent as jest.Mock).mockReturnValueOnce(mockAgent); - // Use jest.spyOn to create a mock const spy = jest.spyOn(OctokitModule, "getProxyAgent"); spy.mockReturnValueOnce(mockAgent); @@ -80,46 +78,23 @@ describe("Smoke test", () => { let dispatcher: any; (undici.fetch as jest.Mock).mockImplementation( (_url: string, options: any) => { - console.log("Inside mock undici.fetch"); // add this log - console.log(options); // log the options here - + console.log("Inside mock undici.fetch"); + console.log(options); dispatcher = options.dispatcher; - // Simulate a real fetch call - // This is your original mock implementation return Promise.resolve(new Response()); }, ); - // Add logging or assertion to check return value of getProxyAgent - console.log(OctokitModule.getProxyAgent()); - // Or - // expect(OctokitModule.getProxyAgent()).toBe(mockAgent); + expect(OctokitModule.getProxyAgent()).toBe(mockAgent); await OctokitModule.customFetch("http://api.github.com", {}); - // Assert against the mocked 'dispatcher' value - expect(dispatcher).toBe(mockAgent); - // expect(dispatcher.uri).toBe("https://example.com"); + expect(JSON.stringify(dispatcher)).toEqual(JSON.stringify(mockAgent)); + spy.mockRestore(); }); - // it("should call undiciFetch with the correct dispatcher", async () => { - // const mockAgent = new ProxyAgent("https://example.com"); - // (OctokitModule.getProxyAgent as jest.Mock).mockReturnValueOnce(mockAgent); - // // jest.spyOn(OctokitModule, "getProxyAgent").mockReturnValueOnce(mockAgent); - // // OctokitModule.getProxyAgent = jest.fn().mockReturnValueOnce(mockAgent) - - // await OctokitModule.customFetch("http://api.github.com", {}); - - // expect(undici.fetch).toHaveBeenCalledWith( - // "http://api.github.com", - // expect.objectContaining({ - // dispatcher: mockAgent, - // }), - // ); - // }); - it("Uses the explicitly provided request.agent value if it's provided", async () => { process.env.GITHUB_TOKEN = "secret123"; process.env.GITHUB_ACTION = "test"; @@ -357,28 +332,4 @@ describe("Smoke test", () => { ); }, ); - - // WIP - // it("test HTTPS_PROXY", async () => { - // process.env.GITHUB_TOKEN = "secret123"; - // process.env.GITHUB_ACTION = "test"; - // process.env.HTTPS_PROXY = "https://localhost"; - - // expect(Octokit).toBeInstanceOf(Function); - // const octokit = new Octokit({ - // auth: "secret123", - // baseUrl: "https://localhost:" + server.address().port, - // }); - - // await octokit.request("GET /", { - // username: "octocat", - // }); - - // expect(ProxyAgent).toHaveBeenCalled(); - // expect(octokit).toHaveProperty("request"); - // }); - - // afterAll((done) => { - // server.close(done); - // }); }); From 5f82b61877467680f33967436c2cb42003d130a1 Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Mon, 17 Jul 2023 15:14:35 -0700 Subject: [PATCH 12/21] Use localhost for consistency --- test/smoke.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/smoke.test.ts b/test/smoke.test.ts index b12e8717..86834896 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -2,7 +2,7 @@ import fetchMock from "fetch-mock"; import { createServer } from "https"; import { Octokit } from "../src"; import * as OctokitModule from "../src"; -import { ProxyAgent /*fetch as undiciFetch*/ } from "undici"; +import { ProxyAgent } from "undici"; jest.mock("undici", () => { return { @@ -51,13 +51,13 @@ describe("Smoke test", () => { }); it("should return a ProxyAgent for the httpProxy environment variable", () => { - process.env.HTTP_PROXY = "http://example.com"; + process.env.HTTP_PROXY = "https://127.0.0.1"; const agent = OctokitModule.getProxyAgent(); expect(agent).toBeInstanceOf(ProxyAgent); }); it("should return a ProxyAgent for the httpsProxy environment variable", () => { - process.env.HTTPS_PROXY = "https://example.com"; + process.env.HTTPS_PROXY = "https://127.0.0.1"; const agent = OctokitModule.getProxyAgent(); expect(agent).toBeInstanceOf(ProxyAgent); }); @@ -68,8 +68,8 @@ describe("Smoke test", () => { }); it("should call undiciFetch with the correct dispatcher", async () => { - process.env.HTTPS_PROXY = "https://example.com"; - const mockAgent = new ProxyAgent("https://example.com"); + process.env.HTTPS_PROXY = "https://127.0.0.1"; + const mockAgent = new ProxyAgent("https://127.0.0.1"); const spy = jest.spyOn(OctokitModule, "getProxyAgent"); spy.mockReturnValueOnce(mockAgent); From f3821ab58c42f0638f52f76ced73da9f6af4d3e3 Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Mon, 17 Jul 2023 15:16:21 -0700 Subject: [PATCH 13/21] Remove extraneous console.log statements --- src/index.ts | 2 -- test/smoke.test.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5a736fcc..f1e7e8e7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,8 +29,6 @@ export function getProxyAgent() { } export const customFetch = async function (url: string, opts: any) { - console.log("inside customFetch"); - console.log(opts); return await undiciFetch(url, { dispatcher: getProxyAgent(), ...opts, diff --git a/test/smoke.test.ts b/test/smoke.test.ts index 86834896..a847781f 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -78,8 +78,6 @@ describe("Smoke test", () => { let dispatcher: any; (undici.fetch as jest.Mock).mockImplementation( (_url: string, options: any) => { - console.log("Inside mock undici.fetch"); - console.log(options); dispatcher = options.dispatcher; return Promise.resolve(new Response()); From b970c0d78853c01fde06e8ec9c6c8b0435437422 Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Mon, 17 Jul 2023 15:18:24 -0700 Subject: [PATCH 14/21] Strongly type Server --- test/smoke.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/smoke.test.ts b/test/smoke.test.ts index a847781f..93763a8d 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -1,5 +1,5 @@ import fetchMock from "fetch-mock"; -import { createServer } from "https"; +import { createServer, type Server } from "https"; import { Octokit } from "../src"; import * as OctokitModule from "../src"; import { ProxyAgent } from "undici"; @@ -13,7 +13,7 @@ jest.mock("undici", () => { const undici = jest.requireMock("undici"); describe("Smoke test", () => { - let server: any; + let server: Server; beforeAll((done) => { server = createServer( From b4dddcabf2e696135c9b3b335241996eb170986d Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Mon, 17 Jul 2023 15:33:29 -0700 Subject: [PATCH 15/21] Some test cleanup --- test/smoke.test.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/test/smoke.test.ts b/test/smoke.test.ts index 93763a8d..9e711fc2 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -4,6 +4,11 @@ import { Octokit } from "../src"; import * as OctokitModule from "../src"; import { ProxyAgent } from "undici"; +// mock undici such that we can substitute our own fetch implementation +// but use the actual ProxyAgent implementation for most tests. the +// exception is "should call undiciFetch with the correct dispatcher" +// where we want to validate that a mocked ProxyAgent is passed through +// to undici.fetch. jest.mock("undici", () => { return { fetch: jest.fn(), @@ -69,12 +74,11 @@ describe("Smoke test", () => { it("should call undiciFetch with the correct dispatcher", async () => { process.env.HTTPS_PROXY = "https://127.0.0.1"; - const mockAgent = new ProxyAgent("https://127.0.0.1"); + const expectedAgent = new ProxyAgent("https://127.0.0.1"); - const spy = jest.spyOn(OctokitModule, "getProxyAgent"); - spy.mockReturnValueOnce(mockAgent); - - // Mock undici.fetch to set the 'dispatcher' option manually + // mock undici.fetch to set the `dispatcher` option manually. + // this allows us to verify that `customFetch` correctly sets + // the dispatcher to `mockAgent` when HTTPS_PROXY is set. let dispatcher: any; (undici.fetch as jest.Mock).mockImplementation( (_url: string, options: any) => { @@ -83,14 +87,12 @@ describe("Smoke test", () => { return Promise.resolve(new Response()); }, ); - - expect(OctokitModule.getProxyAgent()).toBe(mockAgent); - await OctokitModule.customFetch("http://api.github.com", {}); - expect(JSON.stringify(dispatcher)).toEqual(JSON.stringify(mockAgent)); - - spy.mockRestore(); + expect(JSON.stringify(OctokitModule.getProxyAgent())).toBe( + JSON.stringify(expectedAgent), + ); + expect(JSON.stringify(dispatcher)).toEqual(JSON.stringify(expectedAgent)); }); it("Uses the explicitly provided request.agent value if it's provided", async () => { From dd21769d2362600b126a57981b53d0d255c9a595 Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Mon, 17 Jul 2023 15:53:58 -0700 Subject: [PATCH 16/21] WIP comment out spy --- test/smoke.test.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/test/smoke.test.ts b/test/smoke.test.ts index 9e711fc2..b11471a8 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -1,6 +1,6 @@ import fetchMock from "fetch-mock"; import { createServer, type Server } from "https"; -import { Octokit } from "../src"; +import { Octokit, getProxyAgent } from "../src"; import * as OctokitModule from "../src"; import { ProxyAgent } from "undici"; @@ -57,18 +57,18 @@ describe("Smoke test", () => { it("should return a ProxyAgent for the httpProxy environment variable", () => { process.env.HTTP_PROXY = "https://127.0.0.1"; - const agent = OctokitModule.getProxyAgent(); + const agent = getProxyAgent(); expect(agent).toBeInstanceOf(ProxyAgent); }); it("should return a ProxyAgent for the httpsProxy environment variable", () => { process.env.HTTPS_PROXY = "https://127.0.0.1"; - const agent = OctokitModule.getProxyAgent(); + const agent = getProxyAgent(); expect(agent).toBeInstanceOf(ProxyAgent); }); it("should return undefined if no proxy environment variables are set", () => { - const agent = OctokitModule.getProxyAgent(); + const agent = getProxyAgent(); expect(agent).toBeUndefined(); }); @@ -76,9 +76,15 @@ describe("Smoke test", () => { process.env.HTTPS_PROXY = "https://127.0.0.1"; const expectedAgent = new ProxyAgent("https://127.0.0.1"); + // spy on OctokitModule.getProxyAgent to verify that it's called + // when HTTPS_PROXY is set. + // const spy = jest + // .spyOn(OctokitModule, "getProxyAgent") + // .mockImplementation(() => expectedAgent); + // mock undici.fetch to set the `dispatcher` option manually. // this allows us to verify that `customFetch` correctly sets - // the dispatcher to `mockAgent` when HTTPS_PROXY is set. + // the dispatcher to `expectedAgent` when HTTPS_PROXY is set. let dispatcher: any; (undici.fetch as jest.Mock).mockImplementation( (_url: string, options: any) => { @@ -89,10 +95,13 @@ describe("Smoke test", () => { ); await OctokitModule.customFetch("http://api.github.com", {}); - expect(JSON.stringify(OctokitModule.getProxyAgent())).toBe( - JSON.stringify(expectedAgent), - ); + // assert that getProxyAgentSpy was called and that the + // dispatcher was set correctly. + // expect(spy).toHaveBeenCalled(); + expect(OctokitModule.getProxyAgent()).toBe(expectedAgent); expect(JSON.stringify(dispatcher)).toEqual(JSON.stringify(expectedAgent)); + + // spy.mockRestore(); }); it("Uses the explicitly provided request.agent value if it's provided", async () => { From dcd03417bd2cc971d5e7eb6fba2f294b26651b21 Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Mon, 17 Jul 2023 16:04:13 -0700 Subject: [PATCH 17/21] Refactor customFetch tests to own describe block --- test/smoke.test.ts | 70 ++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/test/smoke.test.ts b/test/smoke.test.ts index b11471a8..a597fc0f 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -1,7 +1,6 @@ import fetchMock from "fetch-mock"; import { createServer, type Server } from "https"; -import { Octokit, getProxyAgent } from "../src"; -import * as OctokitModule from "../src"; +import { Octokit, getProxyAgent, customFetch } from "../src"; import { ProxyAgent } from "undici"; // mock undici such that we can substitute our own fetch implementation @@ -72,38 +71,6 @@ describe("Smoke test", () => { expect(agent).toBeUndefined(); }); - it("should call undiciFetch with the correct dispatcher", async () => { - process.env.HTTPS_PROXY = "https://127.0.0.1"; - const expectedAgent = new ProxyAgent("https://127.0.0.1"); - - // spy on OctokitModule.getProxyAgent to verify that it's called - // when HTTPS_PROXY is set. - // const spy = jest - // .spyOn(OctokitModule, "getProxyAgent") - // .mockImplementation(() => expectedAgent); - - // mock undici.fetch to set the `dispatcher` option manually. - // this allows us to verify that `customFetch` correctly sets - // the dispatcher to `expectedAgent` when HTTPS_PROXY is set. - let dispatcher: any; - (undici.fetch as jest.Mock).mockImplementation( - (_url: string, options: any) => { - dispatcher = options.dispatcher; - - return Promise.resolve(new Response()); - }, - ); - await OctokitModule.customFetch("http://api.github.com", {}); - - // assert that getProxyAgentSpy was called and that the - // dispatcher was set correctly. - // expect(spy).toHaveBeenCalled(); - expect(OctokitModule.getProxyAgent()).toBe(expectedAgent); - expect(JSON.stringify(dispatcher)).toEqual(JSON.stringify(expectedAgent)); - - // spy.mockRestore(); - }); - it("Uses the explicitly provided request.agent value if it's provided", async () => { process.env.GITHUB_TOKEN = "secret123"; process.env.GITHUB_ACTION = "test"; @@ -341,4 +308,39 @@ describe("Smoke test", () => { ); }, ); + describe("customFetch", () => { + afterAll(() => { + delete process.env.HTTPS_PROXY; + jest.clearAllMocks(); + }); + it("should call undiciFetch with the correct dispatcher", async () => { + process.env.HTTPS_PROXY = "https://127.0.0.1"; + const expectedAgent = new ProxyAgent("https://127.0.0.1"); + + jest.mock("../src", () => { + const actualModule = jest.requireActual("../src"); + return { + ...actualModule, + getProxyAgent: jest.fn(() => expectedAgent), + }; + }); + expect(JSON.stringify(getProxyAgent())).toBe( + JSON.stringify(expectedAgent), + ); + + // mock undici.fetch to set the `dispatcher` option manually. + // this allows us to verify that `customFetch` correctly sets + // the dispatcher to `expectedAgent` when HTTPS_PROXY is set. + let dispatcher: any; + (undici.fetch as jest.Mock).mockImplementation( + (_url: string, options: any) => { + dispatcher = options.dispatcher; + + return Promise.resolve(new Response()); + }, + ); + await customFetch("http://api.github.com", {}); + expect(JSON.stringify(dispatcher)).toEqual(JSON.stringify(expectedAgent)); + }); + }); }); From 3670f903fd795e33d405780c457953642d1dc0c2 Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Mon, 17 Jul 2023 16:06:20 -0700 Subject: [PATCH 18/21] Comment fix --- test/smoke.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/smoke.test.ts b/test/smoke.test.ts index a597fc0f..ebab6592 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -328,7 +328,7 @@ describe("Smoke test", () => { JSON.stringify(expectedAgent), ); - // mock undici.fetch to set the `dispatcher` option manually. + // mock undici.fetch to extract the `dispatcher` option passed in. // this allows us to verify that `customFetch` correctly sets // the dispatcher to `expectedAgent` when HTTPS_PROXY is set. let dispatcher: any; From ad90bcda68b523e868b0e958f77fad0d07212f55 Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Mon, 17 Jul 2023 16:09:58 -0700 Subject: [PATCH 19/21] Remove redundant tests --- test/smoke.test.ts | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/test/smoke.test.ts b/test/smoke.test.ts index ebab6592..7f910882 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -71,43 +71,6 @@ describe("Smoke test", () => { expect(agent).toBeUndefined(); }); - it("Uses the explicitly provided request.agent value if it's provided", async () => { - process.env.GITHUB_TOKEN = "secret123"; - process.env.GITHUB_ACTION = "test"; - process.env.HTTPS_PROXY = "https://127.0.0.1"; - - const fetchSandbox = fetchMock.sandbox(); - const mock = fetchSandbox.post( - "path:/repos/octocat/hello-world/issues", - { id: 1 }, - { - body: { - title: "My test issue", - }, - }, - ); - - expect(Octokit).toBeInstanceOf(Function); - const octokit = new Octokit({ - auth: "secret123", - request: { - fetch: mock, - }, - }); - await octokit.request("POST /repos/{owner}/{repo}/issues", { - owner: "octocat", - repo: "hello-world", - title: "My test issue", - }); - - const [call] = fetchSandbox.calls(); - expect(call[0]).toEqual( - "https://api.github.com/repos/octocat/hello-world/issues", - ); - - fetchMock.restore(); - }); - it("happy path with GITHUB_TOKEN", () => { process.env.GITHUB_TOKEN = "secret123"; process.env.GITHUB_ACTION = "test"; @@ -313,6 +276,7 @@ describe("Smoke test", () => { delete process.env.HTTPS_PROXY; jest.clearAllMocks(); }); + it("should call undiciFetch with the correct dispatcher", async () => { process.env.HTTPS_PROXY = "https://127.0.0.1"; const expectedAgent = new ProxyAgent("https://127.0.0.1"); From 645878570c1142884177382ea14a62703146313f Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Tue, 18 Jul 2023 09:24:47 -0700 Subject: [PATCH 20/21] Remove unnecessary tests --- test/smoke.test.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/test/smoke.test.ts b/test/smoke.test.ts index 7f910882..b1262c87 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -54,23 +54,6 @@ describe("Smoke test", () => { jest.unmock("undici"); }); - it("should return a ProxyAgent for the httpProxy environment variable", () => { - process.env.HTTP_PROXY = "https://127.0.0.1"; - const agent = getProxyAgent(); - expect(agent).toBeInstanceOf(ProxyAgent); - }); - - it("should return a ProxyAgent for the httpsProxy environment variable", () => { - process.env.HTTPS_PROXY = "https://127.0.0.1"; - const agent = getProxyAgent(); - expect(agent).toBeInstanceOf(ProxyAgent); - }); - - it("should return undefined if no proxy environment variables are set", () => { - const agent = getProxyAgent(); - expect(agent).toBeUndefined(); - }); - it("happy path with GITHUB_TOKEN", () => { process.env.GITHUB_TOKEN = "secret123"; process.env.GITHUB_ACTION = "test"; From 2f41cd597c2080c6c3d997aa2864cb22d247f360 Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Tue, 18 Jul 2023 09:49:05 -0700 Subject: [PATCH 21/21] Revert "Remove unnecessary tests" This reverts commit 645878570c1142884177382ea14a62703146313f in order to increase code coverage. --- test/smoke.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/smoke.test.ts b/test/smoke.test.ts index b1262c87..7f910882 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -54,6 +54,23 @@ describe("Smoke test", () => { jest.unmock("undici"); }); + it("should return a ProxyAgent for the httpProxy environment variable", () => { + process.env.HTTP_PROXY = "https://127.0.0.1"; + const agent = getProxyAgent(); + expect(agent).toBeInstanceOf(ProxyAgent); + }); + + it("should return a ProxyAgent for the httpsProxy environment variable", () => { + process.env.HTTPS_PROXY = "https://127.0.0.1"; + const agent = getProxyAgent(); + expect(agent).toBeInstanceOf(ProxyAgent); + }); + + it("should return undefined if no proxy environment variables are set", () => { + const agent = getProxyAgent(); + expect(agent).toBeUndefined(); + }); + it("happy path with GITHUB_TOKEN", () => { process.env.GITHUB_TOKEN = "secret123"; process.env.GITHUB_ACTION = "test";