ts-jest 29.3.1 → 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,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var ts_jest_transformer_1 = require("./ts-jest-transformer");
3
+ const ts_jest_transformer_1 = require("./ts-jest-transformer");
4
4
  exports.default = {
5
- createTransformer: function (tsJestConfig) {
6
- return new ts_jest_transformer_1.TsJestTransformer(tsJestConfig);
7
- },
5
+ createTransformer: (tsJestConfig) => new ts_jest_transformer_1.TsJestTransformer(tsJestConfig),
8
6
  };
@@ -12,9 +12,6 @@ export declare class TsJestTransformer implements SyncTransformer<TsJestTransfor
12
12
  private _configsFor;
13
13
  protected _createConfigSet(config: TsJestTransformOptions['config'] | undefined): ConfigSet;
14
14
  protected _createCompiler(configSet: ConfigSet, cacheFS: Map<string, string>): void;
15
- /**
16
- * @public
17
- */
18
15
  process(sourceText: string, sourcePath: string, transformOptions: TsJestTransformOptions): TransformedSource;
19
16
  processAsync(sourceText: string, sourcePath: string, transformOptions: TsJestTransformOptions): Promise<TransformedSource>;
20
17
  private processWithTs;
@@ -1,99 +1,42 @@
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __read = (this && this.__read) || function (o, n) {
50
- var m = typeof Symbol === "function" && o[Symbol.iterator];
51
- if (!m) return o;
52
- var i = m.call(o), r, ar = [], e;
53
- try {
54
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
55
- }
56
- catch (error) { e = { error: error }; }
57
- finally {
58
- try {
59
- if (r && !r.done && (m = i["return"])) m.call(i);
60
- }
61
- finally { if (e) throw e.error; }
62
- }
63
- return ar;
64
- };
65
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
66
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
67
- if (ar || !(i in from)) {
68
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
69
- ar[i] = from[i];
70
- }
71
- }
72
- return to.concat(ar || Array.prototype.slice.call(from));
73
- };
74
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
75
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
76
4
  };
77
5
  Object.defineProperty(exports, "__esModule", { value: true });
78
6
  exports.TsJestTransformer = exports.CACHE_KEY_EL_SEPARATOR = void 0;
79
- var fs_1 = require("fs");
80
- var path_1 = __importDefault(require("path"));
81
- var constants_1 = require("../constants");
82
- var utils_1 = require("../utils");
83
- var importer_1 = require("../utils/importer");
84
- var messages_1 = require("../utils/messages");
85
- var sha1_1 = require("../utils/sha1");
86
- var compiler_1 = require("./compiler");
87
- var config_set_1 = require("./config/config-set");
7
+ const fs_1 = require("fs");
8
+ const path_1 = __importDefault(require("path"));
9
+ const typescript_1 = __importDefault(require("typescript"));
10
+ const constants_1 = require("../constants");
11
+ const utils_1 = require("../utils");
12
+ const importer_1 = require("../utils/importer");
13
+ const messages_1 = require("../utils/messages");
14
+ const sha1_1 = require("../utils/sha1");
15
+ const compiler_1 = require("./compiler");
16
+ const compiler_utils_1 = require("./compiler/compiler-utils");
17
+ const config_set_1 = require("./config/config-set");
18
+ const isNodeModule = (filePath) => {
19
+ return path_1.default.normalize(filePath).split(path_1.default.sep).includes('node_modules');
20
+ };
88
21
  /**
89
22
  * @internal
90
23
  */
91
24
  exports.CACHE_KEY_EL_SEPARATOR = '\x00';
92
- var TsJestTransformer = /** @class */ (function () {
93
- function TsJestTransformer(transformerOptions) {
25
+ class TsJestTransformer {
26
+ transformerOptions;
27
+ /**
28
+ * cache ConfigSet between test runs
29
+ *
30
+ * @internal
31
+ */
32
+ static _cachedConfigSets = [];
33
+ _logger;
34
+ _compiler;
35
+ _transformCfgStr;
36
+ _depGraphs = new Map();
37
+ _watchMode = false;
38
+ constructor(transformerOptions) {
94
39
  this.transformerOptions = transformerOptions;
95
- this._depGraphs = new Map();
96
- this._watchMode = false;
97
40
  this._logger = utils_1.rootLogger.child({ namespace: 'ts-jest-transformer' });
98
41
  /**
99
42
  * For some unknown reasons, `this` is undefined in `getCacheKey` and `process`
@@ -106,11 +49,10 @@ var TsJestTransformer = /** @class */ (function () {
106
49
  this._logger.debug('created new transformer');
107
50
  process.env.TS_JEST = '1';
108
51
  }
109
- TsJestTransformer.prototype._configsFor = function (transformOptions) {
110
- var _a, _b, _c;
111
- var config = transformOptions.config, cacheFS = transformOptions.cacheFS;
112
- var ccs = TsJestTransformer._cachedConfigSets.find(function (cs) { return cs.jestConfig.value === config; });
113
- var configSet;
52
+ _configsFor(transformOptions) {
53
+ const { config, cacheFS } = transformOptions;
54
+ const ccs = TsJestTransformer._cachedConfigSets.find((cs) => cs.jestConfig.value === config);
55
+ let configSet;
114
56
  if (ccs) {
115
57
  this._transformCfgStr = ccs.transformerCfgStr;
116
58
  this._compiler = ccs.compiler;
@@ -120,8 +62,8 @@ var TsJestTransformer = /** @class */ (function () {
120
62
  }
121
63
  else {
122
64
  // try to look-it up by stringified version
123
- var serializedJestCfg_1 = (0, utils_1.stringify)(config);
124
- var serializedCcs = TsJestTransformer._cachedConfigSets.find(function (cs) { return cs.jestConfig.serialized === serializedJestCfg_1; });
65
+ const serializedJestCfg = (0, utils_1.stringify)(config);
66
+ const serializedCcs = TsJestTransformer._cachedConfigSets.find((cs) => cs.jestConfig.serialized === serializedJestCfg);
125
67
  if (serializedCcs) {
126
68
  // update the object so that we can find it later
127
69
  // this happens because jest first calls getCacheKey with stringified version of
@@ -136,24 +78,34 @@ var TsJestTransformer = /** @class */ (function () {
136
78
  else {
137
79
  // create the new record in the index
138
80
  this._logger.info('no matching config-set found, creating a new one');
139
- if ((_a = config.globals) === null || _a === void 0 ? void 0 : _a['ts-jest']) {
81
+ if (config.globals?.['ts-jest']) {
140
82
  this._logger.warn("Define `ts-jest` config under `globals` is deprecated. Please do\ntransform: {\n <transform_regex>: ['ts-jest', { /* ts-jest config goes here in Jest */ }],\n},\nSee more at https://kulshekhar.github.io/ts-jest/docs/getting-started/presets#advanced" /* Deprecations.GlobalsTsJestConfigOption */);
141
83
  }
142
- var jestGlobalsConfig = (_b = config.globals) !== null && _b !== void 0 ? _b : {};
143
- var tsJestGlobalsConfig = (_c = jestGlobalsConfig['ts-jest']) !== null && _c !== void 0 ? _c : {};
144
- var migratedConfig = this.transformerOptions
145
- ? __assign(__assign({}, config), { globals: __assign(__assign({}, jestGlobalsConfig), { 'ts-jest': __assign(__assign({}, tsJestGlobalsConfig), this.transformerOptions) }) }) : config;
84
+ const jestGlobalsConfig = config.globals ?? {};
85
+ const tsJestGlobalsConfig = jestGlobalsConfig['ts-jest'] ?? {};
86
+ const migratedConfig = this.transformerOptions
87
+ ? {
88
+ ...config,
89
+ globals: {
90
+ ...jestGlobalsConfig,
91
+ 'ts-jest': {
92
+ ...tsJestGlobalsConfig,
93
+ ...this.transformerOptions,
94
+ },
95
+ },
96
+ }
97
+ : config;
146
98
  configSet = this._createConfigSet(migratedConfig);
147
- var jest_1 = __assign({}, migratedConfig);
99
+ const jest = { ...migratedConfig };
148
100
  // we need to remove some stuff from jest config
149
101
  // this which does not depend on config
150
- jest_1.cacheDirectory = undefined; // eslint-disable-line @typescript-eslint/no-explicit-any
151
- this._transformCfgStr = "".concat(new utils_1.JsonableValue(jest_1).serialized).concat(configSet.cacheSuffix);
102
+ jest.cacheDirectory = undefined; // eslint-disable-line @typescript-eslint/no-explicit-any
103
+ this._transformCfgStr = `${new utils_1.JsonableValue(jest).serialized}${configSet.cacheSuffix}`;
152
104
  this._createCompiler(configSet, cacheFS);
153
105
  this._watchMode = process.argv.includes('--watch');
154
106
  TsJestTransformer._cachedConfigSets.push({
155
107
  jestConfig: new utils_1.JsonableValue(config),
156
- configSet: configSet,
108
+ configSet,
157
109
  transformerCfgStr: this._transformCfgStr,
158
110
  compiler: this._compiler,
159
111
  depGraphs: this._depGraphs,
@@ -162,76 +114,68 @@ var TsJestTransformer = /** @class */ (function () {
162
114
  }
163
115
  }
164
116
  return configSet;
165
- };
166
- TsJestTransformer.prototype._createConfigSet = function (config) {
117
+ }
118
+ _createConfigSet(config) {
167
119
  return new config_set_1.ConfigSet(config);
168
- };
169
- TsJestTransformer.prototype._createCompiler = function (configSet, cacheFS) {
120
+ }
121
+ _createCompiler(configSet, cacheFS) {
170
122
  this._compiler = new compiler_1.TsJestCompiler(configSet, cacheFS);
171
- };
172
- /**
173
- * @public
174
- */
175
- TsJestTransformer.prototype.process = function (sourceText, sourcePath, transformOptions) {
176
- this._logger.debug({ fileName: sourcePath, transformOptions: transformOptions }, 'processing', sourcePath);
177
- var configs = this._configsFor(transformOptions);
178
- var shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
179
- var babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
180
- var result = {
123
+ }
124
+ process(sourceText, sourcePath, transformOptions) {
125
+ this._logger.debug({ fileName: sourcePath, transformOptions }, 'processing', sourcePath);
126
+ const configs = this._configsFor(transformOptions);
127
+ const shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
128
+ const babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
129
+ let result = {
181
130
  code: this.processWithTs(sourceText, sourcePath, transformOptions).code,
182
131
  };
183
132
  if (babelJest) {
184
133
  this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
185
134
  // do not instrument here, jest will do it anyway afterwards
186
- result = babelJest.process(result.code, sourcePath, __assign(__assign({}, transformOptions), { instrument: false }));
135
+ result = babelJest.process(result.code, sourcePath, {
136
+ ...transformOptions,
137
+ instrument: false,
138
+ });
187
139
  }
188
140
  result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
189
141
  return result;
190
- };
191
- TsJestTransformer.prototype.processAsync = function (sourceText, sourcePath, transformOptions) {
192
- return __awaiter(this, void 0, void 0, function () {
193
- var configs, shouldStringifyContent, babelJest, result, processWithTsResult;
194
- var _a;
195
- return __generator(this, function (_b) {
196
- switch (_b.label) {
197
- case 0:
198
- this._logger.debug({ fileName: sourcePath, transformOptions: transformOptions }, 'processing', sourcePath);
199
- configs = this._configsFor(transformOptions);
200
- shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
201
- babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
202
- processWithTsResult = this.processWithTs(sourceText, sourcePath, transformOptions);
203
- result = {
204
- code: processWithTsResult.code,
205
- };
206
- if ((_a = processWithTsResult.diagnostics) === null || _a === void 0 ? void 0 : _a.length) {
207
- throw configs.createTsError(processWithTsResult.diagnostics);
208
- }
209
- if (!babelJest) return [3 /*break*/, 2];
210
- this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
211
- return [4 /*yield*/, babelJest.processAsync(result.code, sourcePath, __assign(__assign({}, transformOptions), { instrument: false }))];
212
- case 1:
213
- // do not instrument here, jest will do it anyway afterwards
214
- result = _b.sent();
215
- _b.label = 2;
216
- case 2:
217
- result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
218
- return [2 /*return*/, result];
219
- }
142
+ }
143
+ async processAsync(sourceText, sourcePath, transformOptions) {
144
+ this._logger.debug({ fileName: sourcePath, transformOptions }, 'processing', sourcePath);
145
+ const configs = this._configsFor(transformOptions);
146
+ const shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
147
+ const babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
148
+ let result;
149
+ const processWithTsResult = this.processWithTs(sourceText, sourcePath, transformOptions);
150
+ result = {
151
+ code: processWithTsResult.code,
152
+ };
153
+ if (processWithTsResult.diagnostics?.length) {
154
+ throw configs.createTsError(processWithTsResult.diagnostics);
155
+ }
156
+ if (babelJest) {
157
+ this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
158
+ // do not instrument here, jest will do it anyway afterwards
159
+ result = await babelJest.processAsync(result.code, sourcePath, {
160
+ ...transformOptions,
161
+ instrument: false,
220
162
  });
221
- });
222
- };
223
- TsJestTransformer.prototype.processWithTs = function (sourceText, sourcePath, transformOptions) {
224
- var result;
225
- var configs = this._configsFor(transformOptions);
226
- var shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
227
- var babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
228
- var isDefinitionFile = sourcePath.endsWith(constants_1.DECLARATION_TYPE_EXT);
229
- var isJsFile = constants_1.JS_JSX_REGEX.test(sourcePath);
230
- var isTsFile = !isDefinitionFile && constants_1.TS_TSX_REGEX.test(sourcePath);
163
+ }
164
+ result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
165
+ return result;
166
+ }
167
+ processWithTs(sourceText, sourcePath, transformOptions) {
168
+ let result;
169
+ const configs = this._configsFor(transformOptions);
170
+ const shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
171
+ const babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
172
+ const isDefinitionFile = sourcePath.endsWith(constants_1.DECLARATION_TYPE_EXT);
173
+ const isJsFile = constants_1.JS_JSX_REGEX.test(sourcePath);
174
+ const isTsFile = !isDefinitionFile && constants_1.TS_TSX_REGEX.test(sourcePath);
231
175
  if (shouldStringifyContent) {
232
176
  // handles here what we should simply stringify
233
177
  result = {
234
- code: "module.exports=".concat((0, utils_1.stringify)(sourceText)),
178
+ code: `module.exports=${(0, utils_1.stringify)(sourceText)}`,
235
179
  };
236
180
  }
237
181
  else if (isDefinitionFile) {
@@ -240,51 +184,60 @@ var TsJestTransformer = /** @class */ (function () {
240
184
  code: '',
241
185
  };
242
186
  }
243
- else if (!configs.parsedTsConfig.options.allowJs && isJsFile) {
244
- // we've got a '.js' but the compiler option `allowJs` is not set or set to false
245
- this._logger.warn({ fileName: sourcePath }, (0, messages_1.interpolate)("Got a `.js` file to compile while `allowJs` option is not set to `true` (file: {{path}}). To fix this:\n - if you want TypeScript to process JS files, set `allowJs` to `true` in your TypeScript config (usually tsconfig.json)\n - if you do not want TypeScript to process your `.js` files, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match `.js` files anymore" /* Errors.GotJsFileButAllowJsFalse */, { path: sourcePath }));
246
- result = {
247
- code: sourceText,
248
- };
249
- }
250
187
  else if (isJsFile || isTsFile) {
251
- // transpile TS code (source maps are included)
252
- result = this._compiler.getCompiledOutput(sourceText, sourcePath, {
253
- depGraphs: this._depGraphs,
254
- supportsStaticESM: transformOptions.supportsStaticESM,
255
- watchMode: this._watchMode,
256
- });
188
+ if (isJsFile && isNodeModule(sourcePath)) {
189
+ const transpiledResult = typescript_1.default.transpileModule(sourceText, {
190
+ compilerOptions: {
191
+ ...configs.parsedTsConfig.options,
192
+ module: transformOptions.supportsStaticESM && transformOptions.transformerConfig.useESM
193
+ ? typescript_1.default.ModuleKind.ESNext
194
+ : typescript_1.default.ModuleKind.CommonJS,
195
+ },
196
+ fileName: sourcePath,
197
+ });
198
+ result = {
199
+ code: (0, compiler_utils_1.updateOutput)(transpiledResult.outputText, sourcePath, transpiledResult.sourceMapText),
200
+ };
201
+ }
202
+ else {
203
+ // transpile TS code (source maps are included)
204
+ result = this._compiler.getCompiledOutput(sourceText, sourcePath, {
205
+ depGraphs: this._depGraphs,
206
+ supportsStaticESM: transformOptions.supportsStaticESM,
207
+ watchMode: this._watchMode,
208
+ });
209
+ }
257
210
  }
258
211
  else {
259
212
  // we should not get called for files with other extension than js[x], ts[x] and d.ts,
260
213
  // TypeScript will bail if we try to compile, and if it was to call babel, users can
261
214
  // define the transform value with `babel-jest` for this extension instead
262
- var message = babelJest ? "Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore. If you still want Babel to process it, add another entry to the `transform` option with value `babel-jest` which key matches this type of files." /* Errors.GotUnknownFileTypeWithBabel */ : "Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore." /* Errors.GotUnknownFileTypeWithoutBabel */;
215
+ const message = babelJest ? "Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore. If you still want Babel to process it, add another entry to the `transform` option with value `babel-jest` which key matches this type of files." /* Errors.GotUnknownFileTypeWithBabel */ : "Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore." /* Errors.GotUnknownFileTypeWithoutBabel */;
263
216
  this._logger.warn({ fileName: sourcePath }, (0, messages_1.interpolate)(message, { path: sourcePath }));
264
217
  result = {
265
218
  code: sourceText,
266
219
  };
267
220
  }
268
221
  return result;
269
- };
270
- TsJestTransformer.prototype.runTsJestHook = function (sourcePath, sourceText, transformOptions, compiledOutput) {
271
- var hooksFile = process.env.TS_JEST_HOOKS;
272
- var hooks;
222
+ }
223
+ runTsJestHook(sourcePath, sourceText, transformOptions, compiledOutput) {
224
+ let hooksFile = process.env.TS_JEST_HOOKS;
225
+ let hooks;
273
226
  /* istanbul ignore next (cover by e2e) */
274
227
  if (hooksFile) {
275
228
  hooksFile = path_1.default.resolve(this._configsFor(transformOptions).cwd, hooksFile);
276
229
  hooks = importer_1.importer.tryTheseOr(hooksFile, {});
277
230
  }
278
231
  // This is not supposed to be a public API but we keep it as some people use it
279
- if (hooks === null || hooks === void 0 ? void 0 : hooks.afterProcess) {
232
+ if (hooks?.afterProcess) {
280
233
  this._logger.debug({ fileName: sourcePath, hookName: 'afterProcess' }, 'calling afterProcess hook');
281
- var newResult = hooks.afterProcess([sourceText, sourcePath, transformOptions.config, transformOptions], compiledOutput);
234
+ const newResult = hooks.afterProcess([sourceText, sourcePath, transformOptions.config, transformOptions], compiledOutput);
282
235
  if (newResult) {
283
236
  return newResult;
284
237
  }
285
238
  }
286
239
  return compiledOutput;
287
- };
240
+ }
288
241
  /**
289
242
  * Jest uses this to cache the compiled version of a file
290
243
  *
@@ -292,61 +245,49 @@ var TsJestTransformer = /** @class */ (function () {
292
245
  *
293
246
  * @public
294
247
  */
295
- TsJestTransformer.prototype.getCacheKey = function (fileContent, filePath, transformOptions) {
296
- var _a;
297
- var configs = this._configsFor(transformOptions);
298
- this._logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'computing cache key for', filePath);
248
+ getCacheKey(fileContent, filePath, transformOptions) {
249
+ const configs = this._configsFor(transformOptions);
250
+ this._logger.debug({ fileName: filePath, transformOptions }, 'computing cache key for', filePath);
299
251
  // we do not instrument, ensure it is false all the time
300
- var supportsStaticESM = transformOptions.supportsStaticESM, _b = transformOptions.instrument, instrument = _b === void 0 ? false : _b;
301
- var constructingCacheKeyElements = [
252
+ const { supportsStaticESM, instrument = false } = transformOptions;
253
+ const constructingCacheKeyElements = [
302
254
  this._transformCfgStr,
303
255
  exports.CACHE_KEY_EL_SEPARATOR,
304
256
  configs.rootDir,
305
257
  exports.CACHE_KEY_EL_SEPARATOR,
306
- "instrument:".concat(instrument ? 'on' : 'off'),
258
+ `instrument:${instrument ? 'on' : 'off'}`,
307
259
  exports.CACHE_KEY_EL_SEPARATOR,
308
- "supportsStaticESM:".concat(supportsStaticESM ? 'on' : 'off'),
260
+ `supportsStaticESM:${supportsStaticESM ? 'on' : 'off'}`,
309
261
  exports.CACHE_KEY_EL_SEPARATOR,
310
262
  fileContent,
311
263
  exports.CACHE_KEY_EL_SEPARATOR,
312
264
  filePath,
313
265
  ];
314
266
  if (!configs.isolatedModules && configs.tsCacheDir) {
315
- var resolvedModuleNames = void 0;
316
- if (((_a = this._depGraphs.get(filePath)) === null || _a === void 0 ? void 0 : _a.fileContent) === fileContent) {
317
- this._logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'getting resolved modules from disk caching or memory caching for', filePath);
267
+ let resolvedModuleNames;
268
+ if (this._depGraphs.get(filePath)?.fileContent === fileContent) {
269
+ this._logger.debug({ fileName: filePath, transformOptions }, 'getting resolved modules from disk caching or memory caching for', filePath);
318
270
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
319
271
  resolvedModuleNames = this._depGraphs
320
272
  .get(filePath)
321
- .resolvedModuleNames.filter(function (moduleName) { return (0, fs_1.existsSync)(moduleName); });
273
+ .resolvedModuleNames.filter((moduleName) => (0, fs_1.existsSync)(moduleName));
322
274
  }
323
275
  else {
324
- this._logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'getting resolved modules from TypeScript API for', filePath);
276
+ this._logger.debug({ fileName: filePath, transformOptions }, 'getting resolved modules from TypeScript API for', filePath);
325
277
  resolvedModuleNames = this._compiler.getResolvedModules(fileContent, filePath, transformOptions.cacheFS);
326
278
  this._depGraphs.set(filePath, {
327
- fileContent: fileContent,
328
- resolvedModuleNames: resolvedModuleNames,
279
+ fileContent,
280
+ resolvedModuleNames,
329
281
  });
330
282
  }
331
- resolvedModuleNames.forEach(function (moduleName) {
283
+ resolvedModuleNames.forEach((moduleName) => {
332
284
  constructingCacheKeyElements.push(exports.CACHE_KEY_EL_SEPARATOR, moduleName, exports.CACHE_KEY_EL_SEPARATOR, (0, fs_1.statSync)(moduleName).mtimeMs.toString());
333
285
  });
334
286
  }
335
- return sha1_1.sha1.apply(void 0, __spreadArray([], __read(constructingCacheKeyElements), false));
336
- };
337
- TsJestTransformer.prototype.getCacheKeyAsync = function (sourceText, sourcePath, transformOptions) {
338
- return __awaiter(this, void 0, void 0, function () {
339
- return __generator(this, function (_a) {
340
- return [2 /*return*/, Promise.resolve(this.getCacheKey(sourceText, sourcePath, transformOptions))];
341
- });
342
- });
343
- };
344
- /**
345
- * cache ConfigSet between test runs
346
- *
347
- * @internal
348
- */
349
- TsJestTransformer._cachedConfigSets = [];
350
- return TsJestTransformer;
351
- }());
287
+ return (0, sha1_1.sha1)(...constructingCacheKeyElements);
288
+ }
289
+ async getCacheKeyAsync(sourceText, sourcePath, transformOptions) {
290
+ return Promise.resolve(this.getCacheKey(sourceText, sourcePath, transformOptions));
291
+ }
292
+ }
352
293
  exports.TsJestTransformer = TsJestTransformer;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var create_jest_preset_1 = require("./create-jest-preset");
4
- var allPresets = {
3
+ const create_jest_preset_1 = require("./create-jest-preset");
4
+ const allPresets = {
5
5
  get defaults() {
6
6
  return (0, create_jest_preset_1.createDefaultPreset)();
7
7
  },