ts-jest 28.0.4 → 28.0.5

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
- 3ec913f3824bb3d8e0a11ca9d34fe5f15cb00d40
1
+ 60d8111ee0c613e292a844a081abf56c285c9036
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [28.0.5](https://github.com/kulshekhar/ts-jest/compare/v28.0.4...v28.0.5) (2022-06-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **legacy:** throw type check error in ESM mode with `reject` ([#3618](https://github.com/kulshekhar/ts-jest/issues/3618)) ([7dd01ff](https://github.com/kulshekhar/ts-jest/commit/7dd01ffe0c7ad3add87b11227964544f2586355a)), closes [#3507](https://github.com/kulshekhar/ts-jest/issues/3507)
7
+
8
+
9
+
1
10
  ## [28.0.4](https://github.com/kulshekhar/ts-jest/compare/v28.0.3...v28.0.4) (2022-06-02)
2
11
 
3
12
 
@@ -1,7 +1,7 @@
1
- import type { TransformedSource } from '@jest/transform';
2
1
  import { Logger } from 'bs-logger';
3
2
  import type { CompilerOptions, CustomTransformers, Program, TranspileOutput } from 'typescript';
4
3
  import type { StringMap, TsCompilerInstance, TsJestAstTransformer, TsJestCompileOptions, TTypeScript } from '../../types';
4
+ import { CompiledOutput } from '../../types';
5
5
  import type { ConfigSet } from '../config/config-set';
6
6
  export declare class TsCompiler implements TsCompilerInstance {
7
7
  readonly configSet: ConfigSet;
@@ -15,7 +15,7 @@ export declare class TsCompiler implements TsCompilerInstance {
15
15
  program: Program | undefined;
16
16
  constructor(configSet: ConfigSet, runtimeCacheFS: StringMap);
17
17
  getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[];
18
- getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): TransformedSource;
18
+ getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): CompiledOutput;
19
19
  protected _transpileOutput(fileContent: string, fileName: string): TranspileOutput;
20
20
  protected _makeTransformers(customTransformers: TsJestAstTransformer): CustomTransformers;
21
21
  }
@@ -107,10 +107,12 @@ var TsCompiler = (function () {
107
107
  return importedModulePaths;
108
108
  };
109
109
  TsCompiler.prototype.getCompiledOutput = function (fileContent, fileName, options) {
110
+ var e_1, _a;
110
111
  var moduleKind = this._initialCompilerOptions.module;
111
112
  var esModuleInterop = this._initialCompilerOptions.esModuleInterop;
112
113
  var allowSyntheticDefaultImports = this._initialCompilerOptions.allowSyntheticDefaultImports;
113
114
  var currentModuleKind = this._compilerOptions.module;
115
+ var isEsmMode = this.configSet.useESM && options.supportsStaticESM;
114
116
  if ((this.configSet.babelJestTransformer || (!this.configSet.babelJestTransformer && options.supportsStaticESM)) &&
115
117
  this.configSet.useESM) {
116
118
  moduleKind =
@@ -130,7 +132,33 @@ var TsCompiler = (function () {
130
132
  this._logger.debug({ fileName: fileName }, 'getCompiledOutput(): compiling using language service');
131
133
  this._updateMemoryCache(fileContent, fileName, currentModuleKind === moduleKind);
132
134
  var output = this._languageService.getEmitOutput(fileName);
133
- this._doTypeChecking(fileName, options.depGraphs, options.watchMode);
135
+ var diagnostics = this.getDiagnostics(fileName);
136
+ if (!isEsmMode && diagnostics.length) {
137
+ this.configSet.raiseDiagnostics(diagnostics, fileName, this._logger);
138
+ if (options.watchMode) {
139
+ this._logger.debug({ fileName: fileName }, '_doTypeChecking(): starting watch mode computing diagnostics');
140
+ try {
141
+ for (var _b = __values(options.depGraphs.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
142
+ var entry = _c.value;
143
+ var normalizedModuleNames = entry[1].resolvedModuleNames.map(function (moduleName) { return (0, path_1.normalize)(moduleName); });
144
+ var fileToReTypeCheck = entry[0];
145
+ if (normalizedModuleNames.includes(fileName) && this.configSet.shouldReportDiagnostics(fileToReTypeCheck)) {
146
+ this._logger.debug({ fileToReTypeCheck: fileToReTypeCheck }, '_doTypeChecking(): computing diagnostics using language service');
147
+ this._updateMemoryCache(this._getFileContentFromCache(fileToReTypeCheck), fileToReTypeCheck);
148
+ var importedModulesDiagnostics = __spreadArray(__spreadArray([], __read(this._languageService.getSemanticDiagnostics(fileToReTypeCheck)), false), __read(this._languageService.getSyntacticDiagnostics(fileToReTypeCheck)), false);
149
+ this.configSet.raiseDiagnostics(importedModulesDiagnostics, fileName, this._logger);
150
+ }
151
+ }
152
+ }
153
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
154
+ finally {
155
+ try {
156
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
157
+ }
158
+ finally { if (e_1) throw e_1.error; }
159
+ }
160
+ }
161
+ }
134
162
  if (output.emitSkipped) {
135
163
  if (constants_1.TS_TSX_REGEX.test(fileName)) {
136
164
  throw new Error((0, messages_1.interpolate)("Unable to process '{{file}}', please make sure that `outDir` in your tsconfig is neither `''` or `'.'`. You can also configure Jest config option `transformIgnorePatterns` to inform `ts-jest` to transform {{file}}", { file: fileName }));
@@ -151,9 +179,11 @@ var TsCompiler = (function () {
151
179
  return this._compilerOptions.sourceMap
152
180
  ? {
153
181
  code: (0, compiler_utils_1.updateOutput)(outputFiles[1].text, fileName, outputFiles[0].text),
182
+ diagnostics: diagnostics,
154
183
  }
155
184
  : {
156
185
  code: (0, compiler_utils_1.updateOutput)(outputFiles[0].text, fileName),
186
+ diagnostics: diagnostics,
157
187
  };
158
188
  }
159
189
  else {
@@ -191,6 +221,7 @@ var TsCompiler = (function () {
191
221
  };
192
222
  TsCompiler.prototype._createLanguageService = function () {
193
223
  var _this = this;
224
+ var _a;
194
225
  this._parsedTsConfig.fileNames
195
226
  .filter(function (fileName) { return constants_1.TS_TSX_REGEX.test(fileName) && !_this.configSet.isTestFile(fileName); })
196
227
  .forEach(function (fileName) { return _this._fileVersionCache.set(fileName, 0); });
@@ -220,7 +251,7 @@ var TsCompiler = (function () {
220
251
  return _this._ts.ScriptSnapshot.fromString(contents);
221
252
  },
222
253
  fileExists: (0, lodash_memoize_1.default)(this._ts.sys.fileExists),
223
- readFile: this._cachedReadFile,
254
+ readFile: (_a = this._cachedReadFile) !== null && _a !== void 0 ? _a : this._ts.sys.readFile,
224
255
  readDirectory: (0, lodash_memoize_1.default)(this._ts.sys.readDirectory),
225
256
  getDirectories: (0, lodash_memoize_1.default)(this._ts.sys.getDirectories),
226
257
  directoryExists: (0, lodash_memoize_1.default)(this._ts.sys.directoryExists),
@@ -290,36 +321,13 @@ var TsCompiler = (function () {
290
321
  if (shouldIncrementProjectVersion)
291
322
  this._projectVersion++;
292
323
  };
293
- TsCompiler.prototype._doTypeChecking = function (fileName, depGraphs, watchMode) {
294
- var e_1, _a;
324
+ TsCompiler.prototype.getDiagnostics = function (fileName) {
325
+ var diagnostics = [];
295
326
  if (this.configSet.shouldReportDiagnostics(fileName)) {
296
327
  this._logger.debug({ fileName: fileName }, '_doTypeChecking(): computing diagnostics using language service');
297
- var diagnostics = __spreadArray(__spreadArray([], __read(this._languageService.getSemanticDiagnostics(fileName)), false), __read(this._languageService.getSyntacticDiagnostics(fileName)), false);
298
- this.configSet.raiseDiagnostics(diagnostics, fileName, this._logger);
299
- }
300
- if (watchMode) {
301
- this._logger.debug({ fileName: fileName }, '_doTypeChecking(): starting watch mode computing diagnostics');
302
- try {
303
- for (var _b = __values(depGraphs.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
304
- var entry = _c.value;
305
- var normalizedModuleNames = entry[1].resolvedModuleNames.map(function (moduleName) { return (0, path_1.normalize)(moduleName); });
306
- var fileToReTypeCheck = entry[0];
307
- if (normalizedModuleNames.includes(fileName) && this.configSet.shouldReportDiagnostics(fileToReTypeCheck)) {
308
- this._logger.debug({ fileToReTypeCheck: fileToReTypeCheck }, '_doTypeChecking(): computing diagnostics using language service');
309
- this._updateMemoryCache(this._getFileContentFromCache(fileToReTypeCheck), fileToReTypeCheck);
310
- var importedModulesDiagnostics = __spreadArray(__spreadArray([], __read(this._languageService.getSemanticDiagnostics(fileToReTypeCheck)), false), __read(this._languageService.getSyntacticDiagnostics(fileToReTypeCheck)), false);
311
- this.configSet.raiseDiagnostics(importedModulesDiagnostics, fileName, this._logger);
312
- }
313
- }
314
- }
315
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
316
- finally {
317
- try {
318
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
319
- }
320
- finally { if (e_1) throw e_1.error; }
321
- }
328
+ diagnostics.push.apply(diagnostics, __spreadArray(__spreadArray([], __read(this._languageService.getSemanticDiagnostics(fileName)), false), __read(this._languageService.getSyntacticDiagnostics(fileName)), false));
322
329
  }
330
+ return diagnostics;
323
331
  };
324
332
  return TsCompiler;
325
333
  }());
@@ -1,9 +1,8 @@
1
- import type { TransformedSource } from '@jest/transform';
2
- import type { CompilerInstance, StringMap, TsJestCompileOptions } from '../../types';
1
+ import type { CompilerInstance, CompiledOutput, StringMap, TsJestCompileOptions } from '../../types';
3
2
  import type { ConfigSet } from '../config/config-set';
4
3
  export declare class TsJestCompiler implements CompilerInstance {
5
4
  private readonly _compilerInstance;
6
5
  constructor(configSet: ConfigSet, runtimeCacheFS: StringMap);
7
6
  getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[];
8
- getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): TransformedSource;
7
+ getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): CompiledOutput;
9
8
  }
@@ -457,7 +457,7 @@ var ConfigSet = (function () {
457
457
  });
458
458
  if (!filteredDiagnostics.length)
459
459
  return;
460
- var error = this._createTsError(filteredDiagnostics);
460
+ var error = this.createTsError(filteredDiagnostics);
461
461
  var importantCategories = [DiagnosticCategory.Warning, DiagnosticCategory.Error];
462
462
  if (this._diagnostics.throws && filteredDiagnostics.some(function (d) { return importantCategories.includes(d.category); })) {
463
463
  throw error;
@@ -470,7 +470,7 @@ var ConfigSet = (function () {
470
470
  ? this.parsedTsConfig.options.checkJs && !this._shouldIgnoreDiagnosticsForFile(filePath)
471
471
  : !this._shouldIgnoreDiagnosticsForFile(filePath);
472
472
  };
473
- ConfigSet.prototype._createTsError = function (diagnostics) {
473
+ ConfigSet.prototype.createTsError = function (diagnostics) {
474
474
  var _this = this;
475
475
  var formatDiagnostics = this._diagnostics.pretty
476
476
  ? this.compilerModule.formatDiagnosticsWithColorAndContext
@@ -157,7 +157,9 @@ var TsJestTransformer = (function () {
157
157
  var configs = this._configsFor(transformOptions);
158
158
  var shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
159
159
  var babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
160
- var result = this.processWithTs(sourceText, sourcePath, transformOptions);
160
+ var result = {
161
+ code: this.processWithTs(sourceText, sourcePath, transformOptions).code,
162
+ };
161
163
  if (babelJest) {
162
164
  this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
163
165
  result = babelJest.process(result.code, sourcePath, __assign(__assign({}, transformOptions), { instrument: false }));
@@ -170,21 +172,28 @@ var TsJestTransformer = (function () {
170
172
  var _this = this;
171
173
  return __generator(this, function (_a) {
172
174
  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) {
175
+ return [2, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
176
+ var configs, shouldStringifyContent, babelJest, result, processWithTsResult;
177
+ var _a;
178
+ return __generator(this, function (_b) {
179
+ switch (_b.label) {
177
180
  case 0:
178
181
  configs = this._configsFor(transformOptions);
179
182
  shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
180
183
  babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
181
- result = this.processWithTs(sourceText, sourcePath, transformOptions);
184
+ processWithTsResult = this.processWithTs(sourceText, sourcePath, transformOptions);
185
+ result = {
186
+ code: processWithTsResult.code,
187
+ };
188
+ if ((_a = processWithTsResult.diagnostics) === null || _a === void 0 ? void 0 : _a.length) {
189
+ reject(configs.createTsError(processWithTsResult.diagnostics));
190
+ }
182
191
  if (!babelJest) return [3, 2];
183
192
  this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
184
193
  return [4, babelJest.processAsync(result.code, sourcePath, __assign(__assign({}, transformOptions), { instrument: false }))];
185
194
  case 1:
186
- result = _a.sent();
187
- _a.label = 2;
195
+ result = _b.sent();
196
+ _b.label = 2;
188
197
  case 2:
189
198
  result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
190
199
  resolve(result);
@@ -292,9 +301,8 @@ var TsJestTransformer = (function () {
292
301
  };
293
302
  TsJestTransformer.prototype.getCacheKeyAsync = function (sourceText, sourcePath, transformOptions) {
294
303
  return __awaiter(this, void 0, void 0, function () {
295
- var _this = this;
296
304
  return __generator(this, function (_a) {
297
- return [2, new Promise(function (resolve) { return resolve(_this.getCacheKey(sourceText, sourcePath, transformOptions)); })];
305
+ return [2, Promise.resolve(this.getCacheKey(sourceText, sourcePath, transformOptions))];
298
306
  });
299
307
  });
300
308
  };
package/dist/types.d.ts CHANGED
@@ -79,9 +79,12 @@ export interface TsJestCompileOptions {
79
79
  watchMode: boolean;
80
80
  supportsStaticESM: boolean;
81
81
  }
82
+ export interface CompiledOutput extends TransformedSource {
83
+ diagnostics?: _ts.Diagnostic[];
84
+ }
82
85
  export interface CompilerInstance {
83
86
  getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[];
84
- getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): TransformedSource;
87
+ getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): CompiledOutput;
85
88
  }
86
89
  export interface TsCompilerInstance extends CompilerInstance {
87
90
  configSet: ConfigSet;
package/globals.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ declare global {
2
+ const beforeAll: typeof import('@jest/globals').beforeAll
3
+ const beforeEach: typeof import('@jest/globals').beforeEach
4
+ const afterAll: typeof import('@jest/globals').afterAll
5
+ const afterEach: typeof import('@jest/globals').afterEach
6
+ const describe: typeof import('@jest/globals').describe
7
+ const fdescribe: typeof import('@jest/globals').fdescribe
8
+ const xdescribe: typeof import('@jest/globals').xdescribe
9
+ const it: typeof import('@jest/globals').it
10
+ const fit: typeof import('@jest/globals').fit
11
+ const xit: typeof import('@jest/globals').xit
12
+ const test: typeof import('@jest/globals').test
13
+ const xtest: typeof import('@jest/globals').xtest
14
+ const expect: typeof import('@jest/globals').expect
15
+ const jest: typeof import('@jest/globals').jest
16
+ }
17
+
18
+ export {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-jest",
3
- "version": "28.0.4",
3
+ "version": "28.0.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "bin": {
@@ -58,7 +58,7 @@
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": "^21.0.1"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "@babel/core": ">=7.0.0-beta.0 <8",
@@ -87,12 +87,11 @@
87
87
  "devDependencies": {
88
88
  "@commitlint/cli": "17.x",
89
89
  "@commitlint/config-angular": "^17.0.0",
90
- "@jest/transform": "^28.0.0",
91
- "@jest/types": "^28.0.0",
90
+ "@jest/transform": "^28.1.1",
91
+ "@jest/types": "^28.1.1",
92
92
  "@types/babel__core": "7.x",
93
93
  "@types/cross-spawn": "latest",
94
94
  "@types/fs-extra": "latest",
95
- "@types/jest": "^27.0.3",
96
95
  "@types/js-yaml": "latest",
97
96
  "@types/lodash.camelcase": "4.x",
98
97
  "@types/lodash.memoize": "4.x",
@@ -104,13 +103,14 @@
104
103
  "@types/rimraf": "^3.0.2",
105
104
  "@types/semver": "latest",
106
105
  "@types/yargs": "latest",
107
- "@types/yargs-parser": "20.x",
108
- "@typescript-eslint/eslint-plugin": "^5.3.0",
109
- "@typescript-eslint/parser": "^5.3.0",
106
+ "@types/yargs-parser": "21.x",
107
+ "@typescript-eslint/eslint-plugin": "^5.27.1",
108
+ "@typescript-eslint/parser": "^5.27.1",
109
+ "babel-jest": "^28.1.1",
110
110
  "conventional-changelog-cli": "2.x",
111
111
  "cross-spawn": "latest",
112
- "esbuild": "~0.14.42",
113
- "eslint": "^8.4.1",
112
+ "esbuild": "~0.14.43",
113
+ "eslint": "^8.17.0",
114
114
  "eslint-config-prettier": "latest",
115
115
  "eslint-plugin-import": "latest",
116
116
  "eslint-plugin-jest": "latest",
@@ -122,16 +122,16 @@
122
122
  "glob": "^8.0.3",
123
123
  "glob-gitignore": "latest",
124
124
  "husky": "4.x",
125
- "jest": "^28.0.0",
125
+ "jest": "^28.1.1",
126
126
  "jest-snapshot-serializer-raw": "^1.2.0",
127
127
  "js-yaml": "latest",
128
- "json-schema-to-typescript": "^10.1.4",
128
+ "json-schema-to-typescript": "^10.1.5",
129
129
  "lint-staged": "latest",
130
130
  "lodash.camelcase": "^4.3.0",
131
131
  "lodash.set": "^4.3.2",
132
- "node-fetch": "^3.0.0",
133
- "prettier": "^2.4.0",
134
- "typescript": "~4.6.2"
132
+ "node-fetch": "^3.2.6",
133
+ "prettier": "^2.6.2",
134
+ "typescript": "~4.7.3"
135
135
  },
136
136
  "lint-staged": {
137
137
  "*.{ts,tsx,js,jsx}": [
package/renovate.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "extends": [
3
- ":dependencyDashboard",
4
3
  "group:babelMonorepo",
5
4
  "group:commitlintMonorepo",
6
5
  "group:docusaurusMonorepo",
7
6
  ":prHourlyLimit2",
8
- "workarounds:all"
7
+ "workarounds:all",
8
+ "helpers:pinGitHubActionDigests"
9
9
  ],
10
10
  "timezone": "UTC",
11
11
  "rangeStrategy": "bump",
@@ -53,10 +53,7 @@
53
53
  },
54
54
  {
55
55
  "matchPaths": ["e2e/**"],
56
- "matchPackageNames": [
57
- "react",
58
- "react-intl"
59
- ],
56
+ "matchPackagePatterns": ["react"],
60
57
  "groupName": "React e2e packages",
61
58
  "enabled": true
62
59
  },