@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/index.d.ts ADDED
@@ -0,0 +1,142 @@
1
+ import { Table } from '@yarn-tool/table';
2
+ import { TableConstructorOptions } from 'cli-table3';
3
+ import { InitialOptionsTsJest, JestConfigWithTsJest } from 'ts-jest';
4
+ import { ITSWriteable } from 'ts-type/lib/helper/readonly';
5
+ import { ITSValueOrArrayMaybeReadonly } from 'ts-type/lib/type/base';
6
+
7
+ export type IJestConfig = InitialOptionsTsJest | JestConfigWithTsJest;
8
+ export interface IRuntime<T extends IJestConfig = IJestConfig> {
9
+ jestConfig: T;
10
+ autoPrint: boolean;
11
+ options: IOptionsPrintJestConfigInfo;
12
+ newJestConfig?: T;
13
+ }
14
+ export declare function _newTableBorderless(options?: TableConstructorOptions): Table.Table;
15
+ export interface IOptionsPrintJestConfigInfo {
16
+ cwd?: string;
17
+ file?: string;
18
+ }
19
+ export declare function printJestConfigInfo(jestConfig: IJestConfig, options?: IOptionsPrintJestConfigInfo): void;
20
+ export declare function _requireResolve(name: string): string;
21
+ export declare function makeTestRegexConfig<T extends string>(testExt: ITSValueOrArrayMaybeReadonly<T>): Pick<InitialOptionsTsJest, "testMatch" | "testRegex">;
22
+ export declare function _handleFileExtensionsCore<T extends string>(testExt: ITSValueOrArrayMaybeReadonly<T>): T[];
23
+ export declare function _handleFileExtensions<T extends string>(testExt: ITSValueOrArrayMaybeReadonly<T>, sep: string): string;
24
+ export declare function fixJestConfig<T extends IJestConfig>(jestConfig: T): T;
25
+ export declare function defaultTestFileExtensions(): [
26
+ "ts",
27
+ "tsx",
28
+ "mts",
29
+ "cts"
30
+ ];
31
+ /**
32
+ * @see https://jestjs.io/docs/configuration#options
33
+ */
34
+ export declare function defaultModuleFileExtensions(): [
35
+ "js",
36
+ "mjs",
37
+ "cjs",
38
+ "jsx",
39
+ "ts",
40
+ "mts",
41
+ "cts",
42
+ "tsx",
43
+ "json",
44
+ "node"
45
+ ];
46
+ export declare function defaultCoverageFileExtensions(): [
47
+ "js",
48
+ "mjs",
49
+ "cjs",
50
+ "jsx",
51
+ "ts",
52
+ "mts",
53
+ "cts",
54
+ "tsx"
55
+ ];
56
+ export declare function defaultTransformFileExtensions(): [
57
+ "ts",
58
+ "tsx",
59
+ "mts",
60
+ "cts"
61
+ ];
62
+ export declare function defaultCoveragePathIgnorePatterns(): [
63
+ "/node_modules/",
64
+ "/__snapshots__/",
65
+ "/__tests__/",
66
+ "/__test__/",
67
+ "/dist/",
68
+ "/test/",
69
+ "/fixture/",
70
+ "/__file_snapshots__/",
71
+ "/__fixtures__/"
72
+ ];
73
+ export declare function defaultTestPathIgnorePatterns(): [
74
+ "/node_modules/",
75
+ "/__fixtures__/",
76
+ "/__file_snapshots__/",
77
+ "/fixtures/",
78
+ "/__tests__/helpers/",
79
+ "/__tests__/utils/",
80
+ "__mocks__",
81
+ "/dist/"
82
+ ];
83
+ export declare function defaultTransform(runtime: IRuntime): ITSWriteable<{
84
+ readonly [x: string]: import("@jest/types/build/Config").TransformerConfig;
85
+ }>;
86
+ export declare const cacheDirectory: string;
87
+ export declare function mixinJestConfig<T extends IJestConfig>(jestConfig?: T, autoPrint?: boolean, options?: IOptionsPrintJestConfigInfo): {
88
+ testPathIgnorePatterns: [
89
+ "/node_modules/",
90
+ "/__fixtures__/",
91
+ "/__file_snapshots__/",
92
+ "/fixtures/",
93
+ "/__tests__/helpers/",
94
+ "/__tests__/utils/",
95
+ "__mocks__",
96
+ "/dist/"
97
+ ];
98
+ setupFilesAfterEnv: any[];
99
+ verbose: true;
100
+ /**
101
+ * if didn't set `coverageProvider` to `v8`
102
+ * with `collectCoverage` `true`, nodejs debug point maybe will fail
103
+ */
104
+ coverageProvider: "v8";
105
+ collectCoverage: false;
106
+ coveragePathIgnorePatterns: [
107
+ "/node_modules/",
108
+ "/__snapshots__/",
109
+ "/__tests__/",
110
+ "/__test__/",
111
+ "/dist/",
112
+ "/test/",
113
+ "/fixture/",
114
+ "/__file_snapshots__/",
115
+ "/__fixtures__/"
116
+ ];
117
+ testMatch?: string[];
118
+ testRegex?: string | string[];
119
+ globals: {};
120
+ cacheDirectory: string;
121
+ maxWorkers: number;
122
+ clearMocks: true;
123
+ passWithNoTests: true;
124
+ moduleFileExtensions: [
125
+ "js",
126
+ "mjs",
127
+ "cjs",
128
+ "jsx",
129
+ "ts",
130
+ "mts",
131
+ "cts",
132
+ "tsx",
133
+ "json",
134
+ "node"
135
+ ];
136
+ } & T;
137
+
138
+ export {
139
+ mixinJestConfig as default,
140
+ };
141
+
142
+ export {};
package/jest-preset.cjs CHANGED
@@ -1,3 +1,23 @@
1
+ /**
2
+ * Jest Preset (CommonJS) - Jest 預設配置(CommonJS 版本)
3
+ *
4
+ * 此檔案是發布模組時的必要檔案,用於支援 CommonJS 環境的 Jest 配置載入
5
+ * This file is required for npm publishing, used for Jest configuration loading in CommonJS environments
6
+ *
7
+ * 發布注意事項 / Publishing Notes:
8
+ * - 此檔案必須包含在 npm 發布中 / This file must be included in npm publish
9
+ * - 對應的 exports 配置: "./jest-preset": { "require": "./jest-preset.cjs", ... }
10
+ * - 請確保 .npmignore 中有 `!jest-preset.cjs` 以保留此檔案
11
+ * - Please ensure .npmignore has `!jest-preset.cjs` to keep this file
12
+ *
13
+ * @see https://jestjs.io/docs/configuration#preset-string
14
+ * @see package.json exports 配置 / package.json exports configuration
15
+ */
16
+
1
17
  const { mixinJestConfig } = require('./dist/index.cjs.development.cjs');
2
18
 
19
+ /**
20
+ * 匯出預設的 Jest 配置物件
21
+ * Export default Jest configuration object
22
+ */
3
23
  module.exports = mixinJestConfig();
package/jest-preset.mjs CHANGED
@@ -1,3 +1,28 @@
1
+ /**
2
+ * Jest Preset (ES Module) - Jest 預設配置(ES 模組版本)
3
+ *
4
+ * 此檔案是發布模組時的必要檔案,用於支援 ESM 環境的 Jest 配置載入
5
+ * This file is required for npm publishing, used for Jest configuration loading in ESM environments
6
+ *
7
+ * 發布注意事項 / Publishing Notes:
8
+ * - 此檔案必須包含在 npm 發布中 / This file must be included in npm publish
9
+ * - 對應的 exports 配置: "./jest-preset": { ..., "import": "./jest-preset.mjs" }
10
+ * - 請確保 .npmignore 中有 `!jest-preset.mjs` 以保留此檔案
11
+ * - Please ensure .npmignore has `!jest-preset.mjs` to keep this file
12
+ *
13
+ * 關於 jest-preset.js / About jest-preset.js:
14
+ * - jest-preset.js 不需要實際存在 / jest-preset.js does not need to physically exist
15
+ * - package.json exports 中已定義其映射關係至 .cjs 和 .mjs
16
+ * - The mapping is defined in package.json exports to .cjs and .mjs
17
+ *
18
+ * @see https://jestjs.io/docs/configuration#preset-string
19
+ * @see package.json exports 配置 / package.json exports configuration
20
+ */
21
+
1
22
  import { mixinJestConfig } from './dist/index.esm.mjs';
2
23
 
24
+ /**
25
+ * 匯出預設的 Jest 配置物件
26
+ * Export default Jest configuration object
27
+ */
3
28
  export default mixinJestConfig();
package/jest.config.js CHANGED
@@ -1,18 +1,62 @@
1
1
  // @ts-check
2
2
 
3
+ /**
4
+ * Jest 自動配置模組
5
+ * Jest Auto Configuration Module
6
+ *
7
+ * 此模組自動偵測並配置 Jest 測試環境,支援多層級配置解析
8
+ * This module automatically detects and configures Jest test environment with multi-level configuration resolution
9
+ */
10
+
3
11
  const { basename, extname, dirname } = require('path');
4
12
 
5
13
  /**
6
- * // @type { import('@jest/types').Config.InitialOptions }
7
- * @type { import('ts-jest').InitialOptionsTsJest }
14
+ * Jest 配置物件
15
+ * Jest configuration object
16
+ *
17
+ * @type { import('ts-jest').JestConfigWithTsJest }
18
+ */
19
+ let jestConfig = {}
20
+
21
+ /**
22
+ * 嘗試使用 `@yarn-tool/require-resolve` 載入模組的工具函數
23
+ * Utility function for lazy loading modules
24
+ *
25
+ * @param {string} name - 模組名稱 Module name
26
+ * @param {string[]} [paths] - 搜尋路徑 Search paths
27
+ * @private
8
28
  */
9
- let jestConfig = {
29
+ function _lazyRequire(name, paths)
30
+ {
31
+ let m;
32
+ try
33
+ {
34
+ /**
35
+ * 嘗試使用 require-resolve 工具載入模組
36
+ * Try to load module using require-resolve tool
37
+ */
38
+ m = require('@yarn-tool/require-resolve').requireExtra(name, {
39
+ includeCurrentDirectory: true,
40
+ includeGlobal: true,
41
+ paths,
42
+ });
43
+ }
44
+ catch (e)
45
+ {}
10
46
 
47
+ /**
48
+ * 如果失敗則使用標準 require
49
+ * If failed, use standard require
50
+ */
51
+ return typeof m === 'undefined' ? require(name) : m;
11
52
  }
12
53
 
13
54
  /**
14
- * @param {string} name
15
- * @returns {string}
55
+ * 嘗試使用 `@yarn-tool/require-resolve` 解析模組路徑的工具函數
56
+ * Utility function for resolving module paths
57
+ *
58
+ * @param {string} name - 模組名稱 Module name
59
+ * @returns {string} - 解析後的路徑 Resolved path
16
60
  * @private
17
61
  */
18
62
  function _requireResolve(name)
@@ -21,9 +65,13 @@ function _requireResolve(name)
21
65
 
22
66
  try
23
67
  {
24
- // @ts-ignore
25
- const { requireResolveExtra, requireResolveCore } = require('@yarn-tool/require-resolve');
68
+ /** @type {import('@yarn-tool/require-resolve')} */
69
+ const { requireResolveExtra, requireResolveCore } = _lazyRequire('@yarn-tool/require-resolve');
26
70
 
71
+ /**
72
+ * 嘗試從多個路徑解析 TSDX 相關模組
73
+ * Try to resolve TSDX related modules from multiple paths
74
+ */
27
75
  const paths = [
28
76
  requireResolveExtra('@bluelovers/tsdx').result,
29
77
  requireResolveExtra('tsdx').result,
@@ -40,6 +88,10 @@ function _requireResolve(name)
40
88
 
41
89
  }
42
90
 
91
+ /**
92
+ * 如果都失敗,使用標準 resolve
93
+ * If all failed, use standard resolve
94
+ */
43
95
  result = result || require.resolve(name);
44
96
 
45
97
  console.info('[require.resolve]', name, '=>', result)
@@ -47,18 +99,34 @@ function _requireResolve(name)
47
99
  return result
48
100
  }
49
101
 
50
- let _ok = true;
102
+ /**
103
+ * 配置解析狀態標誌
104
+ * Configuration resolution status flag
105
+ */
106
+ let _isNeedConfig = true;
51
107
 
52
108
  try
53
109
  {
110
+ /**
111
+ * 第一層:搜尋工作區中的配置檔案
112
+ * First level: Search for configuration files in workspace
113
+ */
54
114
  if (!jestConfig.preset)
55
115
  {
56
-
57
- let result = require('@yarn-tool/ws-find-up-paths').findUpPathsWorkspaces([
116
+ /** @type {import('@yarn-tool/ws-find-up-paths')} */
117
+ const { findUpPathsWorkspaces } = _lazyRequire('@yarn-tool/ws-find-up-paths');
118
+
119
+ /**
120
+ * 向上搜尋 jest-preset.js 和 jest.config.js
121
+ * Search upwards for jest-preset.js and jest.config.js
122
+ */
123
+ let result = findUpPathsWorkspaces([
58
124
  'jest-preset.js',
59
125
  'jest.config.js',
60
126
  ], {
127
+ /** 忽略當前套件 / Ignore current package */
61
128
  ignoreCurrentPackage: true,
129
+ /** 只搜尋檔案 / Only search for files */
62
130
  onlyFiles: true,
63
131
  }).result;
64
132
 
@@ -68,9 +136,19 @@ try
68
136
 
69
137
  switch (name)
70
138
  {
139
+ /**
140
+ * 如果是 jest-preset.js,使用其目錄作為 preset
141
+ * If it's jest-preset.js, use its directory as preset
142
+ */
71
143
  case 'jest-preset':
72
- jestConfig.preset = dirname(result);
144
+ // @ts-ignore
145
+ // jestConfig.preset = dirname(result);
146
+ jestConfig.preset = result;
73
147
  break;
148
+ /**
149
+ * 其他情況,載入配置檔案內容
150
+ * Otherwise, load the configuration file content
151
+ */
74
152
  default:
75
153
  jestConfig = {
76
154
  ...require(result),
@@ -79,7 +157,7 @@ try
79
157
  break;
80
158
  }
81
159
 
82
- _ok = false;
160
+ _isNeedConfig = false;
83
161
  }
84
162
  }
85
163
  }
@@ -90,13 +168,18 @@ catch (e)
90
168
 
91
169
  try
92
170
  {
93
- if (_ok && !jestConfig.preset)
171
+ /**
172
+ * 第二層:嘗試解析 @bluelovers/jest-config
173
+ * Second level: Try to resolve @bluelovers/jest-config
174
+ */
175
+ if (_isNeedConfig && !jestConfig.preset)
94
176
  {
95
177
  let result = _requireResolve('@bluelovers/jest-config/package.json');
96
178
  if (result)
97
179
  {
180
+ // @ts-ignore
98
181
  jestConfig.preset = dirname(result);
99
- _ok = false;
182
+ _isNeedConfig = false;
100
183
  }
101
184
  }
102
185
  }
@@ -105,12 +188,21 @@ catch (e)
105
188
 
106
189
  }
107
190
 
108
- if (_ok && !jestConfig.preset)
191
+ if (_isNeedConfig && !jestConfig.preset)
109
192
  {
193
+ /**
194
+ * 第三層:使用預設的 @bluelovers/jest-config
195
+ * Third level: Use default @bluelovers/jest-config
196
+ */
197
+ // @ts-ignore
110
198
  jestConfig.preset = '@bluelovers/jest-config';
111
- _ok = false;
199
+ _isNeedConfig = false;
112
200
  }
113
201
 
202
+ /**
203
+ * 輸出最終的 preset 設定
204
+ * Output the final preset configuration
205
+ */
114
206
  console.info(`jest.config.preset: ${jestConfig.preset}`);
115
207
 
116
208
  module.exports = jestConfig
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bluelovers/jest-config",
3
- "version": "1.1.11",
4
- "description": "Jest preset configuration with ts-jest typescript",
3
+ "version": "1.1.13",
4
+ "description": "Jest configuration preset with TypeScript support, providing automatic ts-jest transform chain integration, cache management, and coverage settings / 具備 TypeScript 支援的 Jest 配置預設套件,提供自動 ts-jest 轉換鏈整合、快取管理和覆蓋率設定",
5
5
  "keywords": [
6
6
  "jest-preset",
7
7
  "jest",
@@ -33,23 +33,23 @@
33
33
  "exports": {
34
34
  ".": {
35
35
  "types": "./dist/index.d.ts",
36
- "import": "./dist/index.esm.mjs",
37
- "require": "./dist/index.cjs"
36
+ "require": "./dist/index.cjs",
37
+ "import": "./dist/index.esm.mjs"
38
38
  },
39
39
  "./dist/jest-preset.cjs": "./jest-preset.cjs",
40
40
  "./dist/jest-preset.js": {
41
- "import": "./jest-preset.mjs",
42
- "require": "./jest-preset.cjs"
41
+ "require": "./jest-preset.cjs",
42
+ "import": "./jest-preset.mjs"
43
43
  },
44
44
  "./dist/jest-preset.mjs": "./jest-preset.mjs",
45
45
  "./jest-preset": {
46
- "import": "./jest-preset.mjs",
47
- "require": "./jest-preset.cjs"
46
+ "require": "./jest-preset.cjs",
47
+ "import": "./jest-preset.mjs"
48
48
  },
49
49
  "./jest-preset.cjs": "./jest-preset.cjs",
50
50
  "./jest-preset.js": {
51
- "import": "./jest-preset.mjs",
52
- "require": "./jest-preset.cjs"
51
+ "require": "./jest-preset.cjs",
52
+ "import": "./jest-preset.mjs"
53
53
  },
54
54
  "./jest-preset.mjs": "./jest-preset.mjs",
55
55
  "./package.json": "./package.json",
@@ -61,59 +61,49 @@
61
61
  "types": "dist/index.d.ts",
62
62
  "typings": "dist/index.d.ts",
63
63
  "scripts": {
64
- "review": "yarn run review:coverage",
65
- "review:coverage": "yarn run lint && yarn run coverage",
66
- "review:test": "yarn run lint && yarn run test",
67
- "coverage": "yarn run test -- --coverage",
68
- "lint": "yarn run lint:eslint",
69
- "lint:eslint": "ynpx eslint --ext .ts,.tsx,.mts,.cts ./",
70
- "pretest": "echo pretest",
64
+ "pretest": "pnpm run build",
71
65
  "test": "jest --passWithNoTests",
72
66
  "test:jest": "jest --passWithNoTests",
73
- "test:jest:snapshot": "yarn run test:jest -- -u",
67
+ "test:jest:coverage": "pnpm run test:jest -- --coverage",
68
+ "test:jest:snapshot": "pnpm run test:jest -- -u",
74
69
  "test:mocha": "ynpx --quiet -p ts-node -p mocha mocha -- --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"",
75
- "test:snapshot": "yarn run test -- -u",
70
+ "test:snapshot": "pnpm run test -u",
76
71
  "test:tsd": "ynpx tsd",
77
72
  "test:tsdx": "ynpx @bluelovers/tsdx test --passWithNoTests",
78
- "posttest": "yarn run build",
79
- "build": "yarn run build:tsdx && yarn run build:dts:bundle",
80
- "build:dts:bundle": "ynpx dts-bundle-generator -o ./dist/index.d.ts ./src/index.ts --no-banner --inline-declare-global & echo build:dts:bundle",
73
+ "build": "pnpm run build:tsdx && pnpm run build:dts:bundle",
74
+ "build:dts:bundle": "node --run build:dts:copy2 & ynpx @bluelovers/dts-bundle-generator -o ./dist/index.d.ts ./src/index.ts --no-banner --inline-declare-global & echo build:dts:bundle",
81
75
  "build:dts:copy": "copy .\\src\\index.d.ts .\\dist\\index.d.ts & echo build:dts",
82
- "build:dts:tsc": "yarn run build:dts:tsc:emit && yarn run build:dts:copy",
83
- "build:dts:tsc:emit": "tsc --emitDeclarationOnly --declaration --noEmit false",
76
+ "build:dts:copy2": "copy .\\index.d.ts .\\dist\\index.d.ts & echo copy:dts",
77
+ "build:dts:tsc": "pnpm run build:dts:tsc:emit & pnpm run build:dts:copy",
78
+ "build:dts:tsc:emit": "cd src && tsc --emitDeclarationOnly --declaration --noEmit false",
84
79
  "build:microbundle": "ynpx microbundle --target node",
85
80
  "build:tsdx": "ynpx @bluelovers/tsdx build --target node --name index",
86
81
  "ci:install": "echo ci:install",
87
82
  "ci:build": "echo ci:build",
88
- "preversion": "yarn run test",
83
+ "preversion": "pnpm run test",
89
84
  "version": "echo version",
90
- "postversion": "echo postversion && yarn run test & git commit ./dist -m \"build(dist): update build\" & echo update build",
91
- "prepublish": "echo prepublish",
92
- "prepare": "echo prepare",
85
+ "postversion": "echo postversion && pnpm run test & git commit ./dist -m \"build(dist): update build\" & echo update build",
93
86
  "prepublishOnly": "echo prepublishOnly",
94
- "prepublishOnly:update": "yarn run ncu && yarn run sort-package-json",
95
- "prepack": "echo prepack",
96
- "pack": "echo pack",
97
- "postpack": "echo postpack",
87
+ "prepublishOnly:update": "pnpm run ncu && pnpm run sort-package-json",
98
88
  "publish": "echo publish",
99
- "postpublish": "echo postpublish",
100
89
  "postpublishOnly": "echo postpublishOnly",
101
90
  "ncu": "yarn-tool ncu -u",
102
91
  "sort-package-json": "yarn-tool sort",
103
92
  "tsc:showConfig": "ynpx get-current-tsconfig -p"
104
93
  },
105
94
  "dependencies": {
106
- "@yarn-tool/require-resolve": "^3.0.0",
107
- "@yarn-tool/table": "^2.0.13",
108
- "array-hyper-unique": "^2.1.4",
95
+ "@yarn-tool/require-resolve": "^4.0.9",
96
+ "@yarn-tool/table": "^2.0.22",
97
+ "array-hyper-unique": "^2.1.8",
98
+ "cli-table3": "^0.6.5",
109
99
  "debug-color2": "^1.3.2",
110
- "jest-cache-directory": "^1.0.6",
111
- "jest-chain-transform": "^0.0.5",
112
- "ts-type": ">=2"
100
+ "jest-cache-directory": "^1.0.7",
101
+ "jest-chain-transform": "^0.0.8",
102
+ "regexp-helper-core": "^2.0.13",
103
+ "ts-type": ">=3.0.8"
113
104
  },
114
- "packageManager": "yarn@1.22.19",
115
105
  "publishConfig": {
116
106
  "access": "public"
117
107
  },
118
- "gitHead": "4afc40e52c2dbf807ec50ccab179c969c36f270d"
108
+ "gitHead": "aebbf6f90595ed291660067da304cfd9110d6314"
119
109
  }
@@ -0,0 +1,49 @@
1
+ import { IJestConfig, IRuntime } from './types';
2
+ import { detectIncludes } from './util';
3
+ import { _requireResolve2 } from './helper';
4
+ import { ITSPickExtra } from 'ts-type';
5
+
6
+ /** 環境設置載入的檔案 / Files to load environment setup */
7
+ export function defaultSetupFiles(runtime?: ITSPickExtra<IRuntime, 'jestConfig'>)
8
+ {
9
+ const jestConfig = runtime?.jestConfig ?? {} as IJestConfig;
10
+
11
+ let detect = detectIncludes(jestConfig.setupFiles, 'dotenv');
12
+
13
+ const setupFiles: IJestConfig['setupFiles'] = [
14
+ /**
15
+ * @see https://lusbuab.medium.com/using-dotenv-with-jest-7e735b34e55f
16
+ */
17
+ !detect['dotenv'] && _requireResolve2('dotenv/config').result,
18
+ ...(jestConfig.setupFiles ?? []),
19
+
20
+ ].filter(Boolean);
21
+
22
+ const setupFilesAfterEnv = [
23
+ // 可選擇性啟用的 Jest 擴充套件 / Optional Jest extensions
24
+ //"jest-chain",
25
+ //"jest-extended/all",
26
+ //"jest-extended-extra",
27
+ //"jest-num-close-with",
28
+ /**
29
+ * 跨平台測試支援參考 / Cross-platform testing support reference
30
+ * @see https://medium.com/doctolib/how-to-run-the-same-jest-test-suite-across-several-platforms-jest-os-detection-plugin-included-f8113832482b
31
+ * @see https://github.com/doctolib/jest-os-detection
32
+ */
33
+ //'jest-os-detection',
34
+ ...(jestConfig.setupFilesAfterEnv ?? []),
35
+ ].filter(Boolean);
36
+
37
+ const ret = {} as Pick<IJestConfig, 'setupFiles' | 'setupFilesAfterEnv'>;
38
+
39
+ if (setupFiles.length)
40
+ {
41
+ ret.setupFiles = setupFiles;
42
+ }
43
+ if (setupFilesAfterEnv.length)
44
+ {
45
+ ret.setupFilesAfterEnv = setupFilesAfterEnv;
46
+ }
47
+
48
+ return ret
49
+ }
@@ -0,0 +1,96 @@
1
+ import { IJestConfig, IRuntime } from './types';
2
+ import { _handleFileExtensions, _requireResolve } from './helper';
3
+ import { defaultTsJestTransformerOptions } from './plugin/ts-jest';
4
+ import { defaultTransformFileExtensions } from './defaults';
5
+ import { IOptionsRequireResolve as IOptions, requireResolveExtra } from '@yarn-tool/require-resolve';
6
+ import { ITSWriteable } from 'ts-type';
7
+
8
+ /**
9
+ * 建立預設的轉換器配置
10
+ * Create default transformer configuration
11
+ *
12
+ * 配置 ts-jest 作為主要轉換器,並在可用時整合 jest-tsd-transform 和 jest-chain-transform
13
+ * Configures ts-jest as the main transformer, integrating jest-tsd-transform and jest-chain-transform when available
14
+ *
15
+ * @param {IRuntime} runtime - 執行時期配置 / Runtime configuration
16
+ * @returns {object} 轉換器配置物件 / Transformer configuration object
17
+ */
18
+ export function defaultTransform(runtime: IRuntime)
19
+ {
20
+ /**
21
+ * 搜尋路徑列表,用於解析相關模組
22
+ * Search paths list for resolving related modules
23
+ */
24
+ const paths: string[] = [
25
+ requireResolveExtra('@bluelovers/jest-config').result,
26
+ ].filter(Boolean);
27
+
28
+ /**
29
+ * 模組解析選項 / Module resolution options
30
+ */
31
+ const opts: IOptions = {
32
+ includeGlobal: true,
33
+ includeCurrentDirectory: true,
34
+ paths,
35
+ };
36
+
37
+ /**
38
+ * ts-jest 轉換器配置
39
+ * ts-jest transformer configuration
40
+ */
41
+ let ts_transform: IJestConfig["transform"][string] = _requireResolve('ts-jest') as 'ts-jest';
42
+
43
+ /**
44
+ * 將 ts-jest 與其選項合併
45
+ * Merge ts-jest with its options
46
+ */
47
+ ts_transform = [ts_transform, defaultTsJestTransformerOptions(runtime)];
48
+
49
+ /**
50
+ * 嘗試解析 jest-tsd-transform(TypeScript 宣告檔轉換器)
51
+ * Try to resolve jest-tsd-transform (TypeScript declaration file transformer)
52
+ */
53
+ const { result: tsd } = requireResolveExtra('jest-tsd-transform', opts);
54
+
55
+ /**
56
+ * 如果 jest-tsd-transform 可用,嘗試建立轉換鏈
57
+ * If jest-tsd-transform is available, try to create transform chain
58
+ */
59
+ if (tsd?.length)
60
+ {
61
+ /**
62
+ * 嘗試解析 jest-chain-transform(轉換鏈協調器)
63
+ * Try to resolve jest-chain-transform (transform chain coordinator)
64
+ */
65
+ const { result: chain } = requireResolveExtra('jest-chain-transform', opts);
66
+
67
+ /**
68
+ * 如果 jest-chain-transform 可用,建立轉換鏈
69
+ * If jest-chain-transform is available, create transform chain
70
+ */
71
+ if (chain?.length)
72
+ {
73
+ ts_transform = [
74
+ chain as 'jest-chain-transform', {
75
+ transformers: [
76
+ tsd as 'jest-tsd-transform',
77
+ // @ts-ignore
78
+ ts_transform as 'ts-jest',
79
+ ],
80
+ },
81
+ ] satisfies [
82
+ string,
83
+ Record<string, unknown>
84
+ ]
85
+ }
86
+ }
87
+
88
+ /**
89
+ * 建立最終的轉換器配置物件
90
+ * Create final transformer configuration object
91
+ */
92
+ const value = {
93
+ [`.(${_handleFileExtensions(defaultTransformFileExtensions(), '|')})$`]: ts_transform,
94
+ } as const
95
+ return value as ITSWriteable<typeof value>;
96
+ }