Files
LagZero/tests/unit/JsonStore.spec.ts
ZenEcho 489f3d4f1f feat: 新增游戏平台扫描、主题模式与重置功能
- 新增 BattleNet、WeGame、GOG 等游戏平台扫描支持
- 添加系统代理绕过列表和 Bootstrap DNS 配置
- 实现应用重置功能,支持清理数据并重启
- 增加主题模式选择(亮色/暗色/自动)
- 优化本地游戏扫描性能,支持并行扫描
- 改进代理监控,支持链式代理子进程检测
- 修复日志发送时的窗口销毁检查
- 更新图标和侧边栏布局
- 移除 prepare-singbox-core 脚本,简化构建流程
2026-02-22 03:57:55 +08:00

76 lines
2.0 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { JsonStore } from '../../electron/common/store';
import fs from 'fs-extra';
import path from 'path';
import os from 'os';
describe('JsonStore', () => {
let tempDir: string;
let store: JsonStore<any>;
beforeEach(async () => {
tempDir = path.join(os.tmpdir(), 'lagzero-test-' + Date.now());
await fs.ensureDir(tempDir);
});
afterEach(async () => {
await fs.remove(tempDir);
});
it('should initialize with default values', async () => {
store = new JsonStore({
name: 'test-config',
cwd: tempDir,
defaults: { foo: 'bar' }
});
// Wait for async file operations
await new Promise(r => setTimeout(r, 100));
const content = await fs.readJson(path.join(tempDir, 'test-config.json'));
expect(content).toEqual({ foo: 'bar' });
});
it('should save and load data', async () => {
store = new JsonStore({
name: 'test-config',
cwd: tempDir,
defaults: { foo: 'bar' }
});
await new Promise(r => setTimeout(r, 50));
store.set({ foo: 'baz' });
// Wait for async save
await new Promise(r => setTimeout(r, 100));
expect(store.get()).toEqual({ foo: 'baz' });
const content = await fs.readJson(path.join(tempDir, 'test-config.json'));
expect(content.foo).toBe('baz');
});
it('should create backups on save', async () => {
store = new JsonStore({
name: 'test-backup',
cwd: tempDir,
defaults: { count: 0 },
backupCount: 3
});
await new Promise(r => setTimeout(r, 50));
store.set({ count: 1 });
await new Promise(r => setTimeout(r, 100));
store.set({ count: 2 });
await new Promise(r => setTimeout(r, 100));
const backupDir = path.join(tempDir, 'backups', 'test-backup');
expect(await fs.pathExists(backupDir)).toBe(true);
const files = await fs.readdir(backupDir);
// At least 1 backup should exist (from first save or subsequent saves)
expect(files.length).toBeGreaterThan(0);
});
});