Skip to content

Commit

Permalink
Tests for #28 bundleExportKey
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jul 5, 2024
1 parent 10f19ef commit 1997df2
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
]
},
"devDependencies": {
"@11ty/eleventy": "3.0.0-alpha.9",
"@11ty/eleventy": "3.0.0-alpha.14",
"ava": "^5.3.1",
"postcss": "^8.4.31",
"postcss-nested": "^6.0.1",
Expand Down
4 changes: 4 additions & 0 deletions test/stubs/export-key-obj/eleventy.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function(eleventyConfig) {
eleventyConfig.addBundle("css");
eleventyConfig.addBundle("js");
};
8 changes: 8 additions & 0 deletions test/stubs/export-key-obj/template.11ty.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const bundle = {
css: "/* CSS */",
js: "/* JS */"
};

export function render(data) {
return `<style>${this.getBundle("css")}</style><script>${this.getBundle("js")}</script>`;
}
4 changes: 4 additions & 0 deletions test/stubs/export-key-str-rename/eleventy.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function(eleventyConfig) {
eleventyConfig.addBundle("css", { bundleExportKey: "css" });
eleventyConfig.addBundle("js", { bundleExportKey: "js" });
};
6 changes: 6 additions & 0 deletions test/stubs/export-key-str-rename/template.11ty.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const js = "/* JS */";
export const css = "/* CSS */";

export function render(data) {
return `<style>${this.getBundle("css")}</style><script>${this.getBundle("js")}</script>`;
}
4 changes: 4 additions & 0 deletions test/stubs/export-key-str/eleventy.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function(eleventyConfig) {
eleventyConfig.addBundle("css");
eleventyConfig.addBundle("js");
};
5 changes: 5 additions & 0 deletions test/stubs/export-key-str/template.11ty.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const bundle = "/* Hello */";

export function render(data) {
return `<style>${this.getBundle("css")}</style><script>${this.getBundle("js")}</script>`;
}
18 changes: 18 additions & 0 deletions test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,21 @@ test("`defer` hoisting", async t => {
<style></style>
<style></style>`);
});

test("Bundle export key as string (11ty.js)", async t => {
let elev = new Eleventy("test/stubs/export-key-str/", "_site", { configPath: "test/stubs/export-key-str/eleventy.config.js" });
let results = await elev.toJSON();
t.deepEqual(normalize(results[0].content), `<style>/* Hello */</style><script>/* Hello */</script>`)
});

test("Bundle export key as object (11ty.js)", async t => {
let elev = new Eleventy("test/stubs/export-key-obj/", "_site", { configPath: "test/stubs/export-key-obj/eleventy.config.js" });
let results = await elev.toJSON();
t.deepEqual(normalize(results[0].content), `<style>/* CSS */</style><script>/* JS */</script>`)
});

test("Bundle export key as string, using separate bundleExportKey’s (11ty.js)", async t => {
let elev = new Eleventy("test/stubs/export-key-str-rename/", "_site", { configPath: "test/stubs/export-key-str-rename/eleventy.config.js" });
let results = await elev.toJSON();
t.deepEqual(normalize(results[0].content), `<style>/* CSS */</style><script>/* JS */</script>`)
});

0 comments on commit 1997df2

Please sign in to comment.