-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
markdown.test.ts
61 lines (51 loc) 路 2 KB
/
markdown.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { assert, assertStrictEquals as equals } from "../deps/assert.ts";
import { getSite, pageExists, testPage } from "./utils.ts";
Deno.test("build a markdown site", async () => {
const site = getSite({
dev: true,
src: "markdown",
location: new URL("https://example.com/blog"),
});
await site.build();
testPage(site, "/basic", (page) => {
equals(page.document?.querySelectorAll("li").length, 3);
});
testPage(site, "/with-nunjucks", (page) => {
equals(page.document?.querySelectorAll("li").length, 3);
equals(
page.document?.querySelector("li")?.innerHTML,
'one: <a href="/items/un.html">un</a>',
);
});
testPage(site, "/with-attributes", (page) => {
const el = page.document?.querySelector("a");
equals(el?.getAttribute("href"), "#foo");
equals(el?.getAttribute("target"), "_blank");
});
testPage(site, "/with-deflist", (page) => {
equals(page.document?.querySelectorAll("dl")?.length, 1);
equals(page.document?.querySelectorAll("dt")?.length, 2);
equals(page.document?.querySelectorAll("dd")?.length, 3);
});
testPage(site, "/with-code", (page) => {
const codes = page.document?.querySelectorAll("code");
equals(codes?.length, 2);
// @ts-ignore getAttribute does not exist on Node
equals(codes?.item(0)?.getAttribute("class"), "language-html");
equals(page.document?.querySelectorAll("pre")?.length, 2);
});
assert(pageExists(site, "/empty") === false);
testPage(site, "/with-module", (page) => {
equals(page.document?.querySelectorAll("h1").length, 1);
equals(page.document?.querySelector("h1")?.innerText, page.data.title);
equals(page.document?.querySelector("a")?.getAttribute("href"), "/");
});
testPage(site, "/with-filter", (page) => {
equals(page.document?.querySelectorAll("p").length, 1);
equals(
page.document?.querySelector("h1")?.innerHTML,
"Module <strong>example</strong>",
);
equals(page.document?.querySelector("a")?.getAttribute("href"), "/");
});
});