Skip to content

Commit

Permalink
Only delete dummy image files if they exist
Browse files Browse the repository at this point in the history
See #237
  • Loading branch information
mdaines committed Feb 24, 2024
1 parent aeaf0e9 commit c7b3e0f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/viz/src/viz.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ function createImageFiles(module, images) {

function removeImageFiles(module, imageFilePaths) {
for (const path of imageFilePaths) {
module.FS.unlink(path);
if (module.FS.analyzePath(path).exists) {
module.FS.unlink(path);
}
}
}

Expand Down
23 changes: 23 additions & 0 deletions packages/viz/test/render.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,29 @@ stop
});
});

it("accept two images with the same name", function() {
const result = viz.render("graph { a[image=\"test.png\"] }", {
images: [
{ name: "test.png", width: 300, height: 200 },
{ name: "test.png", width: 300, height: 200 }
]
});

assert.deepStrictEqual(result, {
status: "success",
output: `graph {
graph [bb="0,0,321.03,214.96"];
node [label="\\N"];
a [height=2.9856,
image="test.png",
pos="160.51,107.48",
width=4.4587];
}
`,
errors: []
});
});

it("accepts URLs for image names", function() {
const result = viz.render("graph { a[image=\"http://example.com/test.png\"] }", {
images: [
Expand Down

0 comments on commit c7b3e0f

Please sign in to comment.