feat(DOC): 完整地审查了代码,更完整的注释说明
- 无代码修改
This commit is contained in:
@@ -2,21 +2,6 @@
|
||||
|
||||
本目录包含了对新认证架构的全面测试套件,验证SessionManager、AccessTokenManager、SessionAuthService、ExtendedApiClient和兼容性处理的功能和安全性。
|
||||
|
||||
## 测试结构
|
||||
|
||||
```
|
||||
test/
|
||||
├── auth/
|
||||
│ ├── session-manager.test.ts # SessionManager测试
|
||||
│ ├── access-token-manager.test.ts # AccessTokenManager测试
|
||||
│ ├── session-auth-service.test.ts # SessionAuthService测试
|
||||
│ ├── compatibility.test.ts # 兼容性处理测试
|
||||
│ └── integration.test.ts # 集成测试
|
||||
├── api/
|
||||
│ └── extended-client.test.ts # ExtendedApiClient测试
|
||||
└── setup.ts # 测试环境设置
|
||||
```
|
||||
|
||||
## 测试覆盖范围
|
||||
|
||||
### SessionManager测试
|
||||
@@ -26,7 +11,7 @@ test/
|
||||
- Session清除
|
||||
- 用户角色检查
|
||||
|
||||
### AccessTokenManager测试
|
||||
### AccessTokenManager测试(已废弃)
|
||||
- Token生成
|
||||
- Token获取和缓存
|
||||
- Token刷新
|
||||
@@ -45,50 +30,17 @@ test/
|
||||
- Token注入
|
||||
- 错误处理
|
||||
|
||||
### 兼容性处理测试
|
||||
### 兼容性处理测试(已废弃)
|
||||
- 认证模式切换
|
||||
- Token到Session的迁移
|
||||
- 混合认证模式
|
||||
|
||||
### 集成测试
|
||||
### 集成测试(并没有)
|
||||
- 端到端认证流程
|
||||
- API请求流程
|
||||
- 事件处理
|
||||
- 错误处理
|
||||
|
||||
## 运行测试
|
||||
|
||||
### 运行所有认证架构测试
|
||||
```bash
|
||||
npx ts-node scripts/run-auth-tests.ts
|
||||
```
|
||||
|
||||
### 运行特定测试
|
||||
```bash
|
||||
# SessionManager测试
|
||||
npx vitest run test/auth/session-manager.test.ts
|
||||
|
||||
# AccessTokenManager测试
|
||||
npx vitest run test/auth/access-token-manager.test.ts
|
||||
|
||||
# SessionAuthService测试
|
||||
npx vitest run test/auth/session-auth-service.test.ts
|
||||
|
||||
# ExtendedApiClient测试
|
||||
npx vitest run test/api/extended-client.test.ts
|
||||
|
||||
# 兼容性测试
|
||||
npx vitest run test/auth/compatibility.test.ts
|
||||
|
||||
# 集成测试
|
||||
npx vitest run test/auth/integration.test.ts
|
||||
```
|
||||
|
||||
### 运行覆盖率测试
|
||||
```bash
|
||||
npx ts-node scripts/run-auth-tests.ts --coverage
|
||||
```
|
||||
|
||||
## 测试环境
|
||||
|
||||
测试使用Vitest框架,配置了以下环境:
|
||||
@@ -102,16 +54,16 @@ npx ts-node scripts/run-auth-tests.ts --coverage
|
||||
测试中使用了以下模拟对象:
|
||||
- ApiClient:模拟HTTP客户端
|
||||
- SessionManager:模拟Session管理器
|
||||
- AccessTokenManager:模拟Access Token管理器
|
||||
- AccessTokenManager:模拟Access Token管理器(已废弃)
|
||||
- AuthEventManager:模拟认证事件管理器
|
||||
- TokenManager:模拟Token管理器(用于兼容性测试)
|
||||
- TokenManager:模拟Token管理器(已废弃)
|
||||
|
||||
## 测试数据
|
||||
|
||||
测试使用以下模拟数据:
|
||||
- 用户信息
|
||||
- Session信息
|
||||
- Access Token信息
|
||||
- Access Token信息(已废弃)
|
||||
- API响应数据
|
||||
|
||||
## 断言
|
||||
@@ -123,10 +75,3 @@ npx ts-node scripts/run-auth-tests.ts --coverage
|
||||
- 数据转换
|
||||
- 安全性检查
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 确保在运行测试前已安装所有依赖
|
||||
2. 测试使用模拟数据,不会影响实际系统
|
||||
3. 测试覆盖了主要功能和边界情况
|
||||
4. 测试验证了安全性和错误处理
|
||||
5. 测试确保了兼容性和平滑迁移
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { vi } from 'vitest';
|
||||
|
||||
// 模拟浏览器API
|
||||
// 模拟浏览器API(其实用不到)
|
||||
Object.defineProperty(window, 'localStorage', {
|
||||
value: {
|
||||
getItem: vi.fn(),
|
||||
@@ -26,24 +26,24 @@ Object.defineProperty(window, 'sessionStorage', {
|
||||
writable: true
|
||||
});
|
||||
|
||||
// 模拟IntersectionObserver
|
||||
// 模拟IntersectionObserver(其实用不到)
|
||||
globalThis.IntersectionObserver = vi.fn().mockImplementation(() => ({
|
||||
observe: vi.fn(),
|
||||
unobserve: vi.fn(),
|
||||
disconnect: vi.fn()
|
||||
}));
|
||||
|
||||
// 模拟ResizeObserver
|
||||
// 模拟ResizeObserver(其实用不到)
|
||||
globalThis.ResizeObserver = vi.fn().mockImplementation(() => ({
|
||||
observe: vi.fn(),
|
||||
unobserve: vi.fn(),
|
||||
disconnect: vi.fn()
|
||||
}));
|
||||
|
||||
// 模拟requestAnimationFrame
|
||||
// 模拟requestAnimationFrame(其实用不到)
|
||||
globalThis.requestAnimationFrame = vi.fn((cb: FrameRequestCallback) => setTimeout(cb, 0));
|
||||
|
||||
// 模拟cancelAnimationFrame
|
||||
// 模拟cancelAnimationFrame(其实用不到)
|
||||
globalThis.cancelAnimationFrame = vi.fn((id: number) => clearTimeout(id));
|
||||
|
||||
// 模拟fetch
|
||||
|
||||
Reference in New Issue
Block a user