diff --git a/test/EleventyTest.js b/test/EleventyTest.js index 97af8a38d..d4be319af 100644 --- a/test/EleventyTest.js +++ b/test/EleventyTest.js @@ -709,3 +709,13 @@ test("this.eleventy on JavaScript template functions, issue #2790", async (t) => t.deepEqual(result.length, 1); t.deepEqual(result[0].content, `

Eleventy

`); }); + +test("Global data JS files should only execute once, issue #2753", async (t) => { + let elev = new Eleventy("./test/stubs-2753", "./test/stubs-2753/_site", { + config: function (eleventyConfig) {}, + }); + let result = await elev.toJSON(); + t.deepEqual(result.length, 2); + t.deepEqual(result[0].content, `1`); + t.deepEqual(result[0].content, `1`); +}); diff --git a/test/stubs-2753/_data/global.js b/test/stubs-2753/_data/global.js new file mode 100644 index 000000000..cb033e328 --- /dev/null +++ b/test/stubs-2753/_data/global.js @@ -0,0 +1,4 @@ +let count = 0; +module.exports = async function () { + return ++count; +}; diff --git a/test/stubs-2753/page1.njk b/test/stubs-2753/page1.njk new file mode 100644 index 000000000..542ba7525 --- /dev/null +++ b/test/stubs-2753/page1.njk @@ -0,0 +1 @@ +{{ global }} \ No newline at end of file diff --git a/test/stubs-2753/page2.njk b/test/stubs-2753/page2.njk new file mode 100644 index 000000000..542ba7525 --- /dev/null +++ b/test/stubs-2753/page2.njk @@ -0,0 +1 @@ +{{ global }} \ No newline at end of file