From e8701d4eeb1b463ed595ecf569c5f80d1771f292 Mon Sep 17 00:00:00 2001 From: Muse Date: Sat, 14 Nov 2026 11:23:38 +0800 Subject: [PATCH] =?UTF-8?q?test(export):=20Mermaid=20=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E7=AE=A1=E7=BA=BF=E6=A1=A9=E6=B8=B2=E6=9F=93=E5=9B=9E=E5=BD=92?= =?UTF-8?q?=EF=BC=88=E6=9B=BF=E6=8D=A2=E4=B8=8E=20PNG=20=E5=85=9C=E5=BA=95?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit jsdom 跑不了 mermaid.render(缺 SVG 布局 API),用 vi.mock 桩验证剪贴板版 Mermaid 被替换为渲染结果而非代码块;全量 80 通过 + 2 跳过。 --- tests/stage5.test.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/stage5.test.ts b/tests/stage5.test.ts index 28d758d..67993db 100644 --- a/tests/stage5.test.ts +++ b/tests/stage5.test.ts @@ -1,8 +1,17 @@ // 阶段 5 验收:主题注册表完整性、导出 HTML 管线(结构/表格/公式/代码)、HTML 导入转换。 -import { describe, it, expect } from 'vitest' +import { describe, it, expect, vi } from 'vitest' import { DOC_THEMES, docThemeById } from '../src/themes' import { markdownToExportHtml, htmlToMarkdown, exportCss } from '../src/services/exportHtml' +// jsdom 里 mermaid.render 依赖真实 SVG 布局 API 会失败;用桩验证导出管线的 +// 替换与兜底逻辑(真机栅格化 PNG 只能在 Windows 复验) +vi.mock('mermaid', () => ({ + default: { + initialize: () => undefined, + render: async () => ({ svg: '图' }), + }, +})) + describe('文档主题注册表', () => { it('7 套主题 id 唯一且可查', () => { expect(DOC_THEMES).toHaveLength(7) @@ -87,3 +96,14 @@ describe('二轮验收:导出与导入', () => { expect(md).not.toContain('color:red') }) }) + +describe('二轮验收:Mermaid 导出替换', () => { + it('剪贴板版 Mermaid 经桩渲染后不再是代码块(PNG 栅格化失败退回 SVG)', async () => { + const html = await markdownToExportHtml('```mermaid\ngraph TD\n A-->B\n```\n', { + title: 't', themeId: 'default', imageMode: 'embed', forClipboard: true, mermaidPng: true, + highlight: false, + }) + expect(html).toContain('data-stub="mermaid"') + expect(html).not.toContain('language-mermaid') + }) +})