ts-jest 27.0.2 → 27.0.6

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
- 379ec6d53df43eff4f1a882c7005e069f36949a1
1
+ e9db4ba030213abeffbfd32c95a365f4f30952fc
package/CHANGELOG.md CHANGED
@@ -1,3 +1,59 @@
1
+ ## [27.0.6](https://github.com/kulshekhar/ts-jest/compare/v27.0.5...v27.0.6) (2021-10-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * use specific `lodash` package instead of full package `lodash` ([#2959](https://github.com/kulshekhar/ts-jest/issues/2959)) ([dc89fe5](https://github.com/kulshekhar/ts-jest/commit/dc89fe55f2b77da76443f827fe3055f07cf4809c)), closes [#2954](https://github.com/kulshekhar/ts-jest/issues/2954)
7
+
8
+
9
+
10
+ ## [27.0.5](https://github.com/kulshekhar/ts-jest/compare/v27.0.4...v27.0.5) (2021-08-14)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **cli:** add migration `tsConfig` option for `ts-jest` config options ([#2794](https://github.com/kulshekhar/ts-jest/issues/2794)) ([781710b](https://github.com/kulshekhar/ts-jest/commit/781710bf6b84853fffbb02543062a726fe1ad9c2)), closes [#2764](https://github.com/kulshekhar/ts-jest/issues/2764)
16
+ * **cli:** fix `config:init` genarate invalid type comment ([#2773](https://github.com/kulshekhar/ts-jest/issues/2773)) ([ede8a20](https://github.com/kulshekhar/ts-jest/commit/ede8a2061e20b717c0d56e4d81a3cd0ec7db8b1a)), closes [#2772](https://github.com/kulshekhar/ts-jest/issues/2772)
17
+ * **config:** handle `./` in tsconfig `paths` for `pathsToModuleNameMapper` ([#2797](https://github.com/kulshekhar/ts-jest/issues/2797)) ([42ff5e4](https://github.com/kulshekhar/ts-jest/commit/42ff5e469fb5d315b92e85eee105e5a040949c01)), closes [#2709](https://github.com/kulshekhar/ts-jest/issues/2709)
18
+
19
+
20
+ ### Code Refactoring
21
+
22
+ * use native `Buffer.from` and `mkdird` ([#2774](https://github.com/kulshekhar/ts-jest/issues/2774)) ([4869660](https://github.com/kulshekhar/ts-jest/commit/4869660e3917deb063745c5acaf079123d6d2ca8))
23
+
24
+
25
+
26
+ ## [27.0.4](https://github.com/kulshekhar/ts-jest/compare/v27.0.3...v27.0.4) (2021-07-21)
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * 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))
32
+ * 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))
33
+ * **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)
34
+
35
+
36
+ ### Features
37
+
38
+ * 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))
39
+ * 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)
40
+
41
+
42
+
43
+ ## [27.0.3](https://github.com/kulshekhar/ts-jest/compare/v27.0.2...v27.0.3) (2021-06-06)
44
+
45
+
46
+ ### Bug Fixes
47
+
48
+ * 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))
49
+
50
+
51
+ ### Features
52
+
53
+ * 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)
54
+
55
+
56
+
1
57
  ## [27.0.2](https://github.com/kulshekhar/ts-jest/compare/v27.0.1...v27.0.2) (2021-05-30)
2
58
 
3
59
 
package/README.md CHANGED
@@ -6,9 +6,9 @@
6
6
  <a href="https://www.npmjs.com/package/ts-jest"><img src="https://img.shields.io/npm/v/ts-jest/latest.svg?style=flat-square" alt="NPM version" /> </a>
7
7
  <a href="https://www.npmjs.com/package/ts-jest"><img src="https://img.shields.io/npm/dm/ts-jest.svg?style=flat-square" alt="NPM downloads"/> </a>
8
8
  <a href="https://snyk.io/test/github/kulshekhar/ts-jest"><img src="https://snyk.io/test/github/kulshekhar/ts-jest/badge.svg?style=flat-square" alt="Known vulnerabilities"/> </a>
9
- <a href="https://coveralls.io/github/kulshekhar/ts-jest?branch=master"><img src="https://coveralls.io/repos/github/kulshekhar/ts-jest/badge.svg?branch=master" alt="Coverage status"/> </a>
10
- <a href="https://actions-badge.atrox.dev/kulshekhar/ts-jest/goto?ref=master"><img alt="GitHub actions" src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fkulshekhar%2Fts-jest%2Fbadge%3Fref%3Dmaster&style=flat-square" /> </a>
11
- <a href="https://github.com/kulshekhar/ts-jest/blob/master/LICENSE.md"><img src="https://img.shields.io/npm/l/ts-jest.svg?style=flat-square" alt="GitHub license"/> </a>
9
+ <a href="https://coveralls.io/github/kulshekhar/ts-jest?branch=main"><img src="https://coveralls.io/repos/github/kulshekhar/ts-jest/badge.svg?branch=main" alt="Coverage status"/> </a>
10
+ <a href="https://actions-badge.atrox.dev/kulshekhar/ts-jest/goto?ref=main"><img alt="GitHub actions" src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fkulshekhar%2Fts-jest%2Fbadge%3Fref%3Dmain&style=flat-square" /> </a>
11
+ <a href="https://github.com/kulshekhar/ts-jest/blob/main/LICENSE.md"><img src="https://img.shields.io/npm/l/ts-jest.svg?style=flat-square" alt="GitHub license"/> </a>
12
12
  </p>
13
13
 
14
14
  <img src="./icon.png" align="right" title="ts-jest Logo" width="128" height="128">
@@ -10,7 +10,7 @@ Cannot find module "" from ""
10
10
 
11
11
  - Check if `rootDir` is referenced correctly. If not add this on your existing jest configuration.
12
12
 
13
- ```javascipt
13
+ ```javascript
14
14
  module.exports = {
15
15
  ...
16
16
  roots: ["<rootDir>"]
@@ -19,7 +19,7 @@ module.exports = {
19
19
 
20
20
  - Check if module directories are included on your jest configuration. If not add this on your existing jest configuration.
21
21
 
22
- ```javascipt
22
+ ```javascript
23
23
  module.exports = {
24
24
  ...
25
25
  moduleDirectories: ["node_modules","<module-directory>"],
@@ -29,7 +29,7 @@ module.exports = {
29
29
 
30
30
  - Check if module name is properly mapped and can be referenced by jest. If not, you can define moduleNameMapper for your jest configuration.
31
31
 
32
- ```javascipt
32
+ ```javascript
33
33
  module.exports = {
34
34
  ...
35
35
  moduleNameMapper: {
@@ -39,3 +39,37 @@ module.exports = {
39
39
  ```
40
40
 
41
41
  - Check github folder names if its identical to you local folder names. Sometimes github never updates your folder names even if you rename it locally. If this happens rename your folders via github or use this command `git mv <source> <destination>` and commit changes.
42
+
43
+ ## Transform (node)-module explicitly
44
+
45
+ ### PROBLEM
46
+
47
+ SyntaxError: Cannot use import statement outside a module
48
+
49
+ ### SOLUTION
50
+
51
+ One of the node modules hasn't the correct syntax for Jests execution step. It needs to
52
+ be transformed first.
53
+
54
+ There is a good chance that the error message shows which module is affected:
55
+
56
+ ```shell
57
+ SyntaxError: Cannot use import statement outside a module
58
+ > 22 | import Component from "../../node_modules/some-module/lib";
59
+ | ^
60
+ ```
61
+
62
+ In this case **some-module** is the problem and needs to be transformed.
63
+ By adding the following line to the configuration file it will tell Jest which modules
64
+ shouldnt be ignored during the transformation step:
65
+
66
+ ```javascript
67
+ module.exports = {
68
+ ...
69
+ transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]
70
+ };
71
+ ```
72
+
73
+ **some-module** and **another-module** will be transformed.
74
+
75
+ For more information see [here](https://stackoverflow.com/questions/63389757/jest-unit-test-syntaxerror-cannot-use-import-statement-outside-a-module) and [here](https://stackoverflow.com/questions/52035066/how-to-write-jest-transformignorepatterns).
@@ -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 + "',");
@@ -107,7 +107,8 @@ var TsCompiler = (function () {
107
107
  var esModuleInterop = this._initialCompilerOptions.esModuleInterop;
108
108
  var allowSyntheticDefaultImports = this._initialCompilerOptions.allowSyntheticDefaultImports;
109
109
  var currentModuleKind = this._compilerOptions.module;
110
- if (options.supportsStaticESM && this.configSet.useESM) {
110
+ if ((this.configSet.babelJestTransformer || (!this.configSet.babelJestTransformer && options.supportsStaticESM)) &&
111
+ this.configSet.useESM) {
111
112
  moduleKind =
112
113
  !moduleKind ||
113
114
  (moduleKind &&
@@ -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');
@@ -42,8 +42,9 @@ var pathsToModuleNameMapper = function (mapping, _a) {
42
42
  }
43
43
  else if (segments.length === 2) {
44
44
  var paths = toPaths.map(function (target) {
45
+ var enrichedTarget = target.startsWith('./') && prefix !== '' ? target.substring(target.indexOf('/') + 1) : target;
45
46
  var enrichedPrefix = prefix !== '' && !prefix.endsWith('/') ? prefix + "/" : prefix;
46
- return "" + enrichedPrefix + target.replace(/\*/g, '$1');
47
+ return "" + enrichedPrefix + enrichedTarget.replace(/\*/g, '$1');
47
48
  });
48
49
  pattern = "^" + escapeRegex(segments[0]) + "(.*)" + escapeRegex(segments[1]) + "$";
49
50
  jestMap[pattern] = paths.length === 1 ? paths[0] : paths;
@@ -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;
@@ -31,14 +31,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
31
31
  to[j] = from[i];
32
32
  return to;
33
33
  };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
34
  Object.defineProperty(exports, "__esModule", { value: true });
38
35
  exports.TsJestTransformer = exports.CACHE_KEY_EL_SEPARATOR = void 0;
39
36
  var fs_1 = require("fs");
40
37
  var path_1 = require("path");
41
- var mkdirp_1 = __importDefault(require("mkdirp"));
42
38
  var ts_jest_compiler_1 = require("./compiler/ts-jest-compiler");
43
39
  var config_set_1 = require("./config/config-set");
44
40
  var constants_1 = require("./constants");
@@ -59,6 +55,7 @@ var TsJestTransformer = (function () {
59
55
  this.getCacheKey = this.getCacheKey.bind(this);
60
56
  this.process = this.process.bind(this);
61
57
  this._logger.debug('created new transformer');
58
+ process.env.TS_JEST = '1';
62
59
  }
63
60
  TsJestTransformer.prototype._configsFor = function (transformOptions) {
64
61
  var config = transformOptions.config, cacheFS = transformOptions.cacheFS;
@@ -209,7 +206,7 @@ var TsJestTransformer = (function () {
209
206
  TsJestTransformer.prototype._getFsCachedResolvedModules = function (configSet) {
210
207
  var cacheDir = configSet.tsCacheDir;
211
208
  if (!configSet.isolatedModules && cacheDir) {
212
- mkdirp_1.default.sync(cacheDir);
209
+ fs_1.mkdirSync(cacheDir, { recursive: true });
213
210
  this._tsResolvedModulesCachePath = path_1.join(cacheDir, sha1_1.sha1('ts-jest-resolved-modules', exports.CACHE_KEY_EL_SEPARATOR));
214
211
  try {
215
212
  var cachedTSResolvedModules = fs_1.readFileSync(this._tsResolvedModulesCachePath, 'utf-8');
@@ -56,6 +56,13 @@ var backportJestConfig = function (logger, config) {
56
56
  }
57
57
  delete tsJest.tsConfigFile;
58
58
  }
59
+ if ('tsConfig' in tsJest) {
60
+ warnConfig('globals.ts-jest.tsConfig', 'globals.ts-jest.tsconfig');
61
+ if (tsJest.tsConfig) {
62
+ mergeTsJest.tsconfig = tsJest.tsConfig;
63
+ }
64
+ delete tsJest.tsConfig;
65
+ }
59
66
  if ('enableTsDiagnostics' in tsJest) {
60
67
  warnConfig('globals.ts-jest.enableTsDiagnostics', 'globals.ts-jest.diagnostics');
61
68
  if (tsJest.enableTsDiagnostics) {
package/package.json CHANGED
@@ -1,16 +1,8 @@
1
1
  {
2
2
  "name": "ts-jest",
3
- "version": "27.0.2",
3
+ "version": "27.0.6",
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
- "./presets": "./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
  },
@@ -65,20 +57,32 @@
65
57
  "homepage": "https://kulshekhar.github.io/ts-jest",
66
58
  "dependencies": {
67
59
  "bs-logger": "0.x",
68
- "buffer-from": "1.x",
69
60
  "fast-json-stable-stringify": "2.x",
70
61
  "jest-util": "^27.0.0",
71
62
  "json5": "2.x",
72
- "lodash": "4.x",
63
+ "lodash.memoize": "4.x",
73
64
  "make-error": "1.x",
74
- "mkdirp": "1.x",
75
65
  "semver": "7.x",
76
66
  "yargs-parser": "20.x"
77
67
  },
78
68
  "peerDependencies": {
69
+ "@babel/core": ">=7.0.0-beta.0 <8",
70
+ "@types/jest": "^27.0.0",
71
+ "babel-jest": ">=27.0.0 <28",
79
72
  "jest": "^27.0.0",
80
73
  "typescript": ">=3.8 <5.0"
81
74
  },
75
+ "peerDependenciesMeta": {
76
+ "babel-jest": {
77
+ "optional": true
78
+ },
79
+ "@babel/core": {
80
+ "optional": true
81
+ },
82
+ "@types/jest": {
83
+ "optional": true
84
+ }
85
+ },
82
86
  "husky": {
83
87
  "hooks": {
84
88
  "pre-commit": "lint-staged",
@@ -87,21 +91,21 @@
87
91
  }
88
92
  },
89
93
  "devDependencies": {
90
- "@commitlint/cli": "12.x",
91
- "@commitlint/config-angular": "^12.0.0",
92
- "@jest/transform": "^27.0.0",
93
- "@jest/types": "^27.0.0",
94
+ "@commitlint/cli": "13.x",
95
+ "@commitlint/config-angular": "^13.1.0",
96
+ "@jest/transform": "^27.1.1",
97
+ "@jest/types": "^27.1.1",
94
98
  "@types/babel__core": "7.x",
95
- "@types/buffer-from": "latest",
96
99
  "@types/cross-spawn": "latest",
97
100
  "@types/fs-extra": "latest",
98
101
  "@types/jest": "latest",
99
102
  "@types/js-yaml": "latest",
100
- "@types/lodash": "4.x",
103
+ "@types/lodash.camelcase": "4.x",
104
+ "@types/lodash.memoize": "4.x",
105
+ "@types/lodash.set": "4.x",
101
106
  "@types/micromatch": "4.x",
102
- "@types/mkdirp": "latest",
103
- "@types/node": "14.14.43",
104
- "@types/node-fetch": "^2.5.8",
107
+ "@types/node": "16.10.9",
108
+ "@types/node-fetch": "^3.0.3",
105
109
  "@types/react": "17.x",
106
110
  "@types/semver": "latest",
107
111
  "@types/yargs": "latest",
@@ -122,15 +126,17 @@
122
126
  "glob": "^7.1.7",
123
127
  "glob-gitignore": "latest",
124
128
  "husky": "4.x",
125
- "jest": "^27.0.0",
129
+ "jest": "^27.1.1",
126
130
  "js-yaml": "latest",
127
131
  "json-schema-to-typescript": "^10.1.4",
128
132
  "lint-staged": "latest",
129
- "node-fetch": "^2.6.1",
133
+ "lodash.camelcase": "^4.3.0",
134
+ "lodash.set": "^4.3.2",
135
+ "node-fetch": "^3.0.0",
130
136
  "npm-run-all": "latest",
131
- "prettier": "2.3.0",
137
+ "prettier": "^2.4.0",
132
138
  "source-map": "latest",
133
- "typescript": "^4.1.2"
139
+ "typescript": "~4.2.4"
134
140
  },
135
141
  "lint-staged": {
136
142
  "*.{ts,tsx,js,jsx}": [