ts-jest 27.1.4 → 28.0.0-next.2

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.
Files changed (43) hide show
  1. package/.ts-jest-digest +1 -1
  2. package/CHANGELOG.md +72 -0
  3. package/dist/config/index.d.ts +0 -1
  4. package/dist/config/index.js +0 -1
  5. package/dist/index.d.ts +7 -6
  6. package/dist/index.js +9 -6
  7. package/dist/{compiler → legacy/compiler}/index.d.ts +0 -1
  8. package/dist/{compiler → legacy/compiler}/index.js +0 -1
  9. package/dist/{compiler → legacy/compiler}/ts-compiler.d.ts +5 -4
  10. package/dist/{compiler → legacy/compiler}/ts-compiler.js +17 -8
  11. package/dist/{compiler → legacy/compiler}/ts-jest-compiler.d.ts +4 -3
  12. package/dist/{compiler → legacy/compiler}/ts-jest-compiler.js +0 -0
  13. package/dist/{config → legacy/config}/config-set.d.ts +2 -2
  14. package/dist/{config → legacy/config}/config-set.js +13 -13
  15. package/dist/legacy/index.d.ts +5 -0
  16. package/dist/legacy/index.js +6 -0
  17. package/dist/{ts-jest-transformer.d.ts → legacy/ts-jest-transformer.d.ts} +6 -5
  18. package/dist/{ts-jest-transformer.js → legacy/ts-jest-transformer.js} +82 -42
  19. package/dist/presets/create-jest-preset.d.ts +1 -1
  20. package/dist/presets/create-jest-preset.js +5 -2
  21. package/dist/transformers/hoist-jest.d.ts +1 -1
  22. package/dist/transformers/hoist-jest.js +5 -8
  23. package/dist/types.d.ts +7 -5
  24. package/dist/utils/index.d.ts +0 -1
  25. package/dist/utils/version-checkers.js +3 -3
  26. package/legacy.js +1 -0
  27. package/package.json +13 -13
  28. package/presets/default-esm-legacy/jest-preset.js +1 -0
  29. package/presets/default-legacy/jest-preset.js +1 -0
  30. package/presets/index.d.ts +6 -0
  31. package/presets/index.js +36 -5
  32. package/presets/js-with-babel-esm-legacy/jest-preset.js +1 -0
  33. package/presets/js-with-babel-legacy/jest-preset.js +1 -0
  34. package/presets/js-with-ts-esm-legacy/jest-preset.js +1 -0
  35. package/presets/js-with-ts-legacy/jest-preset.js +1 -0
  36. package/dist/compiler/compiler-utils.d.ts +0 -2
  37. package/dist/compiler/compiler-utils.js +0 -24
  38. package/dist/transformers/path-mapping.d.ts +0 -5
  39. package/dist/transformers/path-mapping.js +0 -129
  40. package/dist/utils/testing.d.ts +0 -33
  41. package/dist/utils/testing.js +0 -8
  42. package/utils/index.d.ts +0 -3
  43. package/utils/index.js +0 -28
package/.ts-jest-digest CHANGED
@@ -1 +1 @@
1
- 606cdd028ccae5bd2e9b9917b4e8ac7f4e76229a
1
+ a33d3c3435f0ce0d59e132c0594636ecb76175d9
package/CHANGELOG.md CHANGED
@@ -1,3 +1,75 @@
1
+ # [28.0.0-next.2](https://github.com/kulshekhar/ts-jest/compare/v28.0.0-next.1...v28.0.0-next.2) (2022-04-27)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * revert deprecation message for `TsJestTransformer` ([#3466](https://github.com/kulshekhar/ts-jest/issues/3466)) ([cefa0da](https://github.com/kulshekhar/ts-jest/commit/cefa0da660c4f99cf6595e253981af6855bcc80c))
7
+
8
+
9
+ ### Features
10
+
11
+ * **presets:** add presets for legacy mode ([#3465](https://github.com/kulshekhar/ts-jest/issues/3465)) ([543b4ad](https://github.com/kulshekhar/ts-jest/commit/543b4ad729d20fbd46a2de5cd4660dc50b94ebe7))
12
+
13
+
14
+
15
+ # [28.0.0-next.1](https://github.com/kulshekhar/ts-jest/compare/v28.0.0-next.0...v28.0.0-next.1) (2022-04-26)
16
+
17
+
18
+ ### Features
19
+
20
+ * mark `ConfigSet` as legacy ([#3456](https://github.com/kulshekhar/ts-jest/issues/3456)) ([a986729](https://github.com/kulshekhar/ts-jest/commit/a98672977a679d1ed882605a3e71ed405432ffdc))
21
+ * mark `TsCompiler` and `TsJestCompiler` as legacy ([#3457](https://github.com/kulshekhar/ts-jest/issues/3457)) ([0f2fe30](https://github.com/kulshekhar/ts-jest/commit/0f2fe306762d8549bd29737becd4aed14a650427))
22
+ * remove `path-mapping` AST transformer ([#3455](https://github.com/kulshekhar/ts-jest/issues/3455)) ([f566869](https://github.com/kulshekhar/ts-jest/commit/f5668698f8fab78b3008d936aa5001f134f530e2))
23
+ * set Jest peer dependencies to v28 ([#3454](https://github.com/kulshekhar/ts-jest/issues/3454)) ([1e880ff](https://github.com/kulshekhar/ts-jest/commit/1e880fffe82bca231d1d23f6508f4ab4bc31e03e))
24
+
25
+
26
+ ### BREAKING CHANGES
27
+
28
+ * `path-mapping` AST transformer is no longer shipped in `ts-jest` v28. Please use an alternative one like https://github.com/LeDDGroup/typescript-transform-paths instead.
29
+ * Any imports `ts-jest/dist/compiler/ts-compiler` should change to `ts-jest/dist/legacy/compiler/ts-compiler`
30
+ * Any imports `ts-jest/dist/compiler/ts-jest-compiler` should change to `ts-jest/dist/legacy/compiler/ts-jest-compiler`
31
+ * Any imports `ts-jest/dist/config/config-set` should change to `ts-jest/dist/legacy/config/config-set
32
+
33
+
34
+
35
+ # [28.0.0-next.0](https://github.com/kulshekhar/ts-jest/compare/v27.1.3...v28.0.0-next.0) (2022-04-24)
36
+
37
+
38
+ ### Bug Fixes
39
+
40
+ * **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))
41
+
42
+
43
+ ### Features
44
+
45
+ * **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))
46
+ * **core:** remove `mocked` testing util ([#3333](https://github.com/kulshekhar/ts-jest/issues/3333)) ([2d9017d](https://github.com/kulshekhar/ts-jest/commit/2d9017ddfea39f45aa991876b314d1dbe4a36aad))
47
+ * **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))
48
+ * mark `TsJestTransformer` as legacy ([#3451](https://github.com/kulshekhar/ts-jest/issues/3451)) ([b090179](https://github.com/kulshekhar/ts-jest/commit/b0901799adc519959a954dba5e7b8fc8b97a9665))
49
+
50
+
51
+ ### BREAKING CHANGES
52
+
53
+ * Minimum support TypeScript version is now **4.3** since Jest 28 requires it
54
+ * Jest 28 is required
55
+ * **core:** Any imports `ts-jest/utils` should be replaced with `ts-jest`.
56
+ * **core:** Starting from Jest 27.4, `mocked` has been integrated into Jest repo.
57
+ * **core:** Support for Node.js v10 has been removed as Jest drops support for it
58
+ * All presets now will they are preserved for refactored codes. If you wish to use the old codes, please do the following
59
+ *
60
+ ```diff
61
+ // jest.config.js
62
+ module.exports = {
63
+ // [...]
64
+ - preset: 'ts-jest', // or 'js-with-babel'/'js-with-ts'
65
+ + transform: {
66
+ '^.+\\.tsx?$': 'ts-jest/legacy' // or '^.+\\.[tj]sx?$': 'ts-jest' to use legacy codes
67
+ }
68
+ }
69
+ ```
70
+
71
+
72
+
1
73
  ## [27.1.4](https://github.com/kulshekhar/ts-jest/compare/v27.1.3...v27.1.4) (2022-03-24)
2
74
 
3
75
 
@@ -1,2 +1 @@
1
- export * from './config-set';
2
1
  export * from './paths-to-module-name-mapper';
@@ -14,5 +14,4 @@ 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("./config-set"), exports);
18
17
  __exportStar(require("./paths-to-module-name-mapper"), exports);
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
- import { TsJestTransformer } from './ts-jest-transformer';
2
- export * from './constants';
3
- export * from './compiler';
1
+ import { TsJestTransformer } from './legacy/ts-jest-transformer';
4
2
  export * from './config';
3
+ export * from './constants';
4
+ export * from './legacy/compiler';
5
+ export * from './legacy/ts-jest-transformer';
6
+ export * from './legacy/config/config-set';
5
7
  export * from './presets/create-jest-preset';
6
- export * from './utils';
7
8
  export * from './raw-compiler-options';
8
- export * from './ts-jest-transformer';
9
+ export * from './utils';
9
10
  export * from './types';
10
11
  declare const _default: {
11
- createTransformer: () => TsJestTransformer;
12
+ createTransformer(): TsJestTransformer;
12
13
  };
13
14
  export default _default;
package/dist/index.js CHANGED
@@ -14,15 +14,18 @@ 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");
18
- __exportStar(require("./constants"), exports);
19
- __exportStar(require("./compiler"), exports);
17
+ var ts_jest_transformer_1 = require("./legacy/ts-jest-transformer");
20
18
  __exportStar(require("./config"), exports);
19
+ __exportStar(require("./constants"), exports);
20
+ __exportStar(require("./legacy/compiler"), exports);
21
+ __exportStar(require("./legacy/ts-jest-transformer"), exports);
22
+ __exportStar(require("./legacy/config/config-set"), exports);
21
23
  __exportStar(require("./presets/create-jest-preset"), exports);
22
- __exportStar(require("./utils"), exports);
23
24
  __exportStar(require("./raw-compiler-options"), exports);
24
- __exportStar(require("./ts-jest-transformer"), exports);
25
+ __exportStar(require("./utils"), exports);
25
26
  __exportStar(require("./types"), exports);
26
27
  exports.default = {
27
- createTransformer: function () { return new ts_jest_transformer_1.TsJestTransformer(); },
28
+ createTransformer: function () {
29
+ return new ts_jest_transformer_1.TsJestTransformer();
30
+ },
28
31
  };
@@ -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,7 +1,8 @@
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 { ConfigSet } from '../config';
4
- import type { StringMap, TsCompilerInstance, TsJestAstTransformer, TsJestCompileOptions, TTypeScript } from '../types';
3
+ import type { CompilerOptions, CustomTransformers, Program, TranspileOutput } from 'typescript';
4
+ import type { StringMap, TsCompilerInstance, TsJestAstTransformer, TsJestCompileOptions, TTypeScript } from '../../types';
5
+ import type { ConfigSet } from '../config/config-set';
5
6
  export declare class TsCompiler implements TsCompilerInstance {
6
7
  readonly configSet: ConfigSet;
7
8
  readonly runtimeCacheFS: StringMap;
@@ -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
  }
@@ -54,10 +54,9 @@ exports.TsCompiler = void 0;
54
54
  var path_1 = require("path");
55
55
  var bs_logger_1 = require("bs-logger");
56
56
  var lodash_memoize_1 = __importDefault(require("lodash.memoize"));
57
- var constants_1 = require("../constants");
58
- var utils_1 = require("../utils");
59
- var messages_1 = require("../utils/messages");
60
- var compiler_utils_1 = require("./compiler-utils");
57
+ var constants_1 = require("../../constants");
58
+ var utils_1 = require("../../utils");
59
+ var messages_1 = require("../../utils/messages");
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 { ConfigSet } from '../config';
2
- import type { CompilerInstance, StringMap, TsJestCompileOptions } from '../types';
1
+ import type { TransformedSource } from '@jest/transform';
2
+ import type { CompilerInstance, StringMap, TsJestCompileOptions } from '../../types';
3
+ import type { ConfigSet } from '../config/config-set';
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
  }
@@ -1,7 +1,7 @@
1
1
  import { Logger } from 'bs-logger';
2
2
  import type * as ts from 'typescript';
3
- import type { RawCompilerOptions } from '../raw-compiler-options';
4
- import type { ProjectConfigTsJest, TsJestAstTransformer, TTypeScript } from '../types';
3
+ import type { RawCompilerOptions } from '../../raw-compiler-options';
4
+ import type { ProjectConfigTsJest, TsJestAstTransformer, TTypeScript } from '../../types';
5
5
  export declare class ConfigSet {
6
6
  readonly parentLogger?: Logger | undefined;
7
7
  readonly tsJestDigest: string;
@@ -57,15 +57,15 @@ var path_1 = require("path");
57
57
  var bs_logger_1 = require("bs-logger");
58
58
  var jest_util_1 = require("jest-util");
59
59
  var json5_1 = __importDefault(require("json5"));
60
- var constants_1 = require("../constants");
61
- var utils_1 = require("../utils");
62
- var backports_1 = require("../utils/backports");
63
- var importer_1 = require("../utils/importer");
64
- var messages_1 = require("../utils/messages");
65
- var normalize_slashes_1 = require("../utils/normalize-slashes");
66
- var sha1_1 = require("../utils/sha1");
67
- var ts_error_1 = require("../utils/ts-error");
68
- exports.MY_DIGEST = (0, fs_1.readFileSync)((0, path_1.resolve)(__dirname, '..', '..', '.ts-jest-digest'), 'utf8');
60
+ var constants_1 = require("../../constants");
61
+ var utils_1 = require("../../utils");
62
+ var backports_1 = require("../../utils/backports");
63
+ var importer_1 = require("../../utils/importer");
64
+ var messages_1 = require("../../utils/messages");
65
+ var normalize_slashes_1 = require("../../utils/normalize-slashes");
66
+ var sha1_1 = require("../../utils/sha1");
67
+ var ts_error_1 = require("../../utils/ts-error");
68
+ exports.MY_DIGEST = (0, fs_1.readFileSync)((0, path_1.resolve)(__dirname, '../../../.ts-jest-digest'), 'utf8');
69
69
  exports.IGNORE_DIAGNOSTIC_CODES = [
70
70
  6059,
71
71
  18002,
@@ -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;
@@ -232,7 +232,7 @@ var ConfigSet = (function () {
232
232
  this.parsedTsConfig = this._getAndResolveTsConfig(typeof tsconfigOpt === 'object' ? tsconfigOpt : undefined, configFilePath);
233
233
  this.raiseDiagnostics(this.parsedTsConfig.errors, configFilePath);
234
234
  this.logger.debug({ tsconfig: this.parsedTsConfig }, 'normalized typescript config via ts-jest option');
235
- this.resolvedTransformers.before = [require('../transformers/hoist-jest')];
235
+ this.resolvedTransformers.before = [require('../../transformers/hoist-jest')];
236
236
  var astTransformers = options.astTransformers;
237
237
  if (astTransformers) {
238
238
  var resolveTransformerFunc_1 = function (transformerPath) {
@@ -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],
@@ -0,0 +1,5 @@
1
+ import { TsJestTransformer } from './ts-jest-transformer';
2
+ declare const _default: {
3
+ createTransformer: () => TsJestTransformer;
4
+ };
5
+ export default _default;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var ts_jest_transformer_1 = require("./ts-jest-transformer");
4
+ exports.default = {
5
+ createTransformer: function () { return new ts_jest_transformer_1.TsJestTransformer(); },
6
+ };
@@ -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 type { CompilerInstance, ProjectConfigTsJest, TransformOptionsTsJest } from '../types';
3
+ import { ConfigSet } from './config/config-set';
5
4
  export declare class TsJestTransformer implements SyncTransformer {
6
5
  private readonly _logger;
7
6
  protected _compiler: CompilerInstance;
@@ -13,8 +12,10 @@ export declare class TsJestTransformer implements SyncTransformer {
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,14 +78,14 @@ 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 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 version_checkers_1 = require("../utils/version-checkers");
81
87
  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");
88
+ var config_set_1 = require("./config/config-set");
89
89
  exports.CACHE_KEY_EL_SEPARATOR = '\x00';
90
90
  var TsJestTransformer = (function () {
91
91
  function TsJestTransformer() {
@@ -128,7 +128,6 @@ var TsJestTransformer = (function () {
128
128
  this._logger.info('no matching config-set found, creating a new one');
129
129
  configSet = this._createConfigSet(config);
130
130
  var jest_1 = __assign({}, config);
131
- jest_1.name = undefined;
132
131
  jest_1.cacheDirectory = undefined;
133
132
  this._transformCfgStr = "".concat(new utils_1.JsonableValue(jest_1).serialized).concat(configSet.cacheSuffix);
134
133
  this._createCompiler(configSet, cacheFS);
@@ -148,38 +147,80 @@ var TsJestTransformer = (function () {
148
147
  return configSet;
149
148
  };
150
149
  TsJestTransformer.prototype._createConfigSet = function (config) {
151
- return new config_1.ConfigSet(config);
150
+ return new config_set_1.ConfigSet(config);
152
151
  };
153
152
  TsJestTransformer.prototype._createCompiler = function (configSet, cacheFS) {
154
153
  this._compiler = new compiler_1.TsJestCompiler(configSet, cacheFS);
155
154
  };
156
- TsJestTransformer.prototype.process = function (fileContent, filePath, transformOptions) {
157
- this._logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'processing', filePath);
158
- var result;
155
+ TsJestTransformer.prototype.process = function (sourceText, sourcePath, transformOptions) {
156
+ this._logger.debug({ fileName: sourcePath, transformOptions: transformOptions }, 'processing', sourcePath);
159
157
  var configs = this._configsFor(transformOptions);
160
- var shouldStringifyContent = configs.shouldStringifyContent(filePath);
158
+ var shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
161
159
  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, {});
160
+ var result = this.processWithTs(sourceText, sourcePath, transformOptions);
161
+ if (babelJest) {
162
+ this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
163
+ result = babelJest.process(result.code, sourcePath, __assign(__assign({}, transformOptions), { instrument: false }));
170
164
  }
165
+ result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
166
+ return result;
167
+ };
168
+ TsJestTransformer.prototype.processAsync = function (sourceText, sourcePath, transformOptions) {
169
+ return __awaiter(this, void 0, void 0, function () {
170
+ var _this = this;
171
+ return __generator(this, function (_a) {
172
+ this._logger.debug({ fileName: sourcePath, transformOptions: transformOptions }, 'processing', sourcePath);
173
+ return [2, new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
174
+ var configs, shouldStringifyContent, babelJest, result;
175
+ return __generator(this, function (_a) {
176
+ switch (_a.label) {
177
+ case 0:
178
+ configs = this._configsFor(transformOptions);
179
+ shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
180
+ babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
181
+ result = this.processWithTs(sourceText, sourcePath, transformOptions);
182
+ if (!babelJest) return [3, 2];
183
+ this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
184
+ return [4, babelJest.processAsync(result.code, sourcePath, __assign(__assign({}, transformOptions), { instrument: false }))];
185
+ case 1:
186
+ result = _a.sent();
187
+ _a.label = 2;
188
+ case 2:
189
+ result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
190
+ resolve(result);
191
+ return [2];
192
+ }
193
+ });
194
+ }); })];
195
+ });
196
+ });
197
+ };
198
+ TsJestTransformer.prototype.processWithTs = function (sourceText, sourcePath, transformOptions) {
199
+ var result;
200
+ var configs = this._configsFor(transformOptions);
201
+ var shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
202
+ var babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
203
+ var isDefinitionFile = sourcePath.endsWith(constants_1.DECLARATION_TYPE_EXT);
204
+ var isJsFile = constants_1.JS_JSX_REGEX.test(sourcePath);
205
+ var isTsFile = !isDefinitionFile && constants_1.TS_TSX_REGEX.test(sourcePath);
171
206
  if (shouldStringifyContent) {
172
- result = "module.exports=".concat((0, utils_1.stringify)(fileContent));
207
+ result = {
208
+ code: "module.exports=".concat((0, utils_1.stringify)(sourceText)),
209
+ };
173
210
  }
174
211
  else if (isDefinitionFile) {
175
- result = '';
212
+ result = {
213
+ code: '',
214
+ };
176
215
  }
177
216
  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;
217
+ 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 }));
218
+ result = {
219
+ code: sourceText,
220
+ };
180
221
  }
181
222
  else if (isJsFile || isTsFile) {
182
- result = this._compiler.getCompiledOutput(fileContent, filePath, {
223
+ result = this._compiler.getCompiledOutput(sourceText, sourcePath, {
183
224
  depGraphs: this._depGraphs,
184
225
  supportsStaticESM: transformOptions.supportsStaticESM,
185
226
  watchMode: this._watchMode,
@@ -187,29 +228,28 @@ var TsJestTransformer = (function () {
187
228
  }
188
229
  else {
189
230
  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;
231
+ this._logger.warn({ fileName: sourcePath }, (0, messages_1.interpolate)(message, { path: sourcePath }));
232
+ result = {
233
+ code: sourceText,
234
+ };
192
235
  }
193
- if (babelJest) {
194
- this._logger.debug({ fileName: filePath }, 'calling babel-jest processor');
195
- result = babelJest.process(result, filePath, __assign(__assign({}, transformOptions), { instrument: false }));
236
+ return result;
237
+ };
238
+ TsJestTransformer.prototype.runTsJestHook = function (sourcePath, sourceText, transformOptions, compiledOutput) {
239
+ var hooksFile = process.env.TS_JEST_HOOKS;
240
+ var hooks;
241
+ if (hooksFile) {
242
+ hooksFile = path_1.default.resolve(this._configsFor(transformOptions).cwd, hooksFile);
243
+ hooks = importer_1.importer.tryTheseOr(hooksFile, {});
196
244
  }
197
245
  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);
246
+ this._logger.debug({ fileName: sourcePath, hookName: 'afterProcess' }, 'calling afterProcess hook');
247
+ var newResult = hooks.afterProcess([sourceText, sourcePath, transformOptions.config, transformOptions], compiledOutput);
200
248
  if (newResult) {
201
249
  return newResult;
202
250
  }
203
251
  }
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
- });
252
+ return compiledOutput;
213
253
  };
214
254
  TsJestTransformer.prototype.getCacheKey = function (fileContent, filePath, transformOptions) {
215
255
  var _a;
@@ -1,3 +1,3 @@
1
1
  import type { Config } from '@jest/types';
2
2
  import type { TsJestPresets } from '../types';
3
- export declare function createJestPreset(allowJs?: boolean, extraOptions?: Config.InitialOptions): TsJestPresets;
3
+ export declare function createJestPreset(legacy?: boolean, allowJs?: boolean, extraOptions?: Config.InitialOptions): TsJestPresets;
@@ -14,13 +14,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.createJestPreset = void 0;
15
15
  var utils_1 = require("../utils");
16
16
  var logger = utils_1.rootLogger.child({ namespace: 'jest-preset' });
17
- function createJestPreset(allowJs, extraOptions) {
17
+ function createJestPreset(legacy, allowJs, extraOptions) {
18
18
  var _a;
19
+ if (legacy === void 0) { legacy = false; }
19
20
  if (allowJs === void 0) { allowJs = false; }
20
21
  if (extraOptions === void 0) { extraOptions = {}; }
21
22
  logger.debug({ allowJs: allowJs }, 'creating jest presets', allowJs ? 'handling' : 'not handling', 'JavaScript files');
22
23
  var extensionsToTreatAsEsm = extraOptions.extensionsToTreatAsEsm, moduleFileExtensions = extraOptions.moduleFileExtensions, testMatch = extraOptions.testMatch;
23
24
  var supportESM = extensionsToTreatAsEsm === null || extensionsToTreatAsEsm === void 0 ? void 0 : extensionsToTreatAsEsm.length;
24
- return __assign(__assign(__assign(__assign({}, (extensionsToTreatAsEsm ? { extensionsToTreatAsEsm: extensionsToTreatAsEsm } : undefined)), (moduleFileExtensions ? { moduleFileExtensions: moduleFileExtensions } : undefined)), (testMatch ? { testMatch: testMatch } : undefined)), { transform: __assign(__assign({}, extraOptions.transform), (_a = {}, _a[allowJs ? (supportESM ? '^.+\\.m?[tj]sx?$' : '^.+\\.[tj]sx?$') : '^.+\\.tsx?$'] = 'ts-jest', _a)) });
25
+ return __assign(__assign(__assign(__assign({}, (extensionsToTreatAsEsm ? { extensionsToTreatAsEsm: extensionsToTreatAsEsm } : undefined)), (moduleFileExtensions ? { moduleFileExtensions: moduleFileExtensions } : undefined)), (testMatch ? { testMatch: testMatch } : undefined)), { transform: __assign(__assign({}, extraOptions.transform), (_a = {}, _a[allowJs ? (supportESM ? '^.+\\.m?[tj]sx?$' : '^.+\\.[tj]sx?$') : '^.+\\.tsx?$'] = legacy
26
+ ? 'ts-jest/legacy'
27
+ : 'ts-jest', _a)) });
25
28
  }
26
29
  exports.createJestPreset = createJestPreset;
@@ -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,8 +1,9 @@
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
- import type { ConfigSet } from './config';
6
+ import type { ConfigSet } from './legacy/config/config-set';
6
7
  import type { RawCompilerOptions } from './raw-compiler-options';
7
8
  declare module '@jest/types' {
8
9
  namespace 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 <29"),
11
+ typescript: createVersionChecker('typescript', ">=4.3 <5"),
12
+ babelJest: createVersionChecker('babel-jest', ">=28.0.0 <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.2",
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",
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",
67
+ "jest": "^28.0.0",
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",
95
+ "@jest/types": "^28.0.0",
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.29",
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",
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
  }
@@ -0,0 +1 @@
1
+ module.exports = require('..').defaultsESMLegacy
@@ -0,0 +1 @@
1
+ module.exports = require('..').defaultsLegacy
@@ -2,10 +2,16 @@ import type { TsJestPresets } from '../dist'
2
2
 
3
3
  declare const _default: {
4
4
  defaults: TsJestPresets;
5
+ defaultsLegacy: TsJestPresets;
5
6
  defaultsESM: TsJestPresets;
7
+ defaultsESMLegacy: TsJestPresets;
6
8
  jsWithTs: TsJestPresets;
9
+ jsWithTsLegacy: TsJestPresets;
7
10
  jsWithTsESM: TsJestPresets;
11
+ jsWithTsESMLegacy: TsJestPresets;
8
12
  jsWithBabel: TsJestPresets;
13
+ jsWithBabelLegacy: TsJestPresets;
9
14
  jsWithBabelESM: TsJestPresets;
15
+ jsWithBabelESMLegacy: TsJestPresets;
10
16
  };
11
17
  export = _default;
package/presets/index.js CHANGED
@@ -5,24 +5,55 @@ module.exports = {
5
5
  get defaults() {
6
6
  return createJestPreset()
7
7
  },
8
+ get defaultsLegacy() {
9
+ return createJestPreset(true, false)
10
+ },
8
11
  get defaultsESM() {
9
- return createJestPreset(false, { extensionsToTreatAsEsm: TS_EXT_TO_TREAT_AS_ESM })
12
+ return createJestPreset(false, false, { extensionsToTreatAsEsm: TS_EXT_TO_TREAT_AS_ESM })
13
+ },
14
+ get defaultsESMLegacy() {
15
+ return createJestPreset(true, false, { extensionsToTreatAsEsm: TS_EXT_TO_TREAT_AS_ESM })
10
16
  },
11
17
  get jsWithTs() {
12
- return createJestPreset(true)
18
+ return createJestPreset(false, true)
19
+ },
20
+ get jsWithTsLegacy() {
21
+ return createJestPreset(true, true)
13
22
  },
14
23
  get jsWithTsESM() {
15
- return createJestPreset(true, { extensionsToTreatAsEsm: [...JS_EXT_TO_TREAT_AS_ESM, ...TS_EXT_TO_TREAT_AS_ESM] })
24
+ return createJestPreset(false, true, {
25
+ extensionsToTreatAsEsm: [...JS_EXT_TO_TREAT_AS_ESM, ...TS_EXT_TO_TREAT_AS_ESM],
26
+ })
27
+ },
28
+ get jsWithTsESMLegacy() {
29
+ return createJestPreset(true, true, {
30
+ extensionsToTreatAsEsm: [...JS_EXT_TO_TREAT_AS_ESM, ...TS_EXT_TO_TREAT_AS_ESM],
31
+ })
16
32
  },
17
33
  get jsWithBabel() {
18
- return createJestPreset(false, {
34
+ return createJestPreset(false, false, {
35
+ transform: {
36
+ '^.+\\.jsx?$': 'babel-jest',
37
+ },
38
+ })
39
+ },
40
+ get jsWithBabelLegacy() {
41
+ return createJestPreset(true, false, {
19
42
  transform: {
20
43
  '^.+\\.jsx?$': 'babel-jest',
21
44
  },
22
45
  })
23
46
  },
24
47
  get jsWithBabelESM() {
25
- return createJestPreset(false, {
48
+ return createJestPreset(false, false, {
49
+ extensionsToTreatAsEsm: [...JS_EXT_TO_TREAT_AS_ESM, ...TS_EXT_TO_TREAT_AS_ESM],
50
+ transform: {
51
+ '^.+\\.m?[j]sx?$': 'babel-jest',
52
+ },
53
+ })
54
+ },
55
+ get jsWithBabelESMLegacy() {
56
+ return createJestPreset(true, false, {
26
57
  extensionsToTreatAsEsm: [...JS_EXT_TO_TREAT_AS_ESM, ...TS_EXT_TO_TREAT_AS_ESM],
27
58
  transform: {
28
59
  '^.+\\.m?[j]sx?$': 'babel-jest',
@@ -0,0 +1 @@
1
+ module.exports = require('..').jsWithBabelESMLegacy
@@ -0,0 +1 @@
1
+ module.exports = require('..').jsWithBabelLegacy
@@ -0,0 +1 @@
1
+ module.exports = require('..').jsWithTsESMLegacy
@@ -0,0 +1 @@
1
+ module.exports = require('..').jsWithTsLegacy
@@ -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,5 +0,0 @@
1
- import type * as _ts from 'typescript';
2
- import type { TsCompilerInstance } from '../types';
3
- export declare const version = 2;
4
- export declare const name = "path-mapping";
5
- export declare function factory({ configSet, }: TsCompilerInstance): (ctx: _ts.TransformationContext) => _ts.Transformer<_ts.SourceFile>;
@@ -1,129 +0,0 @@
1
- "use strict";
2
- var __values = (this && this.__values) || function(o) {
3
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
- if (m) return m.call(o);
5
- if (o && typeof o.length === "number") return {
6
- next: function () {
7
- if (o && i >= o.length) o = void 0;
8
- return { value: o && o[i++], done: !o };
9
- }
10
- };
11
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.factory = exports.name = exports.version = void 0;
15
- var path_1 = require("path");
16
- var bs_logger_1 = require("bs-logger");
17
- exports.version = 2;
18
- exports.name = 'path-mapping';
19
- var isBaseDir = function (base, dir) { var _a; return !((_a = (0, path_1.relative)(base, dir)) === null || _a === void 0 ? void 0 : _a.startsWith('.')); };
20
- function factory(_a) {
21
- var _b;
22
- var configSet = _a.configSet;
23
- var logger = configSet.logger.child({ namespace: exports.name });
24
- logger.warn('path-mapping AST transformer is deprecated and will be removed in `ts-jest` v28. Please use an alternative one, like https://github.com/LeDDGroup/typescript-transform-paths instead');
25
- var ts = configSet.compilerModule;
26
- var tsFactory = ts.factory ? ts.factory : ts;
27
- var compilerOptions = configSet.parsedTsConfig.options;
28
- var rootDirs = (_b = compilerOptions.rootDirs) === null || _b === void 0 ? void 0 : _b.filter(path_1.isAbsolute);
29
- var isDynamicImport = function (node) {
30
- return ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword;
31
- };
32
- var isRequire = function (node) {
33
- return ts.isCallExpression(node) &&
34
- ts.isIdentifier(node.expression) &&
35
- node.expression.text === 'require' &&
36
- ts.isStringLiteral(node.arguments[0]) &&
37
- node.arguments.length === 1;
38
- };
39
- var createVisitor = function (ctx, sf) {
40
- var fileName = sf.fileName;
41
- var fileDir = (0, path_1.normalize)((0, path_1.dirname)(fileName));
42
- var rewritePath = function (importPath) {
43
- var e_1, _a;
44
- var p = importPath;
45
- var resolvedModule = ts.resolveModuleName(importPath, fileName, compilerOptions, ts.sys).resolvedModule;
46
- if (resolvedModule) {
47
- var resolvedFileName = resolvedModule.resolvedFileName;
48
- var filePath = fileDir;
49
- var modulePath = (0, path_1.dirname)(resolvedFileName);
50
- if (rootDirs) {
51
- var fileRootDir = '';
52
- var moduleRootDir = '';
53
- try {
54
- for (var rootDirs_1 = __values(rootDirs), rootDirs_1_1 = rootDirs_1.next(); !rootDirs_1_1.done; rootDirs_1_1 = rootDirs_1.next()) {
55
- var rootDir = rootDirs_1_1.value;
56
- if (isBaseDir(rootDir, resolvedFileName) && rootDir.length > moduleRootDir.length)
57
- moduleRootDir = rootDir;
58
- if (isBaseDir(rootDir, fileName) && rootDir.length > fileRootDir.length)
59
- fileRootDir = rootDir;
60
- }
61
- }
62
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
63
- finally {
64
- try {
65
- if (rootDirs_1_1 && !rootDirs_1_1.done && (_a = rootDirs_1.return)) _a.call(rootDirs_1);
66
- }
67
- finally { if (e_1) throw e_1.error; }
68
- }
69
- if (fileRootDir && moduleRootDir) {
70
- filePath = (0, path_1.relative)(fileRootDir, filePath);
71
- modulePath = (0, path_1.relative)(moduleRootDir, modulePath);
72
- }
73
- }
74
- p = (0, path_1.normalize)((0, path_1.join)((0, path_1.relative)(filePath, modulePath), (0, path_1.basename)(resolvedFileName)));
75
- p = p.startsWith('.') ? p : "./".concat(p);
76
- }
77
- return p;
78
- };
79
- var visitor = function (node) {
80
- var rewrittenPath;
81
- var newNode = ts.getMutableClone(node);
82
- if (isDynamicImport(node) || isRequire(node)) {
83
- rewrittenPath = rewritePath(node.arguments[0].text);
84
- var argumentArrays = tsFactory.createNodeArray([tsFactory.createStringLiteral(rewrittenPath)]);
85
- return ts.factory
86
- ? ts.factory.updateCallExpression(node, node.expression, node.typeArguments, argumentArrays)
87
- : ts.updateCall(node, node.expression, node.typeArguments, argumentArrays);
88
- }
89
- if (ts.isExternalModuleReference(node) && ts.isStringLiteral(node.expression)) {
90
- rewrittenPath = rewritePath(node.expression.text);
91
- return tsFactory.updateExternalModuleReference(newNode, tsFactory.createStringLiteral(rewrittenPath));
92
- }
93
- if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
94
- rewrittenPath = rewritePath(node.moduleSpecifier.text);
95
- return +ts.versionMajorMinor >= 4.5
96
- ? tsFactory.updateImportDeclaration(node, node.decorators, node.modifiers, node.importClause, tsFactory.createStringLiteral(rewrittenPath), node.assertClause)
97
- :
98
- tsFactory.updateImportDeclaration(node, node.decorators, node.modifiers, node.importClause, tsFactory.createStringLiteral(rewrittenPath));
99
- }
100
- if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
101
- rewrittenPath = rewritePath(node.moduleSpecifier.text);
102
- var stringLiteralNode = tsFactory.createStringLiteral(rewrittenPath);
103
- if (ts.factory) {
104
- return +ts.versionMajorMinor >= 4.5
105
- ? ts.factory.updateExportDeclaration(node, node.decorators, node.modifiers, node.isTypeOnly, node.exportClause, stringLiteralNode, node.assertClause)
106
- :
107
- ts.factory.updateExportDeclaration(node, node.decorators, node.modifiers, node.isTypeOnly, node.exportClause, stringLiteralNode);
108
- }
109
- else {
110
- return ts.updateExportDeclaration(node, node.decorators, node.modifiers, node.exportClause, stringLiteralNode, node.isTypeOnly);
111
- }
112
- }
113
- if (ts.isImportTypeNode(node) &&
114
- ts.isLiteralTypeNode(node.argument) &&
115
- ts.isStringLiteral(node.argument.literal)) {
116
- rewrittenPath = rewritePath(node.argument.literal.text);
117
- var importArguments = tsFactory.createLiteralTypeNode(tsFactory.createStringLiteral(rewrittenPath));
118
- return tsFactory.updateImportTypeNode(node, importArguments, node.qualifier, node.typeArguments, node.isTypeOf);
119
- }
120
- return ts.visitEachChild(node, visitor, ctx);
121
- };
122
- return visitor;
123
- };
124
- return function (ctx) {
125
- var _a;
126
- return logger.wrap((_a = {}, _a[bs_logger_1.LogContexts.logLevel] = bs_logger_1.LogLevels.debug, _a.call = null, _a), 'visitSourceFileNode(): path mapping', function (sf) { return ts.visitNode(sf, createVisitor(ctx, sf)); });
127
- };
128
- }
129
- exports.factory = factory;
@@ -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
- }