Files
WechatExplorer/tests/unit/voice-runtime.test.ts
Wxw-Gu 0a3d930298 fix: 修复媒体导出与 HTML 聊天档案体验
- 修复打包版图片、语音解析不可用,内置 FFmpeg 与必要运行时依赖
- 修复 HTML 导出原图查找、缩略图回退及增量档案媒体解析问题
- 修复本人昵称在软件和 HTML 导出中显示为微信号的问题,并兼容旧档案昵称迁移
- 修复 HTML 语音播放器超出消息气泡的问题
- 优化 HTML 双向滚动加载,大量消息时最多渲染 240 条,避免页面卡顿
- 移除图片解密页面中手动配置 FFmpeg 的相关提示
- 补充图片解密、语音运行时、打包资源和 HTML 导出相关测试
2026-08-04 17:03:07 +08:00

50 lines
1.9 KiB
TypeScript

import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'fs'
import { tmpdir } from 'os'
import { join } from 'path'
import { afterAll, describe, expect, it, vi } from 'vitest'
const root = mkdtempSync(join(tmpdir(), 'wxe-voice-runtime-'))
vi.mock('electron', () => ({ app: { getAppPath: () => join(root, 'development-app') } }))
vi.mock('../../src/main/runtime-mode', () => ({ isPackagedRuntime: () => false }))
vi.mock('../../src/main/wcdb4-client', () => ({ Wcdb4Client: class {} }))
import {
findSilkWasmRuntimeLocation,
getSilkWasmRuntimeLocations
} from '../../src/main/voice-service'
function writeWasm(packagePath: string): void {
mkdirSync(join(packagePath, 'lib'), { recursive: true })
writeFileSync(join(packagePath, 'lib', 'silk.wasm'), Buffer.from([0, 97, 115, 109]))
}
describe('silk-wasm runtime discovery', () => {
afterAll(() => rmSync(root, { recursive: true, force: true }))
it('prefers the unpacked package and still recognizes the legacy asar layout', () => {
const resourcesPath = join(root, 'Resources')
const appPath = join(resourcesPath, 'app.asar')
const asarPackage = join(appPath, 'node_modules', 'silk-wasm')
writeWasm(asarPackage)
const locations = getSilkWasmRuntimeLocations({ packaged: true, resourcesPath, appPath })
expect(findSilkWasmRuntimeLocation(locations)).toMatchObject({ source: 'asar' })
writeWasm(join(resourcesPath, 'app.asar.unpacked', 'node_modules', 'silk-wasm'))
expect(findSilkWasmRuntimeLocation(locations)).toMatchObject({ source: 'unpacked' })
})
it('uses the regular node_modules package in development', () => {
const appPath = join(root, 'development-app')
const locations = getSilkWasmRuntimeLocations({ packaged: false, appPath })
expect(locations).toEqual([
expect.objectContaining({
source: 'development',
packagePath: join(appPath, 'node_modules', 'silk-wasm')
})
])
})
})