@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
package/src/print.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置資訊印出模組 - 格式化並顯示 Jest 配置資訊
|
|
3
|
+
* Configuration Info Print Module - Formats and displays Jest configuration info
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import { applyStyleBorderless, Table } from '@yarn-tool/table';
|
|
2
7
|
import { TableConstructorOptions } from 'cli-table3';
|
|
3
8
|
import { console } from 'debug-color2';
|
|
@@ -5,11 +10,29 @@ import { inspect } from 'util';
|
|
|
5
10
|
import { name as jName, version as jVersion } from '../package.json';
|
|
6
11
|
import { IJestConfig } from './types';
|
|
7
12
|
|
|
13
|
+
/**
|
|
14
|
+
* 建立無邊框表格實例
|
|
15
|
+
* Create borderless table instance
|
|
16
|
+
*
|
|
17
|
+
* 用於以整齊的格式顯示 Jest 配置資訊
|
|
18
|
+
* Used to display Jest configuration info in a neat format
|
|
19
|
+
*
|
|
20
|
+
* @param {TableConstructorOptions} options - 表格建構選項 / Table constructor options
|
|
21
|
+
* @returns {Table} 無邊框表格實例 / Borderless table instance
|
|
22
|
+
*/
|
|
8
23
|
export function _newTableBorderless(options?: TableConstructorOptions)
|
|
9
24
|
{
|
|
25
|
+
/**
|
|
26
|
+
* 建立表格實例,設定欄位對齊方式
|
|
27
|
+
* Create table instance with column alignment settings
|
|
28
|
+
*/
|
|
10
29
|
let table = new Table({
|
|
30
|
+
/** 欄位對齊方式(右對齊, 左對齊) / Column alignments (right, left) */
|
|
11
31
|
colAligns: ['right', 'left'],
|
|
12
|
-
|
|
32
|
+
/**
|
|
33
|
+
* 移除所有邊框字元,創造簡潔的外觀
|
|
34
|
+
* Remove all border characters for clean appearance
|
|
35
|
+
*/
|
|
13
36
|
chars: {
|
|
14
37
|
top: '',
|
|
15
38
|
'top-mid': '',
|
|
@@ -30,44 +53,85 @@ export function _newTableBorderless(options?: TableConstructorOptions)
|
|
|
30
53
|
...options,
|
|
31
54
|
});
|
|
32
55
|
|
|
56
|
+
// 套用無邊框樣式 / Apply borderless style
|
|
33
57
|
table = applyStyleBorderless(table);
|
|
34
58
|
|
|
35
59
|
return table;
|
|
36
60
|
}
|
|
37
61
|
|
|
62
|
+
/**
|
|
63
|
+
* 印出 Jest 配置資訊的選項介面
|
|
64
|
+
* Options interface for printing Jest config info
|
|
65
|
+
*/
|
|
38
66
|
export interface IOptionsPrintJestConfigInfo
|
|
39
67
|
{
|
|
68
|
+
/** 目前工作目錄 / Current working directory */
|
|
40
69
|
cwd?: string;
|
|
70
|
+
/** 配置文件路徑 / Configuration file path */
|
|
41
71
|
file?: string;
|
|
42
72
|
}
|
|
43
73
|
|
|
74
|
+
/**
|
|
75
|
+
* 印出 Jest 配置資訊
|
|
76
|
+
* Print Jest configuration information
|
|
77
|
+
*
|
|
78
|
+
* 以表格格式顯示當前 Jest 配置的關鍵資訊,方便除錯和確認設定
|
|
79
|
+
* Displays key info of current Jest config in table format for debugging and verification
|
|
80
|
+
*
|
|
81
|
+
* @param {IJestConfig} jestConfig - Jest 配置物件 / Jest configuration object
|
|
82
|
+
* @param {IOptionsPrintJestConfigInfo} options - 印出選項 / Print options
|
|
83
|
+
*/
|
|
44
84
|
export function printJestConfigInfo(jestConfig: IJestConfig, options?: IOptionsPrintJestConfigInfo)
|
|
45
85
|
{
|
|
86
|
+
// 建立無邊框表格 / Create borderless table
|
|
46
87
|
const table = _newTableBorderless();
|
|
47
88
|
|
|
89
|
+
// 初始化選項(若未提供) / Initialize options (if not provided)
|
|
48
90
|
options ??= {};
|
|
49
91
|
// @ts-ignore
|
|
50
92
|
jestConfig ??= {};
|
|
51
93
|
|
|
94
|
+
/**
|
|
95
|
+
* 添加基本資訊行到表格
|
|
96
|
+
* Add basic info rows to table
|
|
97
|
+
*/
|
|
98
|
+
// 套件名稱和版本 / Package name and version
|
|
52
99
|
table.push([`${jName}:`, jVersion]);
|
|
100
|
+
// Node.js 版本 / Node.js version
|
|
53
101
|
table.push([`process.versions.node:`, process.versions.node]);
|
|
102
|
+
// 目前工作目錄 / Current working directory
|
|
54
103
|
table.push(['cwd:', options.cwd ?? process.cwd()]);
|
|
55
104
|
|
|
105
|
+
// 配置文件路徑(如果提供) / Config file path (if provided)
|
|
56
106
|
options.file?.length && table.push(['file:', options.file]);
|
|
57
107
|
|
|
108
|
+
// 快取目錄(如果設定) / Cache directory (if set)
|
|
58
109
|
jestConfig.cacheDirectory?.length && table.push(['cacheDirectory:', jestConfig.cacheDirectory]);
|
|
59
110
|
|
|
111
|
+
// 根目錄(如果設定) / Root directory (if set)
|
|
60
112
|
jestConfig.rootDir?.length && table.push(['rootDir:', jestConfig.rootDir]);
|
|
113
|
+
// 根目錄陣列(如果設定) / Roots array (if set)
|
|
61
114
|
jestConfig.roots?.length && table.push(['roots:', inspect(jestConfig.roots)]);
|
|
62
115
|
|
|
116
|
+
// Preset 設定(如果設定) / Preset setting (if set)
|
|
63
117
|
jestConfig.preset?.length && table.push(['preset:', jestConfig.preset]);
|
|
64
118
|
|
|
119
|
+
// 轉換器配置(如果設定) / Transform config (if set)
|
|
65
120
|
jestConfig.transform && table.push(['transform:', inspect(jestConfig.transform, {
|
|
121
|
+
/** 檢視深度限制 / Inspection depth limit */
|
|
66
122
|
depth: 3
|
|
67
123
|
})]);
|
|
68
124
|
|
|
125
|
+
/**
|
|
126
|
+
* 輸出表格到控制台
|
|
127
|
+
* Output table to console
|
|
128
|
+
*/
|
|
129
|
+
// 分隔線 / Separator line
|
|
69
130
|
console.gray.log('─'.repeat(20));
|
|
131
|
+
// 標題 / Title
|
|
70
132
|
console.log(`jest.config`);
|
|
133
|
+
// 表格內容 / Table content
|
|
71
134
|
console.log(table.toString());
|
|
135
|
+
// 分隔線 / Separator line
|
|
72
136
|
console.gray.log('─'.repeat(20));
|
|
73
137
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,12 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 類型定義模組 - 定義 Jest 配置相關的型別介面
|
|
3
|
+
* Type Definitions Module - Defines type interfaces for Jest configuration
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import { InitialOptionsTsJest, JestConfigWithTsJest } from 'ts-jest';
|
|
2
7
|
import { IOptionsPrintJestConfigInfo } from './print';
|
|
3
8
|
|
|
4
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Jest 配置型別別名
|
|
11
|
+
* Jest configuration type alias
|
|
12
|
+
*
|
|
13
|
+
* 支援 ts-jest 提供的兩種配置型別
|
|
14
|
+
* Supports both configuration types provided by ts-jest
|
|
15
|
+
*/
|
|
16
|
+
export type IJestConfig = (InitialOptionsTsJest | JestConfigWithTsJest) & {
|
|
17
|
+
/**
|
|
18
|
+
* testURL 選項已被 testEnvironmentOptions.url 取代
|
|
19
|
+
* testURL option has been replaced by testEnvironmentOptions.url
|
|
20
|
+
*
|
|
21
|
+
* @see https://jestjs.io/docs/configuration#testurl-string
|
|
22
|
+
* @deprecated
|
|
23
|
+
*/
|
|
24
|
+
testURL?: string;
|
|
25
|
+
};
|
|
5
26
|
|
|
27
|
+
/**
|
|
28
|
+
* 執行時期配置介面
|
|
29
|
+
* Runtime configuration interface
|
|
30
|
+
*
|
|
31
|
+
* 用於在配置生成過程中傳遞上下文資訊
|
|
32
|
+
* Used to pass context information during configuration generation
|
|
33
|
+
*/
|
|
6
34
|
export interface IRuntime<T extends IJestConfig = IJestConfig>
|
|
7
35
|
{
|
|
36
|
+
/** 原始 Jest 配置 / Original Jest configuration */
|
|
8
37
|
jestConfig: T,
|
|
38
|
+
/** 是否自動印出配置 / Whether to auto print configuration */
|
|
9
39
|
autoPrint: boolean,
|
|
40
|
+
/** 印出配置的選項 / Options for printing configuration */
|
|
10
41
|
options: IOptionsPrintJestConfigInfo,
|
|
42
|
+
/** 新生成的配置(可選) / Newly generated configuration (optional) */
|
|
11
43
|
newJestConfig?: T,
|
|
12
44
|
}
|
package/src/util.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ITSPartialRecord, ITSValueOrArrayMaybeReadonly } from "ts-type";
|
|
2
|
+
import { escapeRegExp } from "regexp-helper-core";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Detects all values in an array that include any of the given keys.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const arr = ['abc', 'def', 'ghi'];
|
|
9
|
+
* const keys = ['a', 'e', 'i'];
|
|
10
|
+
* const result = detectIncludes(arr, keys);
|
|
11
|
+
* // result is { a: ['abc', 'def'], e: ['def', 'ghi'], i: ['abc', 'ghi'] }
|
|
12
|
+
*
|
|
13
|
+
* @param arr - The array to search.
|
|
14
|
+
* @param keys - The keys to search for.
|
|
15
|
+
* @returns An object with the keys as properties and the
|
|
16
|
+
* corresponding values as arrays of strings.
|
|
17
|
+
*/
|
|
18
|
+
export function detectIncludes<K extends string, V = unknown | string>(arr: V[], keys: ITSValueOrArrayMaybeReadonly<K>)
|
|
19
|
+
{
|
|
20
|
+
let result = {} as ITSPartialRecord<K, string[]>;
|
|
21
|
+
|
|
22
|
+
if (arr?.length)
|
|
23
|
+
{
|
|
24
|
+
if (keys.length)
|
|
25
|
+
{
|
|
26
|
+
keys = Array.isArray(keys) ? keys : [keys] as K[];
|
|
27
|
+
|
|
28
|
+
const re = new RegExp(`(${escapeArrayToRegExpSource(keys as string[])})`);
|
|
29
|
+
|
|
30
|
+
arr.forEach((value) =>
|
|
31
|
+
{
|
|
32
|
+
let m = (value as string)?.match?.(re);
|
|
33
|
+
if (m)
|
|
34
|
+
{
|
|
35
|
+
const k = m[1] as K;
|
|
36
|
+
(result[k] ??= []).push(value as string);
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return result
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Escapes all strings in an array to be used in a regular expression source.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* const arr = ['abc', 'def', 'ghi'];
|
|
51
|
+
* const result = escapeArrayToRegExpSource(arr);
|
|
52
|
+
* // result is 'abc|def|ghi'
|
|
53
|
+
*
|
|
54
|
+
* @param arr - The array of strings to escape.
|
|
55
|
+
* @returns A single string that can be used as a regular expression source.
|
|
56
|
+
*/
|
|
57
|
+
export function escapeArrayToRegExpSource(arr: string[])
|
|
58
|
+
{
|
|
59
|
+
return arr.map(s => escapeRegExp(s)).join("|");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function tsExtensions(js: true): readonly [
|
|
63
|
+
'js',
|
|
64
|
+
'mjs',
|
|
65
|
+
'cjs',
|
|
66
|
+
'jsx',
|
|
67
|
+
];
|
|
68
|
+
export function tsExtensions(js?: false): readonly [
|
|
69
|
+
'ts',
|
|
70
|
+
'tsx',
|
|
71
|
+
'mts',
|
|
72
|
+
'cts',
|
|
73
|
+
];
|
|
74
|
+
export function tsExtensions(js?: boolean): readonly ["js", "mjs", "cjs", "jsx"] | readonly ["ts", "tsx", "mts", "cts"];
|
|
75
|
+
export function tsExtensions(js?: boolean)
|
|
76
|
+
{
|
|
77
|
+
return js ? [
|
|
78
|
+
'js',
|
|
79
|
+
'mjs',
|
|
80
|
+
'cjs',
|
|
81
|
+
'jsx',
|
|
82
|
+
] as const : [
|
|
83
|
+
'ts',
|
|
84
|
+
'tsx',
|
|
85
|
+
'mts',
|
|
86
|
+
'cts',
|
|
87
|
+
] as const;
|
|
88
|
+
}
|
package/jest-preset.js
DELETED