fe421ffc55
Co-authored-by: Cursor <cursoragent@cursor.com>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
import { mkdtempSync, rmSync, existsSync, readFileSync } from 'fs'
|
|
import { join } from 'path'
|
|
import { tmpdir } from 'os'
|
|
import { LogService } from '../../src/main/services/log.service'
|
|
|
|
describe('LogService', () => {
|
|
let dir: string
|
|
let logs: LogService
|
|
|
|
beforeEach(() => {
|
|
dir = mkdtempSync(join(tmpdir(), 'bilin-log-'))
|
|
logs = new LogService(dir)
|
|
})
|
|
|
|
afterEach(() => {
|
|
rmSync(dir, { recursive: true, force: true })
|
|
})
|
|
|
|
it('UT-LOG-01: manual error writes to log file', () => {
|
|
logs.logManualError('UT-LOG-01 test error')
|
|
const logFile = join(dir, 'logs', 'bilin.log')
|
|
expect(existsSync(logFile)).toBe(true)
|
|
const content = readFileSync(logFile, 'utf-8')
|
|
expect(content).toContain('UT-LOG-01 test error')
|
|
})
|
|
|
|
it('detects crash flag from previous run', () => {
|
|
logs.markUncleanExit()
|
|
const next = new LogService(dir)
|
|
expect(next.hadCrashOnLastRun()).toBe(true)
|
|
next.clearCrashFlag()
|
|
expect(next.hadCrashOnLastRun()).toBe(false)
|
|
})
|
|
})
|