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.
@@ -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 (mod) {
30
- if (mod && mod.__esModule) return mod;
31
- var result = {};
32
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
- __setModuleDefault(result, mod);
34
- return result;
35
- };
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
- }
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
- 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
- };
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
- var fs_1 = require("fs");
88
- var module_1 = __importDefault(require("module"));
89
- var path_1 = require("path");
90
- var bs_logger_1 = require("bs-logger");
91
- var jest_util_1 = require("jest-util");
92
- var json5_1 = __importDefault(require("json5"));
93
- var constants_1 = require("../../constants");
94
- var hoistJestTransformer = __importStar(require("../../transformers/hoist-jest"));
95
- var utils_1 = require("../../utils");
96
- var backports_1 = require("../../utils/backports");
97
- var importer_1 = require("../../utils/importer");
98
- var messages_1 = require("../../utils/messages");
99
- var normalize_slashes_1 = require("../../utils/normalize-slashes");
100
- var sha1_1 = require("../../utils/sha1");
101
- var ts_error_1 = require("../../utils/ts-error");
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
- var normalizeRegex = function (pattern) {
119
- return pattern ? (typeof pattern === 'string' ? pattern : pattern.source) : undefined;
120
- };
121
- var toDiagnosticCode = function (code) { var _a; return code ? (_a = parseInt("".concat(code).trim().replace(/^TS/, ''), 10)) !== null && _a !== void 0 ? _a : undefined : undefined; };
122
- var toDiagnosticCodeList = function (items, into) {
123
- var e_1, _a;
124
- if (into === void 0) { into = []; }
125
- try {
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
- var code = toDiagnosticCode(item);
139
- if (code && !into.includes(code))
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
- finally { if (e_1) throw e_1.error; }
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
- var requireFromString = function (code, fileName) {
101
+ const requireFromString = (code, fileName) => {
153
102
  // @ts-expect-error `_nodeModulePaths` is not exposed in typing
154
- var paths = module_1.default._nodeModulePaths((0, path_1.dirname)(fileName));
155
- var parent = module.parent;
156
- var m = new module_1.default(fileName, parent);
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
- var exports = m.exports;
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
- var ConfigSet = /** @class */ (function () {
167
- function ConfigSet(jestConfig, parentLogger) {
168
- var _a, _b;
169
- var _c, _d, _e, _f;
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((_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'config', _a))
196
+ ? this.parentLogger.child({ [bs_logger_1.LogContexts.namespace]: 'config' })
203
197
  : utils_1.rootLogger.child({ namespace: 'config' });
204
- this._backportJestCfg(jestConfig !== null && jestConfig !== void 0 ? jestConfig : Object.create(null));
205
- this.cwd = (0, path_1.normalize)((_c = this._jestCfg.cwd) !== null && _c !== void 0 ? _c : process.cwd());
206
- this.rootDir = (0, path_1.normalize)((_d = this._jestCfg.rootDir) !== null && _d !== void 0 ? _d : this.cwd);
207
- var tsJestCfg = this._jestCfg.globals && this._jestCfg.globals['ts-jest'];
208
- var options = tsJestCfg !== null && tsJestCfg !== void 0 ? tsJestCfg : Object.create(null);
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 */, (_e = options.compiler) !== null && _e !== void 0 ? _e : 'typescript');
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 = __spreadArray(__spreadArray([], __read(this._jestCfg.testMatch), false), __read(this._jestCfg.testRegex), false).filter(function (pattern) {
214
- /**
215
- * jest config testRegex doesn't always deliver the correct RegExp object
216
- * See https://github.com/facebook/jest/issues/9778
217
- */
218
- return pattern instanceof RegExp || typeof pattern === 'string';
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
- (_b = this._matchablePatterns).push.apply(_b, __spreadArray([], __read(constants_1.DEFAULT_JEST_TEST_MATCH), false));
214
+ this._matchablePatterns.push(...constants_1.DEFAULT_JEST_TEST_MATCH);
222
215
  }
223
- this._matchTestFilePath = (0, jest_util_1.globsToMatcher)(this._matchablePatterns.filter(function (pattern) { return typeof pattern === 'string'; }));
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 = (_f = this.parsedTsConfig.options.isolatedModules) !== null && _f !== void 0 ? _f : false;
229
+ this.isolatedModules = this.parsedTsConfig.options.isolatedModules ?? false;
237
230
  this._resolveTsCacheDir();
238
231
  }
239
232
  /**
240
233
  * @internal
241
234
  */
242
- ConfigSet.prototype._backportJestCfg = function (jestCfg) {
243
- var _a, _b;
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 = __assign(__assign({}, config), { testMatch: (_a = config.testMatch) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_JEST_TEST_MATCH, testRegex: (_b = config.testRegex) !== null && _b !== void 0 ? _b : [] });
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
- ConfigSet.prototype._setupConfigSet = function (options) {
252
- var _this = this;
253
- var _a, _b, _c, _d, _e;
247
+ _setupConfigSet(options) {
254
248
  // useESM
255
- this.useESM = (_a = options.useESM) !== null && _a !== void 0 ? _a : false;
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
- var baseBabelCfg = { cwd: this.cwd };
255
+ const baseBabelCfg = { cwd: this.cwd };
262
256
  if (typeof options.babelConfig === 'string') {
263
- var babelCfgPath = this.resolvePath(options.babelConfig);
264
- var babelFileExtName = (0, path_1.extname)(options.babelConfig);
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 = __assign(__assign({}, baseBabelCfg), require(babelCfgPath));
260
+ this.babelConfig = {
261
+ ...baseBabelCfg,
262
+ ...require(babelCfgPath),
263
+ };
267
264
  }
268
265
  else {
269
- this.babelConfig = __assign(__assign({}, baseBabelCfg), json5_1.default.parse((0, fs_1.readFileSync)(babelCfgPath, 'utf-8')));
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 = __assign(__assign({}, baseBabelCfg), options.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
- var diagnosticsOpt = (_b = options.diagnostics) !== null && _b !== void 0 ? _b : true;
286
- var ignoreList = __spreadArray([], __read(exports.IGNORE_DIAGNOSTIC_CODES), false);
288
+ const diagnosticsOpt = options.diagnostics ?? true;
289
+ const ignoreList = [...exports.IGNORE_DIAGNOSTIC_CODES];
287
290
  if (typeof diagnosticsOpt === 'object') {
288
- var ignoreCodes = diagnosticsOpt.ignoreCodes;
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.apply(ignoreList, __spreadArray([], __read(ignoreCodes), false)) : ignoreList.push(ignoreCodes);
294
+ Array.isArray(ignoreCodes) ? ignoreList.push(...ignoreCodes) : ignoreList.push(ignoreCodes);
292
295
  }
293
296
  this._diagnostics = {
294
- pretty: (_c = diagnosticsOpt.pretty) !== null && _c !== void 0 ? _c : true,
295
- exclude: (_d = diagnosticsOpt.exclude) !== null && _d !== void 0 ? _d : [],
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
- : function () { return false; };
314
+ : () => false;
312
315
  }
313
316
  else {
314
- this._shouldIgnoreDiagnosticsForFile = function () { return true; };
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
- var tsconfigOpt = options.tsconfig;
319
- var configFilePath = typeof tsconfigOpt === 'string' ? this.resolvePath(tsconfigOpt) : undefined;
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
- var astTransformers = options.astTransformers;
335
+ const { astTransformers } = options;
333
336
  if (astTransformers) {
334
- var resolveTransformerFunc_1 = function (transformerPath) {
335
- var transformerFunc;
337
+ const resolveTransformerFunc = (transformerPath) => {
338
+ let transformerFunc;
336
339
  if ((0, path_1.extname)(transformerPath) === '.ts') {
337
- var compiledTransformer = importer_1.importer
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
- _this.logger.warn("The AST transformer {{file}} must have an `export const version = <your_transformer_version>`" /* Errors.MissingTransformerVersion */, { file: transformerPath });
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
- _this.logger.warn("The AST transformer {{file}} must have an `export const name = <your_transformer_name>`" /* Errors.MissingTransformerName */, { file: transformerPath });
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
- var resolveTransformers = function (transformers) {
358
- return transformers.map(function (transformer) {
359
- if (typeof transformer === 'string') {
360
- return resolveTransformerFunc_1(_this.resolvePath(transformer, { nodeResolve: true }));
361
- }
362
- else {
363
- return __assign(__assign({}, resolveTransformerFunc_1(_this.resolvePath(transformer.path, { nodeResolve: true }))), { options: transformer.options });
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
- (_e = this.resolvedTransformers.before) === null || _e === void 0 ? void 0 : _e.push.apply(_e, __spreadArray([], __read(resolveTransformers(astTransformers.before)), false));
373
+ this.resolvedTransformers.before?.push(...resolveTransformers(astTransformers.before));
370
374
  }
371
375
  if (astTransformers.after) {
372
- this.resolvedTransformers = __assign(__assign({}, this.resolvedTransformers), { after: resolveTransformers(astTransformers.after) });
376
+ this.resolvedTransformers = {
377
+ ...this.resolvedTransformers,
378
+ after: resolveTransformers(astTransformers.after),
379
+ };
373
380
  }
374
381
  if (astTransformers.afterDeclarations) {
375
- this.resolvedTransformers = __assign(__assign({}, this.resolvedTransformers), { afterDeclarations: resolveTransformers(astTransformers.afterDeclarations) });
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
- ConfigSet.prototype._resolveTsCacheDir = function () {
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(function (prevVal, currentVal) { return __spreadArray(__spreadArray([], __read(prevVal), false), [currentVal], false); })
404
- .map(function (transformer) { return "".concat(transformer.name, "-").concat(transformer.version); }),
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
- var res = (0, path_1.join)(this._jestCfg.cacheDirectory, 'ts-jest', this.cacheSuffix.substr(0, 2), this.cacheSuffix.substr(2));
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
- ConfigSet.prototype._getAndResolveTsConfig = function (compilerOptions, resolvedConfigFile) {
419
- var e_2, _a, _b;
420
- var _c, _d, _e;
421
- var result = this._resolveTsConfig(compilerOptions, resolvedConfigFile);
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
- var target = finalOptions.target;
437
+ const target = finalOptions.target;
430
438
  // compute the default if not set
431
- var defaultModule = [this.compilerModule.ScriptTarget.ES3, this.compilerModule.ScriptTarget.ES5].includes(target)
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
- var moduleValue = (_c = finalOptions.module) !== null && _c !== void 0 ? _c : defaultModule;
435
- var warningModulesForEsmInterop = [
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
- try {
457
- // ensure undefined are removed and other values are overridden
458
- for (var _f = __values(Object.keys(forcedOptions)), _g = _f.next(); !_g.done; _g = _f.next()) {
459
- var key = _g.value;
460
- var val = forcedOptions[key];
461
- if (val === undefined) {
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
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
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
- var nodeJsVer = process.version;
482
- var compilationTarget = result.options.target;
483
- var TARGET_TO_VERSION_MAPPING = (_b = {},
484
- _b[this.compilerModule.ScriptTarget.ES2018] = 'es2018',
485
- _b[this.compilerModule.ScriptTarget.ES2019] = 'es2019',
486
- _b[this.compilerModule.ScriptTarget.ES2020] = 'es2020',
487
- _b[this.compilerModule.ScriptTarget.ESNext] = 'ESNext',
488
- _b);
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
- var 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 */, {
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
- var resultOptions = result.options;
501
- var sourceMap = (_d = resultOptions.sourceMap) !== null && _d !== void 0 ? _d : true;
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 }) });
503
- };
504
- ConfigSet.prototype._resolveTsConfig = function (compilerOptions, resolvedConfigFile) {
505
- var config = { compilerOptions: Object.create(null) };
506
- var basePath = (0, normalize_slashes_1.normalizeSlashes)(this.rootDir);
507
- var ts = this.compilerModule;
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
- var result = ts.readConfigFile(this.tsconfigFilePath, ts.sys.readFile);
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 = __assign(__assign({}, config.compilerOptions), 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
- ConfigSet.prototype.isTestFile = function (fileName) {
528
- var _this = this;
529
- return this._matchablePatterns.some(function (pattern) {
530
- return typeof pattern === 'string' ? _this._matchTestFilePath(fileName) : pattern.test(fileName);
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
- ConfigSet.prototype.raiseDiagnostics = function (diagnostics, filePath, logger) {
537
- var _this = this;
538
- if (logger === void 0) { logger = this.logger; }
539
- var ignoreCodes = this._diagnostics.ignoreCodes;
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(function (diagnostic) {
544
- var _a;
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
- var error = this.createTsError(filteredDiagnostics);
555
+ const error = this.createTsError(filteredDiagnostics);
553
556
  // only throw if `warnOnly` and it is a warning or error
554
- var importantCategories = [DiagnosticCategory.Warning, DiagnosticCategory.Error];
555
- if (this._diagnostics.throws && filteredDiagnostics.some(function (d) { return importantCategories.includes(d.category); })) {
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: error }, error.message);
559
- };
560
- ConfigSet.prototype.shouldReportDiagnostics = function (filePath) {
561
- var fileExtension = (0, path_1.extname)(filePath);
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
- ConfigSet.prototype.createTsError = function (diagnostics) {
570
- var _this = this;
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
- var diagnosticHost = {
576
- getNewLine: function () { return '\n'; },
577
- getCurrentDirectory: function () { return _this.cwd; },
578
- getCanonicalFileName: function (path) { return path; },
577
+ const diagnosticHost = {
578
+ getNewLine: () => '\n',
579
+ getCurrentDirectory: () => this.cwd,
580
+ getCanonicalFileName: (path) => path,
579
581
  };
580
- var diagnosticText = formatDiagnostics(diagnostics, diagnosticHost);
581
- var diagnosticCodes = diagnostics.map(function (x) { return x.code; });
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
- ConfigSet.prototype.resolvePath = function (inputPath, _a) {
585
- var _b = _a === void 0 ? {} : _a, _c = _b.throwIfMissing, throwIfMissing = _c === void 0 ? true : _c, _d = _b.nodeResolve, nodeResolve = _d === void 0 ? false : _d;
586
- var path = inputPath;
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 (_e) {
598
- this.logger.debug({ path: path }, 'failed to resolve path', 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 (_f) {
611
- this.logger.debug({ path: path }, 'failed to resolve path', 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: inputPath, resolvedPath: path }));
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
- return ConfigSet;
621
- }());
620
+ }
621
+ }
622
622
  exports.ConfigSet = ConfigSet;