Skip to content

Commit

Permalink
Rebased and updated tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
thchia committed Aug 27, 2020
1 parent 5726c23 commit e54d915
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"/customers/new": "pages/customers/new.js",
"/api/getCustomers": "pages/api/getCustomers.js",
"/_error": "pages/_error.js",
"/404": "pages/404.html"
"/404": "pages/404.html",
"/preview": "pages/preview.js"
}
},
"html": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe("Lambda@Edge", () => {
await runRedirectTest(path, expectedRedirect);
}
);

it("handles preview mode", async () => {
const event = createCloudFrontEvent({
uri: "/preview",
Expand All @@ -187,15 +187,19 @@ describe("Lambda@Edge", () => {
}
});

mockPageRequire("pages/preview.js");
const result = await handler(event);
const response = result as CloudFrontResultResponse;
const decodedBody = new Buffer(
response.body as string,
"base64"
).toString("utf8");
expect(decodedBody).toBe("pages/preview.js");
expect(response.status).toBe(200);
if (trailingSlash) {
await runRedirectTest("/preview", "/preview/");
} else {
mockPageRequire("pages/preview.js");
const result = await handler(event);
const response = result as CloudFrontResultResponse;
const decodedBody = new Buffer(
response.body as string,
"base64"
).toString("utf8");
expect(decodedBody).toBe("pages/preview.js");
expect(response.status).toBe(200);
}
});
});

Expand Down

0 comments on commit e54d915

Please sign in to comment.