Skip to content

Commit

Permalink
Test for #2348. Fails with the code before #2367 was merged and passe…
Browse files Browse the repository at this point in the history
…s after it was added
  • Loading branch information
zachleat committed May 9, 2022
1 parent bb9caeb commit 0aa204c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 48 deletions.
29 changes: 29 additions & 0 deletions test/EleventyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Eleventy = require("../src/Eleventy");
const EleventyWatchTargets = require("../src/EleventyWatchTargets");
const TemplateConfig = require("../src/TemplateConfig");
const DateGitLastUpdated = require("../src/Util/DateGitLastUpdated");
const normalizeNewLines = require("./Util/normalizeNewLines");

test("Eleventy, defaults inherit from config", async (t) => {
let elev = new Eleventy();
Expand Down Expand Up @@ -500,3 +501,31 @@ test("Paginated template uses proxy and global data", async (t) => {
});
t.is(results.length, allContentMatches.length);
});

test("Liquid shortcode with multiple arguments(issue #2348)", async (t) => {
// NOTE issue #2348 was only active when you were processing multiple templates at the same time.

let elev = new Eleventy("./test/stubs-2367/", "./test/stubs-2367/_site", {
config: function (eleventyConfig) {
eleventyConfig.addShortcode("simplelink", function (...args) {
return JSON.stringify(args);
});
},
});

let arr = [
"layout",
"/mylayout",
"layout",
"/mylayout",
"layout",
"/mylayout",
];
let str = normalizeNewLines(`${JSON.stringify(arr)}
${JSON.stringify(arr)}`);
let results = await elev.toJSON();
t.is(results.length, 2);
let content = results.map((entry) => entry.content).sort();
t.is(normalizeNewLines(content[0]), str);
t.is(normalizeNewLines(content[1]), str);
});
39 changes: 0 additions & 39 deletions test/TemplateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,45 +320,6 @@ test("One Layout (_layoutContent deprecated but supported)", async (t) => {
t.is(data.keylayout, "valuelayout");
});

test("Liquid shortcode with multiple arguments(issue #2348)", async (t) => {
// NOTE issue #2348 was only active when you were processing multiple templates at the same time.

let eleventyConfig = new TemplateConfig();
eleventyConfig.userConfig.addShortcode("simplelink", function (text, url) {
return `<a href="${url}">${text} (${url})</a>`;
});

let dataObj = new TemplateData("./test/stubs/", eleventyConfig);

let tmpl = getNewTemplate(
"./test/stubs/templateWithLiquidShortcodeMultipleArguments.liquid",
"./test/stubs/",
"dist",
dataObj,
null,
eleventyConfig
);

t.is(
(await tmpl.getFrontMatter()).data[tmpl.config.keys.layout],
"layoutLiquid.liquid"
);

let data = await tmpl.getData();
t.is(data[tmpl.config.keys.layout], "layoutLiquid.liquid");

t.is(
normalizeNewLines(cleanHtml(await tmpl.renderLayout(tmpl, data))),
`<div id="layout">
<p>Hello.</p>
<a href="/somepage">world (/somepage)</a>
</div>`
);

t.is(data.keymain, "valuemain");
t.is(data.keylayout, "valuelayout");
});

test("One Layout (liquid test)", async (t) => {
let eleventyConfig = new TemplateConfig();
let dataObj = new TemplateData("./test/stubs/", eleventyConfig);
Expand Down
6 changes: 6 additions & 0 deletions test/stubs-2367/_includes/layout.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
text: layout
url: "/mylayout"
---
{% simplelink text url text url text url %}
{% simplelink text, url, text, url, text, url %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
layout: layout.liquid
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
layout: layout.liquid
---

This file was deleted.

0 comments on commit 0aa204c

Please sign in to comment.