Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

test(mermaid): isolate ELK initialization from browser globals

tianma-if42afbc05be1e
diff --git a/apps/web/src/lib/mermaid-renderer.test.mjs b/apps/web/src/lib/mermaid-renderer.test.mjs
index 51d6ce15..da227020 100644
--- a/apps/web/src/lib/mermaid-renderer.test.mjs
+++ b/apps/web/src/lib/mermaid-renderer.test.mjs
@@ -1,4 +1,5 @@
import { describe, expect, test } from "bun:test";
+import { spawnSync } from "node:child_process";
import { renderMermaidSVG } from "beautiful-mermaid";
import mermaid from "mermaid";
import { renderMermaidWithFallback } from "./mermaid-renderer";
@@ -16,7 +17,15 @@ describe("Mermaid renderer fallback", () => {
C[开发/测试/调试] -->|按需开启| B
E[审计场景] -->|按需开启| B
end`;
- expect(renderMermaidSVG(source)).toContain("<svg");
+ // ELK captures the global window and temporarily replaces timers during
+ // initialization. Other suites install partial browser globals, so verify
+ // the real compact renderer in its own process to avoid leaking that state.
+ const compactRender = spawnSync(process.execPath, ["--eval", `
+ import { renderMermaidSVG } from "beautiful-mermaid";
+ process.stdout.write(renderMermaidSVG(${JSON.stringify(source)}));
+ `], { cwd: import.meta.dir, encoding: "utf8", timeout: 30_000 });
+ expect(compactRender.status).toBe(0);
+ expect(compactRender.stdout).toContain("<svg");
let compactRenderCount = 0;
const svg = await renderMermaidWithFallback({
source,