diff --git a/package-lock.json b/package-lock.json index 8e498ba18..600c9082a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,7 @@ "@types/sinonjs__fake-timers": "^8.1.5", "@vitest/coverage-v8": "^2.1.1", "esbuild": "^0.24.0", - "fetch-mock": "^11.0.0", + "fetch-mock": "^12.0.0", "glob": "^11.0.0", "prettier": "3.3.3", "proxy": "^2.0.0", @@ -3006,25 +3006,20 @@ } }, "node_modules/fetch-mock": { - "version": "11.1.3", - "resolved": "https://registry.npmjs.org/fetch-mock/-/fetch-mock-11.1.3.tgz", - "integrity": "sha512-ATh0dWgnVrUHiiXuvQm1Ry+ThWfSv1QQgqJTCtybrNxyUrFiSOaDKsNG29eyysp1SHeNP6Q+dH50+8VifN51Ig==", + "version": "12.0.2", + "resolved": "https://registry.npmjs.org/fetch-mock/-/fetch-mock-12.0.2.tgz", + "integrity": "sha512-9KVq/Scz06A+ThORLA/J/EACiPzLdSn6DeLV61hni57kd3DXhQVCtkpj4LgwES+8osEVEfcqA6LwdSX2FYVK7w==", "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/fflate": { @@ -3640,11 +3635,16 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "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==", - "dev": true + "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", + "dependencies": { + "typedescriptor": "3.0.2" + } }, "node_modules/is-unicode-supported": { "version": "2.0.0", @@ -8857,6 +8857,14 @@ "node": ">=4" } }, + "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.1.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.3.tgz", diff --git a/package.json b/package.json index fc0a3ab6a..2a0530cfc 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@types/sinonjs__fake-timers": "^8.1.5", "@vitest/coverage-v8": "^2.1.1", "esbuild": "^0.24.0", - "fetch-mock": "^11.0.0", + "fetch-mock": "^12.0.0", "glob": "^11.0.0", "prettier": "3.3.3", "proxy": "^2.0.0", diff --git a/test/auth.test.ts b/test/auth.test.ts index 651049947..1529d2f87 100644 --- a/test/auth.test.ts +++ b/test/auth.test.ts @@ -65,7 +65,7 @@ beforeEach(() => { describe("Authentication", () => { it("new Octokit({ auth: 'secret123' })", () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://api.github.com/", { ok: true }, { @@ -80,7 +80,7 @@ describe("Authentication", () => { const octokit = new Octokit({ auth: "secret123", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -88,7 +88,7 @@ describe("Authentication", () => { }); it("new Octokit({ auth: 'token secret123' })", () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://api.github.com/", { ok: true }, { @@ -103,7 +103,7 @@ describe("Authentication", () => { const octokit = new Octokit({ auth: "token secret123", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -111,7 +111,7 @@ describe("Authentication", () => { }); it("new Octokit({ auth: 'Token secret123' })", () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://api.github.com/", { ok: true }, { @@ -126,7 +126,7 @@ describe("Authentication", () => { const octokit = new Octokit({ auth: "Token secret123", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -136,7 +136,7 @@ describe("Authentication", () => { const BEARER_TOKEN = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NTM4MTkzMTIsImV4cCI6MTU1MzgxOTM3MiwiaXNzIjoxfQ.etiSZ4LFQZ8tiMGJVqKDoGn8hxMCgwL4iLvU5xBUqbAPr4pbk_jJZmMQjuxTlOnRxq4e7NouTizGCdfohRMb3R1mpLzGPzOH9_jqSA_BWYxolsRP_WDSjuNcw6nSxrPRueMVRBKFHrqcTOZJej0djRB5pI61hDZJ_-DGtiOIFexlK3iuVKaqBkvJS5-TbTekGuipJ652g06gXuz-l8i0nHiFJldcuIruwn28hTUrjgtPbjHdSBVn_QQLKc2Fhij8OrhcGqp_D_fvb_KovVmf1X6yWiwXV5VXqWARS-JGD9JTAr2495ZlLV_E4WPxdDpz1jl6XS9HUhMuwBpaCOuipw"; it("new Octokit({ auth: BEARER_TOKEN })", () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://api.github.com/", { ok: true }, { @@ -151,7 +151,7 @@ describe("Authentication", () => { const octokit = new Octokit({ auth: BEARER_TOKEN, request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -163,7 +163,7 @@ describe("Authentication", () => { const CLIENT_SECRET = "0123secret"; const CODE = "code123"; - const mock = fetchMock.sandbox().postOnce( + const mock = fetchMock.createInstance().postOnce( "https://github.com/login/oauth/access_token", { access_token: "token123", @@ -182,7 +182,7 @@ describe("Authentication", () => { const MyOctokit = Octokit.defaults({ authStrategy: createOAuthAppAuth, request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -198,12 +198,12 @@ describe("Authentication", () => { code: CODE, }); - expect(mock.done()).toBe(true); + expect(mock.callHistory.done()).toBe(true); }); it("auth = createAppAuth()", async () => { const mock = fetchMock - .sandbox() + .createInstance() .postOnce("https://api.github.com/app/installations/123/access_tokens", { token: "secret123", expires_at: "1970-01-01T01:00:00.000Z", @@ -242,7 +242,7 @@ describe("Authentication", () => { installationId: 123, }, request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -251,11 +251,11 @@ describe("Authentication", () => { await octokit.request("GET /app"); - expect(mock.done()).toBe(true); + expect(mock.callHistory.done()).toBe(true); }); it("auth = createActionAuth()", async () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://api.github.com/app", { id: 123 }, { @@ -275,7 +275,7 @@ describe("Authentication", () => { const octokit = new Octokit({ authStrategy: createActionAuth, request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -303,7 +303,7 @@ describe("Authentication", () => { it("createAppAuth with GraphQL + GHES (probot/probot#1386)", async () => { const mock = fetchMock - .sandbox() + .createInstance() .postOnce( "https://fake.github-enterprise.com/api/v3/app/installations/123/access_tokens", { @@ -334,7 +334,7 @@ describe("Authentication", () => { }, baseUrl: "https://fake.github-enterprise.com/api/v3", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -344,12 +344,12 @@ describe("Authentication", () => { } }`); - expect(mock.done()).toBe(true); + expect(mock.callHistory.done()).toBe(true); }); it("should pass through the logger (#1277)", async () => { const mock = fetchMock - .sandbox() + .createInstance() .postOnce("https://api.github.com/app/installations/2/access_tokens", { token: "installation-token-123", permissions: {}, @@ -377,7 +377,7 @@ describe("Authentication", () => { installationId: 2, }, request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); diff --git a/test/constructor.test.ts b/test/constructor.test.ts index aecce2d31..55a4d5d23 100644 --- a/test/constructor.test.ts +++ b/test/constructor.test.ts @@ -4,7 +4,7 @@ import { describe, expect, it } from "vitest"; describe("Smoke test", () => { it("previews option", () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://api.github.com/graphql", { ok: true }, { @@ -22,7 +22,7 @@ describe("Smoke test", () => { "symmetra", ], request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -30,7 +30,7 @@ describe("Smoke test", () => { }); it("timeZone option", () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://api.github.com/", { ok: true }, { @@ -44,7 +44,7 @@ describe("Smoke test", () => { const octokit = new Octokit({ timeZone: "Europe/Amsterdam", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); diff --git a/test/defaults.test.ts b/test/defaults.test.ts index 69fe4f2be..e7502650c 100644 --- a/test/defaults.test.ts +++ b/test/defaults.test.ts @@ -13,7 +13,7 @@ describe("Octokit.defaults", () => { }); it("Octokit.defaults({baseUrl})", () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://github.acme-inc.test/api/v3/", { ok: true }, { @@ -27,7 +27,7 @@ describe("Octokit.defaults", () => { const OctokitWithDefaults = Octokit.defaults({ baseUrl: "https://github.acme-inc.test/api/v3", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -37,7 +37,7 @@ describe("Octokit.defaults", () => { }); it("Octokit.defaults({userAgent})", () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://api.github.com/", { ok: true }, { @@ -51,7 +51,7 @@ describe("Octokit.defaults", () => { const OctokitWithDefaults = Octokit.defaults({ userAgent: "my-app/1.2.3", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -61,7 +61,7 @@ describe("Octokit.defaults", () => { }); it("Octokit.defaults({userAgent}) with userAgent Constructor Option", () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://api.github.com/", { ok: true }, { @@ -75,7 +75,7 @@ describe("Octokit.defaults", () => { const OctokitWithDefaults = Octokit.defaults({ userAgent: "my-octokit.js/1.2.3", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -87,7 +87,7 @@ describe("Octokit.defaults", () => { }); it("Octokit.defaults({timeZone})", () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://api.github.com/", { ok: true }, { @@ -102,7 +102,7 @@ describe("Octokit.defaults", () => { const OctokitWithDefaults = Octokit.defaults({ timeZone: "Europe/Amsterdam", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -112,7 +112,7 @@ describe("Octokit.defaults", () => { }); it("Octokit.defaults({ auth })", async () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://api.github.com/app", { id: 123 }, { @@ -132,7 +132,7 @@ describe("Octokit.defaults", () => { const OctokitWithDefaults = Octokit.defaults({ authStrategy: createActionAuth, request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -143,7 +143,7 @@ describe("Octokit.defaults", () => { }); it("Octokit.defaults().defaults()", () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://github.acme-inc.test/api/v3/", { ok: true }, { @@ -157,7 +157,7 @@ describe("Octokit.defaults", () => { const OctokitWithDefaults = Octokit.defaults({ baseUrl: "https://github.acme-inc.test/api/v3", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }).defaults({ userAgent: "my-app/1.2.3", @@ -169,7 +169,7 @@ describe("Octokit.defaults", () => { }); it("Octokit.plugin().defaults()", () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://github.acme-inc.test/api/v3/", { ok: true }, { @@ -187,7 +187,7 @@ describe("Octokit.defaults", () => { }).defaults({ baseUrl: "https://github.acme-inc.test/api/v3", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); diff --git a/test/graphql.test.ts b/test/graphql.test.ts index 7679cc6e8..f1f6fad94 100644 --- a/test/graphql.test.ts +++ b/test/graphql.test.ts @@ -18,9 +18,11 @@ describe("octokit.graphql()", () => { }, }; const mock = fetchMock - .sandbox() + .createInstance() .postOnce("https://api.github.com/graphql", (_url, request) => { - const body = JSON.parse(request.body!.toString()); + const body = JSON.parse( + mock.callHistory.calls()[0].options.body!.toString(), + ); expect(body.query).toEqual(query); return { @@ -31,7 +33,7 @@ describe("octokit.graphql()", () => { const octokit = new Octokit({ auth: `secret123`, request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -57,9 +59,11 @@ describe("octokit.graphql()", () => { }, }; const mock = fetchMock - .sandbox() + .createInstance() .postOnce("https://github.acme-inc.com/api/graphql", (_url, request) => { - const body = JSON.parse(request.body!.toString()); + const body = JSON.parse( + mock.callHistory.calls()[0].options.body!.toString(), + ); expect(body.query).toEqual(query); return { @@ -71,7 +75,7 @@ describe("octokit.graphql()", () => { auth: `secret123`, baseUrl: "https://github.acme-inc.com/api/v3", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -90,10 +94,13 @@ describe("octokit.graphql()", () => { it("custom headers: octokit.graphql({ query, headers })", async () => { const mock = fetchMock - .sandbox() + .createInstance() .postOnce("https://api.github.com/graphql", (_url, request) => { // @ts-ignore `request.headers` are typed incorrectly by fetch-mock - expect(request.headers["x-custom"]).toEqual("value"); + + expect(mock.callHistory.calls()[0].options.headers["x-custom"]).toEqual( + "value", + ); return { data: { ok: true }, @@ -103,7 +110,7 @@ describe("octokit.graphql()", () => { const octokit = new Octokit({ auth: `secret123`, request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -119,12 +126,16 @@ describe("octokit.graphql()", () => { it("custom headers: octokit.graphql(query, { headers })", async () => { const mock = fetchMock - .sandbox() + .createInstance() .postOnce("https://api.github.com/graphql", (_url, request) => { // @ts-ignore `request.headers` are typed incorrectly by fetch-mock - expect(request.headers["x-custom"]).toEqual("value"); + expect(mock.callHistory.calls()[0].options.headers["x-custom"]).toEqual( + "value", + ); - const body = JSON.parse(request.body!.toString()); + const body = JSON.parse( + mock.callHistory.calls()[0].options.body!.toString(), + ); expect(body.variables).toEqual({ foo: "bar" }); return { @@ -135,7 +146,7 @@ describe("octokit.graphql()", () => { const octokit = new Octokit({ auth: `secret123`, request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); diff --git a/test/hook.test.ts b/test/hook.test.ts index d073fba95..c29c7a86a 100644 --- a/test/hook.test.ts +++ b/test/hook.test.ts @@ -30,7 +30,7 @@ describe("octokit.hook", () => { it("octokit.hook.before('request')", () => { const mock = fetchMock - .sandbox() + .createInstance() .getOnce( "https://api.github.com/foo/daz/baz?qux=quux&beforeAddition=works", { ok: true }, @@ -38,7 +38,7 @@ describe("octokit.hook", () => { const octokit = new Octokit({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -61,7 +61,7 @@ describe("octokit.hook", () => { bar: "daz", qux: "quux", request: { - fetch: mock, + fetch: mock.fetchHandler, // @ts-ignore hook: options.request.hook, }, @@ -86,12 +86,12 @@ describe("octokit.hook", () => { it("octokit.hook.after('request')", async () => { const mock = fetchMock - .sandbox() + .createInstance() .getOnce("https://api.github.com/", { ok: true }); const octokit = new Octokit({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -109,7 +109,7 @@ describe("octokit.hook", () => { format: "", }, request: { - fetch: mock, + fetch: mock.fetchHandler, hook: requestOptions.request.hook, }, }); @@ -126,11 +126,13 @@ describe("octokit.hook", () => { }); it("octokit.hook.error('request')", async () => { - const mock = fetchMock.sandbox().getOnce("https://api.github.com/", 500); + const mock = fetchMock + .createInstance() + .getOnce("https://api.github.com/", 500); const octokit = new Octokit({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -150,7 +152,7 @@ describe("octokit.hook", () => { format: "", }, request: { - fetch: mock, + fetch: mock.fetchHandler, hook: requestOptions.request.hook, }, }); diff --git a/test/issues.test.ts b/test/issues.test.ts index 166de3741..fac727173 100644 --- a/test/issues.test.ts +++ b/test/issues.test.ts @@ -15,12 +15,12 @@ import { describe, expect, test } from "vitest"; describe("issues", () => { test("#123 example issue", async () => { const mock = fetchMock - .sandbox() + .createInstance() .getOnce("https://api.github.com/", { ok: true }); const octokit = new Octokit({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); diff --git a/test/request.test.ts b/test/request.test.ts index 2c343c2b1..cbdeb850b 100644 --- a/test/request.test.ts +++ b/test/request.test.ts @@ -13,7 +13,7 @@ describe("octokit.request()", () => { }); it("GET /", () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://api.github.com/", { ok: true }, { @@ -26,7 +26,7 @@ describe("octokit.request()", () => { const octokit = new Octokit({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -35,13 +35,13 @@ describe("octokit.request()", () => { it("custom baseUrl", () => { const mock = fetchMock - .sandbox() + .createInstance() .getOnce("https://github.acme-inc.com/api/v3/orgs/octokit", { id: 123 }); const octokit = new Octokit({ baseUrl: "https://github.acme-inc.com/api/v3", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -51,7 +51,7 @@ describe("octokit.request()", () => { }); it("custom user agent", () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://api.github.com/", { ok: true }, { @@ -65,7 +65,7 @@ describe("octokit.request()", () => { const octokit = new Octokit({ userAgent: "myApp/1.2.3", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -73,7 +73,7 @@ describe("octokit.request()", () => { }); it("custom time zone", () => { - const mock = fetchMock.sandbox().getOnce( + const mock = fetchMock.createInstance().getOnce( "https://api.github.com/", { ok: true }, { @@ -88,7 +88,7 @@ describe("octokit.request()", () => { const octokit = new Octokit({ timeZone: "Europe/Amsterdam", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -97,7 +97,7 @@ describe("octokit.request()", () => { it("previews", async () => { const mock = fetchMock - .sandbox() + .createInstance() .getOnce( "https://api.github.com/graphql", {}, @@ -122,7 +122,7 @@ describe("octokit.request()", () => { const octokit = new Octokit({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -159,7 +159,7 @@ describe("octokit.request()", () => { }); it("sends null values (octokit/rest.js#765)", () => { - const mock = fetchMock.sandbox().patchOnce( + const mock = fetchMock.createInstance().patchOnce( "https://api.github.com/repos/epmatsw/example-repo/issues/1", {}, { @@ -172,7 +172,7 @@ describe("octokit.request()", () => { const octokit = new Octokit({ auth: "secret123", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); return octokit.request(