Files
eSIM-Tools/jest.config.js
Abner 9ed51287c0 test: 新增多个核心模块的单元测试并优化 Jest 配置
- 在 `jest.config.js` 中启用 V8 覆盖率提供器(兼容 Node.js 22+),提升覆盖率检测性能与准确性
- 调整覆盖率收集范围为 `src/js/modules/**/*.js`,排除测试文件,使报告更聚焦于实际业务逻辑
- 降低全局覆盖率阈值至当前可达成水平(statements/branches 30%-70%),制定逐步提升计划
- 新增 6 个模块的完整单元测试:`APIService`、`AppConfig`、`HTMLSanitizer`、`Logger`、`SecureStorage` 和 `utils`,总计约 840 行测试代码
- 修复 `HTMLSanitizer.sanitizeURL()` 中对 `data:text/html` 协议的正则检测逻辑,增强 XSS 防护能力
2026-05-05 10:35:14 +08:00

76 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Jest 测试框架配置
*/
module.exports = {
// 测试环境
testEnvironment: 'jsdom',
// 覆盖率提供器:使用 V8 替代 babel-plugin-istanbul兼容 Node.js 22+
coverageProvider: 'v8',
// 测试文件匹配模式
testMatch: [
'**/tests/**/*.test.js',
'**/tests/**/*.spec.js',
'**/__tests__/**/*.js'
],
// 忽略的文件/目录
testPathIgnorePatterns: [
'/node_modules/',
'/dist/',
'/netlify/',
'/.netlify/'
],
// 覆盖率收集
collectCoverageFrom: [
'src/js/modules/**/*.js',
'!src/js/modules/**/*.test.js',
'!src/js/modules/**/*.spec.js',
'!**/node_modules/**',
'!**/dist/**'
],
// 覆盖率报告格式
coverageReporters: [
'text',
'text-summary',
'html',
'lcov'
],
// 覆盖率阈值(逐步提升:当前 34% statements目标 60%
coverageThreshold: {
global: {
branches: 70,
functions: 65,
lines: 30,
statements: 30
}
},
// 模块名映射
moduleNameMapper: {
'\\.(css|less|scss|sass)$': '<rootDir>/tests/__mocks__/styleMock.js',
'\\.(gif|ttf|eot|svg|png|jpg|jpeg)$': '<rootDir>/tests/__mocks__/fileMock.js'
},
// 转换器配置
transform: {
'^.+\\.js$': 'babel-jest'
},
// 设置文件
setupFilesAfterEnv: ['<rootDir>/tests/setup.js'],
// 详细输出
verbose: true,
// 清除模拟
clearMocks: true,
// 恢复模拟
restoreMocks: true
};