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.
@@ -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
- 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");
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
- 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)
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
- 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);
80
+ }
81
+ item = children[0];
147
82
  }
148
- finally { if (e_1) throw e_1.error; }
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
- var requireFromString = function (code, fileName) {
91
+ const requireFromString = (code, fileName) => {
153
92
  // @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);
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
- var exports = m.exports;
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
- var ConfigSet = /** @class */ (function () {
167
- function ConfigSet(jestConfig, parentLogger) {
168
- var _a, _b;
169
- var _c, _d, _e, _f;
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((_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'config', _a))
185
+ ? this.parentLogger.child({ [bs_logger_1.LogContexts.namespace]: 'config' })
203
186
  : 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);
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 */, (_e = options.compiler) !== null && _e !== void 0 ? _e : 'typescript');
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 = __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
- });
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
- (_b = this._matchablePatterns).push.apply(_b, __spreadArray([], __read(constants_1.DEFAULT_JEST_TEST_MATCH), false));
203
+ this._matchablePatterns.push(...constants_1.DEFAULT_JEST_TEST_MATCH);
222
204
  }
223
- this._matchTestFilePath = (0, jest_util_1.globsToMatcher)(this._matchablePatterns.filter(function (pattern) { return typeof pattern === 'string'; }));
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 = (_f = this.parsedTsConfig.options.isolatedModules) !== null && _f !== void 0 ? _f : false;
218
+ this.isolatedModules = this.parsedTsConfig.options.isolatedModules ?? false;
237
219
  this._resolveTsCacheDir();
238
220
  }
239
221
  /**
240
222
  * @internal
241
223
  */
242
- ConfigSet.prototype._backportJestCfg = function (jestCfg) {
243
- var _a, _b;
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 = __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
- };
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
- ConfigSet.prototype._setupConfigSet = function (options) {
252
- var _this = this;
253
- var _a, _b, _c, _d, _e;
236
+ _setupConfigSet(options) {
254
237
  // useESM
255
- this.useESM = (_a = options.useESM) !== null && _a !== void 0 ? _a : false;
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
- var baseBabelCfg = { cwd: this.cwd };
244
+ const baseBabelCfg = { cwd: this.cwd };
262
245
  if (typeof options.babelConfig === 'string') {
263
- var babelCfgPath = this.resolvePath(options.babelConfig);
264
- var babelFileExtName = (0, path_1.extname)(options.babelConfig);
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 = __assign(__assign({}, baseBabelCfg), require(babelCfgPath));
249
+ this.babelConfig = {
250
+ ...baseBabelCfg,
251
+ ...require(babelCfgPath),
252
+ };
267
253
  }
268
254
  else {
269
- this.babelConfig = __assign(__assign({}, baseBabelCfg), json5_1.default.parse((0, fs_1.readFileSync)(babelCfgPath, 'utf-8')));
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 = __assign(__assign({}, baseBabelCfg), options.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
- var diagnosticsOpt = (_b = options.diagnostics) !== null && _b !== void 0 ? _b : true;
286
- var ignoreList = __spreadArray([], __read(exports.IGNORE_DIAGNOSTIC_CODES), false);
277
+ const diagnosticsOpt = options.diagnostics ?? true;
278
+ const ignoreList = [...exports.IGNORE_DIAGNOSTIC_CODES];
287
279
  if (typeof diagnosticsOpt === 'object') {
288
- var ignoreCodes = diagnosticsOpt.ignoreCodes;
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.apply(ignoreList, __spreadArray([], __read(ignoreCodes), false)) : ignoreList.push(ignoreCodes);
283
+ Array.isArray(ignoreCodes) ? ignoreList.push(...ignoreCodes) : ignoreList.push(ignoreCodes);
292
284
  }
293
285
  this._diagnostics = {
294
- pretty: (_c = diagnosticsOpt.pretty) !== null && _c !== void 0 ? _c : true,
295
- exclude: (_d = diagnosticsOpt.exclude) !== null && _d !== void 0 ? _d : [],
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
- : function () { return false; };
303
+ : () => false;
312
304
  }
313
305
  else {
314
- this._shouldIgnoreDiagnosticsForFile = function () { return true; };
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
- var tsconfigOpt = options.tsconfig;
319
- var configFilePath = typeof tsconfigOpt === 'string' ? this.resolvePath(tsconfigOpt) : undefined;
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
- var astTransformers = options.astTransformers;
324
+ const { astTransformers } = options;
333
325
  if (astTransformers) {
334
- var resolveTransformerFunc_1 = function (transformerPath) {
335
- var transformerFunc;
326
+ const resolveTransformerFunc = (transformerPath) => {
327
+ let transformerFunc;
336
328
  if ((0, path_1.extname)(transformerPath) === '.ts') {
337
- var compiledTransformer = importer_1.importer
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
- _this.logger.warn("The AST transformer {{file}} must have an `export const version = <your_transformer_version>`" /* Errors.MissingTransformerVersion */, { file: transformerPath });
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
- _this.logger.warn("The AST transformer {{file}} must have an `export const name = <your_transformer_name>`" /* Errors.MissingTransformerName */, { file: transformerPath });
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
- 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
- };
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
- (_e = this.resolvedTransformers.before) === null || _e === void 0 ? void 0 : _e.push.apply(_e, __spreadArray([], __read(resolveTransformers(astTransformers.before)), false));
362
+ this.resolvedTransformers.before?.push(...resolveTransformers(astTransformers.before));
370
363
  }
371
364
  if (astTransformers.after) {
372
- this.resolvedTransformers = __assign(__assign({}, this.resolvedTransformers), { after: resolveTransformers(astTransformers.after) });
365
+ this.resolvedTransformers = {
366
+ ...this.resolvedTransformers,
367
+ after: resolveTransformers(astTransformers.after),
368
+ };
373
369
  }
374
370
  if (astTransformers.afterDeclarations) {
375
- this.resolvedTransformers = __assign(__assign({}, this.resolvedTransformers), { afterDeclarations: resolveTransformers(astTransformers.afterDeclarations) });
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
- ConfigSet.prototype._resolveTsCacheDir = function () {
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(function (prevVal, currentVal) { return __spreadArray(__spreadArray([], __read(prevVal), false), [currentVal], false); })
404
- .map(function (transformer) { return "".concat(transformer.name, "-").concat(transformer.version); }),
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
- var res = (0, path_1.join)(this._jestCfg.cacheDirectory, 'ts-jest', this.cacheSuffix.substr(0, 2), this.cacheSuffix.substr(2));
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
- 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;
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
- var target = finalOptions.target;
426
+ const target = finalOptions.target;
430
427
  // compute the default if not set
431
- var defaultModule = [this.compilerModule.ScriptTarget.ES3, this.compilerModule.ScriptTarget.ES5].includes(target)
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
- var moduleValue = (_c = finalOptions.module) !== null && _c !== void 0 ? _c : defaultModule;
435
- var warningModulesForEsmInterop = [
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
- 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
- }
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
- 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);
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
- 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);
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
- 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 */, {
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
- 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;
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
- var result = ts.readConfigFile(this.tsconfigFilePath, ts.sys.readFile);
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 = __assign(__assign({}, config.compilerOptions), 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
- 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) {
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
- 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)
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(function (diagnostic) {
544
- var _a;
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
- var error = this.createTsError(filteredDiagnostics);
544
+ const error = this.createTsError(filteredDiagnostics);
553
545
  // 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); })) {
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: error }, error.message);
559
- };
560
- ConfigSet.prototype.shouldReportDiagnostics = function (filePath) {
561
- var fileExtension = (0, path_1.extname)(filePath);
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
- ConfigSet.prototype.createTsError = function (diagnostics) {
570
- var _this = this;
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
- var diagnosticHost = {
576
- getNewLine: function () { return '\n'; },
577
- getCurrentDirectory: function () { return _this.cwd; },
578
- getCanonicalFileName: function (path) { return path; },
566
+ const diagnosticHost = {
567
+ getNewLine: () => '\n',
568
+ getCurrentDirectory: () => this.cwd,
569
+ getCanonicalFileName: (path) => path,
579
570
  };
580
- var diagnosticText = formatDiagnostics(diagnostics, diagnosticHost);
581
- var diagnosticCodes = diagnostics.map(function (x) { return x.code; });
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
- 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;
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 (_e) {
598
- this.logger.debug({ path: path }, 'failed to resolve path', 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 (_f) {
611
- this.logger.debug({ path: path }, 'failed to resolve path', 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: inputPath, resolvedPath: path }));
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
- return ConfigSet;
621
- }());
609
+ }
610
+ }
622
611
  exports.ConfigSet = ConfigSet;