ts-jest 27.0.0 → 27.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.ts-jest-digest CHANGED
@@ -1 +1 @@
1
- a1376fb91cb7def505cacd7981109827042bd189
1
+ 728a5836db2d1522482a6d839e7cb4bf9dc045c0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,55 @@
1
+ ## [27.0.4](https://github.com/kulshekhar/ts-jest/compare/v27.0.3...v27.0.4) (2021-07-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add `@types/jest` as optional `peerDependencies` to solve yarn 2 ([#2756](https://github.com/kulshekhar/ts-jest/issues/2756)) ([5fbf43e](https://github.com/kulshekhar/ts-jest/commit/5fbf43e64691d5146add1da4690a14b3095c4234))
7
+ * add `babel-jest` as optional `peerDependencies` to solve yarn 2 ([#2751](https://github.com/kulshekhar/ts-jest/issues/2751)) ([8bede2e](https://github.com/kulshekhar/ts-jest/commit/8bede2e57546a18999b96871069f1f94a3ecf3c1))
8
+ * **config:** include AST transformer's `name` and `version` into cache key ([#2755](https://github.com/kulshekhar/ts-jest/issues/2755)) ([310fb9a](https://github.com/kulshekhar/ts-jest/commit/310fb9a1d7b40a8274d6fb93745e66a6da891a75)), closes [#2753](https://github.com/kulshekhar/ts-jest/issues/2753)
9
+
10
+
11
+ ### Features
12
+
13
+ * link jest config types on `npx ts-jest:init` ([#2742](https://github.com/kulshekhar/ts-jest/issues/2742)) ([f51ba05](https://github.com/kulshekhar/ts-jest/commit/f51ba0507568ba8a5dece48c159d7857a2ed61d6))
14
+ * set env var `TS_JEST` to allow detecting of `ts-jest` ([#2717](https://github.com/kulshekhar/ts-jest/issues/2717)) ([56c137a](https://github.com/kulshekhar/ts-jest/commit/56c137a3c1906f49cb0b9e044fa8e233707cbaa4)), closes [#2716](https://github.com/kulshekhar/ts-jest/issues/2716)
15
+
16
+
17
+
18
+ ## [27.0.3](https://github.com/kulshekhar/ts-jest/compare/v27.0.2...v27.0.3) (2021-06-06)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * revert `exports` field to support all node versions ([#2658](https://github.com/kulshekhar/ts-jest/issues/2658)) ([132c8ba](https://github.com/kulshekhar/ts-jest/commit/132c8ba85c3e61b7d9ede0dc9730580b79618ab7))
24
+
25
+
26
+ ### Features
27
+
28
+ * emit ESM codes if using ESM mode with Babel ([#2661](https://github.com/kulshekhar/ts-jest/issues/2661)) ([9b55404](https://github.com/kulshekhar/ts-jest/commit/9b55404a8dfc760238e19786da98a2edf043b9da)), closes [#2650](https://github.com/kulshekhar/ts-jest/issues/2650)
29
+
30
+
31
+
32
+ ## [27.0.2](https://github.com/kulshekhar/ts-jest/compare/v27.0.1...v27.0.2) (2021-05-30)
33
+
34
+
35
+ ### Bug Fixes
36
+
37
+ * **compiler:** add empty string file content to compiler cache ([#2633](https://github.com/kulshekhar/ts-jest/issues/2633)) ([0feb556](https://github.com/kulshekhar/ts-jest/commit/0feb5560a588f87d1d989bf521859fba0fda20fe)), closes [#2625](https://github.com/kulshekhar/ts-jest/issues/2625)
38
+ * **config:** `exclude` should only exclude files which match glob values ([#2637](https://github.com/kulshekhar/ts-jest/issues/2637)) ([c5ce979](https://github.com/kulshekhar/ts-jest/commit/c5ce97902c1b84dc354f270a4f596a6f5f634611)), closes [#2634](https://github.com/kulshekhar/ts-jest/issues/2634)
39
+
40
+
41
+
42
+ ## [27.0.1](https://github.com/kulshekhar/ts-jest/compare/v27.0.0...v27.0.1) (2021-05-26)
43
+
44
+
45
+ ### Bug Fixes
46
+
47
+ * **cli:** keep `testMatch` if old jest config contains it ([#2618](https://github.com/kulshekhar/ts-jest/issues/2618)) ([c568f49](https://github.com/kulshekhar/ts-jest/commit/c568f49907fb5559ba1e8c67f1ec5d5eb4af920a)), closes [#2616](https://github.com/kulshekhar/ts-jest/issues/2616)
48
+ * **compiler:** make sure `isolatedModules: false` use updated compiler options ([#2628](https://github.com/kulshekhar/ts-jest/issues/2628)) ([348e30f](https://github.com/kulshekhar/ts-jest/commit/348e30f426803efc51ecba26ab42619938fcb5af)), closes [#2629](https://github.com/kulshekhar/ts-jest/issues/2629)
49
+ * add missing export `presets` ([#2624](https://github.com/kulshekhar/ts-jest/issues/2624)) ([0ea025e](https://github.com/kulshekhar/ts-jest/commit/0ea025ebb456d3a31671e31fac0b401c2734a2b1)), closes [#2623](https://github.com/kulshekhar/ts-jest/issues/2623)
50
+
51
+
52
+
1
53
  # [27.0.0](https://github.com/kulshekhar/ts-jest/compare/v26.5.6...v27.0.0) (2021-05-25)
2
54
 
3
55
 
@@ -115,7 +167,7 @@ module.exports = {
115
167
  ```
116
168
  * Remove possibilities to import `mocked`, `createJestPreset`, `pathsToModuleNameMapper` from package entry. One should change to
117
169
  ```
118
- import { mocked, createJestPreset, pathsToModuleNameMapper` } from 'ts-jest/utils'
170
+ import { mocked, createJestPreset, pathsToModuleNameMapper } from 'ts-jest/utils'
119
171
  ```
120
172
  * **config:** One currently uses `tsConfig` should change to `tsconfig` in your `jest.config.js` or `package.json`.
121
173
 
@@ -119,6 +119,7 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
119
119
  if (!jestPreset) {
120
120
  content.push(preset.jsImport('tsjPreset') + ";", '');
121
121
  }
122
+ content.push("/** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */");
122
123
  content.push('module.exports = {');
123
124
  if (jestPreset) {
124
125
  content.push(" preset: '" + preset.name + "',");
@@ -70,8 +70,8 @@ var backports_1 = require("../../utils/backports");
70
70
  var presets_1 = require("../helpers/presets");
71
71
  var run = function (args) { return __awaiter(void 0, void 0, void 0, function () {
72
72
  var nullLogger, file, filePath, footNotes, name, isPackage, actualConfig, migratedConfig, presetName, preset, jsTransformers, jsWithTs, jsWithBabel, presetValue, migratedValue, presetValue, migratedValue, before, after, stringify, prefix;
73
- var _a;
74
- return __generator(this, function (_b) {
73
+ var _a, _b, _c, _d, _e, _f, _g, _h;
74
+ return __generator(this, function (_j) {
75
75
  nullLogger = bs_logger_1.createLogger({ targets: [] });
76
76
  file = (_a = args._[0]) === null || _a === void 0 ? void 0 : _a.toString();
77
77
  filePath = path_1.resolve(process.cwd(), file);
@@ -119,32 +119,32 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
119
119
  presetName = "ts-jest/presets/default";
120
120
  }
121
121
  }
122
- presetName = presetName || "ts-jest/presets/default";
122
+ presetName = presetName !== null && presetName !== void 0 ? presetName : "ts-jest/presets/default";
123
123
  preset = presets_1.allPresets[presetName];
124
124
  footNotes.push("Detected preset '" + preset.label + "' as the best matching preset for your configuration.\nVisit https://kulshekhar.github.io/ts-jest/user/config/#jest-preset for more information about presets.\n");
125
125
  }
126
- else if (migratedConfig.preset && migratedConfig.preset.startsWith('ts-jest')) {
126
+ else if ((_b = migratedConfig.preset) === null || _b === void 0 ? void 0 : _b.startsWith('ts-jest')) {
127
127
  if (args.jestPreset === false) {
128
128
  delete migratedConfig.preset;
129
129
  }
130
130
  else {
131
- preset = presets_1.allPresets[migratedConfig.preset] || presets_1.defaults;
131
+ preset = (_c = presets_1.allPresets[migratedConfig.preset]) !== null && _c !== void 0 ? _c : presets_1.defaults;
132
132
  }
133
133
  }
134
134
  if (preset)
135
135
  migratedConfig.preset = preset.name;
136
- if (migratedConfig.moduleFileExtensions && migratedConfig.moduleFileExtensions.length && preset) {
137
- presetValue = dedupSort(preset.value.moduleFileExtensions || []).join('::');
136
+ if (((_d = migratedConfig.moduleFileExtensions) === null || _d === void 0 ? void 0 : _d.length) && preset) {
137
+ presetValue = dedupSort((_e = preset.value.moduleFileExtensions) !== null && _e !== void 0 ? _e : []).join('::');
138
138
  migratedValue = dedupSort(migratedConfig.moduleFileExtensions).join('::');
139
139
  if (presetValue === migratedValue) {
140
140
  delete migratedConfig.moduleFileExtensions;
141
141
  }
142
142
  }
143
- if (migratedConfig.testRegex && preset) {
144
- migratedConfig.testMatch = null;
143
+ if ((typeof migratedConfig.testRegex === 'string' || ((_f = migratedConfig.testRegex) === null || _f === void 0 ? void 0 : _f.length)) && preset) {
144
+ delete migratedConfig.testMatch;
145
145
  }
146
- else if (migratedConfig.testMatch && migratedConfig.testMatch.length && preset) {
147
- presetValue = dedupSort(preset.value.testMatch || []).join('::');
146
+ else if (((_g = migratedConfig.testMatch) === null || _g === void 0 ? void 0 : _g.length) && preset) {
147
+ presetValue = dedupSort((_h = preset.value.testMatch) !== null && _h !== void 0 ? _h : []).join('::');
148
148
  migratedValue = dedupSort(migratedConfig.testMatch).join('::');
149
149
  if (presetValue === migratedValue) {
150
150
  delete migratedConfig.testMatch;
@@ -191,21 +191,21 @@ function cleanupConfig(config) {
191
191
  if (config.globals['ts-jest'] && Object.keys(config.globals['ts-jest']).length === 0) {
192
192
  delete config.globals['ts-jest'];
193
193
  }
194
- if (Object.keys(config.globals).length === 0) {
194
+ if (!Object.keys(config.globals).length) {
195
195
  delete config.globals;
196
196
  }
197
197
  }
198
- if (config.transform && Object.keys(config.transform).length === 0) {
198
+ if (config.transform && !Object.keys(config.transform).length) {
199
199
  delete config.transform;
200
200
  }
201
201
  if (config.moduleFileExtensions) {
202
202
  config.moduleFileExtensions = dedupSort(config.moduleFileExtensions);
203
- if (config.moduleFileExtensions.length === 0)
203
+ if (!config.moduleFileExtensions.length)
204
204
  delete config.moduleFileExtensions;
205
205
  }
206
206
  if (config.testMatch) {
207
207
  config.testMatch = dedupSort(config.testMatch);
208
- if (config.testMatch.length === 0)
208
+ if (!config.testMatch.length)
209
209
  delete config.testMatch;
210
210
  }
211
211
  if (config.preset === "ts-jest/presets/default")
@@ -106,7 +106,9 @@ var TsCompiler = (function () {
106
106
  var moduleKind = this._initialCompilerOptions.module;
107
107
  var esModuleInterop = this._initialCompilerOptions.esModuleInterop;
108
108
  var allowSyntheticDefaultImports = this._initialCompilerOptions.allowSyntheticDefaultImports;
109
- if (options.supportsStaticESM && this.configSet.useESM) {
109
+ var currentModuleKind = this._compilerOptions.module;
110
+ if ((this.configSet.babelJestTransformer || (!this.configSet.babelJestTransformer && options.supportsStaticESM)) &&
111
+ this.configSet.useESM) {
110
112
  moduleKind =
111
113
  !moduleKind ||
112
114
  (moduleKind &&
@@ -123,7 +125,7 @@ var TsCompiler = (function () {
123
125
  esModuleInterop: esModuleInterop, module: moduleKind });
124
126
  if (this._languageService) {
125
127
  this._logger.debug({ fileName: fileName }, 'getCompiledOutput(): compiling using language service');
126
- this._updateMemoryCache(fileContent, fileName);
128
+ this._updateMemoryCache(fileContent, fileName, currentModuleKind === moduleKind);
127
129
  var output = this._languageService.getEmitOutput(fileName);
128
130
  this._doTypeChecking(fileName, options.depGraphs, options.watchMode);
129
131
  if (output.emitSkipped) {
@@ -195,7 +197,7 @@ var TsCompiler = (function () {
195
197
  _this._logger.trace({ normalizedFileName: normalizedFileName, cacheHit: hit }, 'getScriptSnapshot():', 'cache', hit ? 'hit' : 'miss');
196
198
  if (!hit) {
197
199
  var fileContent = (_d = (_b = (_a = _this._fileContentCache.get(normalizedFileName)) !== null && _a !== void 0 ? _a : _this._runtimeCacheFS.get(normalizedFileName)) !== null && _b !== void 0 ? _b : (_c = _this._cachedReadFile) === null || _c === void 0 ? void 0 : _c.call(_this, normalizedFileName)) !== null && _d !== void 0 ? _d : undefined;
198
- if (fileContent) {
200
+ if (fileContent !== undefined) {
199
201
  _this._fileContentCache.set(normalizedFileName, fileContent);
200
202
  _this._fileVersionCache.set(normalizedFileName, 1);
201
203
  }
@@ -252,7 +254,8 @@ var TsCompiler = (function () {
252
254
  this._fileVersionCache.has(fileName) &&
253
255
  this._fileVersionCache.get(fileName) !== 0);
254
256
  };
255
- TsCompiler.prototype._updateMemoryCache = function (contents, fileName) {
257
+ TsCompiler.prototype._updateMemoryCache = function (contents, fileName, isModuleKindTheSame) {
258
+ if (isModuleKindTheSame === void 0) { isModuleKindTheSame = true; }
256
259
  this._logger.debug({ fileName: fileName }, 'updateMemoryCache: update memory cache for language service');
257
260
  var shouldIncrementProjectVersion = false;
258
261
  var hit = this._isFileInCache(fileName);
@@ -268,7 +271,7 @@ var TsCompiler = (function () {
268
271
  this._fileContentCache.set(fileName, contents);
269
272
  shouldIncrementProjectVersion = true;
270
273
  }
271
- if (!this._parsedTsConfig.fileNames.includes(fileName)) {
274
+ if (!this._parsedTsConfig.fileNames.includes(fileName) || !isModuleKindTheSame) {
272
275
  shouldIncrementProjectVersion = true;
273
276
  }
274
277
  }
@@ -207,9 +207,9 @@ var ConfigSet = (function () {
207
207
  throws: diagnosticsOpt,
208
208
  };
209
209
  }
210
- this._shouldGetDiagnosticsForFile = this._diagnostics.exclude.length
210
+ this._shouldIgnoreDiagnosticsForFile = this._diagnostics.exclude.length
211
211
  ? jest_util_1.globsToMatcher(this._diagnostics.exclude)
212
- : function () { return true; };
212
+ : function () { return false; };
213
213
  this.logger.debug({ diagnostics: this._diagnostics }, 'normalized diagnostics config via ts-jest option');
214
214
  var tsconfigOpt = options.tsconfig;
215
215
  var configFilePath = typeof tsconfigOpt === 'string' ? this.resolvePath(tsconfigOpt) : undefined;
@@ -219,13 +219,23 @@ var ConfigSet = (function () {
219
219
  this.resolvedTransformers.before = [require('../transformers/hoist-jest')];
220
220
  var astTransformers = options.astTransformers;
221
221
  if (astTransformers) {
222
+ var resolveTransformerFunc_1 = function (transformerPath) {
223
+ var transformerFunc = require(transformerPath);
224
+ if (!transformerFunc.version) {
225
+ _this.logger.warn("The AST transformer {{file}} must have an `export const version = <your_transformer_version>`", { file: transformerPath });
226
+ }
227
+ if (!transformerFunc.name) {
228
+ _this.logger.warn("The AST transformer {{file}} must have an `export const name = <your_transformer_name>`", { file: transformerPath });
229
+ }
230
+ return transformerFunc;
231
+ };
222
232
  var resolveTransformers = function (transformers) {
223
233
  return transformers.map(function (transformer) {
224
234
  if (typeof transformer === 'string') {
225
- return require(_this.resolvePath(transformer, { nodeResolve: true }));
235
+ return resolveTransformerFunc_1(_this.resolvePath(transformer, { nodeResolve: true }));
226
236
  }
227
237
  else {
228
- return __assign(__assign({}, require(_this.resolvePath(transformer.path, { nodeResolve: true }))), { options: transformer.options });
238
+ return __assign(__assign({}, resolveTransformerFunc_1(_this.resolvePath(transformer.path, { nodeResolve: true }))), { options: transformer.options });
229
239
  }
230
240
  });
231
241
  };
@@ -253,14 +263,15 @@ var ConfigSet = (function () {
253
263
  version: this.compilerModule.version,
254
264
  digest: this.tsJestDigest,
255
265
  babelConfig: this.babelConfig,
256
- compilerModule: this.compilerModule,
257
266
  tsconfig: {
258
267
  options: this.parsedTsConfig.options,
259
268
  raw: this.parsedTsConfig.raw,
260
269
  },
261
270
  isolatedModules: this.isolatedModules,
262
271
  diagnostics: this._diagnostics,
263
- transformers: this.resolvedTransformers,
272
+ transformers: Object.values(this.resolvedTransformers)
273
+ .reduce(function (prevVal, currentVal) { return __spreadArray(__spreadArray([], __read(prevVal)), [currentVal]); })
274
+ .map(function (transformer) { return transformer.name + "-" + transformer.version; }),
264
275
  }));
265
276
  if (!this._jestCfg.cache) {
266
277
  this.logger.debug('file caching disabled');
@@ -397,8 +408,8 @@ var ConfigSet = (function () {
397
408
  ConfigSet.prototype.shouldReportDiagnostics = function (filePath) {
398
409
  var fileExtension = path_1.extname(filePath);
399
410
  return constants_1.JS_JSX_EXTENSIONS.includes(fileExtension)
400
- ? this.parsedTsConfig.options.checkJs && this._shouldGetDiagnosticsForFile(filePath)
401
- : this._shouldGetDiagnosticsForFile(filePath);
411
+ ? this.parsedTsConfig.options.checkJs && !this._shouldIgnoreDiagnosticsForFile(filePath)
412
+ : !this._shouldIgnoreDiagnosticsForFile(filePath);
402
413
  };
403
414
  ConfigSet.prototype._createTsError = function (diagnostics) {
404
415
  var _this = this;
@@ -1 +1,2 @@
1
- export {};
1
+ export declare const version = 1;
2
+ export declare const name = "hoist-jest";
@@ -32,8 +32,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
32
32
  return to;
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.factory = void 0;
35
+ exports.factory = exports.name = exports.version = void 0;
36
36
  var bs_logger_1 = require("bs-logger");
37
+ exports.version = 1;
38
+ exports.name = 'hoist-jest';
37
39
  var HOIST_METHODS = ['mock', 'unmock', 'enableAutomock', 'disableAutomock', 'deepUnmock'];
38
40
  var JEST_GLOBALS_MODULE_NAME = '@jest/globals';
39
41
  var JEST_GLOBAL_NAME = 'jest';
@@ -1,3 +1,5 @@
1
1
  import type * as _ts from 'typescript';
2
2
  import type { TsCompilerInstance } from '../types';
3
+ export declare const version = 1;
4
+ export declare const name = "hoist-jest";
3
5
  export declare function factory({ configSet, }: TsCompilerInstance): (ctx: _ts.TransformationContext) => _ts.Transformer<_ts.SourceFile>;
@@ -22,9 +22,11 @@ var __values = (this && this.__values) || function(o) {
22
22
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.factory = void 0;
25
+ exports.factory = exports.name = exports.version = void 0;
26
26
  var path_1 = require("path");
27
27
  var bs_logger_1 = require("bs-logger");
28
+ exports.version = 1;
29
+ exports.name = 'hoist-jest';
28
30
  var isBaseDir = function (base, dir) { var _a; return !((_a = path_1.relative(base, dir)) === null || _a === void 0 ? void 0 : _a.startsWith('.')); };
29
31
  function factory(_a) {
30
32
  var _b;
@@ -59,6 +59,7 @@ var TsJestTransformer = (function () {
59
59
  this.getCacheKey = this.getCacheKey.bind(this);
60
60
  this.process = this.process.bind(this);
61
61
  this._logger.debug('created new transformer');
62
+ process.env.TS_JEST = '1';
62
63
  }
63
64
  TsJestTransformer.prototype._configsFor = function (transformOptions) {
64
65
  var config = transformOptions.config, cacheFS = transformOptions.cacheFS;
package/package.json CHANGED
@@ -1,16 +1,8 @@
1
1
  {
2
2
  "name": "ts-jest",
3
- "version": "27.0.0",
3
+ "version": "27.0.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
- "exports": {
7
- ".": "./dist/index.js",
8
- "./dist/*": "./dist/*.js",
9
- "./jest-preset": "./jest-preset.js",
10
- "./preset": "./presets/index.js",
11
- "./utils": "./utils/index.js",
12
- "./package.json": "./package.json"
13
- },
14
6
  "bin": {
15
7
  "ts-jest": "cli.js"
16
8
  },
@@ -77,7 +69,21 @@
77
69
  },
78
70
  "peerDependencies": {
79
71
  "jest": "^27.0.0",
80
- "typescript": ">=3.8 <5.0"
72
+ "typescript": ">=3.8 <5.0",
73
+ "babel-jest": ">=27.0.0 <28",
74
+ "@babel/core": ">=7.0.0-beta.0 <8",
75
+ "@types/jest": "^26.0.0"
76
+ },
77
+ "peerDependenciesMeta": {
78
+ "babel-jest": {
79
+ "optional": true
80
+ },
81
+ "@babel/core": {
82
+ "optional": true
83
+ },
84
+ "@types/jest": {
85
+ "optional": true
86
+ }
81
87
  },
82
88
  "husky": {
83
89
  "hooks": {
@@ -100,7 +106,7 @@
100
106
  "@types/lodash": "4.x",
101
107
  "@types/micromatch": "4.x",
102
108
  "@types/mkdirp": "latest",
103
- "@types/node": "14.14.43",
109
+ "@types/node": "16.4.0",
104
110
  "@types/node-fetch": "^2.5.8",
105
111
  "@types/react": "17.x",
106
112
  "@types/semver": "latest",
@@ -119,6 +125,7 @@
119
125
  "eslint-plugin-prettier": "latest",
120
126
  "execa": "latest",
121
127
  "fs-extra": "10.x",
128
+ "glob": "^7.1.7",
122
129
  "glob-gitignore": "latest",
123
130
  "husky": "4.x",
124
131
  "jest": "^27.0.0",
@@ -127,9 +134,9 @@
127
134
  "lint-staged": "latest",
128
135
  "node-fetch": "^2.6.1",
129
136
  "npm-run-all": "latest",
130
- "prettier": "2.3.0",
137
+ "prettier": "2.3.2",
131
138
  "source-map": "latest",
132
- "typescript": "^4.1.2"
139
+ "typescript": "~4.2.4"
133
140
  },
134
141
  "lint-staged": {
135
142
  "*.{ts,tsx,js,jsx}": [