Skip to content

Commit

Permalink
chore(deps): update dependency fetch-mock to v12 (#606)
Browse files Browse the repository at this point in the history
* 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 <nicholas.floyd.info@gmail.com>
  • Loading branch information
renovate[bot] and nickfloyd authored Dec 26, 2024
1 parent 86bebd1 commit 2764dcd
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 156 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 @@
"@types/jest": "^29.0.0",
"@types/node": "^22.0.0",
"esbuild": "^0.24.0",
"fetch-mock": "^11.0.0",
"fetch-mock": "^12.0.0",
"glob": "^11.0.0",
"jest": "^29.0.0",
"prettier": "3.4.2",
Expand Down
62 changes: 34 additions & 28 deletions test/defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,22 @@ describe("graphql.defaults()", () => {
},
};

const mock = fetchMock.createInstance().post(
"https://api.github.com/graphql",
{ data: mockData },
{
headers: {
authorization: "token secret123",
},
},
);

const authenticatedGraphql = graphql.defaults({
headers: {
authorization: `token secret123`,
},
request: {
fetch: fetchMock.sandbox().post(
"https://api.github.com/graphql",
{ data: mockData },
{
headers: {
authorization: "token secret123",
},
},
),
fetch: mock.fetchHandler,
},
});
return authenticatedGraphql(`{
Expand Down Expand Up @@ -92,20 +94,22 @@ describe("graphql.defaults()", () => {
},
};

const mock = fetchMock.createInstance().post(
"https://github.acme-inc.com/api/graphql",
{ data: mockData },
{
headers: {
authorization: "token secret123",
},
},
);

const authenticatedGraphql = graphql.defaults({
headers: {
authorization: `token secret123`,
},
request: {
fetch: fetchMock.sandbox().post(
"https://github.acme-inc.com/api/graphql",
{ data: mockData },
{
headers: {
authorization: "token secret123",
},
},
),
fetch: mock.fetchHandler,
},
});
const acmeGraphql = authenticatedGraphql.defaults({
Expand All @@ -127,21 +131,23 @@ describe("graphql.defaults()", () => {
});

it("handle baseUrl set with /api/v3 suffix", () => {
const mock = fetchMock.createInstance().post(
"https://github.acme-inc.com/api/graphql",
{ data: { ok: true } },
{
headers: {
authorization: "token secret123",
},
},
);

const ghesGraphQl = graphql.defaults({
baseUrl: "https://github.acme-inc.com/api/v3",
headers: {
authorization: `token secret123`,
},
request: {
fetch: fetchMock.sandbox().post(
"https://github.acme-inc.com/api/graphql",
{ data: { ok: true } },
{
headers: {
authorization: "token secret123",
},
},
),
fetch: mock.fetchHandler,
},
});

Expand Down Expand Up @@ -182,7 +188,7 @@ describe("graphql.defaults()", () => {
authorization: `token secret123`,
},
request: {
fetch: fetchMock.sandbox().post(
fetch: fetchMock.createInstance().post(
"https://github.acme-inc.com/api/graphql",
{ data: mockData },
{
Expand Down
38 changes: 25 additions & 13 deletions test/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ describe("errors", () => {
],
};

const mock = fetchMock
.createInstance()
.post("https://api.github.com/graphql", mockResponse);

return graphql(query, {
headers: {
authorization: `token secret123`,
},
request: {
fetch: fetchMock
.sandbox()
.post("https://api.github.com/graphql", mockResponse),
fetch: mock.fetchHandler,
},
})
.then(() => {
Expand Down Expand Up @@ -72,14 +74,16 @@ describe("errors", () => {
],
};

const mock = fetchMock
.createInstance()
.post("https://api.github.com/graphql", mockResponse);

return graphql(query, {
headers: {
authorization: `token secret123`,
},
request: {
fetch: fetchMock
.sandbox()
.post("https://api.github.com/graphql", mockResponse),
fetch: mock.fetchHandler,
},
})
.then(() => {
Expand Down Expand Up @@ -131,17 +135,21 @@ describe("errors", () => {
],
};

const mock = fetchMock
.createInstance()
.post("https://api.github.com/graphql", {
body: mockResponse,
headers: {
"x-github-request-id": "C5E6:259A:1351B40:2E88B87:5F1F9C41",
},
});

return graphql(query, {
headers: {
authorization: `token secret123`,
},
request: {
fetch: fetchMock.sandbox().post("https://api.github.com/graphql", {
body: mockResponse,
headers: {
"x-github-request-id": "C5E6:259A:1351B40:2E88B87:5F1F9C41",
},
}),
fetch: mock.fetchHandler,
},
})
.then(() => {
Expand Down Expand Up @@ -173,12 +181,16 @@ describe("errors", () => {
}
}`;

const mock = fetchMock
.createInstance()
.post("https://api.github.com/graphql", 500);

return graphql(query, {
headers: {
authorization: `token secret123`,
},
request: {
fetch: fetchMock.sandbox().post("https://api.github.com/graphql", 500),
fetch: mock.fetchHandler,
},
})
.then(() => {
Expand Down
Loading

0 comments on commit 2764dcd

Please sign in to comment.