mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-10-04 03:01:42 +08:00
chore: 打包配置 测试用例
This commit is contained in:
@@ -38,7 +38,13 @@ function makeRoot(): string {
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })))
|
||||
// Windows 上 sqlite 句柄未释放时 unlink 会 EBUSY;retry 吸收瞬时占用,
|
||||
// 免得 teardown 抛错把真正的断言失败盖掉。
|
||||
await Promise.all(
|
||||
roots
|
||||
.splice(0)
|
||||
.map((root) => rm(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 }))
|
||||
)
|
||||
})
|
||||
|
||||
/** 合法 PNG 头 + 唯一尾部:不同 seed → 不同内容身份(sha256)。 */
|
||||
@@ -164,8 +170,14 @@ function harness(options: {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 等整遍 pass 结束。
|
||||
*
|
||||
* 必须显式给预算:这组用例里有 1050 张的 pass,Windows runner 比本机慢一个数量级,
|
||||
* 默认 1000ms 会超时(其余 image-text-index 用例组也是显式 15s~60s)。
|
||||
*/
|
||||
const finishPass = async (service: ImageTextIndexService): Promise<void> => {
|
||||
await vi.waitFor(() => expect(service.isRunning()).toBe(false))
|
||||
await vi.waitFor(() => expect(service.isRunning()).toBe(false), { timeout: 60_000 })
|
||||
}
|
||||
|
||||
describe('并发契约', () => {
|
||||
@@ -491,7 +503,7 @@ describe('并发契约', () => {
|
||||
})
|
||||
|
||||
await restarted.startPass()
|
||||
await vi.waitFor(() => expect(restarted.isRunning()).toBe(false))
|
||||
await vi.waitFor(() => expect(restarted.isRunning()).toBe(false), { timeout: 60_000 })
|
||||
expect(recognize2).not.toHaveBeenCalled()
|
||||
restarted.resetAccount()
|
||||
|
||||
|
||||
@@ -262,6 +262,11 @@ describe('派生库句柄的账号身份缓存', () => {
|
||||
h.service.resetAccount()
|
||||
})
|
||||
|
||||
/**
|
||||
* 显式预算(见结尾 `30_000`):本用例**故意**烧 ≥700ms 的 sleep,再叠两次真实 SQLite pass——
|
||||
* 本机实测 ~3.9s,已吃掉 vitest 默认 5000ms 的约 80%(Windows 实测 5097ms 越线)。
|
||||
* 内外预算本就该对齐:`runPass` 内部已在等 60_000ms,外层卡默认 5s 是漏写。
|
||||
*/
|
||||
it('pre-loop cost is excluded from per-image cost', async () => {
|
||||
const PRE_LOOP_MS = 400
|
||||
const withPreLoop = createHarness({
|
||||
@@ -308,7 +313,7 @@ describe('派生库句柄的账号身份缓存', () => {
|
||||
|
||||
withPreLoop.service.resetAccount()
|
||||
control.service.resetAccount()
|
||||
})
|
||||
}, 30_000)
|
||||
})
|
||||
|
||||
/**
|
||||
|
||||
@@ -118,8 +118,11 @@ describe('preload IPC contract', () => {
|
||||
createTime: 1785553200,
|
||||
svrId: 'server-11'
|
||||
}
|
||||
// preload 把 options 一路透传(不传即显式 undefined),主进程签名是 (reference, options?)。
|
||||
await api.recognizeVoice(voiceReference)
|
||||
expect(invoke).toHaveBeenLastCalledWith('voice:recognize', voiceReference)
|
||||
expect(invoke).toHaveBeenLastCalledWith('voice:recognize', voiceReference, undefined)
|
||||
await api.recognizeVoice(voiceReference, { force: true })
|
||||
expect(invoke).toHaveBeenLastCalledWith('voice:recognize', voiceReference, { force: true })
|
||||
await api.cancelVoiceRecognition(voiceReference)
|
||||
expect(invoke).toHaveBeenLastCalledWith('voice:cancelRecognition', voiceReference)
|
||||
await api.downloadVoiceModel()
|
||||
|
||||
@@ -38,8 +38,25 @@ const expectContainsTokens = (text: string, tokens: string[]): void => {
|
||||
|
||||
const capability = await systemOcrService.getCapability()
|
||||
const onWindows = process.platform === 'win32'
|
||||
const nativeAvailable = onWindows && capability.available
|
||||
const platformGate = onWindows ? it : it.skip
|
||||
const nativeGate = onWindows && capability.available ? it : it.skip
|
||||
const nativeGate = nativeAvailable ? it : it.skip
|
||||
|
||||
/**
|
||||
* Windows 引擎是**按语言包**建识别器的:机器上只有 en-US 时能认英文、认不出中文。
|
||||
* 所以「中文 token」只在确认存在中文识别器时才算硬门槛 —— CI 的 Windows runner
|
||||
* 只装了 en-US,中文识别不能当所有 CI 的硬门槛(文件头的约定)。
|
||||
*
|
||||
* `language` 为 null 表示"跟随系统语言",无法据以判定,按不可用处理(宁可跳过不可误红)。
|
||||
*/
|
||||
const nativeChineseGate = nativeAvailable && /^zh/i.test(capability.language ?? '') ? it : it.skip
|
||||
|
||||
if (nativeAvailable && !/^zh/i.test(capability.language ?? '')) {
|
||||
console.warn(
|
||||
`[integration] Windows OCR 中文用例跳过:识别器语言为「${capability.language ?? '跟随系统语言'}」,` +
|
||||
'本机未安装中文 OCR 语言包。中文用例需在装有 zh-Hans-CN 识别器的 Windows 机器上通过。'
|
||||
)
|
||||
}
|
||||
|
||||
describe('Windows System OCR native fidelity', () => {
|
||||
platformGate('reports a usable capability on this machine', () => {
|
||||
@@ -49,7 +66,7 @@ describe('Windows System OCR native fidelity', () => {
|
||||
}
|
||||
})
|
||||
|
||||
nativeGate('recognizes simplified Chinese text', async () => {
|
||||
nativeChineseGate('recognizes simplified Chinese text', async () => {
|
||||
const result = await systemOcrService.recognize({
|
||||
imageDataUrl: toDataUrl('system-ocr-zh.png', 'image/png')
|
||||
})
|
||||
@@ -72,7 +89,7 @@ describe('Windows System OCR native fidelity', () => {
|
||||
expectContainsTokens(result.text, ['TraceMemo', 'System', 'OCR'])
|
||||
})
|
||||
|
||||
nativeGate('recognizes mixed Chinese/English text', async () => {
|
||||
nativeChineseGate('recognizes mixed Chinese/English text', async () => {
|
||||
const result = await systemOcrService.recognize({
|
||||
imageDataUrl: toDataUrl('system-ocr-mixed.png', 'image/png')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user