返回 oh-my-ppt
renderer-recovery.test.ts
根目录 / tests / unit / main / renderer-recovery.test.ts
1 import { describe, expect, it } from 'vitest'
2 import {
3 isRepeatedRendererCrash,
4 RENDERER_CRASH_WINDOW_MS,
5 shouldRecoverRenderer
6 } from '../../../src/main/app/renderer-recovery'
7
8 describe('renderer recovery', () => {
9 it('recovers crashes and OOM exits but ignores intentional exits', () => {
10 expect(shouldRecoverRenderer('crashed')).toBe(true)
11 expect(shouldRecoverRenderer('oom')).toBe(true)
12 expect(shouldRecoverRenderer('abnormal-exit')).toBe(true)
13 expect(shouldRecoverRenderer('clean-exit')).toBe(false)
14 expect(shouldRecoverRenderer('killed')).toBe(false)
15 })
16
17 it('detects repeated crashes inside the recovery window', () => {
18 expect(isRepeatedRendererCrash(0, RENDERER_CRASH_WINDOW_MS)).toBe(false)
19 expect(isRepeatedRendererCrash(1_000, 1_000 + RENDERER_CRASH_WINDOW_MS)).toBe(true)
20 expect(isRepeatedRendererCrash(1_000, 1_001 + RENDERER_CRASH_WINDOW_MS)).toBe(false)
21 })
22 })
23
23 lines TYPESCRIPT