Skip to content

Commit acd8f0e

Browse files
committed
Fix unintended logging in unit test
1 parent c5d8728 commit acd8f0e

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

packages/remix-server-runtime/__tests__/server-test.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("server", () => {
2626
entry: {
2727
module: {
2828
default: async (request) => {
29-
return new Response(`${request.method}, ${request.url}`);
29+
return new Response(`${request.method}, ${request.url} COMPONENT`);
3030
},
3131
},
3232
},
@@ -35,8 +35,10 @@ describe("server", () => {
3535
id: routeId,
3636
path: "",
3737
module: {
38-
action: () => "ACTION",
39-
loader: () => "LOADER",
38+
action: ({ request }) =>
39+
new Response(`${request.method} ${request.url} ACTION`),
40+
loader: ({ request }) =>
41+
new Response(`${request.method} ${request.url} LOADER`),
4042
default: () => "COMPONENT",
4143
},
4244
},
@@ -57,30 +59,46 @@ describe("server", () => {
5759
} as unknown as ServerBuild;
5860

5961
describe("createRequestHandler", () => {
62+
let spy = spyConsole();
63+
64+
beforeEach(() => {
65+
spy.console.mockClear();
66+
});
67+
6068
let allowThrough = [
6169
["GET", "/"],
62-
["GET", "/_data=root"],
70+
["GET", "/?_data=root"],
6371
["POST", "/"],
64-
["POST", "/_data=root"],
72+
["POST", "/?_data=root"],
6573
["PUT", "/"],
66-
["PUT", "/_data=root"],
74+
["PUT", "/?_data=root"],
6775
["DELETE", "/"],
68-
["DELETE", "/_data=root"],
76+
["DELETE", "/?_data=root"],
6977
["PATCH", "/"],
70-
["PATCH", "/_data=root"],
78+
["PATCH", "/?_data=root"],
7179
];
72-
for (let [method, to] of allowThrough) {
73-
it(`allows through ${method} request to ${to}`, async () => {
80+
it.each(allowThrough)(
81+
`allows through %s request to %s`,
82+
async (method, to) => {
7483
let handler = createRequestHandler(build);
7584
let response = await handler(
7685
new Request(`http://localhost:3000${to}`, {
7786
method,
7887
})
7988
);
8089

81-
expect(await response.text()).toContain(method);
82-
});
83-
}
90+
expect(response.status).toBe(200);
91+
let text = await response.text();
92+
expect(text).toContain(method);
93+
let expected = !to.includes("?_data=root")
94+
? "COMPONENT"
95+
: method === "GET"
96+
? "LOADER"
97+
: "ACTION";
98+
expect(text).toContain(expected);
99+
expect(spy.console).not.toHaveBeenCalled();
100+
}
101+
);
84102

85103
it("strips body for HEAD requests", async () => {
86104
let handler = createRequestHandler(build);

0 commit comments

Comments
 (0)