Files
WechatExplorer/tests/unit/wcdb-close.test.ts
Wxw-Gu c70e49bf16 fix: 完善聊天解析与导出体验
- 修复引用消息名称和图片布局
- 明确单会话图片测试日志范围
- 支持导出文件附件
- 完善图片批测、会话刷新和安全退出
2026-08-04 12:03:07 +08:00

41 lines
1.4 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
import { Wcdb4Client } from '../../src/main/wcdb4-client'
function setPrivate(target: object, key: string, value: unknown): void {
Reflect.set(target, key, value)
}
describe('Wcdb4Client shutdown', () => {
it('waits for tracked Koffi calls before shutting down the native runtime', async () => {
const client = Object.create(Wcdb4Client.prototype) as Wcdb4Client
const shutdown = vi.fn(() => 0)
const inFlight = new Set<Promise<unknown>>()
let finishCall: (() => void) | undefined
const pending = new Promise<void>((resolve) => {
finishCall = resolve
})
inFlight.add(pending)
void pending.then(() => inFlight.delete(pending))
setPrivate(client, 'nativeCallsInFlight', inFlight)
setPrivate(client, 'handle', 1)
setPrivate(client, 'wcdbShutdown', shutdown)
setPrivate(client, 'monitorStarted', false)
setPrivate(client, 'displayNameCache', new Map())
setPrivate(client, 'avatarCache', new Map())
setPrivate(client, 'sessionStatusCache', new Map())
setPrivate(client, 'groupNicknameCache', new Map())
const closing = client.closeAsync(1_000)
expect(shutdown).not.toHaveBeenCalled()
finishCall?.()
await expect(closing).resolves.toBe(true)
if (process.platform === 'win32') {
expect(shutdown).not.toHaveBeenCalled()
} else {
expect(shutdown).toHaveBeenCalledOnce()
}
})
})