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