import { after, test } from 'node:test' import assert from 'node:assert/strict' import { createServer } from 'vite' const server = await createServer({ server: { middlewareMode: true, hmr: false, ws: false }, appType: 'custom', }) const { notificationInlineParts } = await server.ssrLoadModule( '/src/utils/notificationMarkdown.ts', ) after(() => server.close()) test('通知预览呈现加粗、代码和 HTTP(S) 链接', () => { const parts = notificationInlineParts( '项目 **role-user** · `v1.2` [详情](https://example.com/runs)', ) assert.equal(parts.find((part) => part.kind === 'strong').text, 'role-user') assert.equal(parts.find((part) => part.kind === 'code').text, 'v1.2') assert.equal( parts.find((part) => part.kind === 'link').href, 'https://example.com/runs', ) }) test('危险协议和包含凭据的链接按纯文本呈现', () => { for (const url of [ 'javascript:alert', 'data:text/html,hello', 'https://user:pass@example.com/', ]) { assert.equal( notificationInlineParts(`[链接](${url})`).some( (part) => part.kind === 'link', ), false, ) } }) test('模板 HTML 保留为文本节点,不生成可执行节点', () => { const text = '' assert.deepEqual(notificationInlineParts(text), [{ kind: 'text', text }]) })