Skip to content

Commit

Permalink
chore(deps): update dependency fetch-mock to v12 (#774)
Browse files Browse the repository at this point in the history
* 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 <webmaster@wolfy1339.com>
  • Loading branch information
renovate[bot] and wolfy1339 authored Feb 7, 2025
1 parent 1548cb9 commit ccce10b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 55 deletions.
39 changes: 23 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@vitest/coverage-v8": "^3.0.5",
"camelcase": "^8.0.0",
"esbuild": "^0.24.0",
"fetch-mock": "^11.0.0",
"fetch-mock": "^12.0.0",
"github-openapi-graphql-query": "^4.3.1",
"glob": "^11.0.0",
"prettier": "3.4.2",
Expand Down
20 changes: 10 additions & 10 deletions test/deprecations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ describe("Deprecations", () => {
// // have been removed. We keep them here for future reference
// describe("Deprecations", () => {
// it("renamed method", async () => {
// const mock = fetchMock.sandbox().deleteOnce("path:/reactions/1", 204);
// const mock = fetchMock.createInstance().deleteOnce("path:/reactions/1", 204);
// const MyOctokit = Octokit.plugin(restEndpointMethods);
// let warnCalledCount = 0;
// const octokit = new MyOctokit({
// request: {
// fetch: mock,
// fetch: mock.fetchHandler,
// },
// log: {
// warn: (deprecation: Error) => {
Expand All @@ -39,12 +39,12 @@ describe("Deprecations", () => {
// });

// it("deprecated method", async () => {
// const mock = fetchMock.sandbox().deleteOnce("path:/reactions/1", 204);
// const mock = fetchMock.createInstance().deleteOnce("path:/reactions/1", 204);
// const MyOctokit = Octokit.plugin(restEndpointMethods);
// let warnCalledCount = 0;
// const octokit = new MyOctokit({
// request: {
// fetch: mock,
// fetch: mock.fetchHandler,
// },
// log: {
// warn: (deprecation: Error) => {
Expand All @@ -63,7 +63,7 @@ describe("Deprecations", () => {

// it("deprecated parameter", async () => {
// const mock = fetchMock
// .sandbox()
// .createInstance()
// .putOnce("path:/repos/octocat/hello-world/actions/secrets/MY_SECRET", {
// ok: true,
// });
Expand All @@ -72,7 +72,7 @@ describe("Deprecations", () => {
// let warnCalledCount = 0;
// const octokit = new MyOctokit({
// request: {
// fetch: mock,
// fetch: mock.fetchHandler,
// },
// log: {
// warn: (deprecation: Error) => {
Expand All @@ -99,7 +99,7 @@ describe("Deprecations", () => {

// it("deprecated parameter + new parameter", async () => {
// const mock = fetchMock
// .sandbox()
// .createInstance()
// .putOnce("path:/repos/octocat/hello-world/actions/secrets/MY_SECRET2", {
// ok: true,
// });
Expand All @@ -108,7 +108,7 @@ describe("Deprecations", () => {
// let warnCalledCount = 0;
// const octokit = new MyOctokit({
// request: {
// fetch: mock,
// fetch: mock.fetchHandler,
// },
// log: {
// warn: (deprecation: Error) => {
Expand Down Expand Up @@ -136,7 +136,7 @@ describe("Deprecations", () => {

// it("deprecated method + deprecated parameter", async () => {
// const mock = fetchMock
// .sandbox()
// .createInstance()
// .putOnce("path:/repos/octocat/hello-world/actions/secrets/MY_SECRET", {
// ok: true,
// });
Expand All @@ -145,7 +145,7 @@ describe("Deprecations", () => {
// const deprecations: string[] = [];
// const octokit = new MyOctokit({
// request: {
// fetch: mock,
// fetch: mock.fetchHandler,
// },
// log: {
// warn: (deprecation: Error) => {
Expand Down
4 changes: 2 additions & 2 deletions test/issues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { restEndpointMethods } from "../src/index.ts";

describe("https://github.com/octokit/plugin-rest-endpoint-methods.js/issues/83", () => {
it("git.gists.update({ gist_id, files })", async () => {
const mock = fetchMock.sandbox().patchOnce(
const mock = fetchMock.createInstance().patchOnce(
"path:/gists/gist123",
{ ok: true },
{
Expand All @@ -25,7 +25,7 @@ describe("https://github.com/octokit/plugin-rest-endpoint-methods.js/issues/83",
const octokit = new MyOctokit({
auth: "secret123",
request: {
fetch: mock,
fetch: mock.fetchHandler,
},
});

Expand Down
60 changes: 34 additions & 26 deletions test/rest-endpoint-methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { Api } from "../src/types.ts";

describe("REST API endpoint methods", () => {
it("README example", async () => {
const mock = fetchMock.sandbox().post(
const mock = fetchMock.createInstance().post(
"path:/user/repos",
{ id: 1 },
{
Expand All @@ -25,7 +25,7 @@ describe("REST API endpoint methods", () => {
const octokit = new MyOctokit({
auth: "secret123",
request: {
fetch: mock,
fetch: mock.fetchHandler,
},
});

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

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

const MyOctokit = Octokit.plugin(restEndpointMethods);
const octokit = new MyOctokit({
request: {
fetch: mock,
fetch: mock.fetchHandler,
},
});

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

it("octokit.rest.markdown.renderRaw()", async () => {
const mock = fetchMock.sandbox().postOnce(
"path:/markdown/raw",
const mock = fetchMock.createInstance().postOnce(
({ url, options: { body } }) => {
if (url === "https://api.github.com/markdown/raw") {
expect(body).toEqual("# Hello, world!");
return true;
}
return false;
},
{ ok: true },
{
headers: {
"content-type": "text/plain; charset=utf-8",
},
matcher: (_, { body }) => {
expect(body).toEqual("# Hello, world!");
return true;
},
},
);

const MyOctokit = Octokit.plugin(restEndpointMethods);
const octokit = new MyOctokit({
request: {
fetch: mock,
fetch: mock.fetchHandler,
},
});

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

it("octokit.rest.repos.uploadReleaseAsset()", async () => {
const mock = fetchMock.sandbox().postOnce(
"https://uploads.github.com/repos/octocat/hello-world/releases/123/assets",
const mock = fetchMock.createInstance().postOnce(
({ url, options: { body } }) => {
const path = new URL(url);
if (
`${path.origin}${path.pathname}` ===
"https://uploads.github.com/repos/octocat/hello-world/releases/123/assets"
) {
expect(body).toEqual("test 1, 2");
return true;
}
return false;
},
{ ok: true },
{
headers: {
Expand All @@ -100,18 +112,14 @@ describe("REST API endpoint methods", () => {
name: "test.txt",
label: "test",
},
matcher: (_, { body }) => {
expect(body).toEqual("test 1, 2");
return true;
},
},
);

const MyOctokit = Octokit.plugin(restEndpointMethods);
const octokit = new MyOctokit({
auth: "secret123",
request: {
fetch: mock,
fetch: mock.fetchHandler,
},
});

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

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

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

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

const MyOctokit = Octokit.plugin(restEndpointMethods);
const octokit = new MyOctokit({
auth: "secret123",
request: {
fetch: mock,
fetch: mock.fetchHandler,
},
});

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

beforeEach(() => {
const networkMock = fetchMock
.sandbox()
.createInstance()
.getOnce(
"https://api.github.com/repos/octokit/plugin-rest-endpoint-methods/issues/1/labels",
[{ name: "mocked from network" }],
Expand All @@ -195,7 +203,7 @@ describe("REST API endpoint methods", () => {
const MyOctokit = Octokit.plugin(restEndpointMethods);
octokit = new MyOctokit({
request: {
fetch: networkMock,
fetch: networkMock.fetchHandler,
},
});
});
Expand Down Expand Up @@ -278,7 +286,7 @@ describe("REST API endpoint methods", () => {
// We will deprecate the `octokit.*` methods in future, but for now we just make sure they are set

it("legacyRestEndpointMethods", async () => {
const mock = fetchMock.sandbox().post(
const mock = fetchMock.createInstance().post(
"path:/user/repos",
{ id: 1 },
{
Expand All @@ -292,7 +300,7 @@ describe("REST API endpoint methods", () => {
const octokit = new MyOctokit({
auth: "secret123",
request: {
fetch: mock,
fetch: mock.fetchHandler,
},
});

Expand Down

0 comments on commit ccce10b

Please sign in to comment.