ts-jest 29.3.2 → 29.3.3
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/.ts-jest-digest +1 -1
- package/CHANGELOG.md +10 -0
- package/dist/cli/config/init.js +103 -128
- package/dist/cli/config/migrate.js +113 -156
- package/dist/cli/help.js +14 -42
- package/dist/cli/helpers/presets.js +7 -8
- package/dist/cli/index.js +47 -101
- package/dist/config/paths-to-module-name-mapper.js +37 -61
- package/dist/constants.js +1 -5
- package/dist/index.js +2 -2
- package/dist/legacy/compiler/compiler-utils.js +5 -5
- package/dist/legacy/compiler/ts-compiler.js +194 -213
- package/dist/legacy/compiler/ts-jest-compiler.js +9 -9
- package/dist/legacy/config/config-set.js +281 -292
- package/dist/legacy/index.js +2 -4
- package/dist/legacy/ts-jest-transformer.js +134 -201
- package/dist/presets/all-presets.js +2 -2
- package/dist/presets/create-jest-preset.js +101 -139
- package/dist/transformers/hoist-jest.js +30 -43
- package/dist/transpilers/typescript/transpile-module.js +69 -98
- package/dist/types.js +1 -1
- package/dist/utils/backports.js +26 -28
- package/dist/utils/get-package-version.js +2 -2
- package/dist/utils/importer.js +53 -108
- package/dist/utils/json.js +2 -2
- package/dist/utils/jsonable-value.js +20 -27
- package/dist/utils/logger.js +11 -15
- package/dist/utils/memoize.js +11 -17
- package/dist/utils/messages.js +2 -3
- package/dist/utils/sha1.js +7 -11
- package/dist/utils/ts-error.js +19 -35
- package/package.json +18 -18
- package/tsconfig.base.json +20 -0
- package/sonar-project.properties +0 -16
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -33,42 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
33
22
|
__setModuleDefault(result, mod);
|
|
34
23
|
return result;
|
|
35
24
|
};
|
|
36
|
-
var __values = (this && this.__values) || function(o) {
|
|
37
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
38
|
-
if (m) return m.call(o);
|
|
39
|
-
if (o && typeof o.length === "number") return {
|
|
40
|
-
next: function () {
|
|
41
|
-
if (o && i >= o.length) o = void 0;
|
|
42
|
-
return { value: o && o[i++], done: !o };
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
46
|
-
};
|
|
47
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
48
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
49
|
-
if (!m) return o;
|
|
50
|
-
var i = m.call(o), r, ar = [], e;
|
|
51
|
-
try {
|
|
52
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
53
|
-
}
|
|
54
|
-
catch (error) { e = { error: error }; }
|
|
55
|
-
finally {
|
|
56
|
-
try {
|
|
57
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
58
|
-
}
|
|
59
|
-
finally { if (e) throw e.error; }
|
|
60
|
-
}
|
|
61
|
-
return ar;
|
|
62
|
-
};
|
|
63
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
64
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
65
|
-
if (ar || !(i in from)) {
|
|
66
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
67
|
-
ar[i] = from[i];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
71
|
-
};
|
|
72
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
73
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
74
27
|
};
|
|
@@ -84,21 +37,21 @@ exports.ConfigSet = exports.TS_JEST_OUT_DIR = exports.IGNORE_DIAGNOSTIC_CODES =
|
|
|
84
37
|
* version of the `jest.ProjectConfig`, and then later it calls `process()`
|
|
85
38
|
* with the complete, object version of it.
|
|
86
39
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
40
|
+
const fs_1 = require("fs");
|
|
41
|
+
const module_1 = __importDefault(require("module"));
|
|
42
|
+
const path_1 = require("path");
|
|
43
|
+
const bs_logger_1 = require("bs-logger");
|
|
44
|
+
const jest_util_1 = require("jest-util");
|
|
45
|
+
const json5_1 = __importDefault(require("json5"));
|
|
46
|
+
const constants_1 = require("../../constants");
|
|
47
|
+
const hoistJestTransformer = __importStar(require("../../transformers/hoist-jest"));
|
|
48
|
+
const utils_1 = require("../../utils");
|
|
49
|
+
const backports_1 = require("../../utils/backports");
|
|
50
|
+
const importer_1 = require("../../utils/importer");
|
|
51
|
+
const messages_1 = require("../../utils/messages");
|
|
52
|
+
const normalize_slashes_1 = require("../../utils/normalize-slashes");
|
|
53
|
+
const sha1_1 = require("../../utils/sha1");
|
|
54
|
+
const ts_error_1 = require("../../utils/ts-error");
|
|
102
55
|
/**
|
|
103
56
|
* @internal
|
|
104
57
|
*/
|
|
@@ -115,112 +68,141 @@ exports.IGNORE_DIAGNOSTIC_CODES = [
|
|
|
115
68
|
* @internal
|
|
116
69
|
*/
|
|
117
70
|
exports.TS_JEST_OUT_DIR = '$$ts-jest$$';
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
127
|
-
var item = items_1_1.value;
|
|
128
|
-
if (typeof item === 'string') {
|
|
129
|
-
var children = item.trim().split(/\s*,\s*/g);
|
|
130
|
-
if (children.length > 1) {
|
|
131
|
-
toDiagnosticCodeList(children, into);
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
item = children[0];
|
|
135
|
-
}
|
|
136
|
-
if (!item)
|
|
71
|
+
const normalizeRegex = (pattern) => pattern ? (typeof pattern === 'string' ? pattern : pattern.source) : undefined;
|
|
72
|
+
const toDiagnosticCode = (code) => code ? parseInt(`${code}`.trim().replace(/^TS/, ''), 10) ?? undefined : undefined;
|
|
73
|
+
const toDiagnosticCodeList = (items, into = []) => {
|
|
74
|
+
for (let item of items) {
|
|
75
|
+
if (typeof item === 'string') {
|
|
76
|
+
const children = item.trim().split(/\s*,\s*/g);
|
|
77
|
+
if (children.length > 1) {
|
|
78
|
+
toDiagnosticCodeList(children, into);
|
|
137
79
|
continue;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
into.push(code);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
144
|
-
finally {
|
|
145
|
-
try {
|
|
146
|
-
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
80
|
+
}
|
|
81
|
+
item = children[0];
|
|
147
82
|
}
|
|
148
|
-
|
|
83
|
+
if (!item)
|
|
84
|
+
continue;
|
|
85
|
+
const code = toDiagnosticCode(item);
|
|
86
|
+
if (code && !into.includes(code))
|
|
87
|
+
into.push(code);
|
|
149
88
|
}
|
|
150
89
|
return into;
|
|
151
90
|
};
|
|
152
|
-
|
|
91
|
+
const requireFromString = (code, fileName) => {
|
|
153
92
|
// @ts-expect-error `_nodeModulePaths` is not exposed in typing
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
93
|
+
const paths = module_1.default._nodeModulePaths((0, path_1.dirname)(fileName));
|
|
94
|
+
const parent = module.parent;
|
|
95
|
+
const m = new module_1.default(fileName, parent);
|
|
157
96
|
m.filename = fileName;
|
|
158
97
|
m.paths = [].concat(paths);
|
|
159
98
|
// @ts-expect-error `_compile` is not exposed in typing
|
|
160
99
|
m._compile(code, fileName);
|
|
161
|
-
|
|
100
|
+
const exports = m.exports;
|
|
162
101
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
163
102
|
parent && parent.children && parent.children.splice(parent.children.indexOf(m), 1);
|
|
164
103
|
return exports;
|
|
165
104
|
};
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
105
|
+
class ConfigSet {
|
|
106
|
+
parentLogger;
|
|
107
|
+
/**
|
|
108
|
+
* Use by e2e, don't mark as internal
|
|
109
|
+
*/
|
|
110
|
+
tsJestDigest = exports.MY_DIGEST;
|
|
111
|
+
logger;
|
|
112
|
+
compilerModule;
|
|
113
|
+
isolatedModules;
|
|
114
|
+
cwd;
|
|
115
|
+
rootDir;
|
|
116
|
+
cacheSuffix;
|
|
117
|
+
tsCacheDir;
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
119
|
+
parsedTsConfig;
|
|
120
|
+
resolvedTransformers = {
|
|
121
|
+
before: [],
|
|
122
|
+
after: [],
|
|
123
|
+
afterDeclarations: [],
|
|
124
|
+
};
|
|
125
|
+
useESM = false;
|
|
126
|
+
/**
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
babelConfig;
|
|
130
|
+
/**
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
babelJestTransformer;
|
|
134
|
+
/**
|
|
135
|
+
* @internal
|
|
136
|
+
*/
|
|
137
|
+
_jestCfg;
|
|
138
|
+
/**
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
_diagnostics;
|
|
142
|
+
/**
|
|
143
|
+
* @internal
|
|
144
|
+
*/
|
|
145
|
+
_stringifyContentRegExp;
|
|
146
|
+
/**
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
149
|
+
_matchablePatterns;
|
|
150
|
+
/**
|
|
151
|
+
* @internal
|
|
152
|
+
*/
|
|
153
|
+
_matchTestFilePath;
|
|
154
|
+
/**
|
|
155
|
+
* @internal
|
|
156
|
+
*/
|
|
157
|
+
_shouldIgnoreDiagnosticsForFile;
|
|
158
|
+
/**
|
|
159
|
+
* @internal
|
|
160
|
+
*/
|
|
161
|
+
_overriddenCompilerOptions = {
|
|
162
|
+
inlineSourceMap: false,
|
|
163
|
+
declaration: false, // we don't want to create declaration files
|
|
164
|
+
isolatedDeclarations: false, // we don't want to create declaration files
|
|
165
|
+
noEmit: false, // set to true will make compiler API not emit any compiled results.
|
|
166
|
+
// else istanbul related will be dropped
|
|
167
|
+
removeComments: false,
|
|
168
|
+
// to clear out else it's buggy
|
|
169
|
+
out: undefined,
|
|
170
|
+
outFile: undefined,
|
|
171
|
+
composite: undefined, // see https://github.com/TypeStrong/ts-node/pull/657/files
|
|
172
|
+
declarationDir: undefined,
|
|
173
|
+
declarationMap: undefined,
|
|
174
|
+
emitDeclarationOnly: undefined,
|
|
175
|
+
sourceRoot: undefined,
|
|
176
|
+
tsBuildInfoFile: undefined,
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* @internal
|
|
180
|
+
*/
|
|
181
|
+
tsconfigFilePath;
|
|
182
|
+
constructor(jestConfig, parentLogger) {
|
|
170
183
|
this.parentLogger = parentLogger;
|
|
171
|
-
/**
|
|
172
|
-
* Use by e2e, don't mark as internal
|
|
173
|
-
*/
|
|
174
|
-
this.tsJestDigest = exports.MY_DIGEST;
|
|
175
|
-
this.resolvedTransformers = {
|
|
176
|
-
before: [],
|
|
177
|
-
after: [],
|
|
178
|
-
afterDeclarations: [],
|
|
179
|
-
};
|
|
180
|
-
this.useESM = false;
|
|
181
|
-
/**
|
|
182
|
-
* @internal
|
|
183
|
-
*/
|
|
184
|
-
this._overriddenCompilerOptions = {
|
|
185
|
-
inlineSourceMap: false,
|
|
186
|
-
// we don't want to create declaration files
|
|
187
|
-
declaration: false,
|
|
188
|
-
noEmit: false, // set to true will make compiler API not emit any compiled results.
|
|
189
|
-
// else istanbul related will be dropped
|
|
190
|
-
removeComments: false,
|
|
191
|
-
// to clear out else it's buggy
|
|
192
|
-
out: undefined,
|
|
193
|
-
outFile: undefined,
|
|
194
|
-
composite: undefined, // see https://github.com/TypeStrong/ts-node/pull/657/files
|
|
195
|
-
declarationDir: undefined,
|
|
196
|
-
declarationMap: undefined,
|
|
197
|
-
emitDeclarationOnly: undefined,
|
|
198
|
-
sourceRoot: undefined,
|
|
199
|
-
tsBuildInfoFile: undefined,
|
|
200
|
-
};
|
|
201
184
|
this.logger = this.parentLogger
|
|
202
|
-
? this.parentLogger.child(
|
|
185
|
+
? this.parentLogger.child({ [bs_logger_1.LogContexts.namespace]: 'config' })
|
|
203
186
|
: utils_1.rootLogger.child({ namespace: 'config' });
|
|
204
|
-
this._backportJestCfg(jestConfig
|
|
205
|
-
this.cwd = (0, path_1.normalize)(
|
|
206
|
-
this.rootDir = (0, path_1.normalize)(
|
|
207
|
-
|
|
208
|
-
|
|
187
|
+
this._backportJestCfg(jestConfig ?? Object.create(null));
|
|
188
|
+
this.cwd = (0, path_1.normalize)(this._jestCfg.cwd ?? process.cwd());
|
|
189
|
+
this.rootDir = (0, path_1.normalize)(this._jestCfg.rootDir ?? this.cwd);
|
|
190
|
+
const tsJestCfg = this._jestCfg.globals && this._jestCfg.globals['ts-jest'];
|
|
191
|
+
const options = tsJestCfg ?? Object.create(null);
|
|
209
192
|
// compiler module
|
|
210
|
-
this.compilerModule = importer_1.importer.typescript("Using \"ts-jest\" requires this package to be installed." /* ImportReasons.TsJest */,
|
|
193
|
+
this.compilerModule = importer_1.importer.typescript("Using \"ts-jest\" requires this package to be installed." /* ImportReasons.TsJest */, options.compiler ?? 'typescript');
|
|
211
194
|
this.logger.debug({ compilerModule: this.compilerModule }, 'normalized compiler module config via ts-jest option');
|
|
212
195
|
this._setupConfigSet(options);
|
|
213
|
-
this._matchablePatterns =
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
});
|
|
196
|
+
this._matchablePatterns = [...this._jestCfg.testMatch, ...this._jestCfg.testRegex].filter((pattern) =>
|
|
197
|
+
/**
|
|
198
|
+
* jest config testRegex doesn't always deliver the correct RegExp object
|
|
199
|
+
* See https://github.com/facebook/jest/issues/9778
|
|
200
|
+
*/
|
|
201
|
+
pattern instanceof RegExp || typeof pattern === 'string');
|
|
220
202
|
if (!this._matchablePatterns.length) {
|
|
221
|
-
|
|
203
|
+
this._matchablePatterns.push(...constants_1.DEFAULT_JEST_TEST_MATCH);
|
|
222
204
|
}
|
|
223
|
-
this._matchTestFilePath = (0, jest_util_1.globsToMatcher)(this._matchablePatterns.filter(
|
|
205
|
+
this._matchTestFilePath = (0, jest_util_1.globsToMatcher)(this._matchablePatterns.filter((pattern) => typeof pattern === 'string'));
|
|
224
206
|
// isolatedModules
|
|
225
207
|
if (options.isolatedModules) {
|
|
226
208
|
this.parsedTsConfig.options.isolatedModules = true;
|
|
@@ -233,44 +215,54 @@ var ConfigSet = /** @class */ (function () {
|
|
|
233
215
|
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
216
|
}
|
|
235
217
|
}
|
|
236
|
-
this.isolatedModules =
|
|
218
|
+
this.isolatedModules = this.parsedTsConfig.options.isolatedModules ?? false;
|
|
237
219
|
this._resolveTsCacheDir();
|
|
238
220
|
}
|
|
239
221
|
/**
|
|
240
222
|
* @internal
|
|
241
223
|
*/
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
var config = (0, backports_1.backportJestConfig)(this.logger, jestCfg);
|
|
224
|
+
_backportJestCfg(jestCfg) {
|
|
225
|
+
const config = (0, backports_1.backportJestConfig)(this.logger, jestCfg);
|
|
245
226
|
this.logger.debug({ jestConfig: config }, 'normalized jest config');
|
|
246
|
-
this._jestCfg =
|
|
247
|
-
|
|
227
|
+
this._jestCfg = {
|
|
228
|
+
...config,
|
|
229
|
+
testMatch: config.testMatch ?? constants_1.DEFAULT_JEST_TEST_MATCH,
|
|
230
|
+
testRegex: config.testRegex ?? [],
|
|
231
|
+
};
|
|
232
|
+
}
|
|
248
233
|
/**
|
|
249
234
|
* @internal
|
|
250
235
|
*/
|
|
251
|
-
|
|
252
|
-
var _this = this;
|
|
253
|
-
var _a, _b, _c, _d, _e;
|
|
236
|
+
_setupConfigSet(options) {
|
|
254
237
|
// useESM
|
|
255
|
-
this.useESM =
|
|
238
|
+
this.useESM = options.useESM ?? false;
|
|
256
239
|
// babel config (for babel-jest) default is undefined so we don't need to have fallback like tsConfig
|
|
257
240
|
if (!options.babelConfig) {
|
|
258
241
|
this.logger.debug('babel is disabled');
|
|
259
242
|
}
|
|
260
243
|
else {
|
|
261
|
-
|
|
244
|
+
const baseBabelCfg = { cwd: this.cwd };
|
|
262
245
|
if (typeof options.babelConfig === 'string') {
|
|
263
|
-
|
|
264
|
-
|
|
246
|
+
const babelCfgPath = this.resolvePath(options.babelConfig);
|
|
247
|
+
const babelFileExtName = (0, path_1.extname)(options.babelConfig);
|
|
265
248
|
if (babelFileExtName === '.js' || babelFileExtName === '.cjs') {
|
|
266
|
-
this.babelConfig =
|
|
249
|
+
this.babelConfig = {
|
|
250
|
+
...baseBabelCfg,
|
|
251
|
+
...require(babelCfgPath),
|
|
252
|
+
};
|
|
267
253
|
}
|
|
268
254
|
else {
|
|
269
|
-
this.babelConfig =
|
|
255
|
+
this.babelConfig = {
|
|
256
|
+
...baseBabelCfg,
|
|
257
|
+
...json5_1.default.parse((0, fs_1.readFileSync)(babelCfgPath, 'utf-8')),
|
|
258
|
+
};
|
|
270
259
|
}
|
|
271
260
|
}
|
|
272
261
|
else if (typeof options.babelConfig === 'object') {
|
|
273
|
-
this.babelConfig =
|
|
262
|
+
this.babelConfig = {
|
|
263
|
+
...baseBabelCfg,
|
|
264
|
+
...options.babelConfig,
|
|
265
|
+
};
|
|
274
266
|
}
|
|
275
267
|
else {
|
|
276
268
|
this.babelConfig = baseBabelCfg;
|
|
@@ -282,17 +274,17 @@ var ConfigSet = /** @class */ (function () {
|
|
|
282
274
|
this.logger.debug('created babel-jest transformer');
|
|
283
275
|
}
|
|
284
276
|
// diagnostics
|
|
285
|
-
|
|
286
|
-
|
|
277
|
+
const diagnosticsOpt = options.diagnostics ?? true;
|
|
278
|
+
const ignoreList = [...exports.IGNORE_DIAGNOSTIC_CODES];
|
|
287
279
|
if (typeof diagnosticsOpt === 'object') {
|
|
288
|
-
|
|
280
|
+
const { ignoreCodes } = diagnosticsOpt;
|
|
289
281
|
if (ignoreCodes) {
|
|
290
282
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
291
|
-
Array.isArray(ignoreCodes) ? ignoreList.push
|
|
283
|
+
Array.isArray(ignoreCodes) ? ignoreList.push(...ignoreCodes) : ignoreList.push(ignoreCodes);
|
|
292
284
|
}
|
|
293
285
|
this._diagnostics = {
|
|
294
|
-
pretty:
|
|
295
|
-
exclude:
|
|
286
|
+
pretty: diagnosticsOpt.pretty ?? true,
|
|
287
|
+
exclude: diagnosticsOpt.exclude ?? [],
|
|
296
288
|
ignoreCodes: toDiagnosticCodeList(ignoreList),
|
|
297
289
|
throws: !diagnosticsOpt.warnOnly,
|
|
298
290
|
};
|
|
@@ -308,15 +300,15 @@ var ConfigSet = /** @class */ (function () {
|
|
|
308
300
|
if (diagnosticsOpt) {
|
|
309
301
|
this._shouldIgnoreDiagnosticsForFile = this._diagnostics.exclude.length
|
|
310
302
|
? (0, jest_util_1.globsToMatcher)(this._diagnostics.exclude)
|
|
311
|
-
:
|
|
303
|
+
: () => false;
|
|
312
304
|
}
|
|
313
305
|
else {
|
|
314
|
-
this._shouldIgnoreDiagnosticsForFile =
|
|
306
|
+
this._shouldIgnoreDiagnosticsForFile = () => true;
|
|
315
307
|
}
|
|
316
308
|
this.logger.debug({ diagnostics: this._diagnostics }, 'normalized diagnostics config via ts-jest option');
|
|
317
309
|
// tsconfig
|
|
318
|
-
|
|
319
|
-
|
|
310
|
+
const tsconfigOpt = options.tsconfig;
|
|
311
|
+
const configFilePath = typeof tsconfigOpt === 'string' ? this.resolvePath(tsconfigOpt) : undefined;
|
|
320
312
|
this.parsedTsConfig = this._getAndResolveTsConfig(typeof tsconfigOpt === 'object' ? tsconfigOpt : undefined, configFilePath);
|
|
321
313
|
// throw errors if any matching wanted diagnostics
|
|
322
314
|
this.raiseDiagnostics(this.parsedTsConfig.errors, configFilePath);
|
|
@@ -329,12 +321,12 @@ var ConfigSet = /** @class */ (function () {
|
|
|
329
321
|
version: hoistJestTransformer.version,
|
|
330
322
|
},
|
|
331
323
|
];
|
|
332
|
-
|
|
324
|
+
const { astTransformers } = options;
|
|
333
325
|
if (astTransformers) {
|
|
334
|
-
|
|
335
|
-
|
|
326
|
+
const resolveTransformerFunc = (transformerPath) => {
|
|
327
|
+
let transformerFunc;
|
|
336
328
|
if ((0, path_1.extname)(transformerPath) === '.ts') {
|
|
337
|
-
|
|
329
|
+
const compiledTransformer = importer_1.importer
|
|
338
330
|
.esBuild("Using \"esbuild\" requires this package to be installed." /* ImportReasons.EsBuild */)
|
|
339
331
|
.transformSync((0, fs_1.readFileSync)(transformerPath, 'utf-8'), {
|
|
340
332
|
loader: 'ts',
|
|
@@ -347,32 +339,39 @@ var ConfigSet = /** @class */ (function () {
|
|
|
347
339
|
transformerFunc = require(transformerPath);
|
|
348
340
|
}
|
|
349
341
|
if (!transformerFunc.version) {
|
|
350
|
-
|
|
342
|
+
this.logger.warn("The AST transformer {{file}} must have an `export const version = <your_transformer_version>`" /* Errors.MissingTransformerVersion */, { file: transformerPath });
|
|
351
343
|
}
|
|
352
344
|
if (!transformerFunc.name) {
|
|
353
|
-
|
|
345
|
+
this.logger.warn("The AST transformer {{file}} must have an `export const name = <your_transformer_name>`" /* Errors.MissingTransformerName */, { file: transformerPath });
|
|
354
346
|
}
|
|
355
347
|
return transformerFunc;
|
|
356
348
|
};
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
349
|
+
const resolveTransformers = (transformers) => transformers.map((transformer) => {
|
|
350
|
+
if (typeof transformer === 'string') {
|
|
351
|
+
return resolveTransformerFunc(this.resolvePath(transformer, { nodeResolve: true }));
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
return {
|
|
355
|
+
...resolveTransformerFunc(this.resolvePath(transformer.path, { nodeResolve: true })),
|
|
356
|
+
options: transformer.options,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
});
|
|
367
360
|
if (astTransformers.before) {
|
|
368
361
|
/* istanbul ignore next (already covered in unit test) */
|
|
369
|
-
|
|
362
|
+
this.resolvedTransformers.before?.push(...resolveTransformers(astTransformers.before));
|
|
370
363
|
}
|
|
371
364
|
if (astTransformers.after) {
|
|
372
|
-
this.resolvedTransformers =
|
|
365
|
+
this.resolvedTransformers = {
|
|
366
|
+
...this.resolvedTransformers,
|
|
367
|
+
after: resolveTransformers(astTransformers.after),
|
|
368
|
+
};
|
|
373
369
|
}
|
|
374
370
|
if (astTransformers.afterDeclarations) {
|
|
375
|
-
this.resolvedTransformers =
|
|
371
|
+
this.resolvedTransformers = {
|
|
372
|
+
...this.resolvedTransformers,
|
|
373
|
+
afterDeclarations: resolveTransformers(astTransformers.afterDeclarations),
|
|
374
|
+
};
|
|
376
375
|
}
|
|
377
376
|
}
|
|
378
377
|
this.logger.debug({ customTransformers: this.resolvedTransformers }, 'normalized custom AST transformers via ts-jest option');
|
|
@@ -384,11 +383,11 @@ var ConfigSet = /** @class */ (function () {
|
|
|
384
383
|
: options.stringifyContentPathRegex;
|
|
385
384
|
this.logger.debug({ stringifyContentPathRegex: this._stringifyContentRegExp }, 'normalized stringifyContentPathRegex config via ts-jest option');
|
|
386
385
|
}
|
|
387
|
-
}
|
|
386
|
+
}
|
|
388
387
|
/**
|
|
389
388
|
* @internal
|
|
390
389
|
*/
|
|
391
|
-
|
|
390
|
+
_resolveTsCacheDir() {
|
|
392
391
|
this.cacheSuffix = (0, sha1_1.sha1)((0, utils_1.stringify)({
|
|
393
392
|
version: this.compilerModule.version,
|
|
394
393
|
digest: this.tsJestDigest,
|
|
@@ -400,39 +399,37 @@ var ConfigSet = /** @class */ (function () {
|
|
|
400
399
|
isolatedModules: this.isolatedModules,
|
|
401
400
|
diagnostics: this._diagnostics,
|
|
402
401
|
transformers: Object.values(this.resolvedTransformers)
|
|
403
|
-
.reduce(
|
|
404
|
-
.map(
|
|
402
|
+
.reduce((prevVal, currentVal) => [...prevVal, currentVal])
|
|
403
|
+
.map((transformer) => `${transformer.name}-${transformer.version}`),
|
|
405
404
|
}));
|
|
406
405
|
if (!this._jestCfg.cache) {
|
|
407
406
|
this.logger.debug('file caching disabled');
|
|
408
407
|
}
|
|
409
408
|
else {
|
|
410
|
-
|
|
409
|
+
const res = (0, path_1.join)(this._jestCfg.cacheDirectory, 'ts-jest', this.cacheSuffix.substr(0, 2), this.cacheSuffix.substr(2));
|
|
411
410
|
this.logger.debug({ cacheDirectory: res }, 'will use file caching');
|
|
412
411
|
this.tsCacheDir = res;
|
|
413
412
|
}
|
|
414
|
-
}
|
|
413
|
+
}
|
|
415
414
|
/**
|
|
416
415
|
* @internal
|
|
417
416
|
*/
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
var forcedOptions = this._overriddenCompilerOptions;
|
|
423
|
-
var finalOptions = result.options;
|
|
417
|
+
_getAndResolveTsConfig(compilerOptions, resolvedConfigFile) {
|
|
418
|
+
const result = this._resolveTsConfig(compilerOptions, resolvedConfigFile);
|
|
419
|
+
const { _overriddenCompilerOptions: forcedOptions } = this;
|
|
420
|
+
const finalOptions = result.options;
|
|
424
421
|
// Target ES2015 output by default (instead of ES3).
|
|
425
422
|
if (finalOptions.target === undefined) {
|
|
426
423
|
finalOptions.target = this.compilerModule.ScriptTarget.ES2015;
|
|
427
424
|
}
|
|
428
425
|
// check the module interoperability
|
|
429
|
-
|
|
426
|
+
const target = finalOptions.target;
|
|
430
427
|
// compute the default if not set
|
|
431
|
-
|
|
428
|
+
const defaultModule = [this.compilerModule.ScriptTarget.ES3, this.compilerModule.ScriptTarget.ES5].includes(target)
|
|
432
429
|
? this.compilerModule.ModuleKind.CommonJS
|
|
433
430
|
: this.compilerModule.ModuleKind.ESNext;
|
|
434
|
-
|
|
435
|
-
|
|
431
|
+
const moduleValue = finalOptions.module ?? defaultModule;
|
|
432
|
+
const warningModulesForEsmInterop = [
|
|
436
433
|
this.compilerModule.ModuleKind.CommonJS,
|
|
437
434
|
this.compilerModule.ModuleKind.Node16,
|
|
438
435
|
this.compilerModule.ModuleKind.NodeNext,
|
|
@@ -453,65 +450,63 @@ var ConfigSet = /** @class */ (function () {
|
|
|
453
450
|
if (finalOptions.allowJs && !finalOptions.outDir) {
|
|
454
451
|
finalOptions.outDir = exports.TS_JEST_OUT_DIR;
|
|
455
452
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
463
|
-
delete finalOptions[key];
|
|
464
|
-
}
|
|
465
|
-
else {
|
|
466
|
-
finalOptions[key] = val;
|
|
467
|
-
}
|
|
453
|
+
// ensure undefined are removed and other values are overridden
|
|
454
|
+
for (const key of Object.keys(forcedOptions)) {
|
|
455
|
+
const val = forcedOptions[key];
|
|
456
|
+
if (val === undefined) {
|
|
457
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
458
|
+
delete finalOptions[key];
|
|
468
459
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
finally {
|
|
472
|
-
try {
|
|
473
|
-
if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
|
|
460
|
+
else {
|
|
461
|
+
finalOptions[key] = val;
|
|
474
462
|
}
|
|
475
|
-
finally { if (e_2) throw e_2.error; }
|
|
476
463
|
}
|
|
477
464
|
/**
|
|
478
465
|
* See https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping
|
|
479
466
|
* Every time this page is updated, we also need to update here. Here we only show warning message for Node LTS versions
|
|
480
467
|
*/
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
468
|
+
const nodeJsVer = process.version;
|
|
469
|
+
const compilationTarget = result.options.target;
|
|
470
|
+
const TARGET_TO_VERSION_MAPPING = {
|
|
471
|
+
[this.compilerModule.ScriptTarget.ES2018]: 'es2018',
|
|
472
|
+
[this.compilerModule.ScriptTarget.ES2019]: 'es2019',
|
|
473
|
+
[this.compilerModule.ScriptTarget.ES2020]: 'es2020',
|
|
474
|
+
[this.compilerModule.ScriptTarget.ESNext]: 'ESNext',
|
|
475
|
+
};
|
|
489
476
|
/* istanbul ignore next (cover by e2e) */
|
|
490
477
|
if (compilationTarget &&
|
|
491
478
|
!this.babelConfig &&
|
|
492
479
|
nodeJsVer.startsWith('v12') &&
|
|
493
480
|
compilationTarget > this.compilerModule.ScriptTarget.ES2019) {
|
|
494
|
-
|
|
481
|
+
const message = (0, messages_1.interpolate)("There is a mismatch between your NodeJs version {{nodeJsVer}} and your TypeScript target {{compilationTarget}}. This might lead to some unexpected errors when running tests with `ts-jest`. To fix this, you can check https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping" /* Errors.MismatchNodeTargetMapping */, {
|
|
495
482
|
nodeJsVer: process.version,
|
|
496
483
|
compilationTarget: TARGET_TO_VERSION_MAPPING[compilationTarget],
|
|
497
484
|
});
|
|
498
485
|
this.logger.warn(message);
|
|
499
486
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
return
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
487
|
+
const resultOptions = result.options;
|
|
488
|
+
const sourceMap = resultOptions.sourceMap ?? true;
|
|
489
|
+
return {
|
|
490
|
+
...result,
|
|
491
|
+
options: {
|
|
492
|
+
...resultOptions,
|
|
493
|
+
sourceMap,
|
|
494
|
+
inlineSources: sourceMap,
|
|
495
|
+
module: resultOptions.module ?? this.compilerModule.ModuleKind.CommonJS,
|
|
496
|
+
},
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
_resolveTsConfig(compilerOptions, resolvedConfigFile) {
|
|
500
|
+
let config = { compilerOptions: Object.create(null) };
|
|
501
|
+
let basePath = (0, normalize_slashes_1.normalizeSlashes)(this.rootDir);
|
|
502
|
+
const ts = this.compilerModule;
|
|
508
503
|
// Read project configuration when available.
|
|
509
504
|
this.tsconfigFilePath = resolvedConfigFile
|
|
510
505
|
? (0, normalize_slashes_1.normalizeSlashes)(resolvedConfigFile)
|
|
511
506
|
: ts.findConfigFile((0, normalize_slashes_1.normalizeSlashes)(this.rootDir), ts.sys.fileExists);
|
|
512
507
|
if (this.tsconfigFilePath) {
|
|
513
508
|
this.logger.debug({ tsConfigFileName: this.tsconfigFilePath }, 'readTsConfig(): reading', this.tsconfigFilePath);
|
|
514
|
-
|
|
509
|
+
const result = ts.readConfigFile(this.tsconfigFilePath, ts.sys.readFile);
|
|
515
510
|
// Return diagnostics.
|
|
516
511
|
if (result.error) {
|
|
517
512
|
return { errors: [result.error], fileNames: [], options: {} };
|
|
@@ -520,71 +515,66 @@ var ConfigSet = /** @class */ (function () {
|
|
|
520
515
|
basePath = (0, normalize_slashes_1.normalizeSlashes)((0, path_1.dirname)(this.tsconfigFilePath));
|
|
521
516
|
}
|
|
522
517
|
// Override default configuration options `ts-jest` requires.
|
|
523
|
-
config.compilerOptions =
|
|
518
|
+
config.compilerOptions = {
|
|
519
|
+
...config.compilerOptions,
|
|
520
|
+
...compilerOptions,
|
|
521
|
+
};
|
|
524
522
|
// parse json, merge config extending others, ...
|
|
525
523
|
return ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, this.tsconfigFilePath);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
});
|
|
532
|
-
};
|
|
533
|
-
ConfigSet.prototype.shouldStringifyContent = function (filePath) {
|
|
524
|
+
}
|
|
525
|
+
isTestFile(fileName) {
|
|
526
|
+
return this._matchablePatterns.some((pattern) => typeof pattern === 'string' ? this._matchTestFilePath(fileName) : pattern.test(fileName));
|
|
527
|
+
}
|
|
528
|
+
shouldStringifyContent(filePath) {
|
|
534
529
|
return this._stringifyContentRegExp ? this._stringifyContentRegExp.test(filePath) : false;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
var DiagnosticCategory = this.compilerModule.DiagnosticCategory;
|
|
541
|
-
var filteredDiagnostics = filePath && !this.shouldReportDiagnostics(filePath)
|
|
530
|
+
}
|
|
531
|
+
raiseDiagnostics(diagnostics, filePath, logger = this.logger) {
|
|
532
|
+
const { ignoreCodes } = this._diagnostics;
|
|
533
|
+
const { DiagnosticCategory } = this.compilerModule;
|
|
534
|
+
const filteredDiagnostics = filePath && !this.shouldReportDiagnostics(filePath)
|
|
542
535
|
? []
|
|
543
|
-
: diagnostics.filter(
|
|
544
|
-
|
|
545
|
-
if (((_a = diagnostic.file) === null || _a === void 0 ? void 0 : _a.fileName) && !_this.shouldReportDiagnostics(diagnostic.file.fileName)) {
|
|
536
|
+
: diagnostics.filter((diagnostic) => {
|
|
537
|
+
if (diagnostic.file?.fileName && !this.shouldReportDiagnostics(diagnostic.file.fileName)) {
|
|
546
538
|
return false;
|
|
547
539
|
}
|
|
548
540
|
return !ignoreCodes.includes(diagnostic.code);
|
|
549
541
|
});
|
|
550
542
|
if (!filteredDiagnostics.length)
|
|
551
543
|
return;
|
|
552
|
-
|
|
544
|
+
const error = this.createTsError(filteredDiagnostics);
|
|
553
545
|
// only throw if `warnOnly` and it is a warning or error
|
|
554
|
-
|
|
555
|
-
if (this._diagnostics.throws && filteredDiagnostics.some(
|
|
546
|
+
const importantCategories = [DiagnosticCategory.Warning, DiagnosticCategory.Error];
|
|
547
|
+
if (this._diagnostics.throws && filteredDiagnostics.some((d) => importantCategories.includes(d.category))) {
|
|
556
548
|
throw error;
|
|
557
549
|
}
|
|
558
|
-
logger.warn({ error
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
|
|
550
|
+
logger.warn({ error }, error.message);
|
|
551
|
+
}
|
|
552
|
+
shouldReportDiagnostics(filePath) {
|
|
553
|
+
const fileExtension = (0, path_1.extname)(filePath);
|
|
562
554
|
return constants_1.JS_JSX_EXTENSIONS.includes(fileExtension)
|
|
563
555
|
? this.parsedTsConfig.options.checkJs && !this._shouldIgnoreDiagnosticsForFile(filePath)
|
|
564
556
|
: !this._shouldIgnoreDiagnosticsForFile(filePath);
|
|
565
|
-
}
|
|
557
|
+
}
|
|
566
558
|
/**
|
|
567
559
|
* @internal
|
|
568
560
|
*/
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
var formatDiagnostics = this._diagnostics.pretty
|
|
561
|
+
createTsError(diagnostics) {
|
|
562
|
+
const formatDiagnostics = this._diagnostics.pretty
|
|
572
563
|
? this.compilerModule.formatDiagnosticsWithColorAndContext
|
|
573
564
|
: this.compilerModule.formatDiagnostics;
|
|
574
565
|
/* istanbul ignore next (not possible to cover) */
|
|
575
|
-
|
|
576
|
-
getNewLine:
|
|
577
|
-
getCurrentDirectory:
|
|
578
|
-
getCanonicalFileName:
|
|
566
|
+
const diagnosticHost = {
|
|
567
|
+
getNewLine: () => '\n',
|
|
568
|
+
getCurrentDirectory: () => this.cwd,
|
|
569
|
+
getCanonicalFileName: (path) => path,
|
|
579
570
|
};
|
|
580
|
-
|
|
581
|
-
|
|
571
|
+
const diagnosticText = formatDiagnostics(diagnostics, diagnosticHost);
|
|
572
|
+
const diagnosticCodes = diagnostics.map((x) => x.code);
|
|
582
573
|
return new ts_error_1.TSError(diagnosticText, diagnosticCodes);
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
var nodeResolved = false;
|
|
574
|
+
}
|
|
575
|
+
resolvePath(inputPath, { throwIfMissing = true, nodeResolve = false } = {}) {
|
|
576
|
+
let path = inputPath;
|
|
577
|
+
let nodeResolved = false;
|
|
588
578
|
if (path.startsWith('<rootDir>')) {
|
|
589
579
|
path = (0, path_1.resolve)((0, path_1.join)(this.rootDir, path.substr(9)));
|
|
590
580
|
}
|
|
@@ -594,8 +584,8 @@ var ConfigSet = /** @class */ (function () {
|
|
|
594
584
|
path = require.resolve(path);
|
|
595
585
|
nodeResolved = true;
|
|
596
586
|
}
|
|
597
|
-
catch
|
|
598
|
-
this.logger.debug({ path
|
|
587
|
+
catch {
|
|
588
|
+
this.logger.debug({ path }, 'failed to resolve path', path);
|
|
599
589
|
}
|
|
600
590
|
}
|
|
601
591
|
if (!nodeResolved) {
|
|
@@ -607,16 +597,15 @@ var ConfigSet = /** @class */ (function () {
|
|
|
607
597
|
path = require.resolve(path);
|
|
608
598
|
nodeResolved = true;
|
|
609
599
|
}
|
|
610
|
-
catch
|
|
611
|
-
this.logger.debug({ path
|
|
600
|
+
catch {
|
|
601
|
+
this.logger.debug({ path }, 'failed to resolve path', path);
|
|
612
602
|
}
|
|
613
603
|
}
|
|
614
604
|
if (throwIfMissing && !(0, fs_1.existsSync)(path)) {
|
|
615
|
-
throw new Error((0, messages_1.interpolate)("File not found: {{inputPath}} (resolved as: {{resolvedPath}})" /* Errors.FileNotFound */, { inputPath
|
|
605
|
+
throw new Error((0, messages_1.interpolate)("File not found: {{inputPath}} (resolved as: {{resolvedPath}})" /* Errors.FileNotFound */, { inputPath, resolvedPath: path }));
|
|
616
606
|
}
|
|
617
607
|
this.logger.debug({ fromPath: inputPath, toPath: path }, 'resolved path from', inputPath, 'to', path);
|
|
618
608
|
return path;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
}());
|
|
609
|
+
}
|
|
610
|
+
}
|
|
622
611
|
exports.ConfigSet = ConfigSet;
|