@bluelovers/jest-config 1.1.11 → 1.1.13
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/jest-preset.cjs +20 -0
- package/jest-preset.mjs +25 -0
- package/jest.config.js +108 -16
- package/package.json +31 -41
- 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.js +0 -3
|
@@ -8,97 +8,98 @@ var arrayHyperUnique = require('array-hyper-unique');
|
|
|
8
8
|
var table = require('@yarn-tool/table');
|
|
9
9
|
var util = require('util');
|
|
10
10
|
var jestCacheDirectory = require('jest-cache-directory');
|
|
11
|
+
var regexpHelperCore = require('regexp-helper-core');
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
noUnusedParameters: false,
|
|
22
|
-
allowUnusedLabels: true,
|
|
23
|
-
noUnusedLocals: false,
|
|
24
|
-
noPropertyAccessFromIndexSignature: false,
|
|
25
|
-
noImplicitAny: false,
|
|
26
|
-
...tsconfig
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
13
|
+
/**
|
|
14
|
+
* 取得預設的測試檔案副檔名列表
|
|
15
|
+
* Get default test file extensions list
|
|
16
|
+
*
|
|
17
|
+
* 定義哪些副檔名的檔案會被視為測試檔案
|
|
18
|
+
* Defines which file extensions are recognized as test files
|
|
19
|
+
*
|
|
20
|
+
* @returns {string[]} 測試檔案副檔名陣列 / Array of test file extensions
|
|
21
|
+
*/
|
|
31
22
|
function defaultTestFileExtensions() {
|
|
32
|
-
const value = ['ts', 'tsx', 'mts', 'cts'
|
|
33
|
-
// 'js',
|
|
34
|
-
// 'jsx',
|
|
35
|
-
// 'mjs',
|
|
36
|
-
// 'cjs',
|
|
37
|
-
];
|
|
38
|
-
|
|
23
|
+
const value = ['ts', 'tsx', 'mts', 'cts'];
|
|
39
24
|
return value;
|
|
40
25
|
}
|
|
41
26
|
/**
|
|
27
|
+
* 取得預設的模組檔案副檔名列表
|
|
28
|
+
* Get default module file extensions list
|
|
29
|
+
*
|
|
30
|
+
* 定義模組解析時搜尋的副檔名順序
|
|
31
|
+
* Defines the order of extensions to search during module resolution
|
|
32
|
+
*
|
|
42
33
|
* @see https://jestjs.io/docs/configuration#options
|
|
34
|
+
* @returns {string[]} 模組檔案副檔名陣列 / Array of module file extensions
|
|
43
35
|
*/
|
|
44
36
|
function defaultModuleFileExtensions() {
|
|
45
37
|
const value = ['js', 'mjs', 'cjs', 'jsx', 'ts', 'mts', 'cts', 'tsx', 'json', 'node'];
|
|
46
38
|
return value;
|
|
47
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* 取得預設的覆蓋率檔案副檔名列表
|
|
42
|
+
* Get default coverage file extensions list
|
|
43
|
+
*
|
|
44
|
+
* 定義哪些副檔名的檔案會被納入覆蓋率統計
|
|
45
|
+
* Defines which file extensions are included in coverage statistics
|
|
46
|
+
*
|
|
47
|
+
* @returns {string[]} 覆蓋率檔案副檔名陣列 / Array of coverage file extensions
|
|
48
|
+
*/
|
|
48
49
|
function defaultCoverageFileExtensions() {
|
|
49
|
-
const value = ['js', 'mjs', 'cjs', 'jsx', 'ts', 'mts', 'cts', 'tsx'
|
|
50
|
-
//'json',
|
|
51
|
-
//'node',
|
|
52
|
-
];
|
|
53
|
-
|
|
50
|
+
const value = ['js', 'mjs', 'cjs', 'jsx', 'ts', 'mts', 'cts', 'tsx'];
|
|
54
51
|
return value;
|
|
55
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* 取得預設的轉換器檔案副檔名列表
|
|
55
|
+
* Get default transformer file extensions list
|
|
56
|
+
*
|
|
57
|
+
* 定義哪些副檔名的檔案需要經過 ts-jest 轉換
|
|
58
|
+
* Defines which file extensions need to be transformed by ts-jest
|
|
59
|
+
*
|
|
60
|
+
* @returns {string[]} 轉換器檔案副檔名陣列 / Array of transformer file extensions
|
|
61
|
+
*/
|
|
56
62
|
function defaultTransformFileExtensions() {
|
|
57
63
|
const value = ['ts', 'tsx', 'mts', 'cts'];
|
|
58
64
|
return value;
|
|
59
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* 取得預設的覆蓋率忽略路徑模式
|
|
68
|
+
* Get default coverage path ignore patterns
|
|
69
|
+
*
|
|
70
|
+
* 定義哪些路徑的檔案不納入覆蓋率統計
|
|
71
|
+
* Defines which paths are excluded from coverage statistics
|
|
72
|
+
*
|
|
73
|
+
* @returns {string[]} 覆蓋率忽略路徑模式陣列 / Array of coverage ignore patterns
|
|
74
|
+
*/
|
|
60
75
|
function defaultCoveragePathIgnorePatterns() {
|
|
61
|
-
const value = ['/node_modules/', '/__snapshots__/', '/__tests__/', '/__test__/',
|
|
62
|
-
//'**/node_modules/',
|
|
63
|
-
//'**/__snapshots__/',
|
|
64
|
-
//'**/__tests__/',
|
|
65
|
-
'/dist/', '/test/', '/fixture/', '/__file_snapshots__/', '/__fixtures__/'];
|
|
76
|
+
const value = ['/node_modules/', '/__snapshots__/', '/__tests__/', '/__test__/', '/dist/', '/test/', '/fixture/', '/__file_snapshots__/', '/__fixtures__/'];
|
|
66
77
|
return value;
|
|
67
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* 取得預設的測試路徑忽略模式
|
|
81
|
+
* Get default test path ignore patterns
|
|
82
|
+
*
|
|
83
|
+
* 定義哪些路徑的檔案不會被視為測試檔案
|
|
84
|
+
* Defines which paths are excluded from test file recognition
|
|
85
|
+
*
|
|
86
|
+
* @returns {string[]} 測試路徑忽略模式陣列 / Array of test path ignore patterns
|
|
87
|
+
*/
|
|
68
88
|
function defaultTestPathIgnorePatterns() {
|
|
69
89
|
const value = ['/node_modules/', '/__fixtures__/', '/__file_snapshots__/', '/fixtures/', '/__tests__/helpers/', '/__tests__/utils/', '__mocks__', '/dist/'];
|
|
70
90
|
return value;
|
|
71
91
|
}
|
|
72
|
-
function defaultTransform(runtime) {
|
|
73
|
-
const paths = [requireResolve.requireResolveExtra('@bluelovers/jest-config').result].filter(Boolean);
|
|
74
|
-
const opts = {
|
|
75
|
-
includeGlobal: true,
|
|
76
|
-
includeCurrentDirectory: true,
|
|
77
|
-
paths
|
|
78
|
-
};
|
|
79
|
-
let ts_transform = _requireResolve('ts-jest');
|
|
80
|
-
ts_transform = [ts_transform, defaultTsJestTransformerOptions(runtime)];
|
|
81
|
-
const {
|
|
82
|
-
result: tsd
|
|
83
|
-
} = requireResolve.requireResolveExtra('jest-tsd-transform', opts);
|
|
84
|
-
if (tsd !== null && tsd !== void 0 && tsd.length) {
|
|
85
|
-
const {
|
|
86
|
-
result: chain
|
|
87
|
-
} = requireResolve.requireResolveExtra('jest-chain-transform', opts);
|
|
88
|
-
if (chain !== null && chain !== void 0 && chain.length) {
|
|
89
|
-
ts_transform = [chain, {
|
|
90
|
-
transformers: [tsd,
|
|
91
|
-
// @ts-ignore
|
|
92
|
-
ts_transform]
|
|
93
|
-
}];
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
const value = {
|
|
97
|
-
[`.(${_handleFileExtensions(defaultTransformFileExtensions(), '|')})$`]: ts_transform
|
|
98
|
-
};
|
|
99
|
-
return value;
|
|
100
|
-
}
|
|
101
92
|
|
|
93
|
+
/**
|
|
94
|
+
* 解析模組路徑的內部輔助函數
|
|
95
|
+
* Internal helper function for resolving module paths
|
|
96
|
+
*
|
|
97
|
+
* 優先從 @bluelovers/tsdx 或 tsdx 套件路徑中搜尋,若失敗則使用標準 require.resolve
|
|
98
|
+
* Searches from @bluelovers/tsdx or tsdx package paths first, falls back to standard require.resolve
|
|
99
|
+
*
|
|
100
|
+
* @param {string} name - 要解析的模組名稱 / Module name to resolve
|
|
101
|
+
* @returns {string} 解析後的模組絕對路徑 / Resolved absolute module path
|
|
102
|
+
*/
|
|
102
103
|
function _requireResolve(name) {
|
|
103
104
|
const paths = [requireResolve.requireResolveExtra('@bluelovers/tsdx').result, requireResolve.requireResolveExtra('tsdx').result].filter(Boolean);
|
|
104
105
|
const result = requireResolve.requireResolveCore(name, {
|
|
@@ -109,21 +110,64 @@ function _requireResolve(name) {
|
|
|
109
110
|
debugColor2.console.debug('[require.resolve]', name, '=>', result);
|
|
110
111
|
return result;
|
|
111
112
|
}
|
|
113
|
+
function _requireResolve2(name) {
|
|
114
|
+
return requireResolve.requireResolveExtra(name, {
|
|
115
|
+
includeGlobal: true,
|
|
116
|
+
includeCurrentDirectory: true
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 建立測試正則表達式配置
|
|
121
|
+
* Create test regex configuration
|
|
122
|
+
*
|
|
123
|
+
* 根據測試檔案副檔名生成 testMatch 和 testRegex 配置
|
|
124
|
+
* Generates testMatch and testRegex configs based on test file extensions
|
|
125
|
+
*
|
|
126
|
+
* @param {T} testExt - 測試檔案副檔名或陣列 / Test file extension(s)
|
|
127
|
+
* @returns {object} 包含 testMatch 和 testRegex 的配置物件 / Object containing testMatch and testRegex
|
|
128
|
+
*/
|
|
112
129
|
function makeTestRegexConfig(testExt) {
|
|
113
|
-
|
|
114
|
-
(_testExt2 = testExt) !== null && _testExt2 !== void 0 ? _testExt2 : testExt = defaultTestFileExtensions();
|
|
130
|
+
testExt !== null && testExt !== void 0 ? testExt : testExt = defaultTestFileExtensions();
|
|
115
131
|
const _testExt = _handleFileExtensions(testExt, '|');
|
|
116
132
|
return {
|
|
117
133
|
testMatch: null,
|
|
118
134
|
testRegex: [`\\.(tests?|spec)\\.(${_testExt})$`, `__tests__\/\.*\\.(tests?|spec)\\.(${_testExt})$`]
|
|
119
135
|
};
|
|
120
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* 處理檔案副檔名陣列的核心函數
|
|
139
|
+
* Core function for processing file extension arrays
|
|
140
|
+
*
|
|
141
|
+
* 將輸入轉換為唯一的副檔名陣列
|
|
142
|
+
* Converts input to unique array of extensions
|
|
143
|
+
*
|
|
144
|
+
* @param {T} testExt - 輸入的副檔名(可為陣列或單一值) / Input extension(s)
|
|
145
|
+
* @returns {T[]} 唯一的副檔名陣列 / Unique array of extensions
|
|
146
|
+
*/
|
|
121
147
|
function _handleFileExtensionsCore(testExt) {
|
|
122
148
|
return arrayHyperUnique.array_unique([testExt].flat());
|
|
123
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* 處理檔案副檔名並以指定分隔符連接
|
|
152
|
+
* Process file extensions and join with specified separator
|
|
153
|
+
*
|
|
154
|
+
* @param {T} testExt - 輸入的副檔名(可為陣列或單一值) / Input extension(s)
|
|
155
|
+
* @param {string} sep - 分隔符號 / Separator string
|
|
156
|
+
* @returns {string} 連接後的副檔名字串 / Joined extension string
|
|
157
|
+
*/
|
|
124
158
|
function _handleFileExtensions(testExt, sep) {
|
|
125
159
|
return _handleFileExtensionsCore(testExt).join(sep);
|
|
126
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* 修復 Jest 配置中的相容性問題
|
|
163
|
+
* Fix compatibility issues in Jest configuration
|
|
164
|
+
*
|
|
165
|
+
* 處理 testMatch/testRegex 互斥問題以及 testURL 已棄用選項的遷移
|
|
166
|
+
* Handles testMatch/testRegex mutual exclusivity and testURL deprecated option migration
|
|
167
|
+
*
|
|
168
|
+
* @param {T} jestConfig - 原始 Jest 配置 / Original Jest configuration
|
|
169
|
+
* @returns {T} 修復後的 Jest 配置 / Fixed Jest configuration
|
|
170
|
+
*/
|
|
127
171
|
function fixJestConfig(jestConfig) {
|
|
128
172
|
if (jestConfig.testMatch) {
|
|
129
173
|
jestConfig.testRegex = null;
|
|
@@ -131,7 +175,10 @@ function fixJestConfig(jestConfig) {
|
|
|
131
175
|
jestConfig.testMatch = null;
|
|
132
176
|
}
|
|
133
177
|
/**
|
|
134
|
-
*
|
|
178
|
+
* testURL 選項已被 testEnvironmentOptions.url 取代
|
|
179
|
+
* testURL option has been replaced by testEnvironmentOptions.url
|
|
180
|
+
*
|
|
181
|
+
* @see https://jestjs.io/docs/configuration#testurl-string
|
|
135
182
|
*/
|
|
136
183
|
if (jestConfig.testURL) {
|
|
137
184
|
var _jestConfig$testEnvir, _jestConfig$testEnvir2, _url, _jestConfig$testEnvir3;
|
|
@@ -142,12 +189,21 @@ function fixJestConfig(jestConfig) {
|
|
|
142
189
|
}
|
|
143
190
|
|
|
144
191
|
var name = "@bluelovers/jest-config";
|
|
145
|
-
var version = "1.1.
|
|
192
|
+
var version = "1.1.13";
|
|
146
193
|
|
|
194
|
+
/**
|
|
195
|
+
* 建立無邊框表格實例
|
|
196
|
+
* Create borderless table instance
|
|
197
|
+
*
|
|
198
|
+
* 用於以整齊的格式顯示 Jest 配置資訊
|
|
199
|
+
* Used to display Jest configuration info in a neat format
|
|
200
|
+
*
|
|
201
|
+
* @param {TableConstructorOptions} options - 表格建構選項 / Table constructor options
|
|
202
|
+
* @returns {Table} 無邊框表格實例 / Borderless table instance
|
|
203
|
+
*/
|
|
147
204
|
function _newTableBorderless(options) {
|
|
148
205
|
let table$1 = new table.Table({
|
|
149
206
|
colAligns: ['right', 'left'],
|
|
150
|
-
//colAligns: ['left', 'center', 'center', 'center'],
|
|
151
207
|
chars: {
|
|
152
208
|
top: '',
|
|
153
209
|
'top-mid': '',
|
|
@@ -170,12 +226,22 @@ function _newTableBorderless(options) {
|
|
|
170
226
|
table$1 = table.applyStyleBorderless(table$1);
|
|
171
227
|
return table$1;
|
|
172
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* 印出 Jest 配置資訊
|
|
231
|
+
* Print Jest configuration information
|
|
232
|
+
*
|
|
233
|
+
* 以表格格式顯示當前 Jest 配置的關鍵資訊,方便除錯和確認設定
|
|
234
|
+
* Displays key info of current Jest config in table format for debugging and verification
|
|
235
|
+
*
|
|
236
|
+
* @param {IJestConfig} jestConfig - Jest 配置物件 / Jest configuration object
|
|
237
|
+
* @param {IOptionsPrintJestConfigInfo} options - 印出選項 / Print options
|
|
238
|
+
*/
|
|
173
239
|
function printJestConfigInfo(jestConfig, options) {
|
|
174
|
-
var _options
|
|
240
|
+
var _options$cwd, _options$file, _jestConfig$cacheDire, _jestConfig$rootDir, _jestConfig$roots, _jestConfig$preset;
|
|
175
241
|
const table = _newTableBorderless();
|
|
176
|
-
|
|
242
|
+
options !== null && options !== void 0 ? options : options = {};
|
|
177
243
|
// @ts-ignore
|
|
178
|
-
|
|
244
|
+
jestConfig !== null && jestConfig !== void 0 ? jestConfig : jestConfig = {};
|
|
179
245
|
table.push([`${name}:`, version]);
|
|
180
246
|
table.push([`process.versions.node:`, process.versions.node]);
|
|
181
247
|
table.push(['cwd:', (_options$cwd = options.cwd) !== null && _options$cwd !== void 0 ? _options$cwd : process.cwd()]);
|
|
@@ -193,51 +259,198 @@ function printJestConfigInfo(jestConfig, options) {
|
|
|
193
259
|
debugColor2.console.gray.log('─'.repeat(20));
|
|
194
260
|
}
|
|
195
261
|
|
|
262
|
+
/**
|
|
263
|
+
* 取得預設的 ts-jest 轉換器選項
|
|
264
|
+
* Get default ts-jest transformer options
|
|
265
|
+
*
|
|
266
|
+
* 此函數會合併使用者自定義的 ts-jest 設定與預設值,確保測試環境的最佳配置
|
|
267
|
+
* This function merges user custom ts-jest settings with defaults for optimal test environment
|
|
268
|
+
*
|
|
269
|
+
* 主要調整項目:
|
|
270
|
+
* - 禁用輸出檔案(noEmit: true)
|
|
271
|
+
* - 允許未使用的參數和標籤(用於測試開發)
|
|
272
|
+
* - 禁用嚴格的型別檢查選項(確保測試能順利執行)
|
|
273
|
+
*
|
|
274
|
+
* Key adjustments:
|
|
275
|
+
* - Disable file output (noEmit: true)
|
|
276
|
+
* - Allow unused parameters and labels (for test development)
|
|
277
|
+
* - Disable strict type checking options (ensure tests run smoothly)
|
|
278
|
+
*
|
|
279
|
+
* @param runtime - 執行時期配置,包含原始 Jest 配置 / Runtime configuration containing original Jest config
|
|
280
|
+
* @returns ts-jest 轉換器選項 / ts-jest transformer options
|
|
281
|
+
*/
|
|
282
|
+
function defaultTsJestTransformerOptions(runtime) {
|
|
283
|
+
var _runtime$jestConfig$g, _runtime$jestConfig$g2, _tsconfig$types;
|
|
284
|
+
const old = (_runtime$jestConfig$g = (_runtime$jestConfig$g2 = runtime.jestConfig.globals) === null || _runtime$jestConfig$g2 === void 0 ? void 0 : _runtime$jestConfig$g2['ts-jest']) !== null && _runtime$jestConfig$g !== void 0 ? _runtime$jestConfig$g : {};
|
|
285
|
+
const tsconfig = typeof old.tsconfig === 'object' ? old.tsconfig : {};
|
|
286
|
+
const types = arrayHyperUnique.array_unique([...((_tsconfig$types = tsconfig.types) !== null && _tsconfig$types !== void 0 ? _tsconfig$types : []), 'jest']);
|
|
287
|
+
return {
|
|
288
|
+
...old,
|
|
289
|
+
tsconfig: {
|
|
290
|
+
noEmit: true,
|
|
291
|
+
emitDeclarationOnly: false,
|
|
292
|
+
noUnusedParameters: false,
|
|
293
|
+
allowUnusedLabels: true,
|
|
294
|
+
noUnusedLocals: false,
|
|
295
|
+
noPropertyAccessFromIndexSignature: false,
|
|
296
|
+
noImplicitAny: false,
|
|
297
|
+
...tsconfig,
|
|
298
|
+
types
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* 建立預設的轉換器配置
|
|
305
|
+
* Create default transformer configuration
|
|
306
|
+
*
|
|
307
|
+
* 配置 ts-jest 作為主要轉換器,並在可用時整合 jest-tsd-transform 和 jest-chain-transform
|
|
308
|
+
* Configures ts-jest as the main transformer, integrating jest-tsd-transform and jest-chain-transform when available
|
|
309
|
+
*
|
|
310
|
+
* @param {IRuntime} runtime - 執行時期配置 / Runtime configuration
|
|
311
|
+
* @returns {object} 轉換器配置物件 / Transformer configuration object
|
|
312
|
+
*/
|
|
313
|
+
function defaultTransform(runtime) {
|
|
314
|
+
const paths = [requireResolve.requireResolveExtra('@bluelovers/jest-config').result].filter(Boolean);
|
|
315
|
+
const opts = {
|
|
316
|
+
includeGlobal: true,
|
|
317
|
+
includeCurrentDirectory: true,
|
|
318
|
+
paths
|
|
319
|
+
};
|
|
320
|
+
let ts_transform = _requireResolve('ts-jest');
|
|
321
|
+
ts_transform = [ts_transform, defaultTsJestTransformerOptions(runtime)];
|
|
322
|
+
const {
|
|
323
|
+
result: tsd
|
|
324
|
+
} = requireResolve.requireResolveExtra('jest-tsd-transform', opts);
|
|
325
|
+
if (tsd !== null && tsd !== void 0 && tsd.length) {
|
|
326
|
+
const {
|
|
327
|
+
result: chain
|
|
328
|
+
} = requireResolve.requireResolveExtra('jest-chain-transform', opts);
|
|
329
|
+
if (chain !== null && chain !== void 0 && chain.length) {
|
|
330
|
+
ts_transform = [chain, {
|
|
331
|
+
transformers: [tsd,
|
|
332
|
+
// @ts-ignore
|
|
333
|
+
ts_transform]
|
|
334
|
+
}];
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
const value = {
|
|
338
|
+
[`.(${_handleFileExtensions(defaultTransformFileExtensions(), '|')})$`]: ts_transform
|
|
339
|
+
};
|
|
340
|
+
return value;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Detects all values in an array that include any of the given keys.
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* const arr = ['abc', 'def', 'ghi'];
|
|
348
|
+
* const keys = ['a', 'e', 'i'];
|
|
349
|
+
* const result = detectIncludes(arr, keys);
|
|
350
|
+
* // result is { a: ['abc', 'def'], e: ['def', 'ghi'], i: ['abc', 'ghi'] }
|
|
351
|
+
*
|
|
352
|
+
* @param arr - The array to search.
|
|
353
|
+
* @param keys - The keys to search for.
|
|
354
|
+
* @returns An object with the keys as properties and the
|
|
355
|
+
* corresponding values as arrays of strings.
|
|
356
|
+
*/
|
|
357
|
+
function detectIncludes(arr, keys) {
|
|
358
|
+
let result = {};
|
|
359
|
+
if (arr !== null && arr !== void 0 && arr.length) {
|
|
360
|
+
if (keys.length) {
|
|
361
|
+
keys = Array.isArray(keys) ? keys : [keys];
|
|
362
|
+
const re = new RegExp(`(${escapeArrayToRegExpSource(keys)})`);
|
|
363
|
+
arr.forEach(value => {
|
|
364
|
+
var _match, _ref;
|
|
365
|
+
let m = value === null || value === void 0 || (_match = (_ref = value).match) === null || _match === void 0 ? void 0 : _match.call(_ref, re);
|
|
366
|
+
if (m) {
|
|
367
|
+
var _result$k;
|
|
368
|
+
const k = m[1];
|
|
369
|
+
((_result$k = result[k]) !== null && _result$k !== void 0 ? _result$k : result[k] = []).push(value);
|
|
370
|
+
}
|
|
371
|
+
return result;
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return result;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Escapes all strings in an array to be used in a regular expression source.
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* const arr = ['abc', 'def', 'ghi'];
|
|
382
|
+
* const result = escapeArrayToRegExpSource(arr);
|
|
383
|
+
* // result is 'abc|def|ghi'
|
|
384
|
+
*
|
|
385
|
+
* @param arr - The array of strings to escape.
|
|
386
|
+
* @returns A single string that can be used as a regular expression source.
|
|
387
|
+
*/
|
|
388
|
+
function escapeArrayToRegExpSource(arr) {
|
|
389
|
+
return arr.map(s => regexpHelperCore.escapeRegExp(s)).join("|");
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function defaultSetupFiles(runtime) {
|
|
393
|
+
var _runtime$jestConfig, _jestConfig$setupFile, _jestConfig$setupFile2;
|
|
394
|
+
const jestConfig = (_runtime$jestConfig = runtime === null || runtime === void 0 ? void 0 : runtime.jestConfig) !== null && _runtime$jestConfig !== void 0 ? _runtime$jestConfig : {};
|
|
395
|
+
let detect = detectIncludes(jestConfig.setupFiles, 'dotenv');
|
|
396
|
+
const setupFiles = [
|
|
397
|
+
/**
|
|
398
|
+
* @see https://lusbuab.medium.com/using-dotenv-with-jest-7e735b34e55f
|
|
399
|
+
*/
|
|
400
|
+
!detect['dotenv'] && _requireResolve2('dotenv/config').result, ...((_jestConfig$setupFile = jestConfig.setupFiles) !== null && _jestConfig$setupFile !== void 0 ? _jestConfig$setupFile : [])].filter(Boolean);
|
|
401
|
+
const setupFilesAfterEnv = [
|
|
402
|
+
/**
|
|
403
|
+
* 跨平台測試支援參考 / Cross-platform testing support reference
|
|
404
|
+
* @see https://medium.com/doctolib/how-to-run-the-same-jest-test-suite-across-several-platforms-jest-os-detection-plugin-included-f8113832482b
|
|
405
|
+
* @see https://github.com/doctolib/jest-os-detection
|
|
406
|
+
*/
|
|
407
|
+
...((_jestConfig$setupFile2 = jestConfig.setupFilesAfterEnv) !== null && _jestConfig$setupFile2 !== void 0 ? _jestConfig$setupFile2 : [])].filter(Boolean);
|
|
408
|
+
const ret = {};
|
|
409
|
+
if (setupFiles.length) {
|
|
410
|
+
ret.setupFiles = setupFiles;
|
|
411
|
+
}
|
|
412
|
+
if (setupFilesAfterEnv.length) {
|
|
413
|
+
ret.setupFilesAfterEnv = setupFilesAfterEnv;
|
|
414
|
+
}
|
|
415
|
+
return ret;
|
|
416
|
+
}
|
|
417
|
+
|
|
196
418
|
const cacheDirectory = /*#__PURE__*/jestCacheDirectory.getJestCacheDirectory();
|
|
419
|
+
/**
|
|
420
|
+
* 混合 Jest 配置函數 - 將預設配置與使用者自定義配置合併
|
|
421
|
+
* Mix Jest configuration function - Merges default config with user custom config
|
|
422
|
+
*
|
|
423
|
+
* 此函數提供了一個完整的 Jest 配置模板,包含 TypeScript 支援、快取管理、覆蓋率收集等功能
|
|
424
|
+
* This function provides a complete Jest configuration template with TypeScript support,
|
|
425
|
+
* cache management, coverage collection, and more.
|
|
426
|
+
*
|
|
427
|
+
* @param {T} jestConfig - 使用者自定義的 Jest 配置 / User custom Jest configuration
|
|
428
|
+
* @param {boolean} autoPrint - 是否自動印出配置資訊 / Whether to auto print config info
|
|
429
|
+
* @param {IOptionsPrintJestConfigInfo} options - 印出配置的選項 / Options for printing config
|
|
430
|
+
* @returns {T} 合併後的完整 Jest 配置 / Merged complete Jest configuration
|
|
431
|
+
*/
|
|
197
432
|
function mixinJestConfig(jestConfig, autoPrint, options) {
|
|
198
|
-
var
|
|
433
|
+
var _newJestConfig$transf;
|
|
199
434
|
// @ts-ignore
|
|
200
|
-
|
|
435
|
+
jestConfig !== null && jestConfig !== void 0 ? jestConfig : jestConfig = {};
|
|
201
436
|
const newJestConfig = fixJestConfig({
|
|
202
|
-
globals: {
|
|
203
|
-
// 'ts-jest': {
|
|
204
|
-
// //tsconfig: 'tsconfig.spec.json',
|
|
205
|
-
// },
|
|
206
|
-
},
|
|
437
|
+
globals: {},
|
|
207
438
|
cacheDirectory,
|
|
208
439
|
maxWorkers: 1,
|
|
209
440
|
clearMocks: true,
|
|
210
441
|
passWithNoTests: true,
|
|
211
442
|
moduleFileExtensions: defaultModuleFileExtensions(),
|
|
212
|
-
//testEnvironment: 'node',
|
|
213
|
-
//testMatch: ['**/*.test.ts', '**/*.spec.ts'],
|
|
214
443
|
...makeTestRegexConfig(defaultTestFileExtensions()),
|
|
215
444
|
testPathIgnorePatterns: defaultTestPathIgnorePatterns(),
|
|
216
|
-
|
|
217
|
-
setupFilesAfterEnv: [
|
|
218
|
-
//"jest-chain",
|
|
219
|
-
//"jest-extended/all",
|
|
220
|
-
//"jest-extended-extra",
|
|
221
|
-
//"jest-num-close-with",
|
|
222
|
-
/**
|
|
223
|
-
* https://medium.com/doctolib/how-to-run-the-same-jest-test-suite-across-several-platforms-jest-os-detection-plugin-included-f8113832482b
|
|
224
|
-
* https://github.com/doctolib/jest-os-detection
|
|
225
|
-
*/
|
|
226
|
-
//'jest-os-detection',
|
|
227
|
-
],
|
|
228
|
-
//transform: defaultTransform(),
|
|
445
|
+
...defaultSetupFiles(),
|
|
229
446
|
verbose: true,
|
|
230
|
-
/**
|
|
231
|
-
* if didn't set `coverageProvider` to `v8`
|
|
232
|
-
* with `collectCoverage` `true`, nodejs debug point maybe will fail
|
|
233
|
-
*/
|
|
234
447
|
coverageProvider: 'v8',
|
|
235
448
|
collectCoverage: false,
|
|
236
449
|
coveragePathIgnorePatterns: defaultCoveragePathIgnorePatterns(),
|
|
237
450
|
/**
|
|
238
|
-
*
|
|
451
|
+
* Jest 模組解析器參考 / Jest module resolver reference
|
|
452
|
+
* @see https://github.com/facebook/jest/issues/9771#issuecomment-872764344
|
|
239
453
|
*/
|
|
240
|
-
//resolver: 'jest-node-exports-resolver',
|
|
241
454
|
...jestConfig
|
|
242
455
|
});
|
|
243
456
|
(_newJestConfig$transf = newJestConfig.transform) !== null && _newJestConfig$transf !== void 0 ? _newJestConfig$transf : newJestConfig.transform = defaultTransform({
|
|
@@ -254,11 +467,13 @@ exports._handleFileExtensions = _handleFileExtensions;
|
|
|
254
467
|
exports._handleFileExtensionsCore = _handleFileExtensionsCore;
|
|
255
468
|
exports._newTableBorderless = _newTableBorderless;
|
|
256
469
|
exports._requireResolve = _requireResolve;
|
|
470
|
+
exports._requireResolve2 = _requireResolve2;
|
|
257
471
|
exports.cacheDirectory = cacheDirectory;
|
|
258
472
|
exports.default = mixinJestConfig;
|
|
259
473
|
exports.defaultCoverageFileExtensions = defaultCoverageFileExtensions;
|
|
260
474
|
exports.defaultCoveragePathIgnorePatterns = defaultCoveragePathIgnorePatterns;
|
|
261
475
|
exports.defaultModuleFileExtensions = defaultModuleFileExtensions;
|
|
476
|
+
exports.defaultSetupFiles = defaultSetupFiles;
|
|
262
477
|
exports.defaultTestFileExtensions = defaultTestFileExtensions;
|
|
263
478
|
exports.defaultTestPathIgnorePatterns = defaultTestPathIgnorePatterns;
|
|
264
479
|
exports.defaultTransform = defaultTransform;
|