@bluelovers/jest-config 1.1.10 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/README.md +203 -4
- package/dist/index.cjs.development.cjs +316 -101
- package/dist/index.cjs.development.cjs.map +1 -1
- package/dist/index.cjs.production.min.cjs +100 -67
- package/dist/index.cjs.production.min.cjs.map +1 -1
- package/dist/index.esm.mjs +125 -91
- package/dist/index.esm.mjs.map +1 -1
- package/dist/index.umd.development.cjs +319 -105
- package/dist/index.umd.development.cjs.map +1 -1
- package/dist/index.umd.production.min.cjs +104 -73
- package/dist/index.umd.production.min.cjs.map +1 -1
- package/index.d.ts +142 -0
- package/package.json +31 -40
- package/src/default-setup-fles.ts +49 -0
- package/src/default-transform.ts +96 -0
- package/src/defaults.ts +66 -54
- package/src/helper.ts +100 -3
- package/src/index.ts +77 -15
- package/src/plugin/ts-jest.ts +82 -2
- package/src/print.ts +65 -1
- package/src/types.ts +33 -1
- package/src/util.ts +88 -0
- package/jest-preset.cjs +0 -3
- package/jest-preset.js +0 -3
- package/jest-preset.mjs +0 -3
- package/jest.config.js +0 -116
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,64 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.1.12](https://github.com/bluelovers/ws-jest/compare/@bluelovers/jest-config@1.1.11...@bluelovers/jest-config@1.1.12) (2026-09-12)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### ✨ Features
|
|
11
|
+
|
|
12
|
+
* **@bluelovers/jest-config:** 重構配置邏輯並優化環境與轉換器設定 ([861fac6](https://github.com/bluelovers/ws-jest/commit/861fac6f8a2e0e5e1438b9cfd923c120a82690f3))
|
|
13
|
+
* **@bluelovers/jest-config:** 新增 setupFiles 支援並優化依賴解析工具 ([093e468](https://github.com/bluelovers/ws-jest/commit/093e468ff09a923d78feb2329c6079a039910fc5))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### 📚 Documentation
|
|
17
|
+
|
|
18
|
+
* **jest-config:** 完善 JSDoc 文档和双语 README ([90b1e92](https://github.com/bluelovers/ws-jest/commit/90b1e92c35594b4601a1ec788d04d848de98ab4e))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### 🚨 Tests
|
|
22
|
+
|
|
23
|
+
* **@lazy-assert/jest-expect-matcher:** 新增 snapshot 檔案並重構測試結構 ([d371e65](https://github.com/bluelovers/ws-jest/commit/d371e6577c229db949e2e29f080d4bd4c81ed652))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### 🛠 Build System
|
|
27
|
+
|
|
28
|
+
* 升級開發工具鏈與優化 monorepo 配置 ([d5ec02d](https://github.com/bluelovers/ws-jest/commit/d5ec02de7c66ab9cc1ebbe693e9708c561c68c53))
|
|
29
|
+
* **dist:** update build ([4afc40e](https://github.com/bluelovers/ws-jest/commit/4afc40e52c2dbf807ec50ccab179c969c36f270d))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### ♻️ Chores
|
|
33
|
+
|
|
34
|
+
* **workspace:** 更新 .gitignore 和描述信息 ([247fdee](https://github.com/bluelovers/ws-jest/commit/247fdee5667abc19bb11812d1870e4fb9180a675))
|
|
35
|
+
* **workspace:** 迁移至 pnpm 并重构 Jest 配置 ([c09cfc7](https://github.com/bluelovers/ws-jest/commit/c09cfc7e4472b8f0357d45c1c34e57fddde6e1cc))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### 📌 Dependencies
|
|
39
|
+
|
|
40
|
+
* update deps ([a059d4f](https://github.com/bluelovers/ws-jest/commit/a059d4ffd6de4c2ed678ef2c1b1e1a3cf43ef3eb))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### 🔖 Miscellaneous
|
|
44
|
+
|
|
45
|
+
* . ([e93d019](https://github.com/bluelovers/ws-jest/commit/e93d019e665e5d65bae5536f00e8c57f80ed77df))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
## [1.1.11](https://github.com/bluelovers/ws-jest/compare/@bluelovers/jest-config@1.1.10...@bluelovers/jest-config@1.1.11) (2023-11-16)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### 🛠 Build System
|
|
54
|
+
|
|
55
|
+
* **dist:** update build ([3cc032f](https://github.com/bluelovers/ws-jest/commit/3cc032f37b13377df4dc81311b167431ba7f6ffd))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### 🔖 Miscellaneous
|
|
59
|
+
|
|
60
|
+
* . ([f42bfa4](https://github.com/bluelovers/ws-jest/commit/f42bfa49b883d227f669df994390726d419dc9e9))
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
6
64
|
## [1.1.10](https://github.com/bluelovers/ws-jest/compare/@bluelovers/jest-config@1.1.9...@bluelovers/jest-config@1.1.10) (2023-10-22)
|
|
7
65
|
|
|
8
66
|
|
package/README.md
CHANGED
|
@@ -1,17 +1,216 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @bluelovers/jest-config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Jest configuration preset with TypeScript support, providing automatic ts-jest transform chain integration, cache management, and coverage settings.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
具備 TypeScript 支援的 Jest 配置預設套件,提供自動 ts-jest 轉換鏈整合、快取管理和覆蓋率設定。
|
|
6
|
+
|
|
7
|
+
## 特色 / Features
|
|
8
|
+
|
|
9
|
+
- **預設 Jest 配置 / Default Jest Configuration**: 包含完整的 TypeScript 測試環境設定
|
|
10
|
+
- **ts-jest 轉換鏈 / ts-jest Transform Chain**: 自動整合 `jest-tsd-transform` 和 `jest-chain-transform`
|
|
11
|
+
- **配置混合功能 / Configuration Mixing**: 透過 `mixinJestConfig` 函數輕鬆合併自定義配置
|
|
12
|
+
- **快取目錄管理 / Cache Directory Management**: 自動管理 Jest 快取位置
|
|
13
|
+
- **覆蓋率收集 / Coverage Collection**: 內建 v8 覆蓋率提供者設定
|
|
14
|
+
|
|
15
|
+
## 安裝 / Installation
|
|
6
16
|
|
|
7
17
|
```bash
|
|
18
|
+
# Using npm
|
|
19
|
+
npm install @bluelovers/jest-config
|
|
20
|
+
|
|
21
|
+
# Using yarn
|
|
8
22
|
yarn add @bluelovers/jest-config
|
|
23
|
+
|
|
24
|
+
# Using yarn-tool
|
|
9
25
|
yarn-tool add @bluelovers/jest-config
|
|
26
|
+
|
|
27
|
+
# Using yt (short for yarn-tool)
|
|
10
28
|
yt add @bluelovers/jest-config
|
|
29
|
+
|
|
30
|
+
# Using pnpm
|
|
31
|
+
pnpm add @bluelovers/jest-config
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 使用方式 / Usage
|
|
35
|
+
|
|
36
|
+
### 基本使用 / Basic Usage
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
// jest.config.js
|
|
40
|
+
const { mixinJestConfig } = require('@bluelovers/jest-config');
|
|
41
|
+
|
|
42
|
+
module.exports = mixinJestConfig({
|
|
43
|
+
// 你的自定義配置 / Your custom configuration
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### TypeScript 使用 / TypeScript Usage
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
// jest.config.ts
|
|
51
|
+
import { mixinJestConfig } from '@bluelovers/jest-config';
|
|
52
|
+
|
|
53
|
+
export default mixinJestConfig({
|
|
54
|
+
// 你的自定義配置 / Your custom configuration
|
|
55
|
+
});
|
|
11
56
|
```
|
|
12
57
|
|
|
13
|
-
|
|
58
|
+
### 顯示配置資訊 / Display Configuration Info
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { mixinJestConfig } from '@bluelovers/jest-config';
|
|
62
|
+
|
|
63
|
+
// 第二個參數設為 true 會自動印出配置資訊
|
|
64
|
+
// Set second parameter to true to auto print config info
|
|
65
|
+
export default mixinJestConfig({}, true);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 支援的擴充套件 / Supported Extensions
|
|
69
|
+
|
|
70
|
+
- [`jest-tsd-transform`](https://www.npmjs.com/package/jest-tsd-transform): TypeScript 宣告檔轉換 / TypeScript declaration file transformation
|
|
71
|
+
- [`jest-chain-transform`](https://www.npmjs.com/package/jest-chain-transform): Jest 轉換鏈協調 / Jest transform chain coordination
|
|
14
72
|
|
|
15
73
|
```bash
|
|
16
74
|
yarn add jest-tsd-transform jest-chain-transform
|
|
17
75
|
```
|
|
76
|
+
|
|
77
|
+
## 配置選項 / Configuration Options
|
|
78
|
+
|
|
79
|
+
| 選項 / Option | 說明 / Description | 預設值 / Default |
|
|
80
|
+
|--------------|-------------------|-----------------|
|
|
81
|
+
| `cacheDirectory` | Jest 快取目錄 / Jest cache directory | 自動偵測 / Auto-detected |
|
|
82
|
+
| `maxWorkers` | 最大工作執行緒數量 / Maximum worker threads | `1` |
|
|
83
|
+
| `clearMocks` | 是否清除模擬物件 / Clear mocks between tests | `true` |
|
|
84
|
+
| `passWithNoTests` | 沒有測試時是否通過 / Pass when no tests found | `true` |
|
|
85
|
+
| `moduleFileExtensions` | 模組檔案副檔名 / Module file extensions | `['js','mjs','cjs','jsx','ts','mts','cts','tsx','json','node']` |
|
|
86
|
+
| `testPathIgnorePatterns` | 測試路徑忽略模式 / Test path ignore patterns | `['/node_modules/','/__fixtures__/','/dist/']` |
|
|
87
|
+
| `setupFilesAfterEnv` | 環境設置後載入的檔案 / Files to load after environment setup | `[]` |
|
|
88
|
+
| `coverageProvider` | 覆蓋率提供者 / Coverage provider | `'v8'` |
|
|
89
|
+
| `collectCoverage` | 是否收集覆蓋率 / Collect coverage | `false` |
|
|
90
|
+
| `coveragePathIgnorePatterns` | 覆蓋率路徑忽略模式 / Coverage path ignore patterns | `['/node_modules/','/__snapshots__/','/dist/']` |
|
|
91
|
+
|
|
92
|
+
## API 參考 / API Reference
|
|
93
|
+
|
|
94
|
+
### `mixinJestConfig(jestConfig?, autoPrint?, options?)`
|
|
95
|
+
|
|
96
|
+
混合 Jest 配置的函數。
|
|
97
|
+
Function for mixing Jest configurations.
|
|
98
|
+
|
|
99
|
+
**參數 / Parameters:**
|
|
100
|
+
|
|
101
|
+
- `jestConfig` (可選/optional): 使用者自定義的 Jest 配置 / User custom Jest configuration
|
|
102
|
+
- `autoPrint` (可選/optional): 是否自動印出配置資訊 / Whether to auto print configuration info
|
|
103
|
+
- `options` (可選/optional): 印出配置的選項 / Options for printing configuration
|
|
104
|
+
|
|
105
|
+
**回傳值 / Returns:**
|
|
106
|
+
|
|
107
|
+
- 合併後的完整 Jest 配置 / Merged complete Jest configuration
|
|
108
|
+
|
|
109
|
+
**範例 / Example:**
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { mixinJestConfig } from '@bluelovers/jest-config';
|
|
113
|
+
|
|
114
|
+
const config = mixinJestConfig(
|
|
115
|
+
{
|
|
116
|
+
testEnvironment: 'jsdom',
|
|
117
|
+
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
|
|
118
|
+
},
|
|
119
|
+
true, // 自動印出配置 / Auto print config
|
|
120
|
+
{ cwd: __dirname } // 選項 / Options
|
|
121
|
+
);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## 核心功能 / Core Features
|
|
125
|
+
|
|
126
|
+
### 自動轉換鏈整合 / Automatic Transform Chain Integration
|
|
127
|
+
|
|
128
|
+
此套件會自動偵測並整合以下轉換器:
|
|
129
|
+
This package automatically detects and integrates the following transformers:
|
|
130
|
+
|
|
131
|
+
1. **ts-jest**: 主要的 TypeScript 轉換器 / Primary TypeScript transformer
|
|
132
|
+
2. **jest-tsd-transform**: TypeScript 宣告檔測試支援 / TypeScript declaration file testing support
|
|
133
|
+
3. **jest-chain-transform**: 多層轉換協調 / Multi-layer transform coordination
|
|
134
|
+
|
|
135
|
+
### 快取目錄管理 / Cache Directory Management
|
|
136
|
+
|
|
137
|
+
使用 `jest-cache-directory` 自動選擇最佳的快取位置:
|
|
138
|
+
Uses `jest-cache-directory` to automatically select the optimal cache location:
|
|
139
|
+
|
|
140
|
+
- 優先使用本地 `node_modules/.cache/jest` / Prefer local `node_modules/.cache/jest`
|
|
141
|
+
- 若不可寫入則使用系統暫存目錄 / Falls back to system temp directory if not writable
|
|
142
|
+
|
|
143
|
+
### 測試檔案副檔名 / Test File Extensions
|
|
144
|
+
|
|
145
|
+
預設支援的測試檔案副檔名:
|
|
146
|
+
Default supported test file extensions:
|
|
147
|
+
|
|
148
|
+
- `.ts` - TypeScript
|
|
149
|
+
- `.tsx` - TypeScript with JSX
|
|
150
|
+
- `.mts` - TypeScript ES Module
|
|
151
|
+
- `.cts` - TypeScript CommonJS Module
|
|
152
|
+
|
|
153
|
+
## 發布檔案結構 / Published File Structure
|
|
154
|
+
|
|
155
|
+
### Jest Preset 檔案 / Jest Preset Files
|
|
156
|
+
|
|
157
|
+
此套件發布時包含以下 Jest preset 檔案:
|
|
158
|
+
The following Jest preset files are included when publishing this package:
|
|
159
|
+
|
|
160
|
+
| 檔案 / File | 說明 / Description | 必要性 / Required |
|
|
161
|
+
|------------|-------------------|------------------|
|
|
162
|
+
| `jest-preset.cjs` | CommonJS 版本的 Jest preset | ✅ 必須 / Required |
|
|
163
|
+
| `jest-preset.mjs` | ES Module 版本的 Jest preset | ✅ 必須 / Required |
|
|
164
|
+
| `jest-preset.js` | 不需要實體檔案 / No physical file needed | ❌ 省略 / Omitted |
|
|
165
|
+
|
|
166
|
+
### 為什麼 jest-preset.js 不需要?
|
|
167
|
+
|
|
168
|
+
`package.json` 中的 `exports` 欄位已定義了虛擬路徑映射:
|
|
169
|
+
The `exports` field in `package.json` defines virtual path mappings:
|
|
170
|
+
|
|
171
|
+
```json
|
|
172
|
+
{
|
|
173
|
+
"exports": {
|
|
174
|
+
"./jest-preset": {
|
|
175
|
+
"require": "./jest-preset.cjs",
|
|
176
|
+
"import": "./jest-preset.mjs"
|
|
177
|
+
},
|
|
178
|
+
"./jest-preset.js": {
|
|
179
|
+
"require": "./jest-preset.cjs",
|
|
180
|
+
"import": "./jest-preset.mjs"
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
這表示無論使用者使用 `preset: '@bluelovers/jest-config'` 或 `preset: '@bluelovers/jest-config/jest-preset.js'`,
|
|
187
|
+
Node.js 都會根據環境自動導向至正確的 `.cjs` 或 `.mjs` 檔案。
|
|
188
|
+
|
|
189
|
+
This means whether users use `preset: '@bluelovers/jest-config'` or `preset: '@bluelovers/jest-config/jest-preset.js'`,
|
|
190
|
+
Node.js will automatically resolve to the correct `.cjs` or `.mjs` file based on the environment.
|
|
191
|
+
|
|
192
|
+
### .npmignore 配置
|
|
193
|
+
|
|
194
|
+
確保以下檔案不被忽略:
|
|
195
|
+
Ensure these files are not ignored:
|
|
196
|
+
|
|
197
|
+
```gitignore
|
|
198
|
+
# 保留 Jest preset 檔案 / Keep Jest preset files
|
|
199
|
+
!jest-preset.*
|
|
200
|
+
!jest-preset.cjs
|
|
201
|
+
!jest-preset.mjs
|
|
202
|
+
!jest.config.*
|
|
203
|
+
jest.config.js
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## 授權 / License
|
|
207
|
+
|
|
208
|
+
ISC
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## 相關連結 / Related Links
|
|
213
|
+
|
|
214
|
+
- [GitHub 儲存庫 / Repository](https://github.com/bluelovers/ws-jest)
|
|
215
|
+
- [問題回報 / Issue Tracker](https://github.com/bluelovers/ws-jest/issues)
|
|
216
|
+
- [npm 套件頁面 / npm Package](https://www.npmjs.com/package/@bluelovers/jest-config)
|