ts-jest 27.1.4 → 28.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.ts-jest-digest CHANGED
@@ -1 +1 @@
1
- 606cdd028ccae5bd2e9b9917b4e8ac7f4e76229a
1
+ c3a0630ac8f5e24c57ab4b3d834f719f3ad740f2
package/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ # [28.0.0-next.0](https://github.com/kulshekhar/ts-jest/compare/v27.1.3...v28.0.0-next.0) (2022-04-24)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **legacy** invoke Babel `processAsync` for `babel-jest` in ESM mode instead of `process` ([#3430](https://github.com/kulshekhar/ts-jest/issues/3430)) ([0d7356c](https://github.com/kulshekhar/ts-jest/commit/0d7356cd767a924e5b57e3a93679eef4ca8fae51))
7
+
8
+
9
+ ### Features
10
+
11
+ * **core:** drop support for Node.js 10 ([#3332](https://github.com/kulshekhar/ts-jest/issues/3332)) ([7a9aa61](https://github.com/kulshekhar/ts-jest/commit/7a9aa615ea0be881105676a17d5bd655afdc27f5))
12
+ * **core:** remove `mocked` testing util ([#3333](https://github.com/kulshekhar/ts-jest/issues/3333)) ([2d9017d](https://github.com/kulshekhar/ts-jest/commit/2d9017ddfea39f45aa991876b314d1dbe4a36aad))
13
+ * **core:** remove `ts-jest/utils` sub path export ([#3334](https://github.com/kulshekhar/ts-jest/issues/3334)) ([9f253d3](https://github.com/kulshekhar/ts-jest/commit/9f253d31dfcefa35ae00049d0d2dc4a3fe1b2f34))
14
+ * mark `TsJestTransformer` as legacy ([#3451](https://github.com/kulshekhar/ts-jest/issues/3451)) ([b090179](https://github.com/kulshekhar/ts-jest/commit/b0901799adc519959a954dba5e7b8fc8b97a9665))
15
+
16
+
17
+ ### BREAKING CHANGES
18
+
19
+ * Minimum support TypeScript version is now **4.3** since Jest 28 requires it
20
+ * Jest 28 is required
21
+ * **core:** Any imports `ts-jest/utils` should be replaced with `ts-jest`.
22
+ * **core:** Starting from Jest 27.4, `mocked` has been integrated into Jest repo.
23
+ * **core:** Support for Node.js v10 has been removed as Jest drops support for it
24
+
25
+
26
+
1
27
  ## [27.1.4](https://github.com/kulshekhar/ts-jest/compare/v27.1.3...v27.1.4) (2022-03-24)
2
28
 
3
29
 
@@ -1,3 +1,2 @@
1
- export * from './compiler-utils';
2
1
  export * from './ts-compiler';
3
2
  export * from './ts-jest-compiler';
@@ -14,6 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./compiler-utils"), exports);
18
17
  __exportStar(require("./ts-compiler"), exports);
19
18
  __exportStar(require("./ts-jest-compiler"), exports);
@@ -1,5 +1,6 @@
1
+ import type { TransformedSource } from '@jest/transform';
1
2
  import { Logger } from 'bs-logger';
2
- import type { TranspileOutput, CompilerOptions, Program, CustomTransformers } from 'typescript';
3
+ import type { CompilerOptions, CustomTransformers, Program, TranspileOutput } from 'typescript';
3
4
  import type { ConfigSet } from '../config';
4
5
  import type { StringMap, TsCompilerInstance, TsJestAstTransformer, TsJestCompileOptions, TTypeScript } from '../types';
5
6
  export declare class TsCompiler implements TsCompilerInstance {
@@ -14,7 +15,7 @@ export declare class TsCompiler implements TsCompilerInstance {
14
15
  program: Program | undefined;
15
16
  constructor(configSet: ConfigSet, runtimeCacheFS: StringMap);
16
17
  getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[];
17
- getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): string;
18
+ getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): TransformedSource;
18
19
  protected _transpileOutput(fileContent: string, fileName: string): TranspileOutput;
19
20
  protected _makeTransformers(customTransformers: TsJestAstTransformer): CustomTransformers;
20
21
  }
@@ -57,7 +57,6 @@ var lodash_memoize_1 = __importDefault(require("lodash.memoize"));
57
57
  var constants_1 = require("../constants");
58
58
  var utils_1 = require("../utils");
59
59
  var messages_1 = require("../utils/messages");
60
- var compiler_utils_1 = require("./compiler-utils");
61
60
  var TsCompiler = (function () {
62
61
  function TsCompiler(configSet, runtimeCacheFS) {
63
62
  var _a;
@@ -137,7 +136,9 @@ var TsCompiler = (function () {
137
136
  }
138
137
  else {
139
138
  this._logger.warn((0, messages_1.interpolate)("Unable to process '{{file}}', falling back to original file content. You can also configure Jest config option `transformIgnorePatterns` to ignore {{file}} from transformation or make sure that `outDir` in your tsconfig is neither `''` or `'.'`", { file: fileName }));
140
- return (0, compiler_utils_1.updateOutput)(fileContent, fileName, undefined);
139
+ return {
140
+ code: fileContent,
141
+ };
141
142
  }
142
143
  }
143
144
  if (!output.outputFiles.length) {
@@ -146,8 +147,13 @@ var TsCompiler = (function () {
146
147
  }));
147
148
  }
148
149
  return this._compilerOptions.sourceMap
149
- ? (0, compiler_utils_1.updateOutput)(output.outputFiles[1].text, fileName, output.outputFiles[0].text)
150
- : (0, compiler_utils_1.updateOutput)(output.outputFiles[0].text, fileName, undefined);
150
+ ? {
151
+ code: output.outputFiles[1].text,
152
+ map: output.outputFiles[0].text,
153
+ }
154
+ : {
155
+ code: output.outputFiles[0].text,
156
+ };
151
157
  }
152
158
  else {
153
159
  this._logger.debug({ fileName: fileName }, 'getCompiledOutput(): compiling as isolated module');
@@ -155,7 +161,10 @@ var TsCompiler = (function () {
155
161
  if (result.diagnostics && this.configSet.shouldReportDiagnostics(fileName)) {
156
162
  this.configSet.raiseDiagnostics(result.diagnostics, fileName, this._logger);
157
163
  }
158
- return (0, compiler_utils_1.updateOutput)(result.outputText, fileName, result.sourceMapText);
164
+ return {
165
+ code: result.outputText,
166
+ map: result.sourceMapText,
167
+ };
159
168
  }
160
169
  };
161
170
  TsCompiler.prototype._transpileOutput = function (fileContent, fileName) {
@@ -1,8 +1,9 @@
1
+ import type { TransformedSource } from '@jest/transform';
1
2
  import type { ConfigSet } from '../config';
2
3
  import type { CompilerInstance, StringMap, TsJestCompileOptions } from '../types';
3
4
  export declare class TsJestCompiler implements CompilerInstance {
4
5
  private readonly _compilerInstance;
5
6
  constructor(configSet: ConfigSet, runtimeCacheFS: StringMap);
6
7
  getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[];
7
- getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): string;
8
+ getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): TransformedSource;
8
9
  }
@@ -198,7 +198,7 @@ var ConfigSet = (function () {
198
198
  this.logger.debug({ babelConfig: this.babelConfig }, 'normalized babel config via ts-jest option');
199
199
  this.babelJestTransformer = importer_1.importer
200
200
  .babelJest("Using \"babel-jest\" requires this package to be installed.")
201
- .default.createTransformer(this.babelConfig);
201
+ .createTransformer(this.babelConfig);
202
202
  this.logger.debug('created babel-jest transformer');
203
203
  }
204
204
  var diagnosticsOpt = (_b = options.diagnostics) !== null && _b !== void 0 ? _b : true;
@@ -372,8 +372,8 @@ var ConfigSet = (function () {
372
372
  _b);
373
373
  if (compilationTarget &&
374
374
  !this.babelConfig &&
375
- ((nodeJsVer.startsWith('v10') && compilationTarget > this.compilerModule.ScriptTarget.ES2018) ||
376
- (nodeJsVer.startsWith('v12') && compilationTarget > this.compilerModule.ScriptTarget.ES2019))) {
375
+ nodeJsVer.startsWith('v12') &&
376
+ compilationTarget > this.compilerModule.ScriptTarget.ES2019) {
377
377
  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", {
378
378
  nodeJsVer: process.version,
379
379
  compilationTarget: TARGET_TO_VERSION_MAPPING[compilationTarget],
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { TsJestTransformer } from './ts-jest-transformer';
1
+ import { TsJestTransformer } from './legacy';
2
+ export * from './legacy';
2
3
  export * from './constants';
3
4
  export * from './compiler';
4
5
  export * from './config';
5
6
  export * from './presets/create-jest-preset';
6
7
  export * from './utils';
7
8
  export * from './raw-compiler-options';
8
- export * from './ts-jest-transformer';
9
9
  export * from './types';
10
10
  declare const _default: {
11
- createTransformer: () => TsJestTransformer;
11
+ createTransformer(): TsJestTransformer;
12
12
  };
13
13
  export default _default;
package/dist/index.js CHANGED
@@ -14,15 +14,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- var ts_jest_transformer_1 = require("./ts-jest-transformer");
17
+ var legacy_1 = require("./legacy");
18
+ __exportStar(require("./legacy"), exports);
18
19
  __exportStar(require("./constants"), exports);
19
20
  __exportStar(require("./compiler"), exports);
20
21
  __exportStar(require("./config"), exports);
21
22
  __exportStar(require("./presets/create-jest-preset"), exports);
22
23
  __exportStar(require("./utils"), exports);
23
24
  __exportStar(require("./raw-compiler-options"), exports);
24
- __exportStar(require("./ts-jest-transformer"), exports);
25
25
  __exportStar(require("./types"), exports);
26
26
  exports.default = {
27
- createTransformer: function () { return new ts_jest_transformer_1.TsJestTransformer(); },
27
+ createTransformer: function () {
28
+ return new legacy_1.TsJestTransformer(true);
29
+ },
28
30
  };
@@ -0,0 +1,6 @@
1
+ import { TsJestTransformer } from './ts-jest-transformer';
2
+ export * from './ts-jest-transformer';
3
+ declare const _default: {
4
+ createTransformer: () => TsJestTransformer;
5
+ };
6
+ export default _default;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ var ts_jest_transformer_1 = require("./ts-jest-transformer");
18
+ __exportStar(require("./ts-jest-transformer"), exports);
19
+ exports.default = {
20
+ createTransformer: function () { return new ts_jest_transformer_1.TsJestTransformer(); },
21
+ };
@@ -1,7 +1,6 @@
1
1
  import type { SyncTransformer, TransformedSource } from '@jest/transform';
2
- import type { Config } from '@jest/types';
3
- import { ConfigSet } from './config';
4
- import type { CompilerInstance, ProjectConfigTsJest, TransformOptionsTsJest } from './types';
2
+ import { ConfigSet } from '../config';
3
+ import type { CompilerInstance, ProjectConfigTsJest, TransformOptionsTsJest } from '../types';
5
4
  export declare class TsJestTransformer implements SyncTransformer {
6
5
  private readonly _logger;
7
6
  protected _compiler: CompilerInstance;
@@ -9,12 +8,14 @@ export declare class TsJestTransformer implements SyncTransformer {
9
8
  private _transformCfgStr;
10
9
  private _depGraphs;
11
10
  private _watchMode;
12
- constructor();
11
+ constructor(isLegacy?: boolean);
13
12
  private _configsFor;
14
13
  protected _createConfigSet(config: ProjectConfigTsJest | undefined): ConfigSet;
15
14
  protected _createCompiler(configSet: ConfigSet, cacheFS: Map<string, string>): void;
16
- process(fileContent: string, filePath: Config.Path, transformOptions: TransformOptionsTsJest): TransformedSource | string;
17
- processAsync(sourceText: string, sourcePath: Config.Path, transformOptions: TransformOptionsTsJest): Promise<TransformedSource | string>;
15
+ process(sourceText: string, sourcePath: string, transformOptions: TransformOptionsTsJest): TransformedSource;
16
+ processAsync(sourceText: string, sourcePath: string, transformOptions: TransformOptionsTsJest): Promise<TransformedSource>;
17
+ private processWithTs;
18
+ private runTsJestHook;
18
19
  getCacheKey(fileContent: string, filePath: string, transformOptions: TransformOptionsTsJest): string;
19
20
  getCacheKeyAsync(sourceText: string, sourcePath: string, transformOptions: TransformOptionsTsJest): Promise<string>;
20
21
  private _getFsCachedResolvedModules;
@@ -78,21 +78,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
78
78
  exports.TsJestTransformer = exports.CACHE_KEY_EL_SEPARATOR = void 0;
79
79
  var fs_1 = require("fs");
80
80
  var path_1 = __importDefault(require("path"));
81
- var compiler_1 = require("./compiler");
82
- var config_1 = require("./config");
83
- var constants_1 = require("./constants");
84
- var utils_1 = require("./utils");
85
- var importer_1 = require("./utils/importer");
86
- var messages_1 = require("./utils/messages");
87
- var sha1_1 = require("./utils/sha1");
88
- var version_checkers_1 = require("./utils/version-checkers");
81
+ var compiler_1 = require("../compiler");
82
+ var config_1 = require("../config");
83
+ var constants_1 = require("../constants");
84
+ var utils_1 = require("../utils");
85
+ var importer_1 = require("../utils/importer");
86
+ var messages_1 = require("../utils/messages");
87
+ var sha1_1 = require("../utils/sha1");
88
+ var version_checkers_1 = require("../utils/version-checkers");
89
89
  exports.CACHE_KEY_EL_SEPARATOR = '\x00';
90
90
  var TsJestTransformer = (function () {
91
- function TsJestTransformer() {
91
+ function TsJestTransformer(isLegacy) {
92
+ if (isLegacy === void 0) { isLegacy = false; }
92
93
  this._depGraphs = new Map();
93
94
  this._watchMode = false;
94
95
  this._logger = utils_1.rootLogger.child({ namespace: 'ts-jest-transformer' });
95
96
  version_checkers_1.VersionCheckers.jest.warn();
97
+ if (isLegacy) {
98
+ this._logger.warn("Use 'ts-jest' entry point in v28 will resolve in refactored transformer. If you wish to use legacy transformer, please adjust your Jest 'transform' config. For example:\n module.exports = {\n transform: {\n '^.+\\\\.tsx?$': 'ts-jest/legacy'\n }\n }\n ");
99
+ }
96
100
  this.getCacheKey = this.getCacheKey.bind(this);
97
101
  this.getCacheKeyAsync = this.getCacheKeyAsync.bind(this);
98
102
  this.process = this.process.bind(this);
@@ -128,7 +132,6 @@ var TsJestTransformer = (function () {
128
132
  this._logger.info('no matching config-set found, creating a new one');
129
133
  configSet = this._createConfigSet(config);
130
134
  var jest_1 = __assign({}, config);
131
- jest_1.name = undefined;
132
135
  jest_1.cacheDirectory = undefined;
133
136
  this._transformCfgStr = "".concat(new utils_1.JsonableValue(jest_1).serialized).concat(configSet.cacheSuffix);
134
137
  this._createCompiler(configSet, cacheFS);
@@ -153,33 +156,75 @@ var TsJestTransformer = (function () {
153
156
  TsJestTransformer.prototype._createCompiler = function (configSet, cacheFS) {
154
157
  this._compiler = new compiler_1.TsJestCompiler(configSet, cacheFS);
155
158
  };
156
- TsJestTransformer.prototype.process = function (fileContent, filePath, transformOptions) {
157
- this._logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'processing', filePath);
158
- var result;
159
+ TsJestTransformer.prototype.process = function (sourceText, sourcePath, transformOptions) {
160
+ this._logger.debug({ fileName: sourcePath, transformOptions: transformOptions }, 'processing', sourcePath);
159
161
  var configs = this._configsFor(transformOptions);
160
- var shouldStringifyContent = configs.shouldStringifyContent(filePath);
162
+ var shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
161
163
  var babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
162
- var isDefinitionFile = filePath.endsWith(constants_1.DECLARATION_TYPE_EXT);
163
- var isJsFile = constants_1.JS_JSX_REGEX.test(filePath);
164
- var isTsFile = !isDefinitionFile && constants_1.TS_TSX_REGEX.test(filePath);
165
- var hooksFile = process.env.TS_JEST_HOOKS;
166
- var hooks;
167
- if (hooksFile) {
168
- hooksFile = path_1.default.resolve(configs.cwd, hooksFile);
169
- hooks = importer_1.importer.tryTheseOr(hooksFile, {});
164
+ var result = this.processWithTs(sourceText, sourcePath, transformOptions);
165
+ if (babelJest) {
166
+ this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
167
+ result = babelJest.process(result.code, sourcePath, __assign(__assign({}, transformOptions), { instrument: false }));
170
168
  }
169
+ result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
170
+ return result;
171
+ };
172
+ TsJestTransformer.prototype.processAsync = function (sourceText, sourcePath, transformOptions) {
173
+ return __awaiter(this, void 0, void 0, function () {
174
+ var _this = this;
175
+ return __generator(this, function (_a) {
176
+ this._logger.debug({ fileName: sourcePath, transformOptions: transformOptions }, 'processing', sourcePath);
177
+ return [2, new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
178
+ var configs, shouldStringifyContent, babelJest, result;
179
+ return __generator(this, function (_a) {
180
+ switch (_a.label) {
181
+ case 0:
182
+ configs = this._configsFor(transformOptions);
183
+ shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
184
+ babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
185
+ result = this.processWithTs(sourceText, sourcePath, transformOptions);
186
+ if (!babelJest) return [3, 2];
187
+ this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
188
+ return [4, babelJest.processAsync(result.code, sourcePath, __assign(__assign({}, transformOptions), { instrument: false }))];
189
+ case 1:
190
+ result = _a.sent();
191
+ _a.label = 2;
192
+ case 2:
193
+ result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
194
+ resolve(result);
195
+ return [2];
196
+ }
197
+ });
198
+ }); })];
199
+ });
200
+ });
201
+ };
202
+ TsJestTransformer.prototype.processWithTs = function (sourceText, sourcePath, transformOptions) {
203
+ var result;
204
+ var configs = this._configsFor(transformOptions);
205
+ var shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
206
+ var babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
207
+ var isDefinitionFile = sourcePath.endsWith(constants_1.DECLARATION_TYPE_EXT);
208
+ var isJsFile = constants_1.JS_JSX_REGEX.test(sourcePath);
209
+ var isTsFile = !isDefinitionFile && constants_1.TS_TSX_REGEX.test(sourcePath);
171
210
  if (shouldStringifyContent) {
172
- result = "module.exports=".concat((0, utils_1.stringify)(fileContent));
211
+ result = {
212
+ code: "module.exports=".concat((0, utils_1.stringify)(sourceText)),
213
+ };
173
214
  }
174
215
  else if (isDefinitionFile) {
175
- result = '';
216
+ result = {
217
+ code: '',
218
+ };
176
219
  }
177
220
  else if (!configs.parsedTsConfig.options.allowJs && isJsFile) {
178
- this._logger.warn({ fileName: filePath }, (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", { path: filePath }));
179
- result = fileContent;
221
+ 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", { path: sourcePath }));
222
+ result = {
223
+ code: sourceText,
224
+ };
180
225
  }
181
226
  else if (isJsFile || isTsFile) {
182
- result = this._compiler.getCompiledOutput(fileContent, filePath, {
227
+ result = this._compiler.getCompiledOutput(sourceText, sourcePath, {
183
228
  depGraphs: this._depGraphs,
184
229
  supportsStaticESM: transformOptions.supportsStaticESM,
185
230
  watchMode: this._watchMode,
@@ -187,29 +232,28 @@ var TsJestTransformer = (function () {
187
232
  }
188
233
  else {
189
234
  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." : "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.";
190
- this._logger.warn({ fileName: filePath }, (0, messages_1.interpolate)(message, { path: filePath }));
191
- result = fileContent;
235
+ this._logger.warn({ fileName: sourcePath }, (0, messages_1.interpolate)(message, { path: sourcePath }));
236
+ result = {
237
+ code: sourceText,
238
+ };
192
239
  }
193
- if (babelJest) {
194
- this._logger.debug({ fileName: filePath }, 'calling babel-jest processor');
195
- result = babelJest.process(result, filePath, __assign(__assign({}, transformOptions), { instrument: false }));
240
+ return result;
241
+ };
242
+ TsJestTransformer.prototype.runTsJestHook = function (sourcePath, sourceText, transformOptions, compiledOutput) {
243
+ var hooksFile = process.env.TS_JEST_HOOKS;
244
+ var hooks;
245
+ if (hooksFile) {
246
+ hooksFile = path_1.default.resolve(this._configsFor(transformOptions).cwd, hooksFile);
247
+ hooks = importer_1.importer.tryTheseOr(hooksFile, {});
196
248
  }
197
249
  if (hooks === null || hooks === void 0 ? void 0 : hooks.afterProcess) {
198
- this._logger.debug({ fileName: filePath, hookName: 'afterProcess' }, 'calling afterProcess hook');
199
- var newResult = hooks.afterProcess([fileContent, filePath, transformOptions.config, transformOptions], result);
250
+ this._logger.debug({ fileName: sourcePath, hookName: 'afterProcess' }, 'calling afterProcess hook');
251
+ var newResult = hooks.afterProcess([sourceText, sourcePath, transformOptions.config, transformOptions], compiledOutput);
200
252
  if (newResult) {
201
253
  return newResult;
202
254
  }
203
255
  }
204
- return result;
205
- };
206
- TsJestTransformer.prototype.processAsync = function (sourceText, sourcePath, transformOptions) {
207
- return __awaiter(this, void 0, void 0, function () {
208
- var _this = this;
209
- return __generator(this, function (_a) {
210
- return [2, new Promise(function (resolve) { return resolve(_this.process(sourceText, sourcePath, transformOptions)); })];
211
- });
212
- });
256
+ return compiledOutput;
213
257
  };
214
258
  TsJestTransformer.prototype.getCacheKey = function (fileContent, filePath, transformOptions) {
215
259
  var _a;
@@ -1,5 +1,5 @@
1
1
  import type _ts from 'typescript';
2
2
  import type { TsCompilerInstance } from '../types';
3
- export declare const version = 3;
3
+ export declare const version = 4;
4
4
  export declare const name = "hoist-jest";
5
5
  export declare function factory({ configSet }: TsCompilerInstance): (ctx: _ts.TransformationContext) => _ts.Transformer<_ts.SourceFile>;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.factory = exports.name = exports.version = void 0;
4
4
  var bs_logger_1 = require("bs-logger");
5
- exports.version = 3;
5
+ exports.version = 4;
6
6
  exports.name = 'hoist-jest';
7
7
  var HOIST_METHODS = ['mock', 'unmock', 'enableAutomock', 'disableAutomock', 'deepUnmock'];
8
8
  var JEST_GLOBALS_MODULE_NAME = '@jest/globals';
@@ -11,7 +11,6 @@ function factory(_a) {
11
11
  var configSet = _a.configSet;
12
12
  var logger = configSet.logger.child({ namespace: exports.name });
13
13
  var ts = configSet.compilerModule;
14
- var tsFactory = ts.factory ? ts.factory : ts;
15
14
  var importNamesOfJestObj = [];
16
15
  var isJestGlobalImport = function (node) {
17
16
  return (ts.isImportDeclaration(node) &&
@@ -71,8 +70,8 @@ function factory(_a) {
71
70
  var visitor = function (node) {
72
71
  var resultNode = ts.visitEachChild(node, visitor, ctx);
73
72
  if (ts.isBlock(resultNode) && canHoistInBlockScope(resultNode)) {
74
- var newNodeArrayStatements = tsFactory.createNodeArray(sortStatements(resultNode.statements));
75
- return tsFactory.updateBlock(resultNode, newNodeArrayStatements);
73
+ var newNodeArrayStatements = ts.factory.createNodeArray(sortStatements(resultNode.statements));
74
+ return ts.factory.updateBlock(resultNode, newNodeArrayStatements);
76
75
  }
77
76
  else {
78
77
  if (ts.isSourceFile(resultNode)) {
@@ -91,11 +90,9 @@ function factory(_a) {
91
90
  }
92
91
  }
93
92
  });
94
- var newNodeArrayStatements = tsFactory.createNodeArray(sortStatements(resultNode.statements));
93
+ var newNodeArrayStatements = ts.factory.createNodeArray(sortStatements(resultNode.statements));
95
94
  importNamesOfJestObj.length = 0;
96
- return ts.factory
97
- ? ts.factory.updateSourceFile(resultNode, newNodeArrayStatements, resultNode.isDeclarationFile, resultNode.referencedFiles, resultNode.typeReferenceDirectives, resultNode.hasNoDefaultLib, resultNode.libReferenceDirectives)
98
- : ts.updateSourceFileNode(resultNode, newNodeArrayStatements, resultNode.isDeclarationFile, resultNode.referencedFiles, resultNode.typeReferenceDirectives, resultNode.hasNoDefaultLib, resultNode.libReferenceDirectives);
95
+ return ts.factory.updateSourceFile(resultNode, newNodeArrayStatements, resultNode.isDeclarationFile, resultNode.referencedFiles, resultNode.typeReferenceDirectives, resultNode.hasNoDefaultLib, resultNode.libReferenceDirectives);
99
96
  }
100
97
  return resultNode;
101
98
  }
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { TransformOptions } from '@jest/transform';
1
+ import type { TransformedSource, TransformOptions } from '@jest/transform';
2
2
  import type { Config } from '@jest/types';
3
+ import type * as babelJest from 'babel-jest';
3
4
  import type * as _babel from 'babel__core';
4
5
  import type * as _ts from 'typescript';
5
6
  import type { ConfigSet } from './config';
@@ -11,6 +12,7 @@ declare module '@jest/types' {
11
12
  }
12
13
  }
13
14
  }
15
+ export declare type TBabelJest = typeof babelJest;
14
16
  export declare type TTypeScript = typeof _ts;
15
17
  export interface TEsBuild {
16
18
  transformSync(input: string, options?: {
@@ -41,7 +43,7 @@ export interface TsJestGlobalOptions {
41
43
  diagnostics?: boolean | {
42
44
  pretty?: boolean;
43
45
  ignoreCodes?: number | string | Array<number | string>;
44
- exclude?: Config.Glob[];
46
+ exclude?: string[];
45
47
  warnOnly?: boolean;
46
48
  };
47
49
  babelConfig?: boolean | string | BabelConfig;
@@ -51,7 +53,7 @@ export interface TsJestGlobalOptions {
51
53
  export interface TsJestDiagnosticsCfg {
52
54
  pretty: boolean;
53
55
  ignoreCodes: number[];
54
- exclude: Config.Glob[];
56
+ exclude: string[];
55
57
  throws: boolean;
56
58
  warnOnly?: boolean;
57
59
  }
@@ -79,7 +81,7 @@ export interface TsJestCompileOptions {
79
81
  }
80
82
  export interface CompilerInstance {
81
83
  getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[];
82
- getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): string;
84
+ getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): TransformedSource;
83
85
  }
84
86
  export interface TsCompilerInstance extends CompilerInstance {
85
87
  configSet: ConfigSet;
@@ -1,4 +1,3 @@
1
1
  export * from './json';
2
2
  export * from './jsonable-value';
3
3
  export * from './logger';
4
- export type { MockedObject, MockedObjectDeep, MockedFunctionDeep, MockedFunction, MaybeMockedConstructor, MaybeMocked, MaybeMockedDeep, ConstructorArgumentsOf, MockableFunction, ArgumentsOf, MockWithArgs, PropertyKeysOf, MethodKeysOf, } from './testing';
@@ -7,9 +7,9 @@ var logger_1 = require("./logger");
7
7
  var messages_1 = require("./messages");
8
8
  var logger = logger_1.rootLogger.child({ namespace: 'versions' });
9
9
  exports.VersionCheckers = {
10
- jest: createVersionChecker('jest', ">=27.0.0 <28"),
11
- typescript: createVersionChecker('typescript', ">=3.8 <5"),
12
- babelJest: createVersionChecker('babel-jest', ">=27.0.0 <28"),
10
+ jest: createVersionChecker('jest', ">=28.0.0-alpha.11 <29"),
11
+ typescript: createVersionChecker('typescript', ">=4.3 <5"),
12
+ babelJest: createVersionChecker('babel-jest', ">=28.0.0-alpha.11 <29"),
13
13
  babelCore: createVersionChecker('@babel/core', ">=7.0.0-beta.0 <8"),
14
14
  };
15
15
  function checkVersion(name, expectedRange, action) {
package/legacy.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/legacy')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-jest",
3
- "version": "27.1.4",
3
+ "version": "28.0.0-next.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "bin": {
@@ -53,19 +53,19 @@
53
53
  "dependencies": {
54
54
  "bs-logger": "0.x",
55
55
  "fast-json-stable-stringify": "2.x",
56
- "jest-util": "^27.0.0",
56
+ "jest-util": "28.0.0-alpha.9",
57
57
  "json5": "2.x",
58
58
  "lodash.memoize": "4.x",
59
59
  "make-error": "1.x",
60
60
  "semver": "7.x",
61
- "yargs-parser": "20.x"
61
+ "yargs-parser": "^20.x"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "@babel/core": ">=7.0.0-beta.0 <8",
65
65
  "@types/jest": "^27.0.0",
66
- "babel-jest": ">=27.0.0 <28",
67
- "jest": "^27.0.0",
68
- "typescript": ">=3.8 <5.0"
66
+ "babel-jest": "28.0.0-alpha.11",
67
+ "jest": "28.0.0-alpha.11",
68
+ "typescript": ">=4.3"
69
69
  },
70
70
  "peerDependenciesMeta": {
71
71
  "@babel/core": {
@@ -91,8 +91,8 @@
91
91
  "devDependencies": {
92
92
  "@commitlint/cli": "16.x",
93
93
  "@commitlint/config-angular": "^16.0.0",
94
- "@jest/transform": "^27.4.2",
95
- "@jest/types": "^27.4.2",
94
+ "@jest/transform": "28.0.0-alpha.11",
95
+ "@jest/types": "28.0.0-alpha.9",
96
96
  "@types/babel__core": "7.x",
97
97
  "@types/cross-spawn": "latest",
98
98
  "@types/fs-extra": "latest",
@@ -102,9 +102,9 @@
102
102
  "@types/lodash.memoize": "4.x",
103
103
  "@types/lodash.set": "4.x",
104
104
  "@types/micromatch": "4.x",
105
- "@types/node": "17.0.21",
105
+ "@types/node": "17.0.25",
106
106
  "@types/node-fetch": "^3.0.3",
107
- "@types/react": "17.x",
107
+ "@types/react": "18.x",
108
108
  "@types/rimraf": "^3.0.2",
109
109
  "@types/semver": "latest",
110
110
  "@types/yargs": "latest",
@@ -123,10 +123,10 @@
123
123
  "eslint-plugin-prettier": "latest",
124
124
  "execa": "5.1.1",
125
125
  "fs-extra": "10.x",
126
- "glob": "^7.1.7",
126
+ "glob": "^8.0.1",
127
127
  "glob-gitignore": "latest",
128
128
  "husky": "4.x",
129
- "jest": "^27.4.3",
129
+ "jest": "28.0.0-alpha.11",
130
130
  "jest-snapshot-serializer-raw": "^1.2.0",
131
131
  "js-yaml": "latest",
132
132
  "json-schema-to-typescript": "^10.1.4",
@@ -144,6 +144,6 @@
144
144
  ]
145
145
  },
146
146
  "engines": {
147
- "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0"
147
+ "node": "^12.13.0 || ^14.15.0 || ^16.13.0 || >=17.0.0"
148
148
  }
149
149
  }
@@ -1,2 +0,0 @@
1
- export declare const SOURCE_MAPPING_PREFIX = "sourceMappingURL=";
2
- export declare function updateOutput(outputText: string, normalizedFileName: string, sourceMap: string | undefined): string;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateOutput = exports.SOURCE_MAPPING_PREFIX = void 0;
4
- var utils_1 = require("../utils");
5
- exports.SOURCE_MAPPING_PREFIX = 'sourceMappingURL=';
6
- function updateOutput(outputText, normalizedFileName, sourceMap) {
7
- if (sourceMap) {
8
- var base64Map = Buffer.from(updateSourceMap(sourceMap, normalizedFileName), 'utf8').toString('base64');
9
- var sourceMapContent = "data:application/json;charset=utf-8;base64,".concat(base64Map);
10
- return (outputText.slice(0, outputText.lastIndexOf(exports.SOURCE_MAPPING_PREFIX) + exports.SOURCE_MAPPING_PREFIX.length) +
11
- sourceMapContent);
12
- }
13
- else {
14
- return outputText;
15
- }
16
- }
17
- exports.updateOutput = updateOutput;
18
- var updateSourceMap = function (sourceMapText, normalizedFileName) {
19
- var sourceMap = JSON.parse(sourceMapText);
20
- sourceMap.file = normalizedFileName;
21
- sourceMap.sources = [normalizedFileName];
22
- delete sourceMap.sourceRoot;
23
- return (0, utils_1.stringify)(sourceMap);
24
- };
@@ -1,33 +0,0 @@
1
- /// <reference types="jest" />
2
- export declare type MockableFunction = (...args: any[]) => any;
3
- export declare type MethodKeysOf<T> = {
4
- [K in keyof T]: T[K] extends MockableFunction ? K : never;
5
- }[keyof T];
6
- export declare type PropertyKeysOf<T> = {
7
- [K in keyof T]: T[K] extends MockableFunction ? never : K;
8
- }[keyof T];
9
- export declare type ArgumentsOf<T> = T extends (...args: infer A) => any ? A : never;
10
- export declare type ConstructorArgumentsOf<T> = T extends new (...args: infer A) => any ? A : never;
11
- export interface MockWithArgs<T extends MockableFunction> extends jest.MockInstance<ReturnType<T>, ArgumentsOf<T>> {
12
- new (...args: ConstructorArgumentsOf<T>): T;
13
- (...args: ArgumentsOf<T>): ReturnType<T>;
14
- }
15
- export declare type MaybeMockedConstructor<T> = T extends new (...args: any[]) => infer R ? jest.MockInstance<R, ConstructorArgumentsOf<T>> : T;
16
- export declare type MockedFunction<T extends MockableFunction> = MockWithArgs<T> & {
17
- [K in keyof T]: T[K];
18
- };
19
- export declare type MockedFunctionDeep<T extends MockableFunction> = MockWithArgs<T> & MockedObjectDeep<T>;
20
- export declare type MockedObject<T> = MaybeMockedConstructor<T> & {
21
- [K in MethodKeysOf<T>]: T[K] extends MockableFunction ? MockedFunction<T[K]> : T[K];
22
- } & {
23
- [K in PropertyKeysOf<T>]: T[K];
24
- };
25
- export declare type MockedObjectDeep<T> = MaybeMockedConstructor<T> & {
26
- [K in MethodKeysOf<T>]: T[K] extends MockableFunction ? MockedFunctionDeep<T[K]> : T[K];
27
- } & {
28
- [K in PropertyKeysOf<T>]: MaybeMockedDeep<T[K]>;
29
- };
30
- export declare type MaybeMockedDeep<T> = T extends MockableFunction ? MockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T;
31
- export declare type MaybeMocked<T> = T extends MockableFunction ? MockedFunction<T> : T extends object ? MockedObject<T> : T;
32
- export declare function mocked<T>(item: T, deep?: false): MaybeMocked<T>;
33
- export declare function mocked<T>(item: T, deep: true): MaybeMockedDeep<T>;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mocked = void 0;
4
- function mocked(item, _deep) {
5
- if (_deep === void 0) { _deep = false; }
6
- return item;
7
- }
8
- exports.mocked = mocked;
package/utils/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export { pathsToModuleNameMapper } from '../dist/config/paths-to-module-name-mapper'
2
- export { createJestPreset } from '../dist/presets/create-jest-preset'
3
- export { mocked } from '../dist/utils/testing'
package/utils/index.js DELETED
@@ -1,28 +0,0 @@
1
- const { pathsToModuleNameMapper } = require('../dist/config/paths-to-module-name-mapper')
2
- const { createJestPreset } = require('../dist/presets/create-jest-preset')
3
- const { mocked } = require('../dist/utils/testing')
4
-
5
- module.exports = {
6
- get mocked() {
7
- if (!process.env.DISABLE_MOCKED_WARNING) {
8
- console.warn(
9
- '\n`mocked` util function is now deprecated and has been moved to Jest repository,' +
10
- ' see https://github.com/facebook/jest/pull/12089. In `ts-jest` v28.0.0, `mocked` function will be completely removed.' +
11
- ' Users are encouraged to use to Jest v27.4.0 or above to have `mocked` function available from `jest-mock`. ' +
12
- 'One can disable this warning by setting environment variable process.env.DISABLE_MOCKED_WARNING=true\n'
13
- )
14
- }
15
-
16
- return mocked
17
- },
18
- get createJestPreset() {
19
- console.warn('ts-jest[main] (WARN) Replace any occurrences of "ts-jest/utils" with just "ts-jest".')
20
-
21
- return createJestPreset
22
- },
23
- get pathsToModuleNameMapper() {
24
- console.warn('ts-jest[main] (WARN) Replace any occurrences of "ts-jest/utils" with just "ts-jest".')
25
-
26
- return pathsToModuleNameMapper
27
- },
28
- }