Skip to content

Commit

Permalink
Fix up tests expecting unsanitized errors
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Mar 6, 2023
1 parent 2c9d74b commit 4e2096a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
19 changes: 13 additions & 6 deletions integration/error-boundary-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,9 @@ test.describe("ErrorBoundary", () => {
await page.waitForSelector("#child-error");
// Preserves parent loader data
expect(await app.getHtml("#parent-data")).toMatch("PARENT");
expect(await app.getHtml("#child-error")).toMatch("Broken!");
expect(await app.getHtml("#child-error")).toMatch(
"Unexpected Server Error"
);
});

test("renders own boundary in fetcher action submission without action from other routes", async ({
Expand Down Expand Up @@ -988,9 +990,12 @@ test.describe("Default ErrorBoundary", () => {

test.describe("When the root route does not have a boundary", () => {
test.beforeAll(async () => {
fixture = await createFixture({
files: getFiles({ includeRootErrorBoundary: false }),
});
fixture = await createFixture(
{
files: getFiles({ includeRootErrorBoundary: false }),
},
ServerMode.Development
);
appFixture = await createAppFixture(fixture, ServerMode.Development);
});

Expand Down Expand Up @@ -1074,7 +1079,8 @@ test.describe("Default ErrorBoundary", () => {
expect(res.status).toBe(500);
let text = await res.text();
expect(text).toMatch("Root Error Boundary");
expect(text).toMatch("Loader Error");
expect(text).toMatch("Unexpected Server Error");
expect(text).not.toMatch("Loader Error");
expect(text).not.toMatch("Application Error");
});

Expand All @@ -1083,7 +1089,8 @@ test.describe("Default ErrorBoundary", () => {
expect(res.status).toBe(500);
let text = await res.text();
expect(text).toMatch("Root Error Boundary");
expect(text).toMatch("Render Error");
expect(text).toMatch("Unexpected Server Error");
expect(text).not.toMatch("Render Error");
expect(text).not.toMatch("Application Error");
});
});
Expand Down
46 changes: 36 additions & 10 deletions packages/remix-server-runtime/__tests__/server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,9 @@ describe("shared server runtime", () => {
expect(calls.length).toBe(1 * DATA_CALL_MULTIPIER);
let context = calls[0][3].staticHandlerContext as StaticHandlerContext;
expect(context.errors).toBeTruthy();
expect(context.errors!.root.message).toBe("index");
expect(context.errors!.root).toBeInstanceOf(Error);
expect(context.errors!.root.message).toBe("Unexpected Server Error");
expect(context.errors!.root.stack).toBeUndefined();
expect(context.loaderData).toEqual({
root: "root",
});
Expand Down Expand Up @@ -1278,7 +1280,11 @@ describe("shared server runtime", () => {
expect(calls.length).toBe(1 * DATA_CALL_MULTIPIER);
let context = calls[0][3].staticHandlerContext as StaticHandlerContext;
expect(context.errors).toBeTruthy();
expect(context.errors!["routes/index"].message).toBe("index");
expect(context.errors!["routes/index"]).toBeInstanceOf(Error);
expect(context.errors!["routes/index"].message).toBe(
"Unexpected Server Error"
);
expect(context.errors!["routes/index"].stack).toBeUndefined();
expect(context.loaderData).toEqual({
root: "root",
});
Expand Down Expand Up @@ -1326,7 +1332,9 @@ describe("shared server runtime", () => {
expect(calls.length).toBe(1 * DATA_CALL_MULTIPIER);
let context = calls[0][3].staticHandlerContext as StaticHandlerContext;
expect(context.errors).toBeTruthy();
expect(context.errors!.root.message).toBe("test");
expect(context.errors!.root).toBeInstanceOf(Error);
expect(context.errors!.root.message).toBe("Unexpected Server Error");
expect(context.errors!.root.stack).toBeUndefined();
expect(context.loaderData).toEqual({
root: null,
"routes/test": null,
Expand Down Expand Up @@ -1375,7 +1383,9 @@ describe("shared server runtime", () => {
expect(calls.length).toBe(1 * DATA_CALL_MULTIPIER);
let context = calls[0][3].staticHandlerContext as StaticHandlerContext;
expect(context.errors).toBeTruthy();
expect(context.errors!.root.message).toBe("index");
expect(context.errors!.root).toBeInstanceOf(Error);
expect(context.errors!.root.message).toBe("Unexpected Server Error");
expect(context.errors!.root.stack).toBeUndefined();
expect(context.loaderData).toEqual({
root: null,
"routes/index": null,
Expand Down Expand Up @@ -1424,7 +1434,11 @@ describe("shared server runtime", () => {
expect(calls.length).toBe(1 * DATA_CALL_MULTIPIER);
let context = calls[0][3].staticHandlerContext as StaticHandlerContext;
expect(context.errors).toBeTruthy();
expect(context.errors!["routes/test"].message).toBe("test");
expect(context.errors!["routes/test"]).toBeInstanceOf(Error);
expect(context.errors!["routes/test"].message).toBe(
"Unexpected Server Error"
);
expect(context.errors!["routes/test"].stack).toBeUndefined();
expect(context.loaderData).toEqual({
root: "root",
"routes/test": null,
Expand Down Expand Up @@ -1473,7 +1487,11 @@ describe("shared server runtime", () => {
expect(calls.length).toBe(1 * DATA_CALL_MULTIPIER);
let context = calls[0][3].staticHandlerContext as StaticHandlerContext;
expect(context.errors).toBeTruthy();
expect(context.errors!["routes/index"].message).toBe("index");
expect(context.errors!["routes/index"]).toBeInstanceOf(Error);
expect(context.errors!["routes/index"].message).toBe(
"Unexpected Server Error"
);
expect(context.errors!["routes/index"].stack).toBeUndefined();
expect(context.loaderData).toEqual({
root: "root",
"routes/index": null,
Expand Down Expand Up @@ -1530,7 +1548,11 @@ describe("shared server runtime", () => {
expect(calls.length).toBe(1 * DATA_CALL_MULTIPIER);
let context = calls[0][3].staticHandlerContext as StaticHandlerContext;
expect(context.errors).toBeTruthy();
expect(context.errors!["routes/__layout"].message).toBe("action");
expect(context.errors!["routes/__layout"]).toBeInstanceOf(Error);
expect(context.errors!["routes/__layout"].message).toBe(
"Unexpected Server Error"
);
expect(context.errors!["routes/__layout"].stack).toBeUndefined();
expect(context.loaderData).toEqual({
root: "root",
"routes/__layout": null,
Expand Down Expand Up @@ -1588,7 +1610,11 @@ describe("shared server runtime", () => {
expect(calls.length).toBe(1 * DATA_CALL_MULTIPIER);
let context = calls[0][3].staticHandlerContext as StaticHandlerContext;
expect(context.errors).toBeTruthy();
expect(context.errors!["routes/__layout"].message).toBe("action");
expect(context.errors!["routes/__layout"]).toBeInstanceOf(Error);
expect(context.errors!["routes/__layout"].message).toBe(
"Unexpected Server Error"
);
expect(context.errors!["routes/__layout"].stack).toBeUndefined();
expect(context.loaderData).toEqual({
root: "root",
"routes/__layout": null,
Expand Down Expand Up @@ -1624,7 +1650,7 @@ describe("shared server runtime", () => {
calledBefore = true;
return ogHandleDocumentRequest.call(null, arguments);
}) as any;
let handler = createRequestHandler(build, ServerMode.Test);
let handler = createRequestHandler(build, ServerMode.Development);

let request = new Request(`${baseUrl}/`, { method: "get" });

Expand All @@ -1637,7 +1663,7 @@ describe("shared server runtime", () => {
expect(calls.length).toBe(2 * DATA_CALL_MULTIPIER);
let context = calls[1][3].staticHandlerContext;
expect(context.errors.root).toBeTruthy();
expect(context.errors.root.message).toBe("thrown");
expect(context.errors!.root.message).toBe("thrown");
expect(context.loaderData).toEqual({});
});

Expand Down

0 comments on commit 4e2096a

Please sign in to comment.