-
-
Notifications
You must be signed in to change notification settings - Fork 502
/
Copy pathTemplateRenderPugTest.js
166 lines (143 loc) · 4.71 KB
/
TemplateRenderPugTest.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
const test = require("ava");
const TemplateRender = require("../src/TemplateRender");
const TemplateConfig = require("../src/TemplateConfig");
const EleventyExtensionMap = require("../src/EleventyExtensionMap");
function getNewTemplateRender(name, inputDir, config) {
let eleventyConfig = config;
if (!eleventyConfig) {
eleventyConfig = new TemplateConfig();
}
let tr = new TemplateRender(name, inputDir, eleventyConfig);
tr.extensionMap = new EleventyExtensionMap([], eleventyConfig);
return tr;
}
// Pug
test("Pug", (t) => {
t.is(getNewTemplateRender("pug").getEngineName(), "pug");
});
test("Pug Render", async (t) => {
let fn = await getNewTemplateRender("pug").getCompiledTemplate("p= name");
t.is(await fn({ name: "Zach" }), "<p>Zach</p>");
});
test("Pug Render Include (Absolute)", async (t) => {
let fn = await getNewTemplateRender("pug", "./test/stubs/")
.getCompiledTemplate(`p
include /included.pug`);
t.is(await fn({ name: "Zach" }), "<p><span>This is an include.</span></p>");
});
test("Pug Render Include with Data", async (t) => {
let fn = await getNewTemplateRender("pug", "./test/stubs/")
.getCompiledTemplate(`p
include /includedvar.pug`);
t.is(await fn({ name: "Zach" }), "<p><span>This is Zach.</span></p>");
});
test("Pug Render Include with Data, inline var overrides data", async (t) => {
let fn = await getNewTemplateRender("pug", "./test/stubs/")
.getCompiledTemplate(`
- var name = "Bill";
p
include /includedvar.pug`);
t.is(await fn({ name: "Zach" }), "<p><span>This is Bill.</span></p>");
});
test("Pug Render Extends (Layouts)", async (t) => {
let fn = await getNewTemplateRender("pug", "./test/stubs/")
.getCompiledTemplate(`extends /layout.pug
block content
h1= name`);
t.is(await fn({ name: "Zach" }), "<html><body><h1>Zach</h1></body></html>");
});
test("Pug Render Extends (Relative, Layouts)", async (t) => {
let fn = await getNewTemplateRender(
"./test/stubs/does_not_exist_and_thats_ok.pug",
"./test/stubs/"
).getCompiledTemplate(`extends ./layout-relative.pug
block content
h1= name`);
t.is(await fn({ name: "Zach" }), "<html><body><h1>Zach</h1></body></html>");
});
test("Pug Render Include (Relative)", async (t) => {
let fn = await getNewTemplateRender("pug", "./test/stubs/")
.getCompiledTemplate(`p
include _includes/included.pug`);
t.is(await fn({ name: "Zach" }), "<p><span>This is an include.</span></p>");
});
test("Pug Render Include (Relative, again)", async (t) => {
let fn = await getNewTemplateRender(
"./test/stubs/does_not_exist_and_thats_ok.pug",
"./test/stubs/"
).getCompiledTemplate(`p
include included.pug`);
t.is(
await fn({ name: "Zach" }),
"<p><span>This is a relative include.</span></p>"
);
});
test("Pug Render Include (Relative, dot slash)", async (t) => {
let fn = await getNewTemplateRender(
"./test/stubs/does_not_exist_and_thats_ok.pug",
"./test/stubs/"
).getCompiledTemplate(`p
include ./included.pug`);
t.is(
await fn({ name: "Zach" }),
"<p><span>This is a relative include.</span></p>"
);
});
test("Pug Render Include (Relative, dot dot slash)", async (t) => {
let fn = await getNewTemplateRender(
"./test/stubs/dir/does_not_exist_and_thats_ok.pug",
"./test/stubs/"
).getCompiledTemplate(`p
include ../included.pug`);
t.is(
await fn({ name: "Zach" }),
"<p><span>This is a relative include.</span></p>"
);
});
test("Pug Options Overrides", async (t) => {
let cfg = new TemplateConfig();
cfg.userConfig.setPugOptions({
testoption: "testoverride",
});
let tr = getNewTemplateRender("pug", "./test/stubs/", cfg);
let options = tr.engine.getPugOptions();
t.is(options.testoption, "testoverride");
});
test("Pug getEngineLib", async (t) => {
let tr = getNewTemplateRender("pug", "./test/stubs/");
t.truthy(tr.engine.getEngineLib());
});
test("Pug Render: with Library Override", async (t) => {
let tr = getNewTemplateRender("pug");
let lib = require("pug");
tr.engine.setLibrary(lib);
let fn = await tr.getCompiledTemplate("p= name");
t.is(await fn({ name: "Zach" }), "<p>Zach</p>");
});
test("Pug Filter", async (t) => {
let cfg = new TemplateConfig();
cfg.userConfig.setPugOptions({
filters: {
makeUppercase: function (text, options) {
return text.toUpperCase();
},
},
});
let tr = getNewTemplateRender("pug", "./test/stubs/", cfg);
let fn = await tr.getCompiledTemplate(`p
:makeUppercase()
Zach
`);
t.is(await fn({ name: "Test" }), "<p>ZACH</p>");
});
test("Pug Render with Function", async (t) => {
let fn = await getNewTemplateRender("pug").getCompiledTemplate("p= name()");
t.is(
await fn({
name: function () {
return "Zach2";
},
}),
"<p>Zach2</p>"
);
});