-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.config.js
More file actions
72 lines (63 loc) · 1.64 KB
/
jest.config.js
File metadata and controls
72 lines (63 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Jest 测试配置
* 配置前后端测试环境
*/
export default {
// 测试环境
testEnvironment: 'jsdom',
// 模块文件扩展名
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json'],
// 转换配置
transform: {
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
['@babel/preset-react', { runtime: 'automatic' }]
]
}]
},
// 模块名映射
moduleNameMapping: {
'^@/(.*)$': '<rootDir>/src/$1',
'^@components/(.*)$': '<rootDir>/frontend/src/components/$1',
'^@hooks/(.*)$': '<rootDir>/frontend/src/hooks/$1'
},
// 测试文件匹配模式
testMatch: [
'**/__tests__/**/*.(js|jsx|ts|tsx)',
'**/*.(test|spec).(js|jsx|ts|tsx)'
],
// 忽略的文件和目录
testPathIgnorePatterns: [
'/node_modules/',
'/dist/',
'/public/'
],
// 覆盖率配置
collectCoverage: true,
collectCoverageFrom: [
'src/**/*.{js,jsx,ts,tsx}',
'frontend/src/**/*.{js,jsx,ts,tsx}',
'!src/**/*.d.ts',
'!src/**/*.config.js',
'!**/node_modules/**',
'!**/dist/**'
],
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'html'],
coverageThreshold: {
global: {
branches: 60,
functions: 60,
lines: 60,
statements: 60
}
},
// 设置文件
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// 模拟静态资源
moduleNameMapping: {
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/__mocks__/fileMock.js'
}
};