/
nunjucks.test.ts
45 lines (41 loc) 路 1.1 KB
/
nunjucks.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
import { assertSiteSnapshot, build, getSite } from "./utils.ts";
Deno.test("build a site with nunjucks", async (t) => {
const site = getSite({
src: "nunjucks",
location: new URL("https://example.com/blog"),
});
// Register an async filter
site.filter(
"returnAsync",
(text) =>
new Promise((resolve) =>
setTimeout(() => resolve(`${text} (async)`), 10)
),
true,
);
// Register custom helpers
site.helper(
"upperCase",
(text) => `<strong>${(text as string).toUpperCase()}</strong>`,
{ type: "tag" },
);
site.helper(
"upperCaseBody",
(text) => `<strong>${(text as string).toUpperCase()}</strong>`,
{ type: "tag", body: true },
);
site.helper(
"upperCaseAsync",
(text) =>
Promise.resolve(`<strong>${(text as string).toUpperCase()}</strong>`),
{ type: "tag", async: true },
);
site.helper(
"upperCaseBodyAsync",
(text) =>
Promise.resolve(`<strong>${(text as string).toUpperCase()}</strong>`),
{ type: "tag", body: true, async: true },
);
await build(site);
await assertSiteSnapshot(t, site);
});