Skip to content

Commit 5b9f73a

Browse files
committed
Fix tests
1 parent a8e6461 commit 5b9f73a

File tree

1 file changed

+32
-69
lines changed

1 file changed

+32
-69
lines changed

test/TemplateRenderLiquidTest.js

+32-69
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import EleventyExtensionMap from "../src/EleventyExtensionMap.js";
77

88
import { getTemplateConfigInstance } from "./_testHelpers.js";
99

10-
async function getNewTemplateRender(name, inputDir, userConfig = {}) {
10+
async function getNewTemplateRender(name, inputDir, configure = null) {
1111
let eleventyConfig = await getTemplateConfigInstance({
1212
dir: {
1313
input: inputDir
1414
}
15-
}, null, userConfig);
15+
}, null, {});
16+
17+
if (configure) await configure(eleventyConfig);
1618

1719
let tr = new TemplateRender(name, eleventyConfig);
1820
tr.extensionMap = new EleventyExtensionMap(eleventyConfig);
@@ -21,6 +23,16 @@ async function getNewTemplateRender(name, inputDir, userConfig = {}) {
2123
return tr;
2224
}
2325

26+
function noDynamicPartials(eleventyConfig) {
27+
eleventyConfig.setLiquidOptions({
28+
dynamicPartials: false,
29+
});
30+
}
31+
32+
function builtinParameterParsing(eleventyConfig) {
33+
eleventyConfig.setLiquidParameterParsing("builtin");
34+
}
35+
2436
async function getPromise(resolveTo) {
2537
return new Promise(function (resolve) {
2638
setTimeout(function () {
@@ -72,11 +84,7 @@ test("Liquid Render Include", async (t) => {
7284
let tr1 = await getNewTemplateRender("liquid", "./test/stubs/");
7385
t.is(tr1.getEngineName(), "liquid");
7486

75-
let tr2 = await getNewTemplateRender("liquid", "./test/stubs/", {
76-
liquidOptions: {
77-
dynamicPartials: false,
78-
},
79-
});
87+
let tr2 = await getNewTemplateRender("liquid", "./test/stubs/", noDynamicPartials);
8088

8189
let fn = await tr2.getCompiledTemplate("<p>{% include included %}</p>");
8290
t.is(await fn(), "<p>This is an include.</p>");
@@ -86,11 +94,7 @@ test("Liquid Render Relative Include (dynamicPartials off)", async (t) => {
8694
let tr1 = await getNewTemplateRender("liquid", "./test/stubs/");
8795
t.is(tr1.getEngineName(), "liquid");
8896

89-
let tr2 = await getNewTemplateRender("liquid", "./test/stubs/", {
90-
liquidOptions: {
91-
dynamicPartials: false,
92-
},
93-
});
97+
let tr2 = await getNewTemplateRender("liquid", "./test/stubs/", noDynamicPartials);
9498

9599
// Important note: when inputPath is set to `liquid`, this *only* uses _includes relative paths in Liquid->compile
96100
let fn = await tr2.getCompiledTemplate("<p>{% include ./included %}</p>");
@@ -112,11 +116,7 @@ test("Liquid Render Relative (current dir) Include", async (t) => {
112116
let tr = await getNewTemplateRender(
113117
"./test/stubs/relative-liquid/does_not_exist_and_thats_ok.liquid",
114118
"./test/stubs/",
115-
{
116-
liquidOptions: {
117-
dynamicPartials: false,
118-
},
119-
}
119+
noDynamicPartials,
120120
);
121121

122122
let fn = await tr.getCompiledTemplate("<p>{% include ./dir/included %}</p>");
@@ -127,11 +127,7 @@ test("Liquid Render Relative (parent dir) Include", async (t) => {
127127
let tr = await getNewTemplateRender(
128128
"./test/stubs/relative-liquid/dir/does_not_exist_and_thats_ok.liquid",
129129
"./test/stubs/",
130-
{
131-
liquidOptions: {
132-
dynamicPartials: false,
133-
},
134-
}
130+
noDynamicPartials,
135131
);
136132

137133
let fn = await tr.getCompiledTemplate("<p>{% include ../dir/included %}</p>");
@@ -141,8 +137,7 @@ test("Liquid Render Relative (parent dir) Include", async (t) => {
141137
test("Liquid Render Relative (relative include should ignore _includes dir) Include", async (t) => {
142138
let tr = await getNewTemplateRender(
143139
"./test/stubs/does_not_exist_and_thats_ok.liquid",
144-
"./test/stubs/",
145-
{}
140+
"./test/stubs/"
146141
);
147142

148143
let fn = await tr.getCompiledTemplate(`<p>{% include './included' %}</p>`);
@@ -153,11 +148,7 @@ test("Liquid Render Include with Liquid Suffix", async (t) => {
153148
let tr1 = await getNewTemplateRender("liquid", "./test/stubs/");
154149
t.is(tr1.getEngineName(), "liquid");
155150

156-
let tr2 = await getNewTemplateRender("liquid", "./test/stubs/", {
157-
liquidOptions: {
158-
dynamicPartials: false,
159-
},
160-
});
151+
let tr2 = await getNewTemplateRender("liquid", "./test/stubs/", noDynamicPartials);
161152

162153
let fn = await tr2.getCompiledTemplate("<p>{% include included.liquid %}</p>");
163154
t.is(await fn(), "<p>This is an include.</p>");
@@ -167,11 +158,7 @@ test("Liquid Render Include with HTML Suffix", async (t) => {
167158
let tr1 = await getNewTemplateRender("liquid", "./test/stubs/");
168159
t.is(tr1.getEngineName(), "liquid");
169160

170-
let tr2 = await getNewTemplateRender("liquid", "./test/stubs/", {
171-
liquidOptions: {
172-
dynamicPartials: false,
173-
},
174-
});
161+
let tr2 = await getNewTemplateRender("liquid", "./test/stubs/", noDynamicPartials);
175162

176163
let fn = await tr2.getCompiledTemplate("<p>{% include included.html %}</p>");
177164
t.is(await fn(), "<p>This is an include.</p>");
@@ -181,11 +168,7 @@ test("Liquid Render Include with HTML Suffix and Data Pass in", async (t) => {
181168
let tr1 = await getNewTemplateRender("liquid", "./test/stubs/");
182169
t.is(tr1.getEngineName(), "liquid");
183170

184-
let tr2 = await getNewTemplateRender("liquid", "./test/stubs/", {
185-
liquidOptions: {
186-
dynamicPartials: false,
187-
},
188-
});
171+
let tr2 = await getNewTemplateRender("liquid", "./test/stubs/", noDynamicPartials);
189172

190173
let fn = await tr2.getCompiledTemplate("{% include included-data.html, myVariable: 'myValue' %}");
191174
t.is((await fn()).trim(), "This is an include. myValue");
@@ -215,11 +198,7 @@ test("Liquid Async Filter", async (t) => {
215198
});
216199

217200
test("Issue 3206: Strict variables and custom filters in includes", async (t) => {
218-
let tr = await getNewTemplateRender("liquid", "test/stubs", {
219-
liquidOptions: {
220-
strictVariables: true
221-
}
222-
});
201+
let tr = await getNewTemplateRender("liquid", "test/stubs", noDynamicPartials);
223202
tr.engine.addFilter("makeItFoo", function () {
224203
return "foo";
225204
});
@@ -465,33 +444,21 @@ test("Liquid Async Paired Shortcode", async (t) => {
465444
});
466445

467446
test("Liquid Render Include Subfolder", async (t) => {
468-
let tr = await getNewTemplateRender("liquid", "./test/stubs/", {
469-
liquidOptions: {
470-
dynamicPartials: false,
471-
},
472-
});
447+
let tr = await getNewTemplateRender("liquid", "./test/stubs/", noDynamicPartials);
473448

474449
let fn = await tr.getCompiledTemplate(`<p>{% include subfolder/included.liquid %}</p>`);
475450
t.is(await fn(), "<p>This is an include.</p>");
476451
});
477452

478453
test("Liquid Render Include Subfolder HTML", async (t) => {
479-
let tr = await getNewTemplateRender("liquid", "./test/stubs/", {
480-
liquidOptions: {
481-
dynamicPartials: false,
482-
},
483-
});
454+
let tr = await getNewTemplateRender("liquid", "./test/stubs/", noDynamicPartials);
484455

485456
let fn = await tr.getCompiledTemplate(`<p>{% include subfolder/included.html %}</p>`);
486457
t.is(await fn(), "<p>This is an include.</p>");
487458
});
488459

489460
test("Liquid Render Include Subfolder No file extension", async (t) => {
490-
let tr = await getNewTemplateRender("liquid", "./test/stubs/", {
491-
liquidOptions: {
492-
dynamicPartials: false,
493-
},
494-
});
461+
let tr = await getNewTemplateRender("liquid", "./test/stubs/", noDynamicPartials);
495462

496463
let fn = await tr.getCompiledTemplate(`<p>{% include subfolder/included %}</p>`);
497464
t.is(await fn(), "<p>This is an include.</p>");
@@ -537,11 +504,7 @@ test("Liquid Render Include Subfolder Double quotes No file extension", async (t
537504
/* End tests related to dynamicPartials */
538505

539506
test("Liquid Options Overrides", async (t) => {
540-
let tr = await getNewTemplateRender("liquid", "./test/stubs/", {
541-
liquidOptions: {
542-
dynamicPartials: false,
543-
},
544-
});
507+
let tr = await getNewTemplateRender("liquid", "./test/stubs/", noDynamicPartials);
545508

546509
let options = tr.engine.getLiquidOptions();
547510
t.is(options.dynamicPartials, false);
@@ -659,7 +622,7 @@ test("Liquid Nested Paired Shortcode", async (t) => {
659622
});
660623

661624
test("Liquid Paired Kwargs Shortcode with Tag Inside", async (t) => {
662-
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
625+
let tr = await getNewTemplateRender("liquid", "./test/stubs/", builtinParameterParsing);
663626
tr.engine.addPairedShortcode("postfixWithZach", function (content, kwargs) {
664627
var { str } = kwargs ?? {};
665628
return str + content + "Zach";
@@ -675,7 +638,7 @@ test("Liquid Paired Kwargs Shortcode with Tag Inside", async (t) => {
675638
});
676639

677640
test("Liquid Nested Paired Kwargs Shortcode", async (t) => {
678-
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
641+
let tr = await getNewTemplateRender("liquid", "./test/stubs/", builtinParameterParsing);
679642
tr.engine.addPairedShortcode("postfixWithZach", function (content, kwargs) {
680643
var { str } = kwargs ?? {};
681644
return str + content + "Zach";
@@ -706,7 +669,7 @@ test("Liquid Shortcode Multiple Args", async (t) => {
706669
});
707670

708671
test("Liquid Shortcode Keyword Arg", async (t) => {
709-
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
672+
let tr = await getNewTemplateRender("liquid", "./test/stubs/", builtinParameterParsing);
710673
tr.engine.addShortcode("postfixWithZach", function (str, kwargs) {
711674
let { append } = kwargs ?? {};
712675
return str + "Zach" + append;
@@ -722,7 +685,7 @@ test("Liquid Shortcode Keyword Arg", async (t) => {
722685
});
723686

724687
test("Liquid Shortcode Multiple Keyword Args", async (t) => {
725-
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
688+
let tr = await getNewTemplateRender("liquid", "./test/stubs/", builtinParameterParsing);
726689
tr.engine.addShortcode("postfixWithZach", function (str, kwargs) {
727690
let { prepend, append } = kwargs ?? {};
728691
return prepend + str + "Zach" + append;
@@ -741,7 +704,7 @@ test("Liquid Shortcode Multiple Keyword Args", async (t) => {
741704
});
742705

743706
test("Liquid Shortcode Only Keyword Args", async (t) => {
744-
let tr = await getNewTemplateRender("liquid", "./test/stubs/");
707+
let tr = await getNewTemplateRender("liquid", "./test/stubs/", builtinParameterParsing);
745708
tr.engine.addShortcode("postfixWithZach", function (kwargs) {
746709
let { prepend, append } = kwargs ?? {};
747710
return prepend + "Zach" + append;

0 commit comments

Comments
 (0)