test: Add visual testing for examples

This commit is contained in:
Sidharth Vinod
2025-04-05 09:11:18 +05:30
parent 695b5b2fb2
commit a25ee49edd
2 changed files with 43 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
import { urlSnapshotTest } from '../../helpers/util.js';
describe.skip('Examples', () => {
it('should render all examples', () => {
urlSnapshotTest('http://localhost:9000/examples.html');
});
});

View File

@@ -0,0 +1,36 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Examples</title>
</head>
<body>
<script type="module">
import mermaid from './mermaid.esm.mjs';
import { diagramData } from './mermaid-examples.esm.mjs';
for (const d of diagramData) {
const div = document.createElement('div');
const h1 = document.createElement('h1');
h1.appendChild(document.createTextNode(d.name));
div.appendChild(h1);
div.appendChild(document.createTextNode(d.description));
for (const example of d.examples) {
const pre = document.createElement('pre');
pre.classList.add('mermaid');
pre.textContent = example.code;
div.appendChild(pre);
}
document.body.appendChild(div);
}
mermaid.initialize({
startOnLoad: false,
logLevel: 0,
});
await mermaid.run();
if (window.Cypress) {
window.rendered = true;
}
</script>
</body>
</html>