From a07facb86d84b2af231d0dd51b57e96044bf2449 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Wed, 11 Dec 2024 12:04:09 -0600 Subject: [PATCH] Throw an error on invalid passthrough copy modes #3573 --- src/UserConfig.js | 7 ++++++- test/HtmlRelativeCopyTest.js | 24 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/UserConfig.js b/src/UserConfig.js index e694756f5..84e744336 100644 --- a/src/UserConfig.js +++ b/src/UserConfig.js @@ -792,7 +792,12 @@ class UserConfig { * @returns {any} a reference to the `EleventyConfig` object. */ addPassthroughCopy(fileOrDir, copyOptions = {}) { - if (copyOptions.mode === "html-relative") { + if (copyOptions.mode) { + if (copyOptions.mode !== "html-relative") { + throw new Error( + "Invalid `mode` option for `addPassthroughCopy`. Received: '" + copyOptions.mode + "'", + ); + } if (isPlainObject(fileOrDir)) { throw new Error( "mode: 'html-relative' does not yet support passthrough copy objects (input -> output mapping). Use a string glob or an Array of string globs.", diff --git a/test/HtmlRelativeCopyTest.js b/test/HtmlRelativeCopyTest.js index d08ada84b..cc9fddd05 100644 --- a/test/HtmlRelativeCopyTest.js +++ b/test/HtmlRelativeCopyTest.js @@ -592,8 +592,30 @@ test("Input -> output remapping not yet supported (throws error)", async (t) => await t.throwsAsync(async () => { await elev.write(); }, { - message: `mode: \'html-relative\' does not yet support passthrough copy objects (input -> output mapping). Use a string glob or an Array of string globs.` + message: `mode: 'html-relative' does not yet support passthrough copy objects (input -> output mapping). Use a string glob or an Array of string globs.` }); t.is(fs.existsSync("test/stubs-autocopy/_site12/test/index.html"), false); }); + +test("Invalid copy mode throws error", async (t) => { + let elev = new Eleventy("./test/stubs-autocopy/", "./test/stubs-autocopy/_site13", { + configPath: false, + config: function (eleventyConfig) { + // not yet supported + eleventyConfig.addPassthroughCopy({"**/*.png": "yo"}, { + mode: "throw-an-error" + }); + }, + }); + + elev.disableLogger(); + + await t.throwsAsync(async () => { + await elev.write(); + }, { + message: `Invalid \`mode\` option for \`addPassthroughCopy\`. Received: 'throw-an-error'` + }); + + t.is(fs.existsSync("test/stubs-autocopy/_site13/test/index.html"), false); +});