Skip to content

Commit bad97ba

Browse files
committed
fix(tests): replace msw HttpResponse with Response
- Updated test files to use native Response instead of HttpResponse. - Update msw http imports to use "msw/core/http" Signed-off-by: J3m5 <5523410+J3m5@users.noreply.github.com>
1 parent 8600cfb commit bad97ba

File tree

3 files changed

+28
-47
lines changed

3 files changed

+28
-47
lines changed

src/hydra/fetchJsonLd.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { http, HttpResponse } from "msw";
1+
import { http } from "msw/core/http";
22
import { assert, expect, test } from "vitest";
33
import { server } from "../../vitest.setup.js";
44
import fetchJsonLd from "./fetchJsonLd.js";
@@ -14,7 +14,7 @@ const httpResponse = {
1414
test("fetch a JSON-LD document", async () => {
1515
server.use(
1616
http.get("http://localhost/foo.jsonld", () =>
17-
HttpResponse.json(httpResponse, {
17+
Response.json(httpResponse, {
1818
headers: { "Content-Type": "application/ld+json" },
1919
status: 200,
2020
statusText: "OK",
@@ -36,7 +36,7 @@ test("fetch a non JSON-LD document", async () => {
3636
http.get(
3737
"http://localhost/foo.jsonld",
3838
() =>
39-
new HttpResponse(`<body>Hello</body>`, {
39+
new Response(`<body>Hello</body>`, {
4040
headers: { "Content-Type": "text/html" },
4141
status: 200,
4242
statusText: "OK",
@@ -53,7 +53,7 @@ test("fetch a non JSON-LD document", async () => {
5353
test("fetch an error with Content-Type application/ld+json", async () => {
5454
server.use(
5555
http.get("http://localhost/foo.jsonld", () =>
56-
HttpResponse.json(httpResponse, {
56+
Response.json(httpResponse, {
5757
status: 500,
5858
statusText: "Internal Server Error",
5959
headers: { "Content-Type": "application/ld+json" },
@@ -75,7 +75,7 @@ test("fetch an error with Content-Type application/ld+json", async () => {
7575
test("fetch an error with Content-Type application/error+json", async () => {
7676
server.use(
7777
http.get("http://localhost/foo.jsonld", () =>
78-
HttpResponse.json(httpResponse, {
78+
Response.json(httpResponse, {
7979
status: 400,
8080
statusText: "Bad Request",
8181
headers: { "Content-Type": "application/error+json" },
@@ -99,7 +99,7 @@ test("fetch an empty document", async () => {
9999
http.get(
100100
"http://localhost/foo.jsonld",
101101
() =>
102-
new HttpResponse(``, {
102+
new Response(null, {
103103
status: 204,
104104
statusText: "No Content",
105105
headers: { "Content-Type": "text/html" },

src/hydra/parseHydraDocumentation.test.ts

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { http, HttpResponse } from "msw";
1+
import { http } from "msw/core/http";
22
import { assert, expect, test, vi } from "vitest";
33
import { server } from "../../vitest.setup.js";
44
import { parsedJsonReplacer } from "../core/utils/index.js";
@@ -1299,10 +1299,8 @@ const init = {
12991299

13001300
test("parse a Hydra documentation", async () => {
13011301
server.use(
1302-
http.get("http://localhost", () => HttpResponse.json(entrypoint, init)),
1303-
http.get("http://localhost/docs.jsonld", () =>
1304-
HttpResponse.json(docs, init),
1305-
),
1302+
http.get("http://localhost", () => Response.json(entrypoint, init)),
1303+
http.get("http://localhost/docs.jsonld", () => Response.json(docs, init)),
13061304
);
13071305

13081306
const fetchSpy = vi.spyOn(globalThis, "fetch");
@@ -1332,10 +1330,8 @@ function getHeaders(): Headers {
13321330

13331331
test("parse a Hydra documentation using dynamic headers", async () => {
13341332
server.use(
1335-
http.get("http://localhost", () => HttpResponse.json(entrypoint, init)),
1336-
http.get("http://localhost/docs.jsonld", () =>
1337-
HttpResponse.json(docs, init),
1338-
),
1333+
http.get("http://localhost", () => Response.json(entrypoint, init)),
1334+
http.get("http://localhost/docs.jsonld", () => Response.json(docs, init)),
13391335
);
13401336

13411337
const fetchSpy = vi.spyOn(globalThis, "fetch");
@@ -1362,10 +1358,8 @@ test("parse a Hydra documentation using dynamic headers", async () => {
13621358

13631359
test("parse a Hydra documentation (http://localhost/)", async () => {
13641360
server.use(
1365-
http.get("http://localhost", () => HttpResponse.json(entrypoint, init)),
1366-
http.get("http://localhost/docs.jsonld", () =>
1367-
HttpResponse.json(docs, init),
1368-
),
1361+
http.get("http://localhost", () => Response.json(entrypoint, init)),
1362+
http.get("http://localhost/docs.jsonld", () => Response.json(docs, init)),
13691363
);
13701364

13711365
const data = await parseHydraDocumentation("http://localhost/");
@@ -1393,9 +1387,7 @@ test("parse a Hydra documentation without authorization", async () => {
13931387
};
13941388

13951389
server.use(
1396-
http.get("http://localhost", () =>
1397-
HttpResponse.json(expectedResponse, init),
1398-
),
1390+
http.get("http://localhost", () => Response.json(expectedResponse, init)),
13991391
);
14001392
const promise = parseHydraDocumentation("http://localhost");
14011393
await expect(promise).rejects.toMatchObject({
@@ -1434,10 +1426,8 @@ test('Parse entrypoint without "@type" key', async () => {
14341426
};
14351427

14361428
server.use(
1437-
http.get("http://localhost", () => HttpResponse.json(entrypoint, init)),
1438-
http.get("http://localhost/docs.jsonld", () =>
1439-
HttpResponse.json(docs, init),
1440-
),
1429+
http.get("http://localhost", () => Response.json(entrypoint, init)),
1430+
http.get("http://localhost/docs.jsonld", () => Response.json(docs, init)),
14411431
);
14421432

14431433
await expect(parseHydraDocumentation("http://localhost/")).rejects.toThrow(
@@ -1482,10 +1472,8 @@ test('Parse entrypoint class without "supportedClass" key', async () => {
14821472
};
14831473

14841474
server.use(
1485-
http.get("http://localhost", () => HttpResponse.json(entrypoint, init)),
1486-
http.get("http://localhost/docs.jsonld", () =>
1487-
HttpResponse.json(docs, init),
1488-
),
1475+
http.get("http://localhost", () => Response.json(entrypoint, init)),
1476+
http.get("http://localhost/docs.jsonld", () => Response.json(docs, init)),
14891477
);
14901478

14911479
await expect(parseHydraDocumentation("http://localhost/")).rejects.toThrow(
@@ -1546,10 +1534,8 @@ test('Parse entrypoint class without "supportedProperty" key', async () => {
15461534
'The entrypoint definition has no "http://www.w3.org/ns/hydra/core#supportedProperty" key or it is not an array.';
15471535

15481536
server.use(
1549-
http.get("http://localhost", () => HttpResponse.json(entrypoint, init)),
1550-
http.get("http://localhost/docs.jsonld", () =>
1551-
HttpResponse.json(docs, init),
1552-
),
1537+
http.get("http://localhost", () => Response.json(entrypoint, init)),
1538+
http.get("http://localhost/docs.jsonld", () => Response.json(docs, init)),
15531539
);
15541540

15551541
await expect(parseHydraDocumentation("http://localhost/")).rejects.toThrow(
@@ -1561,11 +1547,8 @@ test("Invalid docs JSON", async () => {
15611547
const docs = `{foo,}`;
15621548

15631549
server.use(
1564-
http.get("http://localhost", () => HttpResponse.json(entrypoint, init)),
1565-
http.get(
1566-
"http://localhost/docs.jsonld",
1567-
() => new HttpResponse(docs, init),
1568-
),
1550+
http.get("http://localhost", () => Response.json(entrypoint, init)),
1551+
http.get("http://localhost/docs.jsonld", () => new Response(docs, init)),
15691552
);
15701553

15711554
const promise = parseHydraDocumentation("http://localhost/");
@@ -1578,7 +1561,7 @@ test("Invalid docs JSON", async () => {
15781561
test("Invalid entrypoint JSON", async () => {
15791562
const entrypoint = `{foo,}`;
15801563
server.use(
1581-
http.get("http://localhost", () => new HttpResponse(entrypoint, init)),
1564+
http.get("http://localhost", () => new Response(entrypoint, init)),
15821565
);
15831566

15841567
const promise = parseHydraDocumentation("http://localhost/");
@@ -1591,12 +1574,10 @@ test("Invalid entrypoint JSON", async () => {
15911574
test("Resource parameters can be retrieved", async () => {
15921575
const fetchSpy = vi.spyOn(globalThis, "fetch");
15931576
server.use(
1594-
http.get("http://localhost", () => HttpResponse.json(entrypoint, init)),
1595-
http.get("http://localhost/docs.jsonld", () =>
1596-
HttpResponse.json(docs, init),
1597-
),
1577+
http.get("http://localhost", () => Response.json(entrypoint, init)),
1578+
http.get("http://localhost/docs.jsonld", () => Response.json(docs, init)),
15981579
http.get("http://localhost/books", () =>
1599-
HttpResponse.json(resourceCollectionWithParameters, init),
1580+
Response.json(resourceCollectionWithParameters, init),
16001581
),
16011582
);
16021583

vitest.setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { setupServer } from "msw/node";
21
import type { SetupServerApi } from "msw/node";
3-
import { beforeAll, afterEach, afterAll } from "vitest";
2+
import { setupServer } from "msw/node";
3+
import { afterAll, afterEach, beforeAll } from "vitest";
44

55
export const server: SetupServerApi = setupServer();
66

0 commit comments

Comments
 (0)