Skip to content

Commit a07facb

Browse files
committed
Throw an error on invalid passthrough copy modes #3573
1 parent 8bd3b97 commit a07facb

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/UserConfig.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,12 @@ class UserConfig {
792792
* @returns {any} a reference to the `EleventyConfig` object.
793793
*/
794794
addPassthroughCopy(fileOrDir, copyOptions = {}) {
795-
if (copyOptions.mode === "html-relative") {
795+
if (copyOptions.mode) {
796+
if (copyOptions.mode !== "html-relative") {
797+
throw new Error(
798+
"Invalid `mode` option for `addPassthroughCopy`. Received: '" + copyOptions.mode + "'",
799+
);
800+
}
796801
if (isPlainObject(fileOrDir)) {
797802
throw new Error(
798803
"mode: 'html-relative' does not yet support passthrough copy objects (input -> output mapping). Use a string glob or an Array of string globs.",

test/HtmlRelativeCopyTest.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,30 @@ test("Input -> output remapping not yet supported (throws error)", async (t) =>
592592
await t.throwsAsync(async () => {
593593
await elev.write();
594594
}, {
595-
message: `mode: \'html-relative\' does not yet support passthrough copy objects (input -> output mapping). Use a string glob or an Array of string globs.`
595+
message: `mode: 'html-relative' does not yet support passthrough copy objects (input -> output mapping). Use a string glob or an Array of string globs.`
596596
});
597597

598598
t.is(fs.existsSync("test/stubs-autocopy/_site12/test/index.html"), false);
599599
});
600+
601+
test("Invalid copy mode throws error", async (t) => {
602+
let elev = new Eleventy("./test/stubs-autocopy/", "./test/stubs-autocopy/_site13", {
603+
configPath: false,
604+
config: function (eleventyConfig) {
605+
// not yet supported
606+
eleventyConfig.addPassthroughCopy({"**/*.png": "yo"}, {
607+
mode: "throw-an-error"
608+
});
609+
},
610+
});
611+
612+
elev.disableLogger();
613+
614+
await t.throwsAsync(async () => {
615+
await elev.write();
616+
}, {
617+
message: `Invalid \`mode\` option for \`addPassthroughCopy\`. Received: 'throw-an-error'`
618+
});
619+
620+
t.is(fs.existsSync("test/stubs-autocopy/_site13/test/index.html"), false);
621+
});

0 commit comments

Comments
 (0)