Skip to content

Commit ccce10b

Browse files
chore(deps): update dependency fetch-mock to v12 (#774)
* chore(deps): update dependency fetch-mock to v12 * Migrate to fetch-mock v12 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: wolfy1339 <[email protected]>
1 parent 1548cb9 commit ccce10b

File tree

5 files changed

+70
-55
lines changed

5 files changed

+70
-55
lines changed

package-lock.json

Lines changed: 23 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
@@ -34,7 +34,7 @@
3434
"@vitest/coverage-v8": "^3.0.5",
3535
"camelcase": "^8.0.0",
3636
"esbuild": "^0.24.0",
37-
"fetch-mock": "^11.0.0",
37+
"fetch-mock": "^12.0.0",
3838
"github-openapi-graphql-query": "^4.3.1",
3939
"glob": "^11.0.0",
4040
"prettier": "3.4.2",

test/deprecations.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ describe("Deprecations", () => {
1616
// // have been removed. We keep them here for future reference
1717
// describe("Deprecations", () => {
1818
// it("renamed method", async () => {
19-
// const mock = fetchMock.sandbox().deleteOnce("path:/reactions/1", 204);
19+
// const mock = fetchMock.createInstance().deleteOnce("path:/reactions/1", 204);
2020
// const MyOctokit = Octokit.plugin(restEndpointMethods);
2121
// let warnCalledCount = 0;
2222
// const octokit = new MyOctokit({
2323
// request: {
24-
// fetch: mock,
24+
// fetch: mock.fetchHandler,
2525
// },
2626
// log: {
2727
// warn: (deprecation: Error) => {
@@ -39,12 +39,12 @@ describe("Deprecations", () => {
3939
// });
4040

4141
// it("deprecated method", async () => {
42-
// const mock = fetchMock.sandbox().deleteOnce("path:/reactions/1", 204);
42+
// const mock = fetchMock.createInstance().deleteOnce("path:/reactions/1", 204);
4343
// const MyOctokit = Octokit.plugin(restEndpointMethods);
4444
// let warnCalledCount = 0;
4545
// const octokit = new MyOctokit({
4646
// request: {
47-
// fetch: mock,
47+
// fetch: mock.fetchHandler,
4848
// },
4949
// log: {
5050
// warn: (deprecation: Error) => {
@@ -63,7 +63,7 @@ describe("Deprecations", () => {
6363

6464
// it("deprecated parameter", async () => {
6565
// const mock = fetchMock
66-
// .sandbox()
66+
// .createInstance()
6767
// .putOnce("path:/repos/octocat/hello-world/actions/secrets/MY_SECRET", {
6868
// ok: true,
6969
// });
@@ -72,7 +72,7 @@ describe("Deprecations", () => {
7272
// let warnCalledCount = 0;
7373
// const octokit = new MyOctokit({
7474
// request: {
75-
// fetch: mock,
75+
// fetch: mock.fetchHandler,
7676
// },
7777
// log: {
7878
// warn: (deprecation: Error) => {
@@ -99,7 +99,7 @@ describe("Deprecations", () => {
9999

100100
// it("deprecated parameter + new parameter", async () => {
101101
// const mock = fetchMock
102-
// .sandbox()
102+
// .createInstance()
103103
// .putOnce("path:/repos/octocat/hello-world/actions/secrets/MY_SECRET2", {
104104
// ok: true,
105105
// });
@@ -108,7 +108,7 @@ describe("Deprecations", () => {
108108
// let warnCalledCount = 0;
109109
// const octokit = new MyOctokit({
110110
// request: {
111-
// fetch: mock,
111+
// fetch: mock.fetchHandler,
112112
// },
113113
// log: {
114114
// warn: (deprecation: Error) => {
@@ -136,7 +136,7 @@ describe("Deprecations", () => {
136136

137137
// it("deprecated method + deprecated parameter", async () => {
138138
// const mock = fetchMock
139-
// .sandbox()
139+
// .createInstance()
140140
// .putOnce("path:/repos/octocat/hello-world/actions/secrets/MY_SECRET", {
141141
// ok: true,
142142
// });
@@ -145,7 +145,7 @@ describe("Deprecations", () => {
145145
// const deprecations: string[] = [];
146146
// const octokit = new MyOctokit({
147147
// request: {
148-
// fetch: mock,
148+
// fetch: mock.fetchHandler,
149149
// },
150150
// log: {
151151
// warn: (deprecation: Error) => {

test/issues.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { restEndpointMethods } from "../src/index.ts";
66

77
describe("https://github.com/octokit/plugin-rest-endpoint-methods.js/issues/83", () => {
88
it("git.gists.update({ gist_id, files })", async () => {
9-
const mock = fetchMock.sandbox().patchOnce(
9+
const mock = fetchMock.createInstance().patchOnce(
1010
"path:/gists/gist123",
1111
{ ok: true },
1212
{
@@ -25,7 +25,7 @@ describe("https://github.com/octokit/plugin-rest-endpoint-methods.js/issues/83",
2525
const octokit = new MyOctokit({
2626
auth: "secret123",
2727
request: {
28-
fetch: mock,
28+
fetch: mock.fetchHandler,
2929
},
3030
});
3131

test/rest-endpoint-methods.test.ts

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { Api } from "../src/types.ts";
1111

1212
describe("REST API endpoint methods", () => {
1313
it("README example", async () => {
14-
const mock = fetchMock.sandbox().post(
14+
const mock = fetchMock.createInstance().post(
1515
"path:/user/repos",
1616
{ id: 1 },
1717
{
@@ -25,7 +25,7 @@ describe("REST API endpoint methods", () => {
2525
const octokit = new MyOctokit({
2626
auth: "secret123",
2727
request: {
28-
fetch: mock,
28+
fetch: mock.fetchHandler,
2929
},
3030
});
3131

@@ -39,13 +39,13 @@ describe("REST API endpoint methods", () => {
3939

4040
it("Required preview header", async () => {
4141
const mock = fetchMock
42-
.sandbox()
42+
.createInstance()
4343
.getOnce("path:/codes_of_conduct", [{ key: "mit" }]);
4444

4545
const MyOctokit = Octokit.plugin(restEndpointMethods);
4646
const octokit = new MyOctokit({
4747
request: {
48-
fetch: mock,
48+
fetch: mock.fetchHandler,
4949
},
5050
});
5151

@@ -56,24 +56,26 @@ describe("REST API endpoint methods", () => {
5656
});
5757

5858
it("octokit.rest.markdown.renderRaw()", async () => {
59-
const mock = fetchMock.sandbox().postOnce(
60-
"path:/markdown/raw",
59+
const mock = fetchMock.createInstance().postOnce(
60+
({ url, options: { body } }) => {
61+
if (url === "https://api.github.com/markdown/raw") {
62+
expect(body).toEqual("# Hello, world!");
63+
return true;
64+
}
65+
return false;
66+
},
6167
{ ok: true },
6268
{
6369
headers: {
6470
"content-type": "text/plain; charset=utf-8",
6571
},
66-
matcher: (_, { body }) => {
67-
expect(body).toEqual("# Hello, world!");
68-
return true;
69-
},
7072
},
7173
);
7274

7375
const MyOctokit = Octokit.plugin(restEndpointMethods);
7476
const octokit = new MyOctokit({
7577
request: {
76-
fetch: mock,
78+
fetch: mock.fetchHandler,
7779
},
7880
});
7981

@@ -89,8 +91,18 @@ describe("REST API endpoint methods", () => {
8991
});
9092

9193
it("octokit.rest.repos.uploadReleaseAsset()", async () => {
92-
const mock = fetchMock.sandbox().postOnce(
93-
"https://uploads.github.com/repos/octocat/hello-world/releases/123/assets",
94+
const mock = fetchMock.createInstance().postOnce(
95+
({ url, options: { body } }) => {
96+
const path = new URL(url);
97+
if (
98+
`${path.origin}${path.pathname}` ===
99+
"https://uploads.github.com/repos/octocat/hello-world/releases/123/assets"
100+
) {
101+
expect(body).toEqual("test 1, 2");
102+
return true;
103+
}
104+
return false;
105+
},
94106
{ ok: true },
95107
{
96108
headers: {
@@ -100,18 +112,14 @@ describe("REST API endpoint methods", () => {
100112
name: "test.txt",
101113
label: "test",
102114
},
103-
matcher: (_, { body }) => {
104-
expect(body).toEqual("test 1, 2");
105-
return true;
106-
},
107115
},
108116
);
109117

110118
const MyOctokit = Octokit.plugin(restEndpointMethods);
111119
const octokit = new MyOctokit({
112120
auth: "secret123",
113121
request: {
114-
fetch: mock,
122+
fetch: mock.fetchHandler,
115123
},
116124
});
117125

@@ -135,7 +143,7 @@ describe("REST API endpoint methods", () => {
135143
});
136144

137145
it("octokit.rest.repos.addProtectedBranchRequiredStatusChecksContexts(): `contexts` option value is sent as request body without namespace", async () => {
138-
const mock = fetchMock.sandbox().postOnce(
146+
const mock = fetchMock.createInstance().postOnce(
139147
"https://api.github.com/repos/octocat/hello-world/branches/latest/protection/required_status_checks/contexts",
140148
{ ok: true },
141149
{
@@ -147,7 +155,7 @@ describe("REST API endpoint methods", () => {
147155
const octokit = new MyOctokit({
148156
auth: "secret123",
149157
request: {
150-
fetch: mock,
158+
fetch: mock.fetchHandler,
151159
},
152160
});
153161

@@ -167,14 +175,14 @@ describe("REST API endpoint methods", () => {
167175

168176
it("octokit.rest.apps.listInstallations(): method without options (octokit/rest.js#818)", async () => {
169177
const mock = fetchMock
170-
.sandbox()
178+
.createInstance()
171179
.getOnce("https://api.github.com/app/installations", { ok: true });
172180

173181
const MyOctokit = Octokit.plugin(restEndpointMethods);
174182
const octokit = new MyOctokit({
175183
auth: "secret123",
176184
request: {
177-
fetch: mock,
185+
fetch: mock.fetchHandler,
178186
},
179187
});
180188

@@ -186,7 +194,7 @@ describe("REST API endpoint methods", () => {
186194

187195
beforeEach(() => {
188196
const networkMock = fetchMock
189-
.sandbox()
197+
.createInstance()
190198
.getOnce(
191199
"https://api.github.com/repos/octokit/plugin-rest-endpoint-methods/issues/1/labels",
192200
[{ name: "mocked from network" }],
@@ -195,7 +203,7 @@ describe("REST API endpoint methods", () => {
195203
const MyOctokit = Octokit.plugin(restEndpointMethods);
196204
octokit = new MyOctokit({
197205
request: {
198-
fetch: networkMock,
206+
fetch: networkMock.fetchHandler,
199207
},
200208
});
201209
});
@@ -278,7 +286,7 @@ describe("REST API endpoint methods", () => {
278286
// We will deprecate the `octokit.*` methods in future, but for now we just make sure they are set
279287

280288
it("legacyRestEndpointMethods", async () => {
281-
const mock = fetchMock.sandbox().post(
289+
const mock = fetchMock.createInstance().post(
282290
"path:/user/repos",
283291
{ id: 1 },
284292
{
@@ -292,7 +300,7 @@ describe("REST API endpoint methods", () => {
292300
const octokit = new MyOctokit({
293301
auth: "secret123",
294302
request: {
295-
fetch: mock,
303+
fetch: mock.fetchHandler,
296304
},
297305
});
298306

0 commit comments

Comments
 (0)