From 0aa204c1fd4022a9d1a91f02533c00c5f936d9ca Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Mon, 9 May 2022 15:39:02 -0500 Subject: [PATCH] Test for #2348. Fails with the code before #2367 was merged and passes after it was added --- test/EleventyTest.js | 29 ++++++++++++++ test/TemplateTest.js | 39 ------------------- test/stubs-2367/_includes/layout.liquid | 6 +++ ...hortcodeMultipleArguments-template2.liquid | 3 ++ ...ithLiquidShortcodeMultipleArguments.liquid | 3 ++ ...ithLiquidShortcodeMultipleArguments.liquid | 9 ----- 6 files changed, 41 insertions(+), 48 deletions(-) create mode 100644 test/stubs-2367/_includes/layout.liquid create mode 100644 test/stubs-2367/templateWithLiquidShortcodeMultipleArguments-template2.liquid create mode 100644 test/stubs-2367/templateWithLiquidShortcodeMultipleArguments.liquid delete mode 100644 test/stubs/templateWithLiquidShortcodeMultipleArguments.liquid diff --git a/test/EleventyTest.js b/test/EleventyTest.js index efa918d8c..f1805afe3 100644 --- a/test/EleventyTest.js +++ b/test/EleventyTest.js @@ -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(); @@ -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); +}); diff --git a/test/TemplateTest.js b/test/TemplateTest.js index e3dcd43c1..0b2bb54fa 100644 --- a/test/TemplateTest.js +++ b/test/TemplateTest.js @@ -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 `${text} (${url})`; - }); - - 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))), - `
-

Hello.

- world (/somepage) -
` - ); - - 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); diff --git a/test/stubs-2367/_includes/layout.liquid b/test/stubs-2367/_includes/layout.liquid new file mode 100644 index 000000000..6d74116ff --- /dev/null +++ b/test/stubs-2367/_includes/layout.liquid @@ -0,0 +1,6 @@ +--- +text: layout +url: "/mylayout" +--- +{% simplelink text url text url text url %} +{% simplelink text, url, text, url, text, url %} \ No newline at end of file diff --git a/test/stubs-2367/templateWithLiquidShortcodeMultipleArguments-template2.liquid b/test/stubs-2367/templateWithLiquidShortcodeMultipleArguments-template2.liquid new file mode 100644 index 000000000..716072b7f --- /dev/null +++ b/test/stubs-2367/templateWithLiquidShortcodeMultipleArguments-template2.liquid @@ -0,0 +1,3 @@ +--- +layout: layout.liquid +--- \ No newline at end of file diff --git a/test/stubs-2367/templateWithLiquidShortcodeMultipleArguments.liquid b/test/stubs-2367/templateWithLiquidShortcodeMultipleArguments.liquid new file mode 100644 index 000000000..716072b7f --- /dev/null +++ b/test/stubs-2367/templateWithLiquidShortcodeMultipleArguments.liquid @@ -0,0 +1,3 @@ +--- +layout: layout.liquid +--- \ No newline at end of file diff --git a/test/stubs/templateWithLiquidShortcodeMultipleArguments.liquid b/test/stubs/templateWithLiquidShortcodeMultipleArguments.liquid deleted file mode 100644 index ca2eefe84..000000000 --- a/test/stubs/templateWithLiquidShortcodeMultipleArguments.liquid +++ /dev/null @@ -1,9 +0,0 @@ ---- -layout: layoutLiquid.liquid -keymain: valuemain -title: 'Font Aliasing, or How to Rename a Font in CSS' -permalink: /rename-font2/ ---- - -

Hello.

-{% simplelink "world", "/somepage" %} \ No newline at end of file