Skip to content

Commit

Permalink
fix(test): cI and show warning when pathname duplicated (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
hashrock committed Aug 22, 2023
1 parent 9115589 commit 6402993
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions blog.tsx
Expand Up @@ -284,6 +284,10 @@ async function loadPost(postsDirectory: string, path: string) {
readTime: readingTime(content),
renderMath: data.get("render_math"),
};

if (POSTS.get(pathname)) {
console.warn(`Duplicate blog post path: ${pathname}`);
}
POSTS.set(pathname, post);
}

Expand Down
10 changes: 6 additions & 4 deletions blog_test.ts
Expand Up @@ -152,18 +152,20 @@ Deno.test("posts/ fourth", async () => {
);
});

Deno.test("posts/ fifth", async () => {
const resp = await testHandler(new Request("https://blog.deno.dev/fifth"));
Deno.test("posts/ seventh", async () => {
const resp = await testHandler(
new Request("https://blog.deno.dev/uses-pathname"),
);
assert(resp);
assertEquals(resp.status, 200);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
const body = await resp.text();
assertStringIncludes(body, `<html lang="en-GB">`);
assertStringIncludes(
body,
`<link rel="canonical" href="https://blog.deno.dev/fifth" />`,
`<link rel="canonical" href="https://blog.deno.dev/uses-pathname" />`,
);
assertStringIncludes(body, `fifth post`);
assertStringIncludes(body, `seventh post`);
assertStringIncludes(body, `<time dateTime="2022-05-02T00:00:00.000Z">`);
assertStringIncludes(body, `<p>Lorem Ipsum is simply dummy text`);
});
Expand Down
@@ -1,8 +1,8 @@
---
title: Fifth post
pathname: "/fifth"
title: Seventh post
pathname: "/uses-pathname"
publish_date: 2022-05-02
abstract: This is the fifth post.
abstract: This is the seventh post.
---

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
Expand Down

0 comments on commit 6402993

Please sign in to comment.