From 8d475087d2bf884de0ef5d313f972b2c7c216fdf Mon Sep 17 00:00:00 2001 From: john Date: Wed, 16 Sep 2026 10:35:34 +0800 Subject: [PATCH] =?UTF-8?q?test(wechat):=20=E9=9A=94=E7=A6=BB=20sidecar=20?= =?UTF-8?q?=E7=BC=A9=E7=95=A5=E5=9B=BE=E5=80=99=E9=80=89=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=20SEO=20=E5=9B=9E=E5=A1=AB=E6=B1=A1?= =?UTF-8?q?=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 改用临时目录 fixture,不再依赖本地 MindSpace 可被 backfill 改写的 HTML。 Co-authored-by: Cursor --- mindspace-wechat-page-draft.test.mjs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/mindspace-wechat-page-draft.test.mjs b/mindspace-wechat-page-draft.test.mjs index dc9327a..f2bab1f 100644 --- a/mindspace-wechat-page-draft.test.mjs +++ b/mindspace-wechat-page-draft.test.mjs @@ -1,5 +1,6 @@ import assert from 'node:assert/strict'; import fs from 'node:fs'; +import os from 'node:os'; import path from 'node:path'; import test from 'node:test'; import { @@ -196,12 +197,20 @@ test('convertRichMindSpacePageHtmlToWechatArticle extracts blog and startup temp }); test('collectPageImageCandidates adds sidecar thumbnail when hero image missing', () => { - const publishDir = path.join(process.cwd(), 'MindSpace', '1c99b83b-0454-474f-a5d2-129d34506a32'); - const html = fs.readFileSync(path.join(publishDir, 'public/qiuting-xiaoxi.html'), 'utf8'); - const candidates = mindspaceWechatPageDraftInternals.collectPageImageCandidates(html, { - publishDir, - htmlRelativePath: 'public/qiuting-xiaoxi.html', - }); + const publishDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mindspace-wechat-draft-')); + const htmlRelativePath = 'public/no-hero-page.html'; + const htmlPath = path.join(publishDir, htmlRelativePath); + fs.mkdirSync(path.dirname(htmlPath), { recursive: true }); + fs.writeFileSync( + htmlPath, + '无封面页

无封面页

正文

', + 'utf8', + ); + fs.writeFileSync(htmlPath.replace(/\.html$/i, '.thumbnail.png'), Buffer.from('png'), 'utf8'); + const candidates = mindspaceWechatPageDraftInternals.collectPageImageCandidates( + fs.readFileSync(htmlPath, 'utf8'), + { publishDir, htmlRelativePath }, + ); assert.ok(candidates.some((item) => /\.thumbnail\.(png|svg)$/i.test(item.ref ?? ''))); });