Skip to content

Commit fe79a3e

Browse files
chore(deps): update dependency fetch-mock to v12 (#707)
* chore(deps): update dependency fetch-mock to v12 * updates tests to use the new v12 fetch-mock apis --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Nick Floyd <[email protected]>
1 parent 1a609e8 commit fe79a3e

File tree

9 files changed

+113
-92
lines changed

9 files changed

+113
-92
lines changed

package-lock.json

Lines changed: 24 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@types/sinonjs__fake-timers": "^8.1.5",
4747
"@vitest/coverage-v8": "^2.1.1",
4848
"esbuild": "^0.24.0",
49-
"fetch-mock": "^11.0.0",
49+
"fetch-mock": "^12.0.0",
5050
"glob": "^11.0.0",
5151
"prettier": "3.3.3",
5252
"proxy": "^2.0.0",

test/auth.test.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ beforeEach(() => {
6565

6666
describe("Authentication", () => {
6767
it("new Octokit({ auth: 'secret123' })", () => {
68-
const mock = fetchMock.sandbox().getOnce(
68+
const mock = fetchMock.createInstance().getOnce(
6969
"https://api.github.com/",
7070
{ ok: true },
7171
{
@@ -80,15 +80,15 @@ describe("Authentication", () => {
8080
const octokit = new Octokit({
8181
auth: "secret123",
8282
request: {
83-
fetch: mock,
83+
fetch: mock.fetchHandler,
8484
},
8585
});
8686

8787
return octokit.request("/");
8888
});
8989

9090
it("new Octokit({ auth: 'token secret123' })", () => {
91-
const mock = fetchMock.sandbox().getOnce(
91+
const mock = fetchMock.createInstance().getOnce(
9292
"https://api.github.com/",
9393
{ ok: true },
9494
{
@@ -103,15 +103,15 @@ describe("Authentication", () => {
103103
const octokit = new Octokit({
104104
auth: "token secret123",
105105
request: {
106-
fetch: mock,
106+
fetch: mock.fetchHandler,
107107
},
108108
});
109109

110110
return octokit.request("/");
111111
});
112112

113113
it("new Octokit({ auth: 'Token secret123' })", () => {
114-
const mock = fetchMock.sandbox().getOnce(
114+
const mock = fetchMock.createInstance().getOnce(
115115
"https://api.github.com/",
116116
{ ok: true },
117117
{
@@ -126,7 +126,7 @@ describe("Authentication", () => {
126126
const octokit = new Octokit({
127127
auth: "Token secret123",
128128
request: {
129-
fetch: mock,
129+
fetch: mock.fetchHandler,
130130
},
131131
});
132132

@@ -136,7 +136,7 @@ describe("Authentication", () => {
136136
const BEARER_TOKEN =
137137
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NTM4MTkzMTIsImV4cCI6MTU1MzgxOTM3MiwiaXNzIjoxfQ.etiSZ4LFQZ8tiMGJVqKDoGn8hxMCgwL4iLvU5xBUqbAPr4pbk_jJZmMQjuxTlOnRxq4e7NouTizGCdfohRMb3R1mpLzGPzOH9_jqSA_BWYxolsRP_WDSjuNcw6nSxrPRueMVRBKFHrqcTOZJej0djRB5pI61hDZJ_-DGtiOIFexlK3iuVKaqBkvJS5-TbTekGuipJ652g06gXuz-l8i0nHiFJldcuIruwn28hTUrjgtPbjHdSBVn_QQLKc2Fhij8OrhcGqp_D_fvb_KovVmf1X6yWiwXV5VXqWARS-JGD9JTAr2495ZlLV_E4WPxdDpz1jl6XS9HUhMuwBpaCOuipw";
138138
it("new Octokit({ auth: BEARER_TOKEN })", () => {
139-
const mock = fetchMock.sandbox().getOnce(
139+
const mock = fetchMock.createInstance().getOnce(
140140
"https://api.github.com/",
141141
{ ok: true },
142142
{
@@ -151,7 +151,7 @@ describe("Authentication", () => {
151151
const octokit = new Octokit({
152152
auth: BEARER_TOKEN,
153153
request: {
154-
fetch: mock,
154+
fetch: mock.fetchHandler,
155155
},
156156
});
157157

@@ -163,7 +163,7 @@ describe("Authentication", () => {
163163
const CLIENT_SECRET = "0123secret";
164164
const CODE = "code123";
165165

166-
const mock = fetchMock.sandbox().postOnce(
166+
const mock = fetchMock.createInstance().postOnce(
167167
"https://github.com/login/oauth/access_token",
168168
{
169169
access_token: "token123",
@@ -182,7 +182,7 @@ describe("Authentication", () => {
182182
const MyOctokit = Octokit.defaults({
183183
authStrategy: createOAuthAppAuth,
184184
request: {
185-
fetch: mock,
185+
fetch: mock.fetchHandler,
186186
},
187187
});
188188

@@ -198,12 +198,12 @@ describe("Authentication", () => {
198198
code: CODE,
199199
});
200200

201-
expect(mock.done()).toBe(true);
201+
expect(mock.callHistory.done()).toBe(true);
202202
});
203203

204204
it("auth = createAppAuth()", async () => {
205205
const mock = fetchMock
206-
.sandbox()
206+
.createInstance()
207207
.postOnce("https://api.github.com/app/installations/123/access_tokens", {
208208
token: "secret123",
209209
expires_at: "1970-01-01T01:00:00.000Z",
@@ -242,7 +242,7 @@ describe("Authentication", () => {
242242
installationId: 123,
243243
},
244244
request: {
245-
fetch: mock,
245+
fetch: mock.fetchHandler,
246246
},
247247
});
248248

@@ -251,11 +251,11 @@ describe("Authentication", () => {
251251

252252
await octokit.request("GET /app");
253253

254-
expect(mock.done()).toBe(true);
254+
expect(mock.callHistory.done()).toBe(true);
255255
});
256256

257257
it("auth = createActionAuth()", async () => {
258-
const mock = fetchMock.sandbox().getOnce(
258+
const mock = fetchMock.createInstance().getOnce(
259259
"https://api.github.com/app",
260260
{ id: 123 },
261261
{
@@ -275,7 +275,7 @@ describe("Authentication", () => {
275275
const octokit = new Octokit({
276276
authStrategy: createActionAuth,
277277
request: {
278-
fetch: mock,
278+
fetch: mock.fetchHandler,
279279
},
280280
});
281281

@@ -303,7 +303,7 @@ describe("Authentication", () => {
303303

304304
it("createAppAuth with GraphQL + GHES (probot/probot#1386)", async () => {
305305
const mock = fetchMock
306-
.sandbox()
306+
.createInstance()
307307
.postOnce(
308308
"https://fake.github-enterprise.com/api/v3/app/installations/123/access_tokens",
309309
{
@@ -334,7 +334,7 @@ describe("Authentication", () => {
334334
},
335335
baseUrl: "https://fake.github-enterprise.com/api/v3",
336336
request: {
337-
fetch: mock,
337+
fetch: mock.fetchHandler,
338338
},
339339
});
340340

@@ -344,12 +344,12 @@ describe("Authentication", () => {
344344
}
345345
}`);
346346

347-
expect(mock.done()).toBe(true);
347+
expect(mock.callHistory.done()).toBe(true);
348348
});
349349

350350
it("should pass through the logger (#1277)", async () => {
351351
const mock = fetchMock
352-
.sandbox()
352+
.createInstance()
353353
.postOnce("https://api.github.com/app/installations/2/access_tokens", {
354354
token: "installation-token-123",
355355
permissions: {},
@@ -377,7 +377,7 @@ describe("Authentication", () => {
377377
installationId: 2,
378378
},
379379
request: {
380-
fetch: mock,
380+
fetch: mock.fetchHandler,
381381
},
382382
});
383383

test/constructor.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { describe, expect, it } from "vitest";
44

55
describe("Smoke test", () => {
66
it("previews option", () => {
7-
const mock = fetchMock.sandbox().getOnce(
7+
const mock = fetchMock.createInstance().getOnce(
88
"https://api.github.com/graphql",
99
{ ok: true },
1010
{
@@ -22,15 +22,15 @@ describe("Smoke test", () => {
2222
"symmetra",
2323
],
2424
request: {
25-
fetch: mock,
25+
fetch: mock.fetchHandler,
2626
},
2727
});
2828

2929
return octokit.request("/graphql");
3030
});
3131

3232
it("timeZone option", () => {
33-
const mock = fetchMock.sandbox().getOnce(
33+
const mock = fetchMock.createInstance().getOnce(
3434
"https://api.github.com/",
3535
{ ok: true },
3636
{
@@ -44,7 +44,7 @@ describe("Smoke test", () => {
4444
const octokit = new Octokit({
4545
timeZone: "Europe/Amsterdam",
4646
request: {
47-
fetch: mock,
47+
fetch: mock.fetchHandler,
4848
},
4949
});
5050

0 commit comments

Comments
 (0)