fix(test): 微信草稿缩略图测试改用自包含 fixture #49
@@ -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 = `<!DOCTYPE html><html><head><title>八月午后</title>
|
||||
<meta name="mindspace-cover" content='{"cover":"images/hero-ca5a45b835d8.webp"}'></head>
|
||||
<body><h1>标题</h1></body></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 = `<!DOCTYPE html><html><head><title>无 hero</title></head><body><h1>标题</h1></body></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, 'thumbnail-sidecar');
|
||||
assert.match(resolved.path ?? '', /august-afternoon\.thumbnail\.png$/);
|
||||
|
||||
Reference in New Issue
Block a user