mirror of
https://github.com/Silentely/eSIM-Tools.git
synced 2026-09-06 15:58:25 +08:00
- 更新 CLAUDE.md、docs/ARCHITECTURE.md 中的模块与阶段状态,补充 verify-cookie/health/public-config/notifications 等新节点,并将基础设施阶段由规划中标注为进行中 - 完善 docs/SECURITY.md 的 BFF 代理层与 withAuth 中间件说明,明确 x-esim-key 注入、函数白名单校验以及 CORS/体验验证的统一错误格式化策略 - 更新 src/giffgaff/MODULE_ARCHITECTURE.md 的安全考虑条目,补充 cookie 有效性检查间隔、CSP/Helmet 策略、HTML sanitization(escapeHtml/escapeAttr)以及通过 BFF 代理转发的传输层防护细则 - 扩展 tests/CLAUDE.md 测试范围与表格结构,新增 modules、giffgaff、security 三类的独立测试文件清单,并补充 tests/setup.js 的全局初始化说明 - 调整脚本与模块文档:scripts/CLAUDE.md 新增部署与构建相关脚本清单;src/js/modules/CLAUDE.md 更新 CaptchaManager 集成说明与模块覆盖状态,补充 notification-service/browser-utils 等相关条目
75 lines
2.5 KiB
Markdown
75 lines
2.5 KiB
Markdown
[根目录](../CLAUDE.md) > **tests**
|
||
|
||
# 测试模块
|
||
|
||
## 模块职责
|
||
|
||
提供单元测试,覆盖通用工具模块、Giffgaff/Simyo 业务模块和安全校验逻辑。
|
||
|
||
## 测试框架
|
||
|
||
- **框架**: Jest 30.3.0
|
||
- **环境**: jsdom (模拟浏览器)
|
||
- **配置**: `jest.config.js`
|
||
- **Mock**: `tests/__mocks__/` (styleMock.js, fileMock.js)
|
||
- **Setup**: `tests/setup.js`
|
||
|
||
## 测试文件
|
||
|
||
| 目录 | 文件 | 覆盖模块 | 测试项 |
|
||
|------|------|----------|--------|
|
||
| **modules/** | `app-config.test.js` | App Config | 环境配置管理 |
|
||
| | `logger.test.js` | Logger | 日志输出与脱敏 |
|
||
| | `utils.test.js` | Utils | 工具函数 (debounce/throttle 等) |
|
||
| | `html-sanitizer.test.js` | HTML Sanitizer | XSS 防护 (escapeHtml/escapeAttr) |
|
||
| | `secure-storage.test.js` | Secure Storage | 加密 localStorage (TTL 过期) |
|
||
| | `api-service.test.js` | API Service | HTTP 客户端 (重试/缓存/去重) |
|
||
| **simyo/** | `help.test.js` | Simyo 帮助文档 | 帮助内容渲染 |
|
||
| | `simyo-app-device-change.test.js` | `SimyoApp` | 设备更换流程 |
|
||
| | `device-change-handler.test.js` | 设备更换处理 | 设备更换逻辑 |
|
||
| **giffgaff/** | `direct-fetch.test.js` | Giffgaff 直接请求 | Fetch 调用逻辑 |
|
||
| **security/** | `bff-proxy.test.js` | BFF Proxy | Edge Function 安全校验 |
|
||
| | `functions-auth.test.js` | Functions Auth | withAuth 中间件鉴权 |
|
||
| | `server-routes.test.js` | Server Routes | 本地开发服务器路由 |
|
||
|
||
## 运行方式
|
||
|
||
```bash
|
||
npm test # 运行所有测试
|
||
npm run test:watch # 监听模式
|
||
npm run test:coverage # 生成覆盖率报告
|
||
```
|
||
|
||
## 覆盖率阈值
|
||
|
||
- Branches: 60%
|
||
- Functions: 60%
|
||
- Lines: 60%
|
||
- Statements: 60%
|
||
|
||
## Mock 说明
|
||
|
||
- `styleMock.js`: CSS 导入 mock (返回空对象)
|
||
- `fileMock.js`: 静态文件导入 mock (返回文件名字符串)
|
||
- `setup.js`: 全局 setup 文件,在每个测试前初始化 jsdom 环境
|
||
|
||
## 相关文件清单
|
||
|
||
- `jest.config.js` - Jest 配置
|
||
- `tests/setup.js` - 测试设置
|
||
- `tests/__mocks__/styleMock.js`
|
||
- `tests/__mocks__/fileMock.js`
|
||
- `tests/modules/app-config.test.js`
|
||
- `tests/modules/logger.test.js`
|
||
- `tests/modules/utils.test.js`
|
||
- `tests/modules/html-sanitizer.test.js`
|
||
- `tests/modules/secure-storage.test.js`
|
||
- `tests/modules/api-service.test.js`
|
||
- `tests/simyo/help.test.js`
|
||
- `tests/simyo/simyo-app-device-change.test.js`
|
||
- `tests/simyo/device-change-handler.test.js`
|
||
- `tests/giffgaff/direct-fetch.test.js`
|
||
- `tests/security/bff-proxy.test.js`
|
||
- `tests/security/functions-auth.test.js`
|
||
- `tests/security/server-routes.test.js`
|