-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.config.cjs
More file actions
118 lines (101 loc) · 2.83 KB
/
Copy pathjest.config.cjs
File metadata and controls
118 lines (101 loc) · 2.83 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* Jest 配置文件 - Bunny Click 主專案
* 基於 Context7 最佳實踐配置修復 Haste 模組衝突與 ES6 模組問題
* [context7:/jestjs/jest:2025-08-20T01:33:46+08:00]
* 版本: 2025.8.20
*/
/** @type {import('jest').Config} */
const config = {
// 測試環境配置
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// 解決 Haste 模組命名衝突 (history/ 目錄有重複 package.json)
modulePathIgnorePatterns: [
'<rootDir>/history/',
'<rootDir>/dev-tools/',
'<rootDir>/team-worktrees/',
'<rootDir>/dist/',
'<rootDir>/coverage/',
],
// 模組名稱映射 - 修復 ES6 import 問題
moduleNameMapper: {
// 處理相對路徑 ES6 模組
'^../storage/adapter.js$': '<rootDir>/storage/adapter.js',
'^../storage/(.*)$': '<rootDir>/storage/$1',
// 處理樣式檔案
'\\.(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>/tests/__mocks__/fileMock.js',
},
// 變換配置 - ES6 模組支援
transform: {
'^.+\\.js$': 'babel-jest',
},
// 測試匹配模式
testMatch: ['<rootDir>/tests/**/*.test.js', '<rootDir>/scripts/**/*.test.js'],
// 忽略測試路徑
testPathIgnorePatterns: [
'/node_modules/',
'/history/',
'/dev-tools/',
'/team-worktrees/',
'/dist/',
'.*\\.e2e\\.test\\.js$',
],
// 覆蓋率配置
collectCoverage: true,
coverageProvider: 'v8',
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'html'],
collectCoverageFrom: [
'<rootDir>/storage/**/*.js',
'!<rootDir>/scripts/**/*',
'!<rootDir>/tests/**/*',
'!<rootDir>/dev-tools/**/*',
'!<rootDir>/history/**/*',
'!<rootDir>/team-worktrees/**/*',
'!<rootDir>/*.config.js',
'!<rootDir>/app.js',
],
// 模組文件擴展名
moduleFileExtensions: ['js', 'json', 'jsx'],
// 模組目錄
moduleDirectories: ['node_modules'],
// 測試超時
testTimeout: 10000,
// 快取設定 - 根據 Context7 Jest 最佳實踐
cache: true,
cacheDirectory: '<rootDir>/.jest-cache',
// 監控模式忽略路徑 - 防止快取檔案觸發重新執行
watchPathIgnorePatterns: [
'<rootDir>/\\.jest-cache/',
'<rootDir>/node_modules/',
'<rootDir>/coverage/',
'<rootDir>/dist/',
],
// 並行執行
maxWorkers: '50%',
// 錯誤處理
errorOnDeprecated: false,
// 覆蓋率門檻 (根據 .cursor/rules/quality.mdc 標準)
coverageThreshold: {
global: {
branches: 50,
functions: 60,
lines: 55,
statements: 55,
},
'./storage/': {
branches: 50,
functions: 60,
lines: 55,
statements: 55,
},
},
// Jest 全域變數
globals: {
NODE_ENV: 'test',
},
};
module.exports = config;