From 856096674a722011588dec37912b88b484129ef7 Mon Sep 17 00:00:00 2001 From: john Date: Wed, 16 Sep 2026 16:49:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(test):=20=E5=BE=AE=E4=BF=A1=E8=8D=89?= =?UTF-8?q?=E7=A8=BF=E7=BC=A9=E7=95=A5=E5=9B=BE=E6=B5=8B=E8=AF=95=E6=94=B9?= =?UTF-8?q?=E7=94=A8=E8=87=AA=E5=8C=85=E5=90=AB=20fixture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI 环境无 gitignore 的 MindSpace/august-afternoon.html,导致 resolveWechatDraftThumbPath 用例 ENOENT。 Co-authored-by: Cursor --- mindspace-wechat-page-draft.test.mjs | 31 +++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/mindspace-wechat-page-draft.test.mjs b/mindspace-wechat-page-draft.test.mjs index f2bab1f..2e62c2c 100644 --- a/mindspace-wechat-page-draft.test.mjs +++ b/mindspace-wechat-page-draft.test.mjs @@ -230,26 +230,43 @@ test('convertGenericPageHtmlToWechatArticle leaves length clipping to layout', ( }); test('resolveWechatDraftThumbPath prefers hero image over thumbnail sidecar', () => { - const userId = '1c99b83b-0454-474f-a5d2-129d34506a32'; - const html = fs.readFileSync(`MindSpace/${userId}/public/august-afternoon.html`, 'utf8'); + const userId = 'test-user-hero-pref'; + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'wechat-thumb-hero-')); + const publishDir = path.join(root, 'MindSpace', userId); + const publicDir = path.join(publishDir, 'public'); + fs.mkdirSync(publicDir, { recursive: true }); + const heroPath = path.join(publicDir, 'images', 'hero-ca5a45b835d8.webp'); + fs.mkdirSync(path.dirname(heroPath), { recursive: true }); + fs.writeFileSync(heroPath, Buffer.from('webp')); + fs.writeFileSync(path.join(publicDir, 'august-afternoon.thumbnail.png'), Buffer.from('png')); + const html = `八月午后 + +

标题

`; + fs.writeFileSync(path.join(publicDir, 'august-afternoon.html'), html, 'utf8'); const resolved = resolveWechatDraftThumbPath(html, { - h5Root: process.cwd(), + h5Root: root, userId, workspaceRelativePath: 'public/august-afternoon.html', - publishDir: path.join(process.cwd(), 'MindSpace', userId), + publishDir, }); assert.equal(resolved.source, 'hero'); assert.match(resolved.path ?? '', /hero-ca5a45b835d8\.webp$/); }); test('resolveWechatDraftThumbPath falls back to raster sidecar when hero missing', () => { - const userId = '1c99b83b-0454-474f-a5d2-129d34506a32'; + const userId = 'test-user-sidecar-fallback'; + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'wechat-thumb-sidecar-')); + const publishDir = path.join(root, 'MindSpace', userId); + const publicDir = path.join(publishDir, 'public'); + fs.mkdirSync(publicDir, { recursive: true }); + fs.writeFileSync(path.join(publicDir, 'august-afternoon.thumbnail.png'), Buffer.from('png')); const html = `无 hero

标题

`; + fs.writeFileSync(path.join(publicDir, 'august-afternoon.html'), html, 'utf8'); const resolved = resolveWechatDraftThumbPath(html, { - h5Root: process.cwd(), + h5Root: root, userId, workspaceRelativePath: 'public/august-afternoon.html', - publishDir: path.join(process.cwd(), 'MindSpace', userId), + publishDir, }); assert.equal(resolved.source, 'thumbnail-sidecar'); assert.match(resolved.path ?? '', /august-afternoon\.thumbnail\.png$/); -- 2.52.0