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 ?? ''))); });