Files
iven 0d4fa96b82
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
refactor: 统一项目名称从OpenFang到ZCLAW
重构所有代码和文档中的项目名称,将OpenFang统一更新为ZCLAW。包括:
- 配置文件中的项目名称
- 代码注释和文档引用
- 环境变量和路径
- 类型定义和接口名称
- 测试用例和模拟数据

同时优化部分代码结构,移除未使用的模块,并更新相关依赖项。
2026-03-27 07:36:03 +08:00

83 lines
2.2 KiB
TypeScript

import '@testing-library/jest-dom';
import { vi } from 'vitest';
import { webcrypto } from 'node:crypto';
// Polyfill Web Crypto API for Node.js test environment
Object.defineProperty(global, 'crypto', {
value: webcrypto,
configurable: true,
});
// Mock Tauri API
vi.mock('@tauri-apps/api/core', () => ({
invoke: vi.fn(),
}));
// Mock Tauri runtime check
vi.mock('../src/lib/tauri-gateway', () => ({
isTauriRuntime: () => false,
getGatewayClient: vi.fn(),
startLocalGateway: vi.fn(),
stopLocalGateway: vi.fn(),
getLocalGatewayStatus: vi.fn(),
getLocalGatewayAuth: vi.fn(),
prepareLocalGatewayForTauri: vi.fn(),
approveLocalGatewayDevicePairing: vi.fn(),
getZclawProcessList: vi.fn(),
getZclawProcessLogs: vi.fn(),
getUnsupportedLocalGatewayStatus: vi.fn(() => ({
supported: false,
cliAvailable: false,
runtimeSource: null,
runtimePath: null,
serviceLabel: null,
serviceLoaded: false,
serviceStatus: null,
configOk: false,
port: null,
portStatus: null,
probeUrl: null,
listenerPids: [],
error: null,
raw: {},
})),
}));
// Mock localStorage with export for test access
export const localStorageMock = (() => {
let store: Record<string, string> = {};
return {
getItem: (key: string) => store[key] || null,
setItem: (key: string, value: string) => {
store[key] = value;
},
removeItem: (key: string) => {
delete store[key];
},
clear: () => {
store = {};
},
get length() {
return Object.keys(store).length;
},
key: (index: number) => {
const keys = Object.keys(store);
return keys[index] || null;
},
};
})();
Object.defineProperty(global, 'localStorage', {
value: localStorageMock,
configurable: true,
});
// Note: We intentionally do NOT mock crypto.subtle here.
// Tests that need real crypto operations (like crypto-utils) will use the real Web Crypto API.
// Tests that need to mock crypto operations should do so in their own test files.
//
// If you need to mock crypto.subtle for specific tests, use:
// vi.spyOn(crypto.subtle, 'encrypt').mockImplementation(...)
// Or restore after mocking:
// afterAll(() => vi.restoreAllMocks())