Skip to content

Commit

Permalink
chore: add test for markdown functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
deer committed Aug 14, 2023
1 parent 3f3c795 commit d37da30
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/routes/blog/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default function PostPage(props: PageProps<Post>) {
<>
<Head>
<style dangerouslySetInnerHTML={{ __html: CSS }} />
<link rel="stylesheet" href="/gfm.css" />
</Head>
<br />
<br />
Expand Down
19 changes: 19 additions & 0 deletions tests/fixture/posts/markdown-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: "Markdown Test"
date: 2023-8-14 04:39
author: Some Author
tags:
- example
---

This should actually, you know, work.

<!--more-->

# Big Stuff

hello

## Not quite as big

~~hey again~~
21 changes: 18 additions & 3 deletions tests/main_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Deno.test("reed author page has two posts", async () => {
);
});

Deno.test("archive page has six posts", async () => {
Deno.test("archive page has seven posts", async () => {
const handler = await createHandler(manifest, {
plugins: [blogPlugin(blogConfig)],
});
Expand All @@ -89,7 +89,7 @@ Deno.test("archive page has six posts", async () => {
const postElements = Array.from(doc.querySelectorAll('div[id^="post:"]'));

assertEquals(
6,
7,
postElements.length,
);
});
Expand Down Expand Up @@ -143,7 +143,7 @@ Deno.test("last post has no next", async () => {
plugins: [blogPlugin(blogConfig)],
});
const resp = await handler(
new Request("http://127.0.0.1/blog/single-tag-test"),
new Request("http://127.0.0.1/blog/markdown-test"),
);
const body = await resp.text();
assert(!body.includes("Next Post →"));
Expand Down Expand Up @@ -250,6 +250,21 @@ Deno.test("only one page means no next or previous links", async () => {
assertEquals(previousPageLink, null);
});

Deno.test("markdown test", async () => {
const handler = await createHandler(manifest, {
plugins: [blogPlugin(blogConfig)],
});

const resp = await handler(
new Request("http://127.0.0.1/blog/markdown-test"),
);
const body = await resp.text();
const doc = new DOMParser().parseFromString(body, "text/html")!;

const strikethroughContent = doc.querySelector(".markdown-body p del");
assertEquals(strikethroughContent?.textContent, "hey again");
});

function occurrences(string: string, substring: string) {
return (string.match(new RegExp(substring, "gi")) || []).length;
}

0 comments on commit d37da30

Please sign in to comment.