// 终极:直接构造一个含 font-calligraphy className 的测试元素, // 把它注入到任意真实页面 DOM,读取 computed fontFamily —— 验证 CSS 规则真生效 import { chromium } from 'playwright'; const browser = await chromium.launch(); const page = await browser.newPage({ viewport: { width: 1280, height: 800 } }); await page.goto('http://127.0.0.1:3000/', { waitUntil: 'networkidle' }); await page.waitForTimeout(2000); const result = await page.evaluate(() => { // 找一个已渲染的根节点挂测试元素 const mount = document.body; const probe = document.createElement('span'); probe.id = '__probe_font_calligraphy__'; probe.className = 'font-calligraphy'; probe.textContent = '使命'; probe.style.position = 'fixed'; probe.style.top = '-9999px'; mount.appendChild(probe); const cs = getComputedStyle(probe); const out = { probeFontFamily: cs.fontFamily, probeClassList: Array.from(probe.classList), }; probe.remove(); return out; }); await browser.close(); console.log(JSON.stringify(result, null, 2)); const expectedPrefix = 'STKaiti'; const pass = result.probeFontFamily.startsWith(expectedPrefix); console.log(`\n[assert] probe computed fontFamily starts with ${expectedPrefix}: ${pass}`); console.log(`[result] ${pass ? 'PASS' : 'FAIL'}`);