Skip to content

Commit dd01737

Browse files
authored
Merge pull request #247 from dahlia/main
2 parents 6369ac5 + 64dc818 commit dd01737

7 files changed

Lines changed: 248 additions & 286 deletions

File tree

fedify/deno.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"@cfworker/json-schema": "npm:@cfworker/json-schema@^4.1.1",
2222
"@cloudflare/workers-types": "npm:@cloudflare/workers-types@^4.20250529.0",
2323
"@es-toolkit/es-toolkit": "jsr:@es-toolkit/es-toolkit@^1.38.0",
24-
"@hongminhee/deno-mock-fetch": "jsr:@hongminhee/deno-mock-fetch@^0.3.2",
2524
"@hugoalh/http-header-link": "jsr:@hugoalh/http-header-link@^1.0.2",
2625
"@multiformats/base-x": "npm:@multiformats/base-x@^4.0.1",
2726
"@opentelemetry/api": "npm:@opentelemetry/api@^1.9.0",

fedify/nodeinfo/client.test.ts

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as mf from "@hongminhee/deno-mock-fetch";
21
import { assertEquals } from "@std/assert";
2+
import fetchMock from "fetch-mock";
33
import { test } from "../testing/mod.ts";
44
import {
55
getNodeInfo,
@@ -19,20 +19,17 @@ import type {
1919
} from "./types.ts";
2020

2121
test("getNodeInfo()", async (t) => {
22-
mf.install();
22+
fetchMock.spyGlobal();
2323

24-
mf.mock("GET@/.well-known/nodeinfo", (req) => {
25-
assertEquals(new URL(req.url).host, "example.com");
26-
return new Response(
27-
JSON.stringify({
28-
links: [
29-
{
30-
rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
31-
href: "https://example.com/nodeinfo/2.1",
32-
},
33-
],
34-
}),
35-
);
24+
fetchMock.get("https://example.com/.well-known/nodeinfo", {
25+
body: {
26+
links: [
27+
{
28+
rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
29+
href: "https://example.com/nodeinfo/2.1",
30+
},
31+
],
32+
},
3633
});
3734

3835
const rawExpected = {
@@ -41,17 +38,8 @@ test("getNodeInfo()", async (t) => {
4138
usage: { users: {}, localPosts: 123, localComments: 456 },
4239
};
4340

44-
mf.mock("GET@/nodeinfo/2.1", (req) => {
45-
assertEquals(new URL(req.url).host, "example.com");
46-
return new Response(
47-
JSON.stringify(rawExpected),
48-
);
49-
});
50-
51-
mf.mock("GET@/404", (req) => {
52-
assertEquals(new URL(req.url).host, "example.com");
53-
return new Response(null, { status: 404 });
54-
});
41+
fetchMock.get("https://example.com/nodeinfo/2.1", { body: rawExpected });
42+
fetchMock.get("https://example.com/404", { status: 404 });
5543

5644
const expected: NodeInfo = {
5745
software: {
@@ -78,21 +66,19 @@ test("getNodeInfo()", async (t) => {
7866
assertEquals(info, expected);
7967
});
8068

81-
mf.mock("GET@/.well-known/nodeinfo", (req) => {
82-
assertEquals(new URL(req.url).host, "example.com");
83-
return new Response(JSON.stringify({
84-
links: [],
85-
}));
69+
fetchMock.removeRoutes();
70+
fetchMock.get("https://example.com/.well-known/nodeinfo", {
71+
body: { links: [] },
8672
});
8773

8874
await t.step("indirect: no links", async () => {
8975
const info = await getNodeInfo("https://example.com/");
9076
assertEquals(info, undefined);
9177
});
9278

93-
mf.mock("GET@/.well-known/nodeinfo", (req) => {
94-
assertEquals(new URL(req.url).host, "example.com");
95-
return new Response(null, { status: 404 });
79+
fetchMock.removeRoutes();
80+
fetchMock.get("https://example.com/.well-known/nodeinfo", {
81+
status: 404,
9682
});
9783

9884
await t.step("indirect: 404", async () => {
@@ -113,7 +99,7 @@ test("getNodeInfo()", async (t) => {
11399
assertEquals(info2, undefined);
114100
});
115101

116-
mf.uninstall();
102+
fetchMock.hardReset();
117103
});
118104

119105
test("parseNodeInfo()", () => {

fedify/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
},
105105
"devDependencies": {
106106
"@cloudflare/workers-types": "^4.20250529.0",
107-
"@hongminhee/deno-mock-fetch": "jsr:^0.3.2",
108107
"@std/assert": "jsr:^0.226.0",
109108
"@std/path": "jsr:^1.0.9",
110109
"@std/url": "jsr:1.0.0-rc.3",

0 commit comments

Comments
 (0)