ts-jest 26.4.3 → 26.5.1
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 +1 -1
- package/CHANGELOG.md +43 -0
- package/README.md +12 -10
- package/dist/cli/config/init.js +3 -2
- package/dist/cli/config/migrate.js +3 -2
- package/dist/compiler/language-service.js +1 -1
- package/dist/config/config-set.d.ts +3 -1
- package/dist/config/config-set.js +38 -37
- package/dist/presets/create-jest-preset.d.ts +1 -1
- package/dist/ts-jest-transformer.d.ts +1 -2
- package/dist/ts-jest-transformer.js +46 -43
- package/dist/types.d.ts +10 -0
- package/dist/utils/testing.d.ts +11 -12
- package/package.json +8 -12
- package/presets/index.d.ts +8 -0
package/.ts-jest-digest
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
ce4f21820adc1fe82ffa3a6379b75d5e66b7b8f1
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
+
## [26.5.1](https://github.com/kulshekhar/ts-jest/compare/v26.5.0...v26.5.1) (2021-02-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **config:** support typed config options for jest config typescript ([#2336](https://github.com/kulshekhar/ts-jest/issues/2336)) ([f4f5d32](https://github.com/kulshekhar/ts-jest/commit/f4f5d3205d1c80e545a32c02c6a66e7e91386f7f))
|
|
7
|
+
* **presets:** add typing for `presets` entry point ([#2341](https://github.com/kulshekhar/ts-jest/issues/2341)) ([e12b004](https://github.com/kulshekhar/ts-jest/commit/e12b004dcc5848d5ae0638e885147c54e11cc72b)), closes [#2325](https://github.com/kulshekhar/ts-jest/issues/2325)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# [26.5.0](https://github.com/kulshekhar/ts-jest/compare/v26.5.0...v26.4.4) (2021-01-29)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* reduce size of `node_modules` when adding `ts-jest` ([#2309](https://github.com/kulshekhar/ts-jest/issues/2309)) ([6bf2e8a](https://github.com/kulshekhar/ts-jest/commit/b8d5d2090567f23947d9efd87f5f869b16bf2e8a))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* introduce `exclude` to exclude files from diagnostics ([#2308](https://github.com/kulshekhar/ts-jest/issues/2308)) ([cd82fd3](https://github.com/kulshekhar/ts-jest/commit/0c555c250774a7fd9e356cf20a3d8b693cd82fd3))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### DEPRECATIONS
|
|
25
|
+
|
|
26
|
+
* **config**: deprecate `pathRegex` in favor of `exclude` ([#2308](https://github.com/kulshekhar/ts-jest/issues/2308)) ([cd82fd3](https://github.com/kulshekhar/ts-jest/commit/0c555c250774a7fd9e356cf20a3d8b693cd82fd3))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [26.4.4](https://github.com/kulshekhar/ts-jest/compare/v26.4.3...v26.4.4) (2020-11-08)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* revert usage of `@jest/create-cache-key-function` ([#2108](https://github.com/kulshekhar/ts-jest/issues/2108)) ([dee8231](https://github.com/kulshekhar/ts-jest/commit/dee823172ce1e8eb9e0b2dd3aeed1ab4033bd0d9)), closes [#2080](https://github.com/kulshekhar/ts-jest/issues/2080) [#2090](https://github.com/kulshekhar/ts-jest/issues/2090) [#2104](https://github.com/kulshekhar/ts-jest/issues/2104)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Features
|
|
39
|
+
|
|
40
|
+
* **testing:** expose all types for util `mocked` ([#2096](https://github.com/kulshekhar/ts-jest/issues/2096)) ([b1d072b](https://github.com/kulshekhar/ts-jest/commit/b1d072b52b9a7665b3a6914b0895f84f6ee3f8c0)), closes [#2086](https://github.com/kulshekhar/ts-jest/issues/2086)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
1
44
|
## [26.4.3](https://github.com/kulshekhar/ts-jest/compare/v26.4.2...v26.4.3) (2020-10-26)
|
|
2
45
|
|
|
3
46
|
|
package/README.md
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">ts-jest</h1>
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://npmjs.org/package/ts-jest)
|
|
5
|
-
[](https://snyk.io/test/github/kulshekhar/ts-jest)
|
|
6
|
-
[](https://coveralls.io/github/kulshekhar/ts-jest?branch=master)
|
|
7
|
-
[](https://travis-ci.com/kulshekhar/ts-jest)
|
|
8
|
-
[](https://github.com/kulshekhar/ts-jest/actions)
|
|
9
|
-
[](https://github.com/kulshekhar/ts-jest/actions)
|
|
3
|
+
<p align="center">A TypeScript preprocessor with source map support for Jest that lets you use Jest to test projects written in TypeScript.</p>
|
|
10
4
|
|
|
11
|
-
<
|
|
5
|
+
<p align="center">
|
|
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
|
+
<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
|
+
<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://travis-ci.com/kulshekhar/ts-jest"><img src="https://travis-ci.com/kulshekhar/ts-jest.svg?branch=master" alt="Build status"/> </a>
|
|
11
|
+
<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>
|
|
12
|
+
<a href="https://github.com/kulshekhar/ts-jest/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/ts-jest.svg?style=flat-square" alt="GitHub license"/> </a>
|
|
13
|
+
</p>
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
<img src="./icon.png" align="right" title="ts-jest Logo" width="128" height="128">
|
|
14
16
|
|
|
15
17
|
It supports all features of TypeScript including type-checking. [Read more about Babel7 + `preset-typescript` **vs** TypeScript (and `ts-jest`)](https://kulshekhar.github.io/ts-jest/user/babel7-or-ts).
|
|
16
18
|
|
package/dist/cli/config/init.js
CHANGED
|
@@ -54,8 +54,9 @@ var path_1 = require("path");
|
|
|
54
54
|
var presets_1 = require("../helpers/presets");
|
|
55
55
|
exports.run = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
56
56
|
var file, filePath, name, isPackage, exists, pkgFile, hasPackage, _a, jestPreset, askedTsconfig, force, jsdom, tsconfig, pkgJson, jsFilesProcessor, shouldPostProcessWithBabel, preset, body, base, tsJestConf, content;
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
var _b, _c;
|
|
58
|
+
return __generator(this, function (_d) {
|
|
59
|
+
file = (_c = (_b = args._[0]) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : 'jest.config.js';
|
|
59
60
|
filePath = path_1.join(process.cwd(), file);
|
|
60
61
|
name = path_1.basename(file);
|
|
61
62
|
isPackage = name === 'package.json';
|
|
@@ -66,9 +66,10 @@ var backports_1 = require("../../utils/backports");
|
|
|
66
66
|
var presets_1 = require("../helpers/presets");
|
|
67
67
|
exports.run = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
68
68
|
var nullLogger, file, filePath, footNotes, name, isPackage, actualConfig, migratedConfig, presetName, preset, jsTransformers, jsWithTs, jsWithBabel, presetValue, migratedValue, presetValue, migratedValue, before, after, stringify, prefix;
|
|
69
|
-
|
|
69
|
+
var _a;
|
|
70
|
+
return __generator(this, function (_b) {
|
|
70
71
|
nullLogger = bs_logger_1.createLogger({ targets: [] });
|
|
71
|
-
file = args._[0];
|
|
72
|
+
file = (_a = args._[0]) === null || _a === void 0 ? void 0 : _a.toString();
|
|
72
73
|
filePath = path_1.resolve(process.cwd(), file);
|
|
73
74
|
footNotes = [];
|
|
74
75
|
if (!fs_1.existsSync(filePath)) {
|
|
@@ -71,7 +71,7 @@ exports.initializeLanguageServiceInstance = void 0;
|
|
|
71
71
|
var bs_logger_1 = require("bs-logger");
|
|
72
72
|
var fs_1 = require("fs");
|
|
73
73
|
var path_1 = require("path");
|
|
74
|
-
var memoize = require("lodash
|
|
74
|
+
var memoize = require("lodash/memoize");
|
|
75
75
|
var mkdirp = require("mkdirp");
|
|
76
76
|
var constants_1 = require("../constants");
|
|
77
77
|
var messages_1 = require("../utils/messages");
|
|
@@ -3,6 +3,8 @@ import { Logger } from 'bs-logger';
|
|
|
3
3
|
import { CompilerOptions, CustomTransformers, Diagnostic, ParsedCommandLine } from 'typescript';
|
|
4
4
|
import type { TTypeScript } from '../types';
|
|
5
5
|
export declare class ConfigSet {
|
|
6
|
+
private readonly jestConfig;
|
|
7
|
+
private readonly parentLogger?;
|
|
6
8
|
readonly logger: Logger;
|
|
7
9
|
readonly compilerModule: TTypeScript;
|
|
8
10
|
readonly isolatedModules: boolean;
|
|
@@ -15,7 +17,7 @@ export declare class ConfigSet {
|
|
|
15
17
|
constructor(jestConfig: Config.ProjectConfig, parentLogger?: Logger | undefined);
|
|
16
18
|
protected _resolveTsConfig(compilerOptions?: CompilerOptions, resolvedConfigFile?: string): Record<string, any>;
|
|
17
19
|
get tsJestDigest(): string;
|
|
18
|
-
|
|
20
|
+
isTestFile(fileName: string): boolean;
|
|
19
21
|
shouldStringifyContent(filePath: string): boolean;
|
|
20
22
|
raiseDiagnostics(diagnostics: Diagnostic[], filePath?: string, logger?: Logger): void;
|
|
21
23
|
shouldReportDiagnostics(filePath: string): boolean;
|
|
@@ -117,8 +117,8 @@ var toDiagnosticCodeList = function (items, into) {
|
|
|
117
117
|
};
|
|
118
118
|
var ConfigSet = (function () {
|
|
119
119
|
function ConfigSet(jestConfig, parentLogger) {
|
|
120
|
-
var _a;
|
|
121
|
-
var
|
|
120
|
+
var _a, _b;
|
|
121
|
+
var _c, _d, _e, _f;
|
|
122
122
|
this.jestConfig = jestConfig;
|
|
123
123
|
this.parentLogger = parentLogger;
|
|
124
124
|
this.customTransformers = Object.create(null);
|
|
@@ -141,16 +141,23 @@ var ConfigSet = (function () {
|
|
|
141
141
|
this.logger = this.parentLogger
|
|
142
142
|
? this.parentLogger.child((_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'config', _a))
|
|
143
143
|
: logger_1.rootLogger.child({ namespace: 'config' });
|
|
144
|
-
this.cwd = path_1.normalize((
|
|
145
|
-
this.rootDir = path_1.normalize((
|
|
144
|
+
this.cwd = path_1.normalize((_c = this.jestConfig.cwd) !== null && _c !== void 0 ? _c : process.cwd());
|
|
145
|
+
this.rootDir = path_1.normalize((_d = this.jestConfig.rootDir) !== null && _d !== void 0 ? _d : this.cwd);
|
|
146
146
|
var tsJestCfg = this.jestConfig.globals && this.jestConfig.globals['ts-jest'];
|
|
147
147
|
var options = tsJestCfg !== null && tsJestCfg !== void 0 ? tsJestCfg : Object.create(null);
|
|
148
|
-
this.compilerModule = importer_1.importer.typescript("Using \"ts-jest\" requires this package to be installed.", (
|
|
149
|
-
this.isolatedModules = (
|
|
148
|
+
this.compilerModule = importer_1.importer.typescript("Using \"ts-jest\" requires this package to be installed.", (_e = options.compiler) !== null && _e !== void 0 ? _e : 'typescript');
|
|
149
|
+
this.isolatedModules = (_f = options.isolatedModules) !== null && _f !== void 0 ? _f : false;
|
|
150
150
|
this.logger.debug({ compilerModule: this.compilerModule }, 'normalized compiler module config via ts-jest option');
|
|
151
151
|
this._backportJestCfg();
|
|
152
152
|
this._setupTsJestCfg(options);
|
|
153
153
|
this._resolveTsCacheDir();
|
|
154
|
+
this._matchablePatterns = __spread(this._jestCfg.testMatch, this._jestCfg.testRegex).filter(function (pattern) {
|
|
155
|
+
return pattern instanceof RegExp || typeof pattern === 'string';
|
|
156
|
+
});
|
|
157
|
+
if (!this._matchablePatterns.length) {
|
|
158
|
+
(_b = this._matchablePatterns).push.apply(_b, __spread(constants_1.DEFAULT_JEST_TEST_MATCH));
|
|
159
|
+
}
|
|
160
|
+
this._matchTestFilePath = jest_util_1.globsToMatcher(this._matchablePatterns.filter(function (pattern) { return typeof pattern === 'string'; }));
|
|
154
161
|
}
|
|
155
162
|
ConfigSet.prototype._backportJestCfg = function () {
|
|
156
163
|
var config = backports_1.backportJestConfig(this.logger, this.jestConfig);
|
|
@@ -159,7 +166,7 @@ var ConfigSet = (function () {
|
|
|
159
166
|
};
|
|
160
167
|
ConfigSet.prototype._setupTsJestCfg = function (options) {
|
|
161
168
|
var _this = this;
|
|
162
|
-
var _a, _b, _c;
|
|
169
|
+
var _a, _b, _c, _d;
|
|
163
170
|
if (options.packageJson) {
|
|
164
171
|
this.logger.warn("The option `packageJson` is deprecated and will be removed in ts-jest 27. This option is not used by internal `ts-jest`");
|
|
165
172
|
}
|
|
@@ -203,23 +210,36 @@ var ConfigSet = (function () {
|
|
|
203
210
|
}
|
|
204
211
|
this._diagnostics = {
|
|
205
212
|
pretty: (_b = diagnosticsOpt.pretty) !== null && _b !== void 0 ? _b : true,
|
|
213
|
+
exclude: (_c = diagnosticsOpt.exclude) !== null && _c !== void 0 ? _c : [],
|
|
206
214
|
ignoreCodes: toDiagnosticCodeList(ignoreList),
|
|
207
|
-
pathRegex: normalizeRegex(diagnosticsOpt.pathRegex),
|
|
208
215
|
throws: !diagnosticsOpt.warnOnly,
|
|
209
216
|
};
|
|
217
|
+
if (diagnosticsOpt.pathRegex) {
|
|
218
|
+
this.logger.warn("The option `pathRegex` is deprecated and will be removed in ts-jest 27, use `exclude` instead");
|
|
219
|
+
this._diagnostics = __assign(__assign({}, this._diagnostics), { pathRegex: normalizeRegex(diagnosticsOpt.pathRegex) });
|
|
220
|
+
}
|
|
210
221
|
}
|
|
211
222
|
else {
|
|
212
223
|
this._diagnostics = {
|
|
213
224
|
ignoreCodes: diagnosticsOpt ? toDiagnosticCodeList(ignoreList) : [],
|
|
225
|
+
exclude: [],
|
|
214
226
|
pretty: true,
|
|
215
227
|
throws: diagnosticsOpt,
|
|
216
228
|
};
|
|
217
229
|
}
|
|
230
|
+
if (this._diagnostics.pathRegex && !this._diagnostics.exclude.length) {
|
|
231
|
+
this._shouldGetDiagnosticsForFile = new RegExp(this._diagnostics.pathRegex);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
this._shouldGetDiagnosticsForFile = this._diagnostics.exclude.length
|
|
235
|
+
? jest_util_1.globsToMatcher(this._diagnostics.exclude)
|
|
236
|
+
: function () { return true; };
|
|
237
|
+
}
|
|
218
238
|
this.logger.debug({ diagnostics: this._diagnostics }, 'normalized diagnostics config via ts-jest option');
|
|
219
239
|
if (options.tsConfig) {
|
|
220
240
|
this.logger.warn("The option `tsConfig` is deprecated and will be removed in ts-jest 27, use `tsconfig` instead");
|
|
221
241
|
}
|
|
222
|
-
var tsconfigOpt = (
|
|
242
|
+
var tsconfigOpt = (_d = options.tsConfig) !== null && _d !== void 0 ? _d : options.tsconfig;
|
|
223
243
|
var configFilePath = typeof tsconfigOpt === 'string' ? this.resolvePath(tsconfigOpt) : undefined;
|
|
224
244
|
this.parsedTsConfig = this._resolveTsConfig(typeof tsconfigOpt === 'object' ? tsconfigOpt : undefined, configFilePath);
|
|
225
245
|
this.raiseDiagnostics(this.parsedTsConfig.errors, configFilePath);
|
|
@@ -411,23 +431,12 @@ var ConfigSet = (function () {
|
|
|
411
431
|
enumerable: false,
|
|
412
432
|
configurable: true
|
|
413
433
|
});
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
matchablePatterns.push.apply(matchablePatterns, __spread(constants_1.DEFAULT_JEST_TEST_MATCH));
|
|
421
|
-
}
|
|
422
|
-
var stringPatterns = matchablePatterns.filter(function (pattern) { return typeof pattern === 'string'; });
|
|
423
|
-
var isMatch = jest_util_1.globsToMatcher(stringPatterns);
|
|
424
|
-
return function (fileName) {
|
|
425
|
-
return matchablePatterns.some(function (pattern) { return (typeof pattern === 'string' ? isMatch(fileName) : pattern.test(fileName)); });
|
|
426
|
-
};
|
|
427
|
-
},
|
|
428
|
-
enumerable: false,
|
|
429
|
-
configurable: true
|
|
430
|
-
});
|
|
434
|
+
ConfigSet.prototype.isTestFile = function (fileName) {
|
|
435
|
+
var _this = this;
|
|
436
|
+
return this._matchablePatterns.some(function (pattern) {
|
|
437
|
+
return typeof pattern === 'string' ? _this._matchTestFilePath(fileName) : pattern.test(fileName);
|
|
438
|
+
});
|
|
439
|
+
};
|
|
431
440
|
ConfigSet.prototype.shouldStringifyContent = function (filePath) {
|
|
432
441
|
return this._stringifyContentRegExp ? this._stringifyContentRegExp.test(filePath) : false;
|
|
433
442
|
};
|
|
@@ -454,14 +463,9 @@ var ConfigSet = (function () {
|
|
|
454
463
|
logger ? logger.warn({ error: error }, error.message) : this.logger.warn({ error: error }, error.message);
|
|
455
464
|
};
|
|
456
465
|
ConfigSet.prototype.shouldReportDiagnostics = function (filePath) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
return regex.test(filePath);
|
|
461
|
-
}
|
|
462
|
-
else {
|
|
463
|
-
return true;
|
|
464
|
-
}
|
|
466
|
+
return this._shouldGetDiagnosticsForFile instanceof RegExp
|
|
467
|
+
? this._shouldGetDiagnosticsForFile.test(filePath)
|
|
468
|
+
: this._shouldGetDiagnosticsForFile(filePath);
|
|
465
469
|
};
|
|
466
470
|
ConfigSet.prototype._createTsError = function (diagnostics) {
|
|
467
471
|
var _this = this;
|
|
@@ -518,9 +522,6 @@ var ConfigSet = (function () {
|
|
|
518
522
|
__decorate([
|
|
519
523
|
memoize_1.Memoize()
|
|
520
524
|
], ConfigSet.prototype, "hooks", null);
|
|
521
|
-
__decorate([
|
|
522
|
-
memoize_1.Memoize()
|
|
523
|
-
], ConfigSet.prototype, "isTestFile", null);
|
|
524
525
|
return ConfigSet;
|
|
525
526
|
}());
|
|
526
527
|
exports.ConfigSet = ConfigSet;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Config } from '@jest/types';
|
|
2
|
-
|
|
2
|
+
import type { TsJestPresets } from '../types';
|
|
3
3
|
interface CreateJestPresetOptions {
|
|
4
4
|
allowJs?: boolean;
|
|
5
5
|
}
|
|
@@ -5,9 +5,8 @@ import { ConfigSet } from './config/config-set';
|
|
|
5
5
|
export declare class TsJestTransformer implements Transformer {
|
|
6
6
|
protected readonly logger: Logger;
|
|
7
7
|
protected _transformCfgStr: string;
|
|
8
|
-
protected _configSet: ConfigSet;
|
|
9
8
|
constructor();
|
|
9
|
+
configsFor(jestConfig: Config.ProjectConfig): ConfigSet;
|
|
10
10
|
process(input: string, filePath: Config.Path, jestConfig: Config.ProjectConfig, transformOptions?: TransformOptions): TransformedSource | string;
|
|
11
11
|
getCacheKey(fileContent: string, filePath: string, _jestConfigStr: string, transformOptions: CacheKeyOptions): string;
|
|
12
|
-
protected createOrResolveTransformerCfg(jestConfig: Config.ProjectConfig): void;
|
|
13
12
|
}
|
|
@@ -10,30 +10,64 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
14
|
exports.TsJestTransformer = void 0;
|
|
18
|
-
var create_cache_key_function_1 = __importDefault(require("@jest/create-cache-key-function"));
|
|
19
15
|
var config_set_1 = require("./config/config-set");
|
|
20
16
|
var constants_1 = require("./constants");
|
|
21
17
|
var json_1 = require("./utils/json");
|
|
22
18
|
var jsonable_value_1 = require("./utils/jsonable-value");
|
|
23
19
|
var logger_1 = require("./utils/logger");
|
|
24
20
|
var messages_1 = require("./utils/messages");
|
|
21
|
+
var sha1_1 = require("./utils/sha1");
|
|
25
22
|
var TsJestTransformer = (function () {
|
|
26
23
|
function TsJestTransformer() {
|
|
27
24
|
this.logger = logger_1.rootLogger.child({ namespace: 'ts-jest-transformer' });
|
|
28
25
|
this.logger.debug('created new transformer');
|
|
29
26
|
}
|
|
27
|
+
TsJestTransformer.prototype.configsFor = function (jestConfig) {
|
|
28
|
+
var ccs = TsJestTransformer._cachedConfigSets.find(function (cs) { return cs.jestConfig.value === jestConfig; });
|
|
29
|
+
var configSet;
|
|
30
|
+
if (ccs) {
|
|
31
|
+
this._transformCfgStr = ccs.transformerCfgStr;
|
|
32
|
+
configSet = ccs.configSet;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
var serializedJestCfg_1 = json_1.stringify(jestConfig);
|
|
36
|
+
var serializedCcs = TsJestTransformer._cachedConfigSets.find(function (cs) { return cs.jestConfig.serialized === serializedJestCfg_1; });
|
|
37
|
+
if (serializedCcs) {
|
|
38
|
+
serializedCcs.jestConfig.value = jestConfig;
|
|
39
|
+
this._transformCfgStr = serializedCcs.transformerCfgStr;
|
|
40
|
+
configSet = serializedCcs.configSet;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.logger.info('no matching config-set found, creating a new one');
|
|
44
|
+
configSet = new config_set_1.ConfigSet(jestConfig);
|
|
45
|
+
var jest_1 = __assign({}, jestConfig);
|
|
46
|
+
var globals = (jest_1.globals = __assign({}, jest_1.globals));
|
|
47
|
+
jest_1.name = undefined;
|
|
48
|
+
jest_1.cacheDirectory = undefined;
|
|
49
|
+
delete globals['ts-jest'];
|
|
50
|
+
this._transformCfgStr = new jsonable_value_1.JsonableValue(__assign(__assign({ digest: configSet.tsJestDigest, babel: configSet.babelConfig }, jest_1), { tsconfig: {
|
|
51
|
+
options: configSet.parsedTsConfig.options,
|
|
52
|
+
raw: configSet.parsedTsConfig.raw,
|
|
53
|
+
} })).serialized;
|
|
54
|
+
TsJestTransformer._cachedConfigSets.push({
|
|
55
|
+
jestConfig: new jsonable_value_1.JsonableValue(jestConfig),
|
|
56
|
+
configSet: configSet,
|
|
57
|
+
transformerCfgStr: this._transformCfgStr,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return configSet;
|
|
62
|
+
};
|
|
30
63
|
TsJestTransformer.prototype.process = function (input, filePath, jestConfig, transformOptions) {
|
|
31
64
|
this.logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'processing', filePath);
|
|
32
65
|
var result;
|
|
33
66
|
var source = input;
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
var
|
|
67
|
+
var configs = this.configsFor(jestConfig);
|
|
68
|
+
var hooks = configs.hooks;
|
|
69
|
+
var shouldStringifyContent = configs.shouldStringifyContent(filePath);
|
|
70
|
+
var babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
|
|
37
71
|
var isDefinitionFile = filePath.endsWith(constants_1.DECLARATION_TYPE_EXT);
|
|
38
72
|
var isJsFile = constants_1.JS_JSX_REGEX.test(filePath);
|
|
39
73
|
var isTsFile = !isDefinitionFile && constants_1.TS_TSX_REGEX.test(filePath);
|
|
@@ -43,12 +77,12 @@ var TsJestTransformer = (function () {
|
|
|
43
77
|
else if (isDefinitionFile) {
|
|
44
78
|
result = '';
|
|
45
79
|
}
|
|
46
|
-
else if (!
|
|
80
|
+
else if (!configs.parsedTsConfig.options.allowJs && isJsFile) {
|
|
47
81
|
this.logger.warn({ fileName: filePath }, 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 }));
|
|
48
82
|
result = source;
|
|
49
83
|
}
|
|
50
84
|
else if (isJsFile || isTsFile) {
|
|
51
|
-
result =
|
|
85
|
+
result = configs.tsCompiler.compile(source, filePath);
|
|
52
86
|
}
|
|
53
87
|
else {
|
|
54
88
|
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.";
|
|
@@ -69,41 +103,10 @@ var TsJestTransformer = (function () {
|
|
|
69
103
|
return result;
|
|
70
104
|
};
|
|
71
105
|
TsJestTransformer.prototype.getCacheKey = function (fileContent, filePath, _jestConfigStr, transformOptions) {
|
|
72
|
-
this.
|
|
106
|
+
var configs = this.configsFor(transformOptions.config);
|
|
73
107
|
this.logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'computing cache key for', filePath);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
instrument: false,
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
TsJestTransformer.prototype.createOrResolveTransformerCfg = function (jestConfig) {
|
|
80
|
-
var ccs = TsJestTransformer._cachedConfigSets.find(function (cs) { return cs.jestConfig.value === jestConfig; });
|
|
81
|
-
if (ccs) {
|
|
82
|
-
this._transformCfgStr = ccs.transformerCfgStr;
|
|
83
|
-
this._configSet = ccs.configSet;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
var serializedJestCfg_1 = json_1.stringify(jestConfig);
|
|
87
|
-
var serializedCcs = TsJestTransformer._cachedConfigSets.find(function (cs) { return cs.jestConfig.serialized === serializedJestCfg_1; });
|
|
88
|
-
if (serializedCcs) {
|
|
89
|
-
serializedCcs.jestConfig.value = jestConfig;
|
|
90
|
-
this._transformCfgStr = serializedCcs.transformerCfgStr;
|
|
91
|
-
this._configSet = serializedCcs.configSet;
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
this.logger.info('no matching config-set found, creating a new one');
|
|
95
|
-
this._configSet = new config_set_1.ConfigSet(jestConfig);
|
|
96
|
-
this._transformCfgStr = new jsonable_value_1.JsonableValue(__assign(__assign({ digest: this._configSet.tsJestDigest, babel: this._configSet.babelConfig }, jestConfig), { tsconfig: {
|
|
97
|
-
options: this._configSet.parsedTsConfig.options,
|
|
98
|
-
raw: this._configSet.parsedTsConfig.raw,
|
|
99
|
-
} })).serialized;
|
|
100
|
-
TsJestTransformer._cachedConfigSets.push({
|
|
101
|
-
jestConfig: new jsonable_value_1.JsonableValue(jestConfig),
|
|
102
|
-
configSet: this._configSet,
|
|
103
|
-
transformerCfgStr: this._transformCfgStr,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
108
|
+
var _a = transformOptions.instrument, instrument = _a === void 0 ? false : _a, _b = transformOptions.rootDir, rootDir = _b === void 0 ? configs.rootDir : _b;
|
|
109
|
+
return sha1_1.sha1(this._transformCfgStr, '\x00', rootDir, '\x00', "instrument:" + (instrument ? 'on' : 'off'), '\x00', fileContent, '\x00', filePath);
|
|
107
110
|
};
|
|
108
111
|
TsJestTransformer._cachedConfigSets = [];
|
|
109
112
|
return TsJestTransformer;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Config } from '@jest/types';
|
|
1
2
|
import type * as _babel from 'babel__core';
|
|
2
3
|
import type * as _ts from 'typescript';
|
|
3
4
|
export declare type TTypeScript = typeof _ts;
|
|
@@ -22,15 +23,24 @@ export interface TsJestGlobalOptions {
|
|
|
22
23
|
pretty?: boolean;
|
|
23
24
|
ignoreCodes?: number | string | (number | string)[];
|
|
24
25
|
pathRegex?: RegExp | string;
|
|
26
|
+
exclude?: Config.Glob[];
|
|
25
27
|
warnOnly?: boolean;
|
|
26
28
|
};
|
|
27
29
|
babelConfig?: boolean | string | BabelConfig;
|
|
28
30
|
stringifyContentPathRegex?: string | RegExp;
|
|
29
31
|
}
|
|
32
|
+
export interface GlobalConfigTsJest extends Config.ConfigGlobals {
|
|
33
|
+
'ts-jest': TsJestGlobalOptions;
|
|
34
|
+
}
|
|
35
|
+
export interface InitialOptionsTsJest extends Config.InitialOptions {
|
|
36
|
+
globals?: GlobalConfigTsJest;
|
|
37
|
+
}
|
|
38
|
+
export declare type TsJestPresets = Pick<Config.InitialOptions, 'moduleFileExtensions' | 'transform' | 'testMatch'>;
|
|
30
39
|
export interface TsJestDiagnosticsCfg {
|
|
31
40
|
pretty: boolean;
|
|
32
41
|
ignoreCodes: number[];
|
|
33
42
|
pathRegex?: string | undefined;
|
|
43
|
+
exclude: Config.Glob[];
|
|
34
44
|
throws: boolean;
|
|
35
45
|
warnOnly?: boolean;
|
|
36
46
|
}
|
package/dist/utils/testing.d.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/// <reference types="jest" />
|
|
2
|
-
declare type MockableFunction = (...args: any[]) => any;
|
|
3
|
-
declare type MethodKeysOf<T> = {
|
|
2
|
+
export declare type MockableFunction = (...args: any[]) => any;
|
|
3
|
+
export declare type MethodKeysOf<T> = {
|
|
4
4
|
[K in keyof T]: T[K] extends MockableFunction ? K : never;
|
|
5
5
|
}[keyof T];
|
|
6
|
-
declare type PropertyKeysOf<T> = {
|
|
6
|
+
export declare type PropertyKeysOf<T> = {
|
|
7
7
|
[K in keyof T]: T[K] extends MockableFunction ? never : K;
|
|
8
8
|
}[keyof T];
|
|
9
|
-
declare type ArgumentsOf<T> = T extends (...args: infer A) => any ? A : never;
|
|
10
|
-
declare type ConstructorArgumentsOf<T> = T extends new (...args: infer A) => any ? A : never;
|
|
11
|
-
interface MockWithArgs<T extends MockableFunction> extends jest.MockInstance<ReturnType<T>, ArgumentsOf<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
12
|
new (...args: ConstructorArgumentsOf<T>): T;
|
|
13
13
|
(...args: ArgumentsOf<T>): ReturnType<T>;
|
|
14
14
|
}
|
|
15
|
-
declare type MaybeMockedConstructor<T> = T extends new (...args: any[]) => infer R ? jest.MockInstance<R, ConstructorArgumentsOf<T>> : T;
|
|
16
|
-
declare type MockedFunction<T extends MockableFunction> = MockWithArgs<T> & {
|
|
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
17
|
[K in keyof T]: T[K];
|
|
18
18
|
};
|
|
19
|
-
declare type MockedFunctionDeep<T extends MockableFunction> = MockWithArgs<T> & MockedObjectDeep<T>;
|
|
20
|
-
declare type MockedObject<T> = MaybeMockedConstructor<T> & {
|
|
19
|
+
export declare type MockedFunctionDeep<T extends MockableFunction> = MockWithArgs<T> & MockedObjectDeep<T>;
|
|
20
|
+
export declare type MockedObject<T> = MaybeMockedConstructor<T> & {
|
|
21
21
|
[K in MethodKeysOf<T>]: T[K] extends MockableFunction ? MockedFunction<T[K]> : T[K];
|
|
22
22
|
} & {
|
|
23
23
|
[K in PropertyKeysOf<T>]: T[K];
|
|
24
24
|
};
|
|
25
|
-
declare type MockedObjectDeep<T> = MaybeMockedConstructor<T> & {
|
|
25
|
+
export declare type MockedObjectDeep<T> = MaybeMockedConstructor<T> & {
|
|
26
26
|
[K in MethodKeysOf<T>]: T[K] extends MockableFunction ? MockedFunctionDeep<T[K]> : T[K];
|
|
27
27
|
} & {
|
|
28
28
|
[K in PropertyKeysOf<T>]: MaybeMockedDeep<T[K]>;
|
|
@@ -31,4 +31,3 @@ export declare type MaybeMockedDeep<T> = T extends MockableFunction ? MockedFunc
|
|
|
31
31
|
export declare type MaybeMocked<T> = T extends MockableFunction ? MockedFunction<T> : T extends object ? MockedObject<T> : T;
|
|
32
32
|
export declare function mocked<T>(item: T, deep?: false): MaybeMocked<T>;
|
|
33
33
|
export declare function mocked<T>(item: T, deep: true): MaybeMockedDeep<T>;
|
|
34
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-jest",
|
|
3
|
-
"version": "26.
|
|
3
|
+
"version": "26.5.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
|
-
"bin":
|
|
6
|
+
"bin": {
|
|
7
|
+
"ts-jest": "cli.js"
|
|
8
|
+
},
|
|
7
9
|
"description": "A preprocessor with source maps support to help use TypeScript with Jest",
|
|
8
10
|
"scripts": {
|
|
9
11
|
"prebuild": "node scripts/clean-dist.js",
|
|
10
12
|
"build": "tsc -p tsconfig.build.json",
|
|
11
13
|
"postbuild": "node scripts/post-build.js",
|
|
12
14
|
"clean": "node scripts/clean.js",
|
|
13
|
-
"pretest": "npm run lint",
|
|
14
15
|
"test": "run-s -s test:e2e \"test:unit -- {@}\" --",
|
|
15
16
|
"test:prepare": "npm run test:e2e -- --prepareOnly",
|
|
16
17
|
"test:e2e": "node scripts/e2e.js",
|
|
@@ -56,14 +57,13 @@
|
|
|
56
57
|
},
|
|
57
58
|
"homepage": "https://kulshekhar.github.io/ts-jest",
|
|
58
59
|
"dependencies": {
|
|
59
|
-
"@jest/create-cache-key-function": "^26.5.0",
|
|
60
60
|
"@types/jest": "26.x",
|
|
61
61
|
"bs-logger": "0.x",
|
|
62
62
|
"buffer-from": "1.x",
|
|
63
63
|
"fast-json-stable-stringify": "2.x",
|
|
64
64
|
"jest-util": "^26.1.0",
|
|
65
65
|
"json5": "2.x",
|
|
66
|
-
"lodash
|
|
66
|
+
"lodash": "4.x",
|
|
67
67
|
"make-error": "1.x",
|
|
68
68
|
"mkdirp": "1.x",
|
|
69
69
|
"semver": "7.x",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@commitlint/cli": "11.x",
|
|
85
|
-
"@commitlint/config-
|
|
85
|
+
"@commitlint/config-angular": "^11.0.0",
|
|
86
86
|
"@jest/transform": "26.x",
|
|
87
87
|
"@jest/types": "26.x",
|
|
88
88
|
"@types/babel__core": "7.x",
|
|
@@ -91,12 +91,10 @@
|
|
|
91
91
|
"@types/fs-extra": "latest",
|
|
92
92
|
"@types/js-yaml": "latest",
|
|
93
93
|
"@types/json5": "latest",
|
|
94
|
-
"@types/lodash
|
|
95
|
-
"@types/lodash.merge": "4.x",
|
|
96
|
-
"@types/lodash.set": "4.x",
|
|
94
|
+
"@types/lodash": "4.x",
|
|
97
95
|
"@types/micromatch": "4.x",
|
|
98
96
|
"@types/mkdirp": "latest",
|
|
99
|
-
"@types/node": "
|
|
97
|
+
"@types/node": "14.x",
|
|
100
98
|
"@types/react": "16.x",
|
|
101
99
|
"@types/semver": "latest",
|
|
102
100
|
"@types/yargs": "latest",
|
|
@@ -117,8 +115,6 @@
|
|
|
117
115
|
"jest": "26.x",
|
|
118
116
|
"js-yaml": "latest",
|
|
119
117
|
"lint-staged": "latest",
|
|
120
|
-
"lodash.merge": "4.x",
|
|
121
|
-
"lodash.set": "4.x",
|
|
122
118
|
"npm-run-all": "latest",
|
|
123
119
|
"prettier": "2.x",
|
|
124
120
|
"source-map": "latest",
|