Skip to content

Commit

Permalink
Fix unintended logging in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Jun 1, 2023
1 parent c5d8728 commit acd8f0e
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions packages/remix-server-runtime/__tests__/server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("server", () => {
entry: {
module: {
default: async (request) => {
return new Response(`${request.method}, ${request.url}`);
return new Response(`${request.method}, ${request.url} COMPONENT`);
},
},
},
Expand All @@ -35,8 +35,10 @@ describe("server", () => {
id: routeId,
path: "",
module: {
action: () => "ACTION",
loader: () => "LOADER",
action: ({ request }) =>
new Response(`${request.method} ${request.url} ACTION`),
loader: ({ request }) =>
new Response(`${request.method} ${request.url} LOADER`),
default: () => "COMPONENT",
},
},
Expand All @@ -57,30 +59,46 @@ describe("server", () => {
} as unknown as ServerBuild;

describe("createRequestHandler", () => {
let spy = spyConsole();

beforeEach(() => {
spy.console.mockClear();
});

let allowThrough = [
["GET", "/"],
["GET", "/_data=root"],
["GET", "/?_data=root"],
["POST", "/"],
["POST", "/_data=root"],
["POST", "/?_data=root"],
["PUT", "/"],
["PUT", "/_data=root"],
["PUT", "/?_data=root"],
["DELETE", "/"],
["DELETE", "/_data=root"],
["DELETE", "/?_data=root"],
["PATCH", "/"],
["PATCH", "/_data=root"],
["PATCH", "/?_data=root"],
];
for (let [method, to] of allowThrough) {
it(`allows through ${method} request to ${to}`, async () => {
it.each(allowThrough)(
`allows through %s request to %s`,
async (method, to) => {
let handler = createRequestHandler(build);
let response = await handler(
new Request(`http://localhost:3000${to}`, {
method,
})
);

expect(await response.text()).toContain(method);
});
}
expect(response.status).toBe(200);
let text = await response.text();
expect(text).toContain(method);
let expected = !to.includes("?_data=root")
? "COMPONENT"
: method === "GET"
? "LOADER"
: "ACTION";
expect(text).toContain(expected);
expect(spy.console).not.toHaveBeenCalled();
}
);

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

0 comments on commit acd8f0e

Please sign in to comment.