Skip to content

Commit

Permalink
Add browser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaines committed Feb 21, 2024
1 parent b9e67c3 commit 6988f2e
Show file tree
Hide file tree
Showing 4 changed files with 2,327 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/viz/test/browser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
dist/
.parcel-cache/
46 changes: 46 additions & 0 deletions packages/viz/test/browser/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!doctype html>
<meta charset="utf8">

<link rel="stylesheet" href="npm:mocha/mocha.css">

<div id="mocha"></div>

<script type="module">

import mocha from "mocha";
import assert from "assert";
import * as Viz from "@viz-js/viz";

mocha.setup("bdd");

describe("renderSVGElement", function() {
let viz;

beforeEach(async function() {
viz = await Viz.instance();
});

it("works", async function() {
assert.ok(viz.renderSVGElement("digraph { a -> b }"));
});

it("works with the images option", function() {
const svg = viz.renderSVGElement("graph { a[image=\"test.png\"] }", {
images: [
{ name: "test.png", width: 300, height: 200 }
]
});

assert.ok(svg);

const image = svg.querySelector("image");

assert.equal(image.getAttributeNS("http://www.w3.org/1999/xlink", "href"), "test.png");
assert.equal(image.getAttribute("width"), "300px");
assert.equal(image.getAttribute("height"), "200px");
});
});

mocha.run();

</script>
18 changes: 18 additions & 0 deletions packages/viz/test/browser/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"private": true,
"type": "module",
"scripts": {
"serve": "parcel serve --no-cache --no-autoinstall index.html"
},
"dependencies": {
"@viz-js/viz": "link:../.."
},
"devDependencies": {
"assert": "^2.1.0",
"buffer": "^6.0.3",
"events": "^3.3.0",
"mocha": "^10.3.0",
"parcel": "^2.11.0",
"stream-browserify": "^3.0.0"
}
}
Loading

0 comments on commit 6988f2e

Please sign in to comment.