import * as fs from 'fs'; import * as path from 'path'; describe('UI/UX 规范门禁 (TDD 测试套件: 全面杜绝系统 Emoji)', () => { const rootDir = path.resolve(__dirname, '../../'); const uniPagesDir = path.join(rootDir, 'pwuniapp', 'pages'); const docsDir = path.join(rootDir, 'docs'); // 严格 Emoji 正则:匹配所有系统 Emoji、符号表情及特殊 Pictographic 字符 const emojiRegex = /(?:\p{Extended_Pictographic}|\p{Emoji_Presentation}|[\u2600-\u27BF])/u; function getAllFiles(dir: string, extFilter: string[]): string[] { if (!fs.existsSync(dir)) return []; let results: string[] = []; const list = fs.readdirSync(dir); for (const item of list) { const fullPath = path.join(dir, item); const stat = fs.statSync(fullPath); if (stat.isDirectory()) { results = results.concat(getAllFiles(fullPath, extFilter)); } else if (extFilter.some(ext => item.endsWith(ext))) { results.push(fullPath); } } return results; } describe('1. 首页 (index.vue) 杜绝系统 Emoji 校验', () => { it('首页横幅与卡片中不应含有 ⚡ 或任何系统 Emoji', () => { const indexVuePath = path.join(uniPagesDir, 'index', 'index.vue'); const content = fs.readFileSync(indexVuePath, 'utf-8'); // 验证不包含 ⚡ 闪电 Emoji expect(content).not.toContain('⚡'); // 验证不包含裸写的 ♀ / ♂ 字符(防止系统字体回退为彩色系统 Emoji) expect(content).not.toContain('♀'); expect(content).not.toContain('♂'); }); }); describe('2. 前端 pages 目录下所有页面全局无 Emoji 校验', () => { it('所有 .vue 页面组件模板与文本中严禁包含任何 Emoji 字符', () => { const vueFiles = getAllFiles(uniPagesDir, ['.vue']); const violations: { file: string; line: number; text: string }[] = []; for (const file of vueFiles) { const content = fs.readFileSync(file, 'utf-8'); const lines = content.split('\n'); lines.forEach((line, idx) => { if (emojiRegex.test(line)) { violations.push({ file: path.relative(rootDir, file), line: idx + 1, text: line.trim() }); } }); } expect(violations).toEqual([]); }); }); describe('3. UIUX 约束规范文档纯净度校验', () => { it('设计规范文档中严禁使用 ❌ 系统 Emoji', () => { const docFiles = getAllFiles(docsDir, ['.md']); for (const file of docFiles) { const content = fs.readFileSync(file, 'utf-8'); expect(content).not.toContain('❌'); } }); }); });