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 9b95029
Show file tree
Hide file tree
Showing 2 changed files with 52 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
49 changes: 49 additions & 0 deletions packages/viz/test/render.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,55 @@ stop
});
});

it("accepts 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("the same image can be used twice", function() {
const result = viz.render("graph { a[image=\"test.png\"]; b[image=\"test.png\"] }", {
images: [
{ name: "test.png", width: 300, height: 200 }
]
});

assert.deepStrictEqual(result, {
status: "success",
output: `graph {
graph [bb="0,0,660.03,214.96"];
node [label="\\N"];
a [height=2.9856,
image="test.png",
pos="160.51,107.48",
width=4.4587];
b [height=2.9856,
image="test.png",
pos="499.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 9b95029

Please sign in to comment.