ts-jest 29.2.6 → 29.3.1
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/.lintstagedrc +4 -0
- package/.ts-jest-digest +1 -1
- package/CHANGELOG.md +51 -13
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +1 -0
- package/dist/config/types.d.ts +2 -0
- package/dist/config/types.js +2 -0
- package/dist/legacy/compiler/ts-compiler.d.ts +2 -3
- package/dist/legacy/compiler/ts-compiler.js +43 -7
- package/dist/legacy/config/config-set.d.ts +2 -1
- package/dist/legacy/config/config-set.js +32 -15
- package/dist/legacy/ts-jest-transformer.js +0 -3
- package/dist/raw-compiler-options.d.ts +3 -0
- package/dist/transpilers/typescript/transpile-module.d.ts +8 -0
- package/dist/transpilers/typescript/transpile-module.js +199 -0
- package/dist/types.d.ts +18 -11
- package/dist/utils/get-package-version.js +3 -2
- package/dist/utils/importer.js +6 -36
- package/dist/utils/json.js +1 -2
- package/dist/utils/logger.js +2 -1
- package/dist/utils/messages.d.ts +4 -1
- package/dist/utils/messages.js +5 -0
- package/package.json +28 -36
- package/preprocessor.js +0 -1
- package/dist/utils/version-checkers.d.ts +0 -1
- package/dist/utils/version-checkers.js +0 -63
package/.lintstagedrc
ADDED
package/.ts-jest-digest
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
7d82f2afd50b1c1f02bc1970a3b39858b238dbf9
|
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
## [29.3.1](https://github.com/kulshekhar/ts-jest/compare/v29.3.0...v29.3.1) (2025-03-31)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* fix: allow `isolatedModules` mode to have `ts.Program` under `Node16/Next` ([25157eb](https://github.com/kulshekhar/ts-jest/commit/25157eb))
|
|
7
|
+
* fix: improve message for `isolatedModules` of `ts-jest` config ([547eb6f](https://github.com/kulshekhar/ts-jest/commit/547eb6f))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## [29.3.0](https://github.com/kulshekhar/ts-jest/compare/v29.2.6...v29.3.0) (2025-03-21)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* feat: support hybrid `module` values for `isolatedModules: true` ([f372121](https://github.com/kulshekhar/ts-jest/commit/f372121))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* fix: set `customConditions` to `undefined` in `TsCompiler` ([b091d70](https://github.com/kulshekhar/ts-jest/commit/b091d70)), closes [#4620](https://github.com/kulshekhar/ts-jest/issues/4620)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Code Refactoring
|
|
25
|
+
|
|
26
|
+
* refactor: remove manual version checker ([89458fc](https://github.com/kulshekhar/ts-jest/commit/89458fc))
|
|
27
|
+
* refactor: remove patching deps based on version checker ([bac4c43](https://github.com/kulshekhar/ts-jest/commit/bac4c43))
|
|
28
|
+
* refactor: deprecate `RawCompilerOptions` interface ([2b1b6cd](https://github.com/kulshekhar/ts-jest/commit/2b1b6cd))
|
|
29
|
+
* refactor: deprecate transform option `isolatedModules` ([7dfef71](https://github.com/kulshekhar/ts-jest/commit/7dfef71))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
## DEPRECATIONS
|
|
33
|
+
|
|
34
|
+
* `RawCompilerOptions` is deprecated in favor of `TsConfigJson.CompilerOptions` from `type-fest`
|
|
35
|
+
* `isolatedModules` transform option is deprecated in favor of https://www.typescriptlang.org/tsconfig/#isolatedModules
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## [29.2.6](https://github.com/kulshekhar/ts-jest/compare/v29.2.5...v29.2.6) (2025-02-22)
|
|
2
40
|
|
|
3
41
|
|
|
4
42
|
### Bug Fixes
|
|
@@ -9,7 +47,7 @@
|
|
|
9
47
|
|
|
10
48
|
|
|
11
49
|
|
|
12
|
-
|
|
50
|
+
## [29.2.5](https://github.com/kulshekhar/ts-jest/compare/v29.2.4...v29.2.5) (2024-08-23)
|
|
13
51
|
|
|
14
52
|
|
|
15
53
|
### Bug Fixes
|
|
@@ -20,7 +58,7 @@
|
|
|
20
58
|
|
|
21
59
|
|
|
22
60
|
|
|
23
|
-
|
|
61
|
+
## [29.2.4](https://github.com/kulshekhar/ts-jest/compare/v29.2.3...v29.2.4) (2024-08-01)
|
|
24
62
|
|
|
25
63
|
|
|
26
64
|
### Bug Fixes
|
|
@@ -29,7 +67,7 @@
|
|
|
29
67
|
|
|
30
68
|
|
|
31
69
|
|
|
32
|
-
|
|
70
|
+
## [29.2.3](https://github.com/kulshekhar/ts-jest/compare/v29.2.2...v29.2.3) (2024-07-18)
|
|
33
71
|
|
|
34
72
|
|
|
35
73
|
### Security Fixes
|
|
@@ -52,7 +90,7 @@
|
|
|
52
90
|
|
|
53
91
|
|
|
54
92
|
|
|
55
|
-
|
|
93
|
+
## [29.2.1](https://github.com/kulshekhar/ts-jest/compare/v29.2.0...v29.2.1) (2024-07-10)
|
|
56
94
|
|
|
57
95
|
|
|
58
96
|
### Bug Fixes
|
|
@@ -94,7 +132,7 @@
|
|
|
94
132
|
|
|
95
133
|
|
|
96
134
|
|
|
97
|
-
|
|
135
|
+
## [29.1.5](https://github.com/kulshekhar/ts-jest/compare/v29.1.4...v29.1.5) (2024-06-16)
|
|
98
136
|
|
|
99
137
|
|
|
100
138
|
### Bug Fixes
|
|
@@ -103,7 +141,7 @@
|
|
|
103
141
|
|
|
104
142
|
|
|
105
143
|
|
|
106
|
-
|
|
144
|
+
## [29.1.4](https://github.com/kulshekhar/ts-jest/compare/v29.1.3...v29.1.4) (2024-05-28)
|
|
107
145
|
|
|
108
146
|
|
|
109
147
|
### Bug Fixes
|
|
@@ -117,7 +155,7 @@
|
|
|
117
155
|
|
|
118
156
|
|
|
119
157
|
|
|
120
|
-
|
|
158
|
+
## [29.1.3](https://github.com/kulshekhar/ts-jest/compare/v29.1.2...v29.1.3) (2024-05-21)
|
|
121
159
|
|
|
122
160
|
|
|
123
161
|
### Bug Fixes
|
|
@@ -132,7 +170,7 @@
|
|
|
132
170
|
|
|
133
171
|
|
|
134
172
|
|
|
135
|
-
|
|
173
|
+
## [29.1.2](https://github.com/kulshekhar/ts-jest/compare/v29.1.1...v29.1.2) (2024-01-22)
|
|
136
174
|
|
|
137
175
|
|
|
138
176
|
### Bug Fixes
|
|
@@ -170,7 +208,7 @@
|
|
|
170
208
|
|
|
171
209
|
|
|
172
210
|
|
|
173
|
-
|
|
211
|
+
## [29.0.4](https://github.com/kulshekhar/ts-jest/compare/v29.0.3...v29.0.4) (2023-01-10)
|
|
174
212
|
|
|
175
213
|
|
|
176
214
|
### Bug Fixes
|
|
@@ -180,7 +218,7 @@
|
|
|
180
218
|
|
|
181
219
|
|
|
182
220
|
|
|
183
|
-
|
|
221
|
+
## [29.0.3](https://github.com/kulshekhar/ts-jest/compare/v29.0.2...v29.0.3) (2022-09-28)
|
|
184
222
|
|
|
185
223
|
|
|
186
224
|
### Bug Fixes
|
|
@@ -195,7 +233,7 @@
|
|
|
195
233
|
|
|
196
234
|
|
|
197
235
|
|
|
198
|
-
|
|
236
|
+
## [29.0.2](https://github.com/kulshekhar/ts-jest/compare/v29.0.1...v29.0.2) (2022-09-23)
|
|
199
237
|
|
|
200
238
|
|
|
201
239
|
### Bug Fixes
|
|
@@ -205,7 +243,7 @@
|
|
|
205
243
|
|
|
206
244
|
|
|
207
245
|
|
|
208
|
-
|
|
246
|
+
## [29.0.1](https://github.com/kulshekhar/ts-jest/compare/v29.0.0...v29.0.1) (2022-09-13)
|
|
209
247
|
|
|
210
248
|
|
|
211
249
|
### Bug Fixes
|
package/dist/config/index.d.ts
CHANGED
package/dist/config/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Logger } from 'bs-logger';
|
|
2
|
-
import
|
|
3
|
-
import type { StringMap, TsCompilerInstance, TsJestAstTransformer, TsJestCompileOptions, TTypeScript } from '../../types';
|
|
4
|
-
import { CompiledOutput } from '../../types';
|
|
2
|
+
import { CompilerOptions, CustomTransformers, Program, TranspileOutput } from 'typescript';
|
|
3
|
+
import type { StringMap, TsCompilerInstance, TsJestAstTransformer, TsJestCompileOptions, TTypeScript, CompiledOutput } from '../../types';
|
|
5
4
|
import type { ConfigSet } from '../config/config-set';
|
|
6
5
|
export declare class TsCompiler implements TsCompilerInstance {
|
|
7
6
|
readonly configSet: ConfigSet;
|
|
@@ -54,10 +54,17 @@ exports.TsCompiler = void 0;
|
|
|
54
54
|
var path_1 = require("path");
|
|
55
55
|
var bs_logger_1 = require("bs-logger");
|
|
56
56
|
var lodash_memoize_1 = __importDefault(require("lodash.memoize"));
|
|
57
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
57
58
|
var constants_1 = require("../../constants");
|
|
59
|
+
var transpile_module_1 = require("../../transpilers/typescript/transpile-module");
|
|
58
60
|
var utils_1 = require("../../utils");
|
|
59
61
|
var messages_1 = require("../../utils/messages");
|
|
60
62
|
var compiler_utils_1 = require("./compiler-utils");
|
|
63
|
+
var assertCompilerOptionsWithJestTransformMode = function (compilerOptions, isEsmMode, logger) {
|
|
64
|
+
if (isEsmMode && compilerOptions.module === typescript_1.default.ModuleKind.CommonJS) {
|
|
65
|
+
logger.error("The current compiler option \"module\" value is not suitable for Jest ESM mode. Please either use ES module kinds or Node16/NodeNext module kinds with \"type: module\" in package.json" /* Errors.InvalidModuleKindForEsm */);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
61
68
|
var TsCompiler = /** @class */ (function () {
|
|
62
69
|
function TsCompiler(configSet, runtimeCacheFS) {
|
|
63
70
|
var _a;
|
|
@@ -116,20 +123,31 @@ var TsCompiler = /** @class */ (function () {
|
|
|
116
123
|
var _a, _b;
|
|
117
124
|
var moduleResolution = (_a = this._ts.ModuleResolutionKind.Node10) !== null && _a !== void 0 ? _a : this._ts.ModuleResolutionKind.NodeJs;
|
|
118
125
|
if (!isEsm) {
|
|
119
|
-
return __assign(__assign({}, compilerOptions), { module: this._ts.ModuleKind.CommonJS, moduleResolution: moduleResolution
|
|
126
|
+
return __assign(__assign({}, compilerOptions), { module: this._ts.ModuleKind.CommonJS, moduleResolution: moduleResolution,
|
|
127
|
+
/**
|
|
128
|
+
* This option is only supported in `Node16`/`NodeNext` and `Bundler` module, see https://www.typescriptlang.org/tsconfig/#customConditions
|
|
129
|
+
*/
|
|
130
|
+
customConditions: undefined });
|
|
120
131
|
}
|
|
121
132
|
var moduleKind = (_b = compilerOptions.module) !== null && _b !== void 0 ? _b : this._ts.ModuleKind.ESNext;
|
|
122
133
|
var esModuleInterop = compilerOptions.esModuleInterop;
|
|
123
|
-
if (
|
|
134
|
+
if ((0, transpile_module_1.isModernNodeModuleKind)(moduleKind)) {
|
|
124
135
|
esModuleInterop = true;
|
|
125
136
|
moduleKind = this._ts.ModuleKind.ESNext;
|
|
126
137
|
}
|
|
127
|
-
return __assign(__assign({}, compilerOptions), { module: moduleKind, esModuleInterop: esModuleInterop, moduleResolution: moduleResolution
|
|
138
|
+
return __assign(__assign({}, compilerOptions), { module: moduleKind, esModuleInterop: esModuleInterop, moduleResolution: moduleResolution,
|
|
139
|
+
/**
|
|
140
|
+
* This option is only supported in `Node16`/`NodeNext` and `Bundler` module, see https://www.typescriptlang.org/tsconfig/#customConditions
|
|
141
|
+
*/
|
|
142
|
+
customConditions: undefined });
|
|
128
143
|
};
|
|
129
144
|
TsCompiler.prototype.getCompiledOutput = function (fileContent, fileName, options) {
|
|
130
145
|
var e_1, _a;
|
|
131
146
|
var isEsmMode = this.configSet.useESM && options.supportsStaticESM;
|
|
132
147
|
this._compilerOptions = this.fixupCompilerOptionsForModuleKind(this._initialCompilerOptions, isEsmMode);
|
|
148
|
+
if (!this._initialCompilerOptions.isolatedModules && (0, transpile_module_1.isModernNodeModuleKind)(this._initialCompilerOptions.module)) {
|
|
149
|
+
this._logger.warn("Using hybrid module kind (Node16/18/Next) is only supported in \"isolatedModules: true\". Please set \"isolatedModules: true\" in your tsconfig.json." /* Helps.UsingModernNodeResolution */);
|
|
150
|
+
}
|
|
133
151
|
var moduleKind = this._initialCompilerOptions.module;
|
|
134
152
|
var currentModuleKind = this._compilerOptions.module;
|
|
135
153
|
if (this._languageService) {
|
|
@@ -195,6 +213,7 @@ var TsCompiler = /** @class */ (function () {
|
|
|
195
213
|
}
|
|
196
214
|
else {
|
|
197
215
|
this._logger.debug({ fileName: fileName }, 'getCompiledOutput(): compiling as isolated module');
|
|
216
|
+
assertCompilerOptionsWithJestTransformMode(this._initialCompilerOptions, isEsmMode, this._logger);
|
|
198
217
|
var result = this._transpileOutput(fileContent, fileName);
|
|
199
218
|
if (result.diagnostics && this.configSet.shouldReportDiagnostics(fileName)) {
|
|
200
219
|
this.configSet.raiseDiagnostics(result.diagnostics, fileName, this._logger);
|
|
@@ -205,11 +224,28 @@ var TsCompiler = /** @class */ (function () {
|
|
|
205
224
|
}
|
|
206
225
|
};
|
|
207
226
|
TsCompiler.prototype._transpileOutput = function (fileContent, fileName) {
|
|
208
|
-
|
|
227
|
+
var _this = this;
|
|
228
|
+
/**
|
|
229
|
+
* @deprecated
|
|
230
|
+
*
|
|
231
|
+
* This code path should be removed in the next major version to benefit from checking on compiler options
|
|
232
|
+
*/
|
|
233
|
+
if (!(0, transpile_module_1.isModernNodeModuleKind)(this._initialCompilerOptions.module)) {
|
|
234
|
+
return this._ts.transpileModule(fileContent, {
|
|
235
|
+
fileName: fileName,
|
|
236
|
+
transformers: this._makeTransformers(this.configSet.resolvedTransformers),
|
|
237
|
+
compilerOptions: this._compilerOptions,
|
|
238
|
+
reportDiagnostics: this.configSet.shouldReportDiagnostics(fileName),
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return (0, transpile_module_1.tsTranspileModule)(fileContent, {
|
|
209
242
|
fileName: fileName,
|
|
210
|
-
transformers:
|
|
211
|
-
|
|
212
|
-
|
|
243
|
+
transformers: function (program) {
|
|
244
|
+
_this.program = program;
|
|
245
|
+
return _this._makeTransformers(_this.configSet.resolvedTransformers);
|
|
246
|
+
},
|
|
247
|
+
compilerOptions: this._initialCompilerOptions,
|
|
248
|
+
reportDiagnostics: fileName ? this.configSet.shouldReportDiagnostics(fileName) : false,
|
|
213
249
|
});
|
|
214
250
|
};
|
|
215
251
|
TsCompiler.prototype._makeTransformers = function (customTransformers) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Logger } from 'bs-logger';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
+
import type { TsConfigCompilerOptionsJson } from '../../config/types';
|
|
3
4
|
import type { RawCompilerOptions } from '../../raw-compiler-options';
|
|
4
5
|
import type { TsJestAstTransformer, TsJestTransformOptions, TTypeScript } from '../../types';
|
|
5
6
|
export declare class ConfigSet {
|
|
@@ -23,7 +24,7 @@ export declare class ConfigSet {
|
|
|
23
24
|
* Load TypeScript configuration. Returns the parsed TypeScript config and any `tsconfig` options specified in ts-jest
|
|
24
25
|
* Subclasses which extend `ConfigSet` can override the default behavior
|
|
25
26
|
*/
|
|
26
|
-
protected _resolveTsConfig(compilerOptions?: RawCompilerOptions, resolvedConfigFile?: string): Record<string, any>;
|
|
27
|
+
protected _resolveTsConfig(compilerOptions?: RawCompilerOptions | TsConfigCompilerOptionsJson, resolvedConfigFile?: string): Record<string, any>;
|
|
27
28
|
isTestFile(fileName: string): boolean;
|
|
28
29
|
shouldStringifyContent(filePath: string): boolean;
|
|
29
30
|
raiseDiagnostics(diagnostics: ts.Diagnostic[], filePath?: string, logger?: Logger): void;
|
|
@@ -159,6 +159,7 @@ var requireFromString = function (code, fileName) {
|
|
|
159
159
|
// @ts-expect-error `_compile` is not exposed in typing
|
|
160
160
|
m._compile(code, fileName);
|
|
161
161
|
var exports = m.exports;
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
162
163
|
parent && parent.children && parent.children.splice(parent.children.indexOf(m), 1);
|
|
163
164
|
return exports;
|
|
164
165
|
};
|
|
@@ -207,11 +208,8 @@ var ConfigSet = /** @class */ (function () {
|
|
|
207
208
|
var options = tsJestCfg !== null && tsJestCfg !== void 0 ? tsJestCfg : Object.create(null);
|
|
208
209
|
// compiler module
|
|
209
210
|
this.compilerModule = importer_1.importer.typescript("Using \"ts-jest\" requires this package to be installed." /* ImportReasons.TsJest */, (_e = options.compiler) !== null && _e !== void 0 ? _e : 'typescript');
|
|
210
|
-
// isolatedModules
|
|
211
|
-
this.isolatedModules = (_f = options.isolatedModules) !== null && _f !== void 0 ? _f : false;
|
|
212
211
|
this.logger.debug({ compilerModule: this.compilerModule }, 'normalized compiler module config via ts-jest option');
|
|
213
212
|
this._setupConfigSet(options);
|
|
214
|
-
this._resolveTsCacheDir();
|
|
215
213
|
this._matchablePatterns = __spreadArray(__spreadArray([], __read(this._jestCfg.testMatch), false), __read(this._jestCfg.testRegex), false).filter(function (pattern) {
|
|
216
214
|
/**
|
|
217
215
|
* jest config testRegex doesn't always deliver the correct RegExp object
|
|
@@ -223,6 +221,20 @@ var ConfigSet = /** @class */ (function () {
|
|
|
223
221
|
(_b = this._matchablePatterns).push.apply(_b, __spreadArray([], __read(constants_1.DEFAULT_JEST_TEST_MATCH), false));
|
|
224
222
|
}
|
|
225
223
|
this._matchTestFilePath = (0, jest_util_1.globsToMatcher)(this._matchablePatterns.filter(function (pattern) { return typeof pattern === 'string'; }));
|
|
224
|
+
// isolatedModules
|
|
225
|
+
if (options.isolatedModules) {
|
|
226
|
+
this.parsedTsConfig.options.isolatedModules = true;
|
|
227
|
+
if (this.tsconfigFilePath) {
|
|
228
|
+
this.logger.warn((0, messages_1.interpolate)("\n The \"ts-jest\" config option \"isolatedModules\" is deprecated and will be removed in v30.0.0. Please use \"isolatedModules: true\" in {{tsconfigFilePath}} instead, see https://www.typescriptlang.org/tsconfig/#isolatedModules\n " /* Deprecations.IsolatedModulesWithTsconfigPath */, {
|
|
229
|
+
tsconfigFilePath: this.tsconfigFilePath,
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
this.logger.warn("\n The \"ts-jest\" config option \"isolatedModules\" is deprecated and will be removed in v30.0.0. Please use \"isolatedModules: true\", see https://www.typescriptlang.org/tsconfig/#isolatedModules\n " /* Deprecations.IsolatedModulesWithoutTsconfigPath */);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
this.isolatedModules = (_f = this.parsedTsConfig.options.isolatedModules) !== null && _f !== void 0 ? _f : false;
|
|
237
|
+
this._resolveTsCacheDir();
|
|
226
238
|
}
|
|
227
239
|
/**
|
|
228
240
|
* @internal
|
|
@@ -275,6 +287,7 @@ var ConfigSet = /** @class */ (function () {
|
|
|
275
287
|
if (typeof diagnosticsOpt === 'object') {
|
|
276
288
|
var ignoreCodes = diagnosticsOpt.ignoreCodes;
|
|
277
289
|
if (ignoreCodes) {
|
|
290
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
278
291
|
Array.isArray(ignoreCodes) ? ignoreList.push.apply(ignoreList, __spreadArray([], __read(ignoreCodes), false)) : ignoreList.push(ignoreCodes);
|
|
279
292
|
}
|
|
280
293
|
this._diagnostics = {
|
|
@@ -428,7 +441,7 @@ var ConfigSet = /** @class */ (function () {
|
|
|
428
441
|
!warningModulesForEsmInterop.includes(moduleValue) &&
|
|
429
442
|
!(finalOptions.esModuleInterop || finalOptions.allowSyntheticDefaultImports)) {
|
|
430
443
|
result.errors.push({
|
|
431
|
-
code:
|
|
444
|
+
code: messages_1.TsJestDiagnosticCodes.ConfigModuleOption,
|
|
432
445
|
messageText: "If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information." /* Errors.ConfigNoModuleInterop */,
|
|
433
446
|
category: this.compilerModule.DiagnosticCategory.Message,
|
|
434
447
|
file: undefined,
|
|
@@ -446,6 +459,7 @@ var ConfigSet = /** @class */ (function () {
|
|
|
446
459
|
var key = _g.value;
|
|
447
460
|
var val = forcedOptions[key];
|
|
448
461
|
if (val === undefined) {
|
|
462
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
449
463
|
delete finalOptions[key];
|
|
450
464
|
}
|
|
451
465
|
else {
|
|
@@ -487,29 +501,28 @@ var ConfigSet = /** @class */ (function () {
|
|
|
487
501
|
var sourceMap = (_d = resultOptions.sourceMap) !== null && _d !== void 0 ? _d : true;
|
|
488
502
|
return __assign(__assign({}, result), { options: __assign(__assign({}, resultOptions), { sourceMap: sourceMap, inlineSources: sourceMap, module: (_e = resultOptions.module) !== null && _e !== void 0 ? _e : this.compilerModule.ModuleKind.CommonJS }) });
|
|
489
503
|
};
|
|
490
|
-
// eslint-disable-next-line no-dupe-class-members
|
|
491
504
|
ConfigSet.prototype._resolveTsConfig = function (compilerOptions, resolvedConfigFile) {
|
|
492
505
|
var config = { compilerOptions: Object.create(null) };
|
|
493
506
|
var basePath = (0, normalize_slashes_1.normalizeSlashes)(this.rootDir);
|
|
494
507
|
var ts = this.compilerModule;
|
|
495
508
|
// Read project configuration when available.
|
|
496
|
-
|
|
509
|
+
this.tsconfigFilePath = resolvedConfigFile
|
|
497
510
|
? (0, normalize_slashes_1.normalizeSlashes)(resolvedConfigFile)
|
|
498
511
|
: ts.findConfigFile((0, normalize_slashes_1.normalizeSlashes)(this.rootDir), ts.sys.fileExists);
|
|
499
|
-
if (
|
|
500
|
-
this.logger.debug({ tsConfigFileName:
|
|
501
|
-
var result = ts.readConfigFile(
|
|
512
|
+
if (this.tsconfigFilePath) {
|
|
513
|
+
this.logger.debug({ tsConfigFileName: this.tsconfigFilePath }, 'readTsConfig(): reading', this.tsconfigFilePath);
|
|
514
|
+
var result = ts.readConfigFile(this.tsconfigFilePath, ts.sys.readFile);
|
|
502
515
|
// Return diagnostics.
|
|
503
516
|
if (result.error) {
|
|
504
517
|
return { errors: [result.error], fileNames: [], options: {} };
|
|
505
518
|
}
|
|
506
519
|
config = result.config;
|
|
507
|
-
basePath = (0, normalize_slashes_1.normalizeSlashes)((0, path_1.dirname)(
|
|
520
|
+
basePath = (0, normalize_slashes_1.normalizeSlashes)((0, path_1.dirname)(this.tsconfigFilePath));
|
|
508
521
|
}
|
|
509
522
|
// Override default configuration options `ts-jest` requires.
|
|
510
523
|
config.compilerOptions = __assign(__assign({}, config.compilerOptions), compilerOptions);
|
|
511
524
|
// parse json, merge config extending others, ...
|
|
512
|
-
return ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined,
|
|
525
|
+
return ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, this.tsconfigFilePath);
|
|
513
526
|
};
|
|
514
527
|
ConfigSet.prototype.isTestFile = function (fileName) {
|
|
515
528
|
var _this = this;
|
|
@@ -522,6 +535,7 @@ var ConfigSet = /** @class */ (function () {
|
|
|
522
535
|
};
|
|
523
536
|
ConfigSet.prototype.raiseDiagnostics = function (diagnostics, filePath, logger) {
|
|
524
537
|
var _this = this;
|
|
538
|
+
if (logger === void 0) { logger = this.logger; }
|
|
525
539
|
var ignoreCodes = this._diagnostics.ignoreCodes;
|
|
526
540
|
var DiagnosticCategory = this.compilerModule.DiagnosticCategory;
|
|
527
541
|
var filteredDiagnostics = filePath && !this.shouldReportDiagnostics(filePath)
|
|
@@ -541,8 +555,7 @@ var ConfigSet = /** @class */ (function () {
|
|
|
541
555
|
if (this._diagnostics.throws && filteredDiagnostics.some(function (d) { return importantCategories.includes(d.category); })) {
|
|
542
556
|
throw error;
|
|
543
557
|
}
|
|
544
|
-
|
|
545
|
-
logger ? logger.warn({ error: error }, error.message) : this.logger.warn({ error: error }, error.message);
|
|
558
|
+
logger.warn({ error: error }, error.message);
|
|
546
559
|
};
|
|
547
560
|
ConfigSet.prototype.shouldReportDiagnostics = function (filePath) {
|
|
548
561
|
var fileExtension = (0, path_1.extname)(filePath);
|
|
@@ -581,7 +594,9 @@ var ConfigSet = /** @class */ (function () {
|
|
|
581
594
|
path = require.resolve(path);
|
|
582
595
|
nodeResolved = true;
|
|
583
596
|
}
|
|
584
|
-
catch (
|
|
597
|
+
catch (_e) {
|
|
598
|
+
this.logger.debug({ path: path }, 'failed to resolve path', path);
|
|
599
|
+
}
|
|
585
600
|
}
|
|
586
601
|
if (!nodeResolved) {
|
|
587
602
|
path = (0, path_1.resolve)(this.cwd, path);
|
|
@@ -592,7 +607,9 @@ var ConfigSet = /** @class */ (function () {
|
|
|
592
607
|
path = require.resolve(path);
|
|
593
608
|
nodeResolved = true;
|
|
594
609
|
}
|
|
595
|
-
catch (
|
|
610
|
+
catch (_f) {
|
|
611
|
+
this.logger.debug({ path: path }, 'failed to resolve path', path);
|
|
612
|
+
}
|
|
596
613
|
}
|
|
597
614
|
if (throwIfMissing && !(0, fs_1.existsSync)(path)) {
|
|
598
615
|
throw new Error((0, messages_1.interpolate)("File not found: {{inputPath}} (resolved as: {{resolvedPath}})" /* Errors.FileNotFound */, { inputPath: inputPath, resolvedPath: path }));
|
|
@@ -83,7 +83,6 @@ var utils_1 = require("../utils");
|
|
|
83
83
|
var importer_1 = require("../utils/importer");
|
|
84
84
|
var messages_1 = require("../utils/messages");
|
|
85
85
|
var sha1_1 = require("../utils/sha1");
|
|
86
|
-
var version_checkers_1 = require("../utils/version-checkers");
|
|
87
86
|
var compiler_1 = require("./compiler");
|
|
88
87
|
var config_set_1 = require("./config/config-set");
|
|
89
88
|
/**
|
|
@@ -96,7 +95,6 @@ var TsJestTransformer = /** @class */ (function () {
|
|
|
96
95
|
this._depGraphs = new Map();
|
|
97
96
|
this._watchMode = false;
|
|
98
97
|
this._logger = utils_1.rootLogger.child({ namespace: 'ts-jest-transformer' });
|
|
99
|
-
version_checkers_1.VersionCheckers.jest.warn();
|
|
100
98
|
/**
|
|
101
99
|
* For some unknown reasons, `this` is undefined in `getCacheKey` and `process`
|
|
102
100
|
* when running Jest in ESM mode
|
|
@@ -165,7 +163,6 @@ var TsJestTransformer = /** @class */ (function () {
|
|
|
165
163
|
}
|
|
166
164
|
return configSet;
|
|
167
165
|
};
|
|
168
|
-
// eslint-disable-next-line class-methods-use-this
|
|
169
166
|
TsJestTransformer.prototype._createConfigSet = function (config) {
|
|
170
167
|
return new config_set_1.ConfigSet(config);
|
|
171
168
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
type ExtendedTranspileOptions = Omit<ts.TranspileOptions, 'transformers'> & {
|
|
3
|
+
transformers?: (program: ts.Program) => ts.CustomTransformers;
|
|
4
|
+
};
|
|
5
|
+
type ExtendedTsTranspileModuleFn = (fileContent: string, transpileOptions: ExtendedTranspileOptions) => ts.TranspileOutput;
|
|
6
|
+
export declare const isModernNodeModuleKind: (module: ts.ModuleKind | undefined) => boolean;
|
|
7
|
+
export declare const tsTranspileModule: ExtendedTsTranspileModuleFn;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
+
if (m) return m.call(o);
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
|
+
next: function () {
|
|
7
|
+
if (o && i >= o.length) o = void 0;
|
|
8
|
+
return { value: o && o[i++], done: !o };
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
+
};
|
|
13
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
+
if (!m) return o;
|
|
16
|
+
var i = m.call(o), r, ar = [], e;
|
|
17
|
+
try {
|
|
18
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
+
}
|
|
20
|
+
catch (error) { e = { error: error }; }
|
|
21
|
+
finally {
|
|
22
|
+
try {
|
|
23
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
+
}
|
|
25
|
+
finally { if (e) throw e.error; }
|
|
26
|
+
}
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
+
if (ar || !(i in from)) {
|
|
32
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
+
ar[i] = from[i];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.tsTranspileModule = exports.isModernNodeModuleKind = void 0;
|
|
43
|
+
var node_path_1 = __importDefault(require("node:path"));
|
|
44
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
45
|
+
var messages_1 = require("../../utils/messages");
|
|
46
|
+
var barebonesLibContent = "/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number {}\ninterface Object {}\ninterface RegExp {}\ninterface String {}\ninterface Array<T> { length: number; [n: number]: T; }\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}";
|
|
47
|
+
var barebonesLibName = 'lib.d.ts';
|
|
48
|
+
var barebonesLibSourceFile;
|
|
49
|
+
var carriageReturnLineFeed = '\r\n';
|
|
50
|
+
var lineFeed = '\n';
|
|
51
|
+
function getNewLineCharacter(options) {
|
|
52
|
+
switch (options.newLine) {
|
|
53
|
+
case typescript_1.default.NewLineKind.CarriageReturnLineFeed:
|
|
54
|
+
return carriageReturnLineFeed;
|
|
55
|
+
case typescript_1.default.NewLineKind.LineFeed:
|
|
56
|
+
default:
|
|
57
|
+
return lineFeed;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
var isModernNodeModuleKind = function (module) {
|
|
61
|
+
return module ? [typescript_1.default.ModuleKind.Node16, /* ModuleKind.Node18 */ 101, typescript_1.default.ModuleKind.NodeNext].includes(module) : false;
|
|
62
|
+
};
|
|
63
|
+
exports.isModernNodeModuleKind = isModernNodeModuleKind;
|
|
64
|
+
var shouldCheckProjectPkgJsonContent = function (fileName, moduleKind) {
|
|
65
|
+
return fileName.endsWith('package.json') && (0, exports.isModernNodeModuleKind)(moduleKind);
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Copy source code of {@link ts.transpileModule} from {@link https://github.com/microsoft/TypeScript/blob/main/src/services/transpile.ts}
|
|
69
|
+
* with extra modifications:
|
|
70
|
+
* - Remove generation of declaration files
|
|
71
|
+
* - Allow using custom AST transformers with the internal created {@link Program}
|
|
72
|
+
*/
|
|
73
|
+
var transpileWorker = function (input, transpileOptions) {
|
|
74
|
+
var e_1, _a;
|
|
75
|
+
var _b, _c, _d, _e, _f;
|
|
76
|
+
barebonesLibSourceFile !== null && barebonesLibSourceFile !== void 0 ? barebonesLibSourceFile : (barebonesLibSourceFile = typescript_1.default.createSourceFile(barebonesLibName, barebonesLibContent, {
|
|
77
|
+
languageVersion: typescript_1.default.ScriptTarget.Latest,
|
|
78
|
+
}));
|
|
79
|
+
var diagnostics = [];
|
|
80
|
+
var options = transpileOptions.compilerOptions
|
|
81
|
+
? // @ts-expect-error internal TypeScript API
|
|
82
|
+
typescript_1.default.fixupCompilerOptions(transpileOptions.compilerOptions, diagnostics)
|
|
83
|
+
: {};
|
|
84
|
+
// mix in default options
|
|
85
|
+
var defaultOptions = typescript_1.default.getDefaultCompilerOptions();
|
|
86
|
+
for (var key in defaultOptions) {
|
|
87
|
+
if (Object.hasOwn(defaultOptions, key) && options[key] === undefined) {
|
|
88
|
+
options[key] = defaultOptions[key];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
// @ts-expect-error internal TypeScript API
|
|
93
|
+
for (var _g = __values(typescript_1.default.transpileOptionValueCompilerOptions), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
94
|
+
var option = _h.value;
|
|
95
|
+
// Do not set redundant config options if `verbatimModuleSyntax` was supplied.
|
|
96
|
+
if (options.verbatimModuleSyntax && new Set(['isolatedModules']).has(option.name)) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
options[option.name] = option.transpileOptionValue;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
103
|
+
finally {
|
|
104
|
+
try {
|
|
105
|
+
if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
|
|
106
|
+
}
|
|
107
|
+
finally { if (e_1) throw e_1.error; }
|
|
108
|
+
}
|
|
109
|
+
// transpileModule does not write anything to disk so there is no need to verify that there are no conflicts between input and output paths.
|
|
110
|
+
options.suppressOutputPathCheck = true;
|
|
111
|
+
// Filename can be non-ts file.
|
|
112
|
+
options.allowNonTsExtensions = true;
|
|
113
|
+
options.declaration = false;
|
|
114
|
+
options.declarationMap = false;
|
|
115
|
+
var newLine = getNewLineCharacter(options);
|
|
116
|
+
// if jsx is specified then treat file as .tsx
|
|
117
|
+
var inputFileName = (_b = transpileOptions.fileName) !== null && _b !== void 0 ? _b : (((_c = transpileOptions.compilerOptions) === null || _c === void 0 ? void 0 : _c.jsx) ? 'module.tsx' : 'module.ts');
|
|
118
|
+
// Create a compilerHost object to allow the compiler to read and write files
|
|
119
|
+
var compilerHost = {
|
|
120
|
+
getSourceFile: function (fileName) {
|
|
121
|
+
// @ts-expect-error internal TypeScript API
|
|
122
|
+
if (fileName === typescript_1.default.normalizePath(inputFileName)) {
|
|
123
|
+
return sourceFile;
|
|
124
|
+
}
|
|
125
|
+
// @ts-expect-error internal TypeScript API
|
|
126
|
+
return fileName === typescript_1.default.normalizePath(barebonesLibName) ? barebonesLibSourceFile : undefined;
|
|
127
|
+
},
|
|
128
|
+
writeFile: function (name, text) {
|
|
129
|
+
if (node_path_1.default.extname(name) === '.map') {
|
|
130
|
+
sourceMapText = text;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
outputText = text;
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
getDefaultLibFileName: function () { return barebonesLibName; },
|
|
137
|
+
useCaseSensitiveFileNames: function () { return false; },
|
|
138
|
+
getCanonicalFileName: function (fileName) { return fileName; },
|
|
139
|
+
getCurrentDirectory: function () { return ''; },
|
|
140
|
+
getNewLine: function () { return newLine; },
|
|
141
|
+
fileExists: function (fileName) {
|
|
142
|
+
if (shouldCheckProjectPkgJsonContent(fileName, options.module)) {
|
|
143
|
+
return typescript_1.default.sys.fileExists(fileName);
|
|
144
|
+
}
|
|
145
|
+
return fileName === inputFileName;
|
|
146
|
+
},
|
|
147
|
+
readFile: function (fileName) {
|
|
148
|
+
if (shouldCheckProjectPkgJsonContent(fileName, options.module)) {
|
|
149
|
+
return typescript_1.default.sys.readFile(fileName);
|
|
150
|
+
}
|
|
151
|
+
return '';
|
|
152
|
+
},
|
|
153
|
+
directoryExists: function () { return true; },
|
|
154
|
+
getDirectories: function () { return []; },
|
|
155
|
+
};
|
|
156
|
+
var sourceFile = typescript_1.default.createSourceFile(inputFileName, input, {
|
|
157
|
+
languageVersion: (_d = options.target) !== null && _d !== void 0 ? _d : typescript_1.default.ScriptTarget.ESNext,
|
|
158
|
+
impliedNodeFormat: typescript_1.default.getImpliedNodeFormatForFile(inputFileName,
|
|
159
|
+
/*packageJsonInfoCache*/ undefined, compilerHost, options),
|
|
160
|
+
// @ts-expect-error internal TypeScript API
|
|
161
|
+
setExternalModuleIndicator: typescript_1.default.getSetExternalModuleIndicator(options),
|
|
162
|
+
jsDocParsingMode: (_e = transpileOptions.jsDocParsingMode) !== null && _e !== void 0 ? _e : typescript_1.default.JSDocParsingMode.ParseAll,
|
|
163
|
+
});
|
|
164
|
+
if (transpileOptions.moduleName) {
|
|
165
|
+
sourceFile.moduleName = transpileOptions.moduleName;
|
|
166
|
+
}
|
|
167
|
+
if (transpileOptions.renamedDependencies) {
|
|
168
|
+
// @ts-expect-error internal TypeScript API
|
|
169
|
+
sourceFile.renamedDependencies = new Map(Object.entries(transpileOptions.renamedDependencies));
|
|
170
|
+
}
|
|
171
|
+
// Output
|
|
172
|
+
var outputText;
|
|
173
|
+
var sourceMapText;
|
|
174
|
+
var inputs = [inputFileName];
|
|
175
|
+
var program = typescript_1.default.createProgram(inputs, options, compilerHost);
|
|
176
|
+
if (transpileOptions.reportDiagnostics) {
|
|
177
|
+
diagnostics.push.apply(diagnostics, __spreadArray([], __read(program.getSyntacticDiagnostics(sourceFile)), false));
|
|
178
|
+
}
|
|
179
|
+
diagnostics.push.apply(diagnostics, __spreadArray([], __read(program.getOptionsDiagnostics()), false));
|
|
180
|
+
// Emit
|
|
181
|
+
var result = program.emit(
|
|
182
|
+
/*targetSourceFile*/ undefined,
|
|
183
|
+
/*writeFile*/ undefined,
|
|
184
|
+
/*cancellationToken*/ undefined,
|
|
185
|
+
/*emitOnlyDtsFiles*/ undefined, (_f = transpileOptions.transformers) === null || _f === void 0 ? void 0 : _f.call(transpileOptions, program));
|
|
186
|
+
diagnostics.push.apply(diagnostics, __spreadArray([], __read(result.diagnostics), false));
|
|
187
|
+
if (outputText === undefined) {
|
|
188
|
+
diagnostics.push({
|
|
189
|
+
category: typescript_1.default.DiagnosticCategory.Error,
|
|
190
|
+
code: messages_1.TsJestDiagnosticCodes.Generic,
|
|
191
|
+
messageText: 'No output generated',
|
|
192
|
+
file: sourceFile,
|
|
193
|
+
start: 0,
|
|
194
|
+
length: 0,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return { outputText: outputText !== null && outputText !== void 0 ? outputText : '', diagnostics: diagnostics, sourceMapText: sourceMapText };
|
|
198
|
+
};
|
|
199
|
+
exports.tsTranspileModule = transpileWorker;
|
package/dist/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { TransformedSource, TransformOptions } from '@jest/transform';
|
|
|
2
2
|
import type { Config } from '@jest/types';
|
|
3
3
|
import type * as _babel from 'babel__core';
|
|
4
4
|
import type * as _ts from 'typescript';
|
|
5
|
+
import type { TsConfigCompilerOptionsJson } from './config/types';
|
|
5
6
|
import { ESM_JS_TRANSFORM_PATTERN, ESM_TS_JS_TRANSFORM_PATTERN, ESM_TS_TRANSFORM_PATTERN, JS_TRANSFORM_PATTERN, TS_JS_TRANSFORM_PATTERN, TS_TRANSFORM_PATTERN } from './constants';
|
|
6
7
|
import type { ConfigSet } from './legacy/config/config-set';
|
|
7
8
|
import type { RawCompilerOptions } from './raw-compiler-options';
|
|
@@ -20,7 +21,7 @@ export interface ConfigCustomTransformer {
|
|
|
20
21
|
afterDeclarations?: Array<string | AstTransformer>;
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
|
-
* @deprecated use
|
|
24
|
+
* @deprecated use {@link TsJestTransformerOptions} instead
|
|
24
25
|
*/
|
|
25
26
|
export interface TsJestGlobalOptions {
|
|
26
27
|
/**
|
|
@@ -30,19 +31,25 @@ export interface TsJestGlobalOptions {
|
|
|
30
31
|
* - `path/to/tsconfig.json`: path to a specific tsconfig file (<rootDir> can be used)
|
|
31
32
|
* - `{...}`: an object with inline compiler options
|
|
32
33
|
*
|
|
33
|
-
* @default undefined
|
|
34
|
+
* @default `undefined` (the default config file will be used if it exists)
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
*
|
|
38
|
+
* {@link RawCompilerOptions} will be replaced with {@link TsConfigCompilerOptionsJson} in the next major release
|
|
34
39
|
*/
|
|
35
|
-
tsconfig?: boolean | string | RawCompilerOptions;
|
|
40
|
+
tsconfig?: boolean | string | RawCompilerOptions | TsConfigCompilerOptionsJson;
|
|
36
41
|
/**
|
|
37
|
-
*
|
|
42
|
+
* @deprecated use {@link TsConfigCompilerOptionsJson.isolatedModules} instead
|
|
43
|
+
*
|
|
44
|
+
* Compiles files as isolated modules (disables some features)
|
|
38
45
|
*
|
|
39
|
-
* @default undefined (
|
|
46
|
+
* @default `undefined` (disables transpiling files with {@link _ts.transpileModule})
|
|
40
47
|
*/
|
|
41
48
|
isolatedModules?: boolean;
|
|
42
49
|
/**
|
|
43
50
|
* Compiler to use
|
|
44
51
|
*
|
|
45
|
-
* @default
|
|
52
|
+
* @default `typescript`
|
|
46
53
|
*/
|
|
47
54
|
compiler?: 'typescript' | 'ttypescript' | string;
|
|
48
55
|
/**
|
|
@@ -55,13 +62,13 @@ export interface TsJestGlobalOptions {
|
|
|
55
62
|
* - `false`: hide diagnostics of all files (kind of useless)
|
|
56
63
|
* - `{...}`: an inline object with fine grained settings
|
|
57
64
|
*
|
|
58
|
-
* @default undefined
|
|
65
|
+
* @default `undefined`
|
|
59
66
|
*/
|
|
60
67
|
diagnostics?: boolean | {
|
|
61
68
|
/**
|
|
62
69
|
* Enables colorful and pretty output of errors
|
|
63
70
|
*
|
|
64
|
-
* @default undefined (
|
|
71
|
+
* @default `undefined` (enables formatting errors)
|
|
65
72
|
*/
|
|
66
73
|
pretty?: boolean;
|
|
67
74
|
/**
|
|
@@ -69,7 +76,7 @@ export interface TsJestGlobalOptions {
|
|
|
69
76
|
* [here](https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json).
|
|
70
77
|
*
|
|
71
78
|
* @see https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json
|
|
72
|
-
* @default [6059,18002,18003]
|
|
79
|
+
* @default `[6059,18002,18003]`
|
|
73
80
|
*/
|
|
74
81
|
ignoreCodes?: number | string | Array<number | string>;
|
|
75
82
|
/**
|
|
@@ -79,7 +86,7 @@ export interface TsJestGlobalOptions {
|
|
|
79
86
|
/**
|
|
80
87
|
* Logs TypeScript errors to stderr instead of throwing exceptions
|
|
81
88
|
*
|
|
82
|
-
* @default undefined (
|
|
89
|
+
* @default `undefined` (TypeScript errors will be thrown as exceptions)
|
|
83
90
|
*/
|
|
84
91
|
warnOnly?: boolean;
|
|
85
92
|
};
|
|
@@ -90,7 +97,7 @@ export interface TsJestGlobalOptions {
|
|
|
90
97
|
* - `path/to/.babelrc`: path to a babelrc file (<rootDir> can be used)
|
|
91
98
|
* - `{...}`: an object with inline babel options
|
|
92
99
|
*
|
|
93
|
-
* @default undefined
|
|
100
|
+
* @default `undefined` (not using `Babel`)
|
|
94
101
|
*/
|
|
95
102
|
babelConfig?: boolean | string | BabelConfig;
|
|
96
103
|
/**
|
package/dist/utils/importer.js
CHANGED
|
@@ -47,33 +47,17 @@ exports.__requireModule = __requireModule;
|
|
|
47
47
|
var logger_1 = require("./logger");
|
|
48
48
|
var memoize_1 = require("./memoize");
|
|
49
49
|
var messages_1 = require("./messages");
|
|
50
|
-
var version_checkers_1 = require("./version-checkers");
|
|
51
50
|
var logger = logger_1.rootLogger.child({ namespace: 'Importer' });
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
-
var passThru = function (action) { return function (input) {
|
|
54
|
-
action();
|
|
55
|
-
return input;
|
|
56
|
-
}; };
|
|
57
51
|
/**
|
|
58
52
|
* @internal
|
|
59
53
|
*/
|
|
60
54
|
var Importer = /** @class */ (function () {
|
|
61
|
-
function Importer(
|
|
62
|
-
if (_patches === void 0) { _patches = {}; }
|
|
63
|
-
this._patches = _patches;
|
|
55
|
+
function Importer() {
|
|
64
56
|
}
|
|
65
57
|
Object.defineProperty(Importer, "instance", {
|
|
66
58
|
get: function () {
|
|
67
59
|
logger.debug('creating Importer singleton');
|
|
68
|
-
|
|
69
|
-
// it could be fixes that are not deployed, or
|
|
70
|
-
// abstractions so that multiple versions work the same
|
|
71
|
-
return new Importer({
|
|
72
|
-
'@babel/core': [passThru(version_checkers_1.VersionCheckers.babelCore.warn)],
|
|
73
|
-
'babel-jest': [passThru(version_checkers_1.VersionCheckers.babelJest.warn)],
|
|
74
|
-
typescript: [passThru(version_checkers_1.VersionCheckers.typescript.warn)],
|
|
75
|
-
jest: [passThru(version_checkers_1.VersionCheckers.jest.warn)],
|
|
76
|
-
});
|
|
60
|
+
return new Importer();
|
|
77
61
|
},
|
|
78
62
|
enumerable: false,
|
|
79
63
|
configurable: true
|
|
@@ -107,14 +91,11 @@ var Importer = /** @class */ (function () {
|
|
|
107
91
|
if (req.exists) {
|
|
108
92
|
// module exists
|
|
109
93
|
loaded = req;
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
logger.error({ requireResult: contextReq }, "failed loading module '".concat(name, "'"), loaded.error.message);
|
|
94
|
+
if (req.error) {
|
|
95
|
+
logger.error({ requireResult: contextReq }, "failed loading module '".concat(name, "'"), req.error.message);
|
|
113
96
|
}
|
|
114
97
|
else {
|
|
115
|
-
// it has been loaded, let's patch it
|
|
116
98
|
logger.debug({ requireResult: contextReq }, 'loaded module', name);
|
|
117
|
-
loaded.exports = this._patch(name, loaded.exports);
|
|
118
99
|
}
|
|
119
100
|
break;
|
|
120
101
|
}
|
|
@@ -127,7 +108,6 @@ var Importer = /** @class */ (function () {
|
|
|
127
108
|
// but not one which does not exists
|
|
128
109
|
return loaded;
|
|
129
110
|
};
|
|
130
|
-
// eslint-disable-next-line no-dupe-class-members
|
|
131
111
|
Importer.prototype.tryTheseOr = function (moduleNames, missingResult, allowLoadError) {
|
|
132
112
|
if (allowLoadError === void 0) { allowLoadError = false; }
|
|
133
113
|
var args = Array.isArray(moduleNames) ? moduleNames : [moduleNames];
|
|
@@ -140,19 +120,12 @@ var Importer = /** @class */ (function () {
|
|
|
140
120
|
return missingResult;
|
|
141
121
|
throw result.error;
|
|
142
122
|
};
|
|
143
|
-
Importer.prototype._patch = function (name, unpatched) {
|
|
144
|
-
if (name in this._patches) {
|
|
145
|
-
logger.debug('patching', name);
|
|
146
|
-
return this._patches[name].reduce(function (mod, patcher) { return patcher(mod); }, unpatched);
|
|
147
|
-
}
|
|
148
|
-
return unpatched;
|
|
149
|
-
};
|
|
150
123
|
Importer.prototype._import = function (why, moduleName, _a) {
|
|
151
124
|
var _b = _a === void 0 ? {} : _a, _c = _b.alternatives, alternatives = _c === void 0 ? [] : _c, _d = _b.installTip, installTip = _d === void 0 ? moduleName : _d;
|
|
152
125
|
// try to load any of the alternative after trying main one
|
|
153
126
|
var res = this.tryThese.apply(this, __spreadArray([moduleName], __read(alternatives), false));
|
|
154
127
|
// if we could load one, return it
|
|
155
|
-
if (res
|
|
128
|
+
if (res === null || res === void 0 ? void 0 : res.exists) {
|
|
156
129
|
if (!res.error)
|
|
157
130
|
return res.exports;
|
|
158
131
|
// it could not load because of a failure while importing, but it exists
|
|
@@ -182,9 +155,6 @@ var Importer = /** @class */ (function () {
|
|
|
182
155
|
return args.join(':');
|
|
183
156
|
})
|
|
184
157
|
], Importer.prototype, "tryThese", null);
|
|
185
|
-
__decorate([
|
|
186
|
-
(0, memoize_1.Memoize)(function (name) { return name; })
|
|
187
|
-
], Importer.prototype, "_patch", null);
|
|
188
158
|
__decorate([
|
|
189
159
|
(0, memoize_1.Memoize)()
|
|
190
160
|
], Importer, "instance", null);
|
|
@@ -209,7 +179,7 @@ function requireWrapper(moduleName) {
|
|
|
209
179
|
try {
|
|
210
180
|
result.exports = requireModule(path);
|
|
211
181
|
}
|
|
212
|
-
catch (
|
|
182
|
+
catch (_a) {
|
|
213
183
|
try {
|
|
214
184
|
result.exports = requireModule(moduleName);
|
|
215
185
|
}
|
package/dist/utils/json.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.stringify = stringify;
|
|
7
7
|
exports.parse = parse;
|
|
8
8
|
exports.normalize = normalize;
|
|
9
|
-
/* eslint-disable no-redeclare */
|
|
10
9
|
var fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
|
|
11
10
|
var UNDEFINED = 'undefined';
|
|
12
11
|
function stringify(input) {
|
|
@@ -32,7 +31,7 @@ function normalize(input, _a) {
|
|
|
32
31
|
result = undefined;
|
|
33
32
|
normalize.cache.set(input, result);
|
|
34
33
|
}
|
|
35
|
-
return result
|
|
34
|
+
return result !== null && result !== void 0 ? result : input;
|
|
36
35
|
}
|
|
37
36
|
/**
|
|
38
37
|
* @internal
|
package/dist/utils/logger.js
CHANGED
|
@@ -6,13 +6,14 @@ var backports_1 = require("./backports");
|
|
|
6
6
|
var original = process.env.TS_JEST_LOG;
|
|
7
7
|
var buildOptions = function () {
|
|
8
8
|
var _a;
|
|
9
|
+
var _b;
|
|
9
10
|
return ({
|
|
10
11
|
context: (_a = {},
|
|
11
12
|
_a[bs_logger_1.LogContexts.package] = 'ts-jest',
|
|
12
13
|
_a[bs_logger_1.LogContexts.logLevel] = bs_logger_1.LogLevels.trace,
|
|
13
14
|
_a.version = require('../../package.json').version,
|
|
14
15
|
_a),
|
|
15
|
-
targets: process.env.TS_JEST_LOG
|
|
16
|
+
targets: (_b = process.env.TS_JEST_LOG) !== null && _b !== void 0 ? _b : undefined,
|
|
16
17
|
});
|
|
17
18
|
};
|
|
18
19
|
exports.rootLogger = (0, bs_logger_1.createLogger)(buildOptions());
|
package/dist/utils/messages.d.ts
CHANGED
package/dist/utils/messages.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TsJestDiagnosticCodes = void 0;
|
|
3
4
|
exports.interpolate = interpolate;
|
|
4
5
|
/**
|
|
5
6
|
* @internal
|
|
@@ -10,3 +11,7 @@ function interpolate(msg, vars) {
|
|
|
10
11
|
// eslint-disable-next-line no-useless-escape
|
|
11
12
|
return msg.replace(/\{\{([^\}]+)\}\}/g, function (_, key) { return (key in vars ? vars[key] : _); });
|
|
12
13
|
}
|
|
14
|
+
exports.TsJestDiagnosticCodes = {
|
|
15
|
+
Generic: 151000,
|
|
16
|
+
ConfigModuleOption: 151001,
|
|
17
|
+
};
|
package/package.json
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-jest",
|
|
3
|
-
"version": "29.
|
|
3
|
+
"version": "29.3.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
|
+
"type": "commonjs",
|
|
6
7
|
"bin": {
|
|
7
8
|
"ts-jest": "cli.js"
|
|
8
9
|
},
|
|
9
10
|
"description": "A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript",
|
|
10
11
|
"scripts": {
|
|
11
|
-
"prebuild": "rimraf dist coverage *.tgz",
|
|
12
|
+
"prebuild": "rimraf --glob dist coverage *.tgz",
|
|
12
13
|
"build": "tsc -p tsconfig.build.json",
|
|
13
14
|
"postbuild": "node scripts/post-build.js",
|
|
14
|
-
"test": "jest -c=jest
|
|
15
|
+
"test": "jest -c=jest.config.ts",
|
|
15
16
|
"test-e2e-cjs": "jest -c=jest-e2e.config.cjs --no-cache",
|
|
16
17
|
"test-e2e-esm": "node --experimental-vm-modules --no-warnings node_modules/jest/bin/jest.js -c=jest-e2e.config.mjs --no-cache",
|
|
17
18
|
"test-examples": "node scripts/test-examples.js",
|
|
18
|
-
"lint": "eslint
|
|
19
|
-
"lint-fix": "eslint --fix
|
|
19
|
+
"lint": "eslint .",
|
|
20
|
+
"lint-fix": "eslint --fix .",
|
|
20
21
|
"lint-prettier": "prettier \"**/*.{yml,yaml,md}\" --write",
|
|
21
22
|
"lint-prettier-ci": "prettier '**/*.{yml,yaml,md}' --check",
|
|
22
23
|
"doc": "cd website && npm run start",
|
|
@@ -25,9 +26,7 @@
|
|
|
25
26
|
"prepare": "npm run build",
|
|
26
27
|
"prepublishOnly": "npm run test",
|
|
27
28
|
"preversion": "npm run test",
|
|
28
|
-
"version": "npm run changelog && git add CHANGELOG.md"
|
|
29
|
-
"raw:options": "node scripts/generate-raw-compiler-options.js",
|
|
30
|
-
"update-e2e": "node scripts/update-e2e.js"
|
|
29
|
+
"version": "npm run changelog && git add CHANGELOG.md"
|
|
31
30
|
},
|
|
32
31
|
"repository": {
|
|
33
32
|
"type": "git",
|
|
@@ -60,6 +59,7 @@
|
|
|
60
59
|
"lodash.memoize": "^4.1.2",
|
|
61
60
|
"make-error": "^1.3.6",
|
|
62
61
|
"semver": "^7.7.1",
|
|
62
|
+
"type-fest": "^4.38.0",
|
|
63
63
|
"yargs-parser": "^21.1.1"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
@@ -87,16 +87,12 @@
|
|
|
87
87
|
"optional": true
|
|
88
88
|
}
|
|
89
89
|
},
|
|
90
|
-
"husky": {
|
|
91
|
-
"hooks": {
|
|
92
|
-
"pre-commit": "lint-staged",
|
|
93
|
-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
94
|
-
"post-commit": "git reset"
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
90
|
"devDependencies": {
|
|
98
|
-
"@commitlint/cli": "
|
|
99
|
-
"@commitlint/config-angular": "
|
|
91
|
+
"@commitlint/cli": "^19.8.0",
|
|
92
|
+
"@commitlint/config-angular": "^19.8.0",
|
|
93
|
+
"@eslint/compat": "^1.2.7",
|
|
94
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
95
|
+
"@eslint/js": "^9.23.0",
|
|
100
96
|
"@jest/globals": "^29.7.0",
|
|
101
97
|
"@jest/transform": "^29.7.0",
|
|
102
98
|
"@jest/types": "^29.6.3",
|
|
@@ -109,39 +105,35 @@
|
|
|
109
105
|
"@types/lodash.memoize": "^4.1.9",
|
|
110
106
|
"@types/lodash.set": "^4.3.9",
|
|
111
107
|
"@types/micromatch": "^4.0.9",
|
|
112
|
-
"@types/node": "20.17.
|
|
113
|
-
"@types/semver": "^7.
|
|
108
|
+
"@types/node": "20.17.28",
|
|
109
|
+
"@types/semver": "^7.7.0",
|
|
114
110
|
"@types/yargs": "^17.0.33",
|
|
115
111
|
"@types/yargs-parser": "21.0.3",
|
|
116
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
117
|
-
"@typescript-eslint/parser": "^
|
|
112
|
+
"@typescript-eslint/eslint-plugin": "^8.28.0",
|
|
113
|
+
"@typescript-eslint/parser": "^8.28.0",
|
|
118
114
|
"babel-jest": "^29.7.0",
|
|
119
115
|
"conventional-changelog-cli": "^5.0.0",
|
|
120
|
-
"esbuild": "~0.25.
|
|
121
|
-
"eslint": "^
|
|
122
|
-
"eslint-config-prettier": "^
|
|
116
|
+
"esbuild": "~0.25.1",
|
|
117
|
+
"eslint": "^9.23.0",
|
|
118
|
+
"eslint-config-prettier": "^10.1.1",
|
|
123
119
|
"eslint-plugin-import": "^2.31.0",
|
|
124
120
|
"eslint-plugin-jest": "^28.11.0",
|
|
125
|
-
"eslint-plugin-jsdoc": "^
|
|
126
|
-
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
121
|
+
"eslint-plugin-jsdoc": "^50.6.9",
|
|
127
122
|
"eslint-plugin-prettier": "^4.2.1",
|
|
128
123
|
"execa": "5.1.1",
|
|
129
124
|
"fs-extra": "^11.3.0",
|
|
130
125
|
"glob": "^10.2.6",
|
|
131
126
|
"glob-gitignore": "^1.0.15",
|
|
132
|
-
"
|
|
127
|
+
"globals": "^16.0.0",
|
|
128
|
+
"husky": "^9.1.7",
|
|
133
129
|
"jest": "^29.7.0",
|
|
134
130
|
"js-yaml": "^4.1.0",
|
|
135
|
-
"
|
|
136
|
-
"
|
|
131
|
+
"lint-staged": "^15.5.0",
|
|
132
|
+
"memfs": "^4.17.0",
|
|
137
133
|
"prettier": "^2.8.8",
|
|
138
|
-
"
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
"*.{ts,tsx,js,jsx}": [
|
|
142
|
-
"eslint --fix",
|
|
143
|
-
"git add"
|
|
144
|
-
]
|
|
134
|
+
"rimraf": "^5.0.10",
|
|
135
|
+
"typescript": "~5.5.4",
|
|
136
|
+
"typescript-eslint": "^8.28.0"
|
|
145
137
|
},
|
|
146
138
|
"engines": {
|
|
147
139
|
"node": "^14.15.0 || ^16.10.0 || ^18.0.0 || >=20.0.0"
|
package/preprocessor.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VersionCheckers = void 0;
|
|
4
|
-
var semver_1 = require("semver");
|
|
5
|
-
var get_package_version_1 = require("./get-package-version");
|
|
6
|
-
var logger_1 = require("./logger");
|
|
7
|
-
var messages_1 = require("./messages");
|
|
8
|
-
var logger = logger_1.rootLogger.child({ namespace: 'versions' });
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
exports.VersionCheckers = {
|
|
13
|
-
jest: createVersionChecker('jest', ">=29.0.0 <30" /* ExpectedVersions.Jest */),
|
|
14
|
-
typescript: createVersionChecker('typescript', ">=4.3 <6" /* ExpectedVersions.TypeScript */),
|
|
15
|
-
babelJest: createVersionChecker('babel-jest', ">=29.0.0 <30" /* ExpectedVersions.BabelJest */),
|
|
16
|
-
babelCore: createVersionChecker('@babel/core', ">=7.0.0-beta.0 <8" /* ExpectedVersions.BabelCore */),
|
|
17
|
-
};
|
|
18
|
-
function checkVersion(name, expectedRange, action) {
|
|
19
|
-
if (action === void 0) { action = 'warn'; }
|
|
20
|
-
var success = true;
|
|
21
|
-
if (!('TS_JEST_DISABLE_VER_CHECKER' in process.env)) {
|
|
22
|
-
var version = (0, get_package_version_1.getPackageVersion)(name);
|
|
23
|
-
success = !!version && (0, semver_1.satisfies)(version, expectedRange);
|
|
24
|
-
logger.debug({
|
|
25
|
-
actualVersion: version,
|
|
26
|
-
expectedVersion: expectedRange,
|
|
27
|
-
}, 'checking version of %s: %s', name, success ? 'OK' : 'NOT OK');
|
|
28
|
-
if (!action || success)
|
|
29
|
-
return success;
|
|
30
|
-
var message = (0, messages_1.interpolate)(version ? "Version {{actualVersion}} of {{module}} installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version ({{expectedVersion}}). Please do not report issues in ts-jest if you are using unsupported versions." /* Errors.UntestedDependencyVersion */ : "Module {{module}} is not installed. If you're experiencing issues, consider installing a supported version ({{expectedVersion}})." /* Errors.MissingDependency */, {
|
|
31
|
-
module: name,
|
|
32
|
-
actualVersion: version || '??',
|
|
33
|
-
expectedVersion: rangeToHumanString(expectedRange),
|
|
34
|
-
});
|
|
35
|
-
if (action === 'warn') {
|
|
36
|
-
logger.warn(message);
|
|
37
|
-
}
|
|
38
|
-
else if (action === 'throw') {
|
|
39
|
-
logger.fatal(message);
|
|
40
|
-
throw new RangeError(message);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return success;
|
|
44
|
-
}
|
|
45
|
-
function rangeToHumanString(versionRange) {
|
|
46
|
-
return new semver_1.Range(versionRange).toString();
|
|
47
|
-
}
|
|
48
|
-
function createVersionChecker(moduleName, expectedVersion) {
|
|
49
|
-
var memo;
|
|
50
|
-
var warn = function () {
|
|
51
|
-
if (memo !== undefined)
|
|
52
|
-
return memo;
|
|
53
|
-
return (memo = checkVersion(moduleName, expectedVersion, 'warn'));
|
|
54
|
-
};
|
|
55
|
-
var raise = function () { return checkVersion(moduleName, expectedVersion, 'throw'); };
|
|
56
|
-
return {
|
|
57
|
-
raise: raise,
|
|
58
|
-
warn: warn,
|
|
59
|
-
forget: function () {
|
|
60
|
-
memo = undefined;
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
}
|