Skip to content

Commit

Permalink
Error message test on transform method.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jul 18, 2024
1 parent eca00cc commit 81e5eeb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/transform-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ function transformTag(context, node, opts) {
node.attrs = {};

Object.assign(node, obj);
}, (error) => {
return Promise.reject(error);
});
}

Expand Down
21 changes: 21 additions & 0 deletions test/transform-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,24 @@ test("Using the transform plugin with transform on request during dev mode but d
t.is(results[0].content, `<img loading="lazy" src="https://example.com/" alt="My ugly mug" width="1280" height="853">`);
});

test("Throw a good error with a bad remote image request", async t => {
let elev = new Eleventy( "test", "test/_site", {
config: eleventyConfig => {
eleventyConfig.addTemplate("virtual.html", `<img src="https://images.opencollective.com/sdkljflksjdflksdjf_DOES_NOT_EXIST/NOT_EXIST/avatar.png" alt="My ugly mug">`);

eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
formats: ["auto"],
// transformOnRequest: true,
// dryRun: true, // don’t write image files!

defaultAttributes: {
loading: "lazy",
}
});
}
});
elev.disableLogger();

let e = await t.throwsAsync(() => elev.toJSON());
t.is(e.message, `Having trouble writing to "./test/_site/virtual/index.html" from "./test/virtual.html"`);
});

0 comments on commit 81e5eeb

Please sign in to comment.