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

53 lines
2.2 KiB
TypeScript

import { createRequire } from 'module'
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs'
import { tmpdir } from 'os'
import { dirname, join, resolve } from 'path'
import { afterAll, describe, expect, it } from 'vitest'
const nodeRequire = createRequire(import.meta.url)
const { validateFfmpegRuntime, validateSilkWasmRuntime } = nodeRequire(
'../../scripts/after-pack.cjs'
) as {
validateFfmpegRuntime: (runtimeResources: string, platform?: NodeJS.Platform) => void
validateSilkWasmRuntime: (runtimeResources: string) => void
}
const root = mkdtempSync(join(tmpdir(), 'wxe-runtime-package-'))
describe('production runtime packaging', () => {
afterAll(() => rmSync(root, { recursive: true, force: true }))
it('requires the complete unpacked silk-wasm runtime', () => {
const packagePath = join(root, 'resources', 'app.asar.unpacked', 'node_modules', 'silk-wasm')
mkdirSync(join(packagePath, 'lib'), { recursive: true })
writeFileSync(join(packagePath, 'package.json'), '{}')
writeFileSync(join(packagePath, 'lib', 'index.cjs'), 'module.exports = {}')
expect(() => validateSilkWasmRuntime(join(root, 'resources'))).toThrow(/silk\.wasm/)
writeFileSync(join(packagePath, 'lib', 'silk.wasm'), Buffer.from([0, 97, 115, 109]))
expect(() => validateSilkWasmRuntime(join(root, 'resources'))).not.toThrow()
})
it('keeps silk-wasm in electron-builder asarUnpack', () => {
const config = readFileSync(resolve(__dirname, '../../electron-builder.yml'), 'utf8')
expect(config).toContain('node_modules/silk-wasm/**')
})
it('requires and unpacks the bundled ffmpeg-static executable', () => {
const resources = join(root, 'ffmpeg-resources')
const ffmpegPath = join(
resources,
'app.asar.unpacked',
'node_modules',
'ffmpeg-static',
'ffmpeg'
)
expect(() => validateFfmpegRuntime(resources, 'darwin')).toThrow(/ffmpeg-static/)
mkdirSync(dirname(ffmpegPath), { recursive: true })
writeFileSync(ffmpegPath, 'fixture')
expect(() => validateFfmpegRuntime(resources, 'darwin')).not.toThrow()
const config = readFileSync(resolve(__dirname, '../../electron-builder.yml'), 'utf8')
expect(config).toContain('node_modules/ffmpeg-static/**')
})
})