Update test tooling and scripts, add tsconfig.json

Modernizes test and lint scripts in package.json to use Vitest, Prettier, and ESLint directly. Updates devDependencies to latest versions. Adds a tsconfig.json for type checking and editor support. Improves test mocking in performance.test.js and updates documentation in README.md to reflect new test commands. Cleans up unused options in vitest.config.js.
This commit is contained in:
xixu-me committed 2025-07-24 21:28:47 +08:00
1 parent b34e490e6c
commit da0b518900
5 files changed
+77 -22

No files matched your search

+31 -1
View File
@@ -654,10 +654,40 @@ export const PLATFORMS = {
```bash
npm run dev # 启动开发服务器 (http://localhost:8787)
npm test # 运行测试
npm run test:run # 运行完整测试套件
npm run test:coverage # 生成测试覆盖率报告
npm run lint # 代码检查
npm run format # 代码格式化
npm run deploy # 部署到生产
```
## 🧪 测试
项目包含完整的测试套件,确保代码质量和功能正确性。
### 完整测试
```bash
# 安装测试依赖
npm install
# 运行所有测试
npm run test:run
# 生成覆盖率报告
npm run test:coverage
# 监视模式
npm run test:watch
```
### 测试覆盖
- **单元测试**: 核心功能、平台配置、性能监控
- **集成测试**: 端到端流程、平台集成、Git 协议
- **安全测试**: 输入验证、安全头、权限控制
- **性能测试**: 响应时间、内存使用、并发处理
## 🔍 故障排除
### 常见问题
+11 -15
View File
@@ -3,32 +3,28 @@
"xget": "file:"
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.5.0",
"@cloudflare/workers-types": "^4.20241218.0",
"eslint": "^9.17.0",
"prettier": "^3.4.2",
"vitest": "^2.1.8",
"wrangler": "^4.18.0"
"@cloudflare/vitest-pool-workers": "^0.8.36",
"@cloudflare/workers-types": "^4.20250724.0",
"eslint": "^9.31.0",
"prettier": "^3.6.2",
"vitest": "^3.1.4",
"wrangler": "^3.100.0"
},
"name": "xget",
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"format": "node scripts/test.js format",
"format": "prettier --write src/ test/ *.js *.json *.md",
"format:check": "prettier --check src/ test/ *.js *.json *.md",
"lint": "node scripts/test.js lint",
"lint": "eslint src/ test/",
"lint:fix": "eslint src/ test/ --fix",
"start": "wrangler dev",
"test": "node scripts/test.js run",
"test:bench": "node scripts/test.js bench",
"test:ci": "node scripts/test.js ci",
"test:clean": "node scripts/test.js clean",
"test:coverage": "node scripts/test.js coverage",
"test": "vitest",
"test:coverage": "vitest run --coverage",
"test:run": "vitest run",
"test:setup": "node scripts/test.js setup",
"test:ui": "vitest --ui",
"test:watch": "node scripts/test.js watch",
"test:watch": "vitest --watch",
"type-check": "tsc --noEmit"
},
"version": "1.0.0"
+7 -3
View File
@@ -53,14 +53,18 @@ describe('Performance Monitoring', () => {
});
it('should warn on duplicate mark names', () => {
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
// Mock console.warn for this test
const originalWarn = console.warn;
const mockWarn = vi ? vi.fn() : jest.fn();
console.warn = mockWarn;
monitor.mark('duplicate');
monitor.mark('duplicate');
expect(consoleSpy).toHaveBeenCalledWith('Mark with name duplicate already exists.');
expect(mockWarn).toHaveBeenCalledWith('Mark with name duplicate already exists.');
consoleSpy.mockRestore();
// Restore original console.warn
console.warn = originalWarn;
});
it('should return metrics as plain object', () => {
+27
View File
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "node",
"noEmit": true,
"skipLibCheck": true,
"strict": true,
"target": "ES2022",
"types": [
"@cloudflare/workers-types",
"vitest/globals"
]
},
"exclude": [
"node_modules",
"dist",
"coverage"
],
"include": [
"src/**/*",
"test/**/*"
]
}
+1 -3
View File
@@ -31,8 +31,6 @@ export default defineWorkersConfig({
statements: 80
}
}
},
globals: true,
environment: 'node'
}
},
});