From e99c9ee321d6054b7d0936b8c16d96f382ebb3da Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 24 Oct 2024 11:28:03 +0000 Subject: [PATCH 1/2] chore(deps): update dependency fetch-mock to v12 --- package-lock.json | 39 +++++++++++++++++++++++---------------- package.json | 2 +- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9246bcff..11fb8793 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,7 @@ "@vitest/coverage-v8": "^2.1.1", "esbuild": "^0.24.0", "express": "^4.17.1", - "fetch-mock": "^11.0.0", + "fetch-mock": "^12.0.0", "glob": "^11.0.0", "nock": "^13.0.0", "prettier": "3.3.3", @@ -2034,25 +2034,20 @@ "license": "MIT" }, "node_modules/fetch-mock": { - "version": "11.1.5", - "resolved": "https://registry.npmjs.org/fetch-mock/-/fetch-mock-11.1.5.tgz", - "integrity": "sha512-KHmZDnZ1ry0pCTrX4YG5DtThHi0MH+GNI9caESnzX/nMJBrvppUHMvLx47M0WY9oAtKOMiPfZDRpxhlHg89BOA==", + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/fetch-mock/-/fetch-mock-12.0.0.tgz", + "integrity": "sha512-JSsjzoRN4rYqHa2/+8ushJGDsK9HGNTdBZo6Hrpu3KFN7Y03nRCt2VJ2WG4OUvyTUukOQ4TQIfjcFcEkMPGZ0Q==", "dev": true, "license": "MIT", "dependencies": { "@types/glob-to-regexp": "^0.4.4", "dequal": "^2.0.3", "glob-to-regexp": "^0.4.1", - "is-subset": "^0.1.1", + "is-subset-of": "^3.1.10", "regexparam": "^3.0.0" }, "engines": { - "node": ">=8.0.0" - }, - "peerDependenciesMeta": { - "node-fetch": { - "optional": true - } + "node": ">=18.11.0" } }, "node_modules/fill-range": { @@ -2392,12 +2387,16 @@ "node": ">=0.12.0" } }, - "node_modules/is-subset": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/is-subset/-/is-subset-0.1.1.tgz", - "integrity": "sha512-6Ybun0IkarhmEqxXCNw/C0bna6Zb/TkfUX9UbwJtK6ObwAVCxmAP308WWTHviM/zAqXk05cdhYsUsZeGQh99iw==", + "node_modules/is-subset-of": { + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/is-subset-of/-/is-subset-of-3.1.10.tgz", + "integrity": "sha512-avvaYgVmYWyaZ1NDFiv4y9JGkrE2je3op1Po4VYKKJKR8H2qVPsg1GZuuXl5elCTxTlwAIsrAjWAs4BVrISFRw==", + "deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.", "dev": true, - "license": "MIT" + "license": "MIT", + "dependencies": { + "typedescriptor": "3.0.2" + } }, "node_modules/isexe": { "version": "2.0.0", @@ -3719,6 +3718,14 @@ "node": ">= 0.6" } }, + "node_modules/typedescriptor": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/typedescriptor/-/typedescriptor-3.0.2.tgz", + "integrity": "sha512-hyVbaCUd18UiXk656g/imaBLMogpdijIEpnhWYrSda9rhvO4gOU16n2nh7xG5lv/rjumnZzGOdz0CEGTmFe0fQ==", + "deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.", + "dev": true, + "license": "MIT" + }, "node_modules/typescript": { "version": "5.6.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", diff --git a/package.json b/package.json index 8c875ae6..6f7c2083 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "@vitest/coverage-v8": "^2.1.1", "esbuild": "^0.24.0", "express": "^4.17.1", - "fetch-mock": "^11.0.0", + "fetch-mock": "^12.0.0", "glob": "^11.0.0", "nock": "^13.0.0", "prettier": "3.3.3", From 40efab72dc60a028fb637849ad9b12b73fc1261f Mon Sep 17 00:00:00 2001 From: Nick Floyd Date: Thu, 14 Nov 2024 12:52:10 -0600 Subject: [PATCH 2/2] updates tests to use the new v12 fetch-mock apis --- test/app.test.ts | 80 ++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/test/app.test.ts b/test/app.test.ts index 83a821f5..de6e6005 100644 --- a/test/app.test.ts +++ b/test/app.test.ts @@ -35,7 +35,7 @@ describe("OAuthApp.defaults", () => { describe("app", () => { it("app.getUserOctokit(options)", async () => { const mock = fetchMock - .sandbox() + .createInstance() .postOnce( "https://github.com/login/oauth/access_token", { @@ -63,7 +63,7 @@ describe("app", () => { const Mocktokit = OAuthAppOctokit.defaults({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -113,7 +113,7 @@ describe("app", () => { it("app.createToken(options) for web flow", async () => { const mock = fetchMock - .sandbox() + .createInstance() .postOnce( "https://github.com/login/oauth/access_token", { @@ -141,7 +141,7 @@ describe("app", () => { const Mocktokit = OAuthAppOctokit.defaults({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -197,7 +197,7 @@ describe("app", () => { it("app.createToken(options) for device flow", async () => { const mock = fetchMock - .sandbox() + .createInstance() .postOnce( "https://github.com/login/device/code", { @@ -231,7 +231,7 @@ describe("app", () => { const Mocktokit = OAuthAppOctokit.defaults({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -285,7 +285,7 @@ describe("app", () => { }); it("app.checkToken(options)", async () => { - const mock = fetchMock.sandbox().postOnce( + const mock = fetchMock.createInstance().postOnce( "https://api.github.com/applications/0123/token", { id: 1 }, { @@ -301,7 +301,7 @@ describe("app", () => { const Mocktokit = OAuthAppOctokit.defaults({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -334,13 +334,13 @@ describe("app", () => { "content-type": "application/json", }, "status": 200, - "url": "", + "url": "https://api.github.com/applications/0123/token", } `); }); it("app.resetToken(options)", async () => { - const mock = fetchMock.sandbox().patchOnce( + const mock = fetchMock.createInstance().patchOnce( "https://api.github.com/applications/0123/token", { id: 2, @@ -360,7 +360,7 @@ describe("app", () => { const Mocktokit = OAuthAppOctokit.defaults({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -411,7 +411,7 @@ describe("app", () => { "content-type": "application/json", }, "status": 200, - "url": "", + "url": "https://api.github.com/applications/0123/token", } `); expect(onTokenCallback.mock.calls.length).toEqual(1); @@ -427,7 +427,7 @@ describe("app", () => { }); it("app.resetToken(options) with empty scopes", async () => { - const mock = fetchMock.sandbox().patchOnce( + const mock = fetchMock.createInstance().patchOnce( "https://api.github.com/applications/0123/token", { id: 2, @@ -447,7 +447,7 @@ describe("app", () => { const Mocktokit = OAuthAppOctokit.defaults({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -492,7 +492,7 @@ describe("app", () => { "content-type": "application/json", }, "status": 200, - "url": "", + "url": "https://api.github.com/applications/0123/token", } `); expect(onTokenCallback.mock.calls.length).toEqual(1); @@ -507,7 +507,7 @@ describe("app", () => { }); it("app.resetToken(options) for GitHub App", async () => { - const mock = fetchMock.sandbox().patchOnce( + const mock = fetchMock.createInstance().patchOnce( "https://api.github.com/applications/lv1.1234567890abcdef/token", { id: 2, @@ -529,7 +529,7 @@ describe("app", () => { const Mocktokit = OAuthAppOctokit.defaults({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -573,7 +573,7 @@ describe("app", () => { "content-type": "application/json", }, "status": 200, - "url": "", + "url": "https://api.github.com/applications/lv1.1234567890abcdef/token", } `); expect(onTokenCallback.mock.calls.length).toEqual(1); @@ -588,7 +588,7 @@ describe("app", () => { }); it("app.refreshToken(options)", async () => { - const mock = fetchMock.sandbox().postOnce( + const mock = fetchMock.createInstance().postOnce( "https://github.com/login/oauth/access_token", { body: { @@ -615,7 +615,7 @@ describe("app", () => { const Mocktokit = OAuthAppOctokit.defaults({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -667,7 +667,7 @@ describe("app", () => { "date": "Thu, 1 Jan 1970 00:00:00 GMT", }, "status": 200, - "url": "", + "url": "https://github.com/login/oauth/access_token", } `); expect(onTokenCallback.mock.calls.length).toEqual(1); @@ -699,7 +699,7 @@ describe("app", () => { }); it("app.scopeToken(options)", async () => { - const mock = fetchMock.sandbox().postOnce( + const mock = fetchMock.createInstance().postOnce( "https://api.github.com/applications/lv1.1234567890abcdef/token/scoped", { token: "token456", @@ -720,7 +720,7 @@ describe("app", () => { const Mocktokit = OAuthAppOctokit.defaults({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -771,7 +771,7 @@ describe("app", () => { "content-type": "application/json", }, "status": 200, - "url": "", + "url": "https://api.github.com/applications/lv1.1234567890abcdef/token/scoped", } `); expect(onTokenCallback.mock.calls.length).toEqual(1); @@ -804,7 +804,7 @@ describe("app", () => { it("app.deleteToken(options)", async () => { const mock = fetchMock - .sandbox() + .createInstance() .deleteOnce("https://api.github.com/applications/0123/token", 204, { headers: { authorization: @@ -813,11 +813,12 @@ describe("app", () => { body: { access_token: "token123", }, + matchPartialBody: true, }); const Mocktokit = OAuthAppOctokit.defaults({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -863,7 +864,7 @@ describe("app", () => { it("app.deleteAuthorization(options)", async () => { const mock = fetchMock - .sandbox() + .createInstance() .deleteOnce("https://api.github.com/applications/0123/grant", 204, { headers: { authorization: @@ -876,7 +877,7 @@ describe("app", () => { const Mocktokit = OAuthAppOctokit.defaults({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -930,7 +931,7 @@ describe("app", () => { it('app.on("token.created", ({ octokit }) => octokit.auth({ type: "reset" })', async () => { const mock = fetchMock - .sandbox() + .createInstance() .postOnce( "https://github.com/login/oauth/access_token", { @@ -946,18 +947,23 @@ describe("app", () => { }, }, ) - .deleteOnce((url, options) => { - expect(url).toEqual("https://api.github.com/applications/0123/token"); - // @ts-expect-error options.headers is not guaranteed to exist - expect(options.headers.authorization).toEqual( + .deleteOnce((request: any) => { + expect(request.url).toEqual( + "https://api.github.com/applications/0123/token", + ); + const authorization = request.options.headers["authorization"]; + expect(authorization).toEqual( "basic " + Buffer.from("0123:0123secret").toString("base64"), ); + // expect(request.headers["authorization"]).toEqual( + // "basic " + Buffer.from("0123:0123secret").toString("base64"), + // ); return true; }, {}); const Mocktokit = OAuthAppOctokit.defaults({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -984,12 +990,12 @@ describe("app", () => { await app.createToken({ code: "code123" }); - expect(mock.done()).toEqual(true); + expect(mock.callHistory.done()).toBe(true); }); it("app.on multiple events", async () => { const mock = fetchMock - .sandbox() + .createInstance() .postOnce( "https://github.com/login/oauth/access_token", { @@ -1017,7 +1023,7 @@ describe("app", () => { const Mocktokit = OAuthAppOctokit.defaults({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, });