ts-jest 25.0.0 → 25.3.0
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 +93 -27
- package/CONTRIBUTING.md +1 -1
- package/README.md +3 -5
- package/TROUBLESHOOTING.md +41 -0
- package/dist/cli/config/migrate.js +6 -6
- package/dist/cli/helpers/presets.js +4 -10
- package/dist/{compiler.d.ts → compiler/instance.d.ts} +0 -0
- package/dist/compiler/instance.js +128 -0
- package/dist/compiler/language-service.d.ts +1 -0
- package/dist/compiler/language-service.js +94 -0
- package/dist/compiler/program.d.ts +1 -0
- package/dist/compiler/program.js +123 -0
- package/dist/compiler/transpile-module.d.ts +1 -0
- package/dist/compiler/transpile-module.js +21 -0
- package/dist/config/config-set.d.ts +3 -4
- package/dist/config/config-set.js +23 -46
- package/dist/config/create-jest-preset.d.ts +3 -3
- package/dist/config/paths-to-module-name-mapper.d.ts +1 -1
- package/dist/config/paths-to-module-name-mapper.js +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/transformers/hoist-jest.js +9 -8
- package/dist/ts-jest-transformer.d.ts +8 -9
- package/dist/ts-jest-transformer.js +17 -19
- package/dist/types.d.ts +5 -43
- package/dist/util/backports.js +4 -4
- package/dist/util/importer.js +11 -6
- package/dist/util/messages.js +0 -40
- package/dist/util/ts-error.js +1 -2
- package/dist/util/version-checkers.js +5 -12
- package/package.json +18 -11
- package/dist/compiler.js +0 -235
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
var bs_logger_1 = require("bs-logger");
|
|
15
|
+
var memoize = require("lodash.memoize");
|
|
16
|
+
var path_1 = require("path");
|
|
17
|
+
var messages_1 = require("../util/messages");
|
|
18
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
19
|
+
exports.compileUsingProgram = function (configs, logger, memoryCache) {
|
|
20
|
+
var _a;
|
|
21
|
+
logger.debug('compileUsingProgram(): create typescript compiler');
|
|
22
|
+
var ts = configs.compilerModule, cwd = configs.cwd, _b = configs.typescript, options = _b.options, projectReferences = _b.projectReferences, errors = _b.errors, incremental = configs.tsJest.incremental;
|
|
23
|
+
var compilerHostTraceCtx = (_a = {
|
|
24
|
+
namespace: 'ts:compilerHost',
|
|
25
|
+
call: null
|
|
26
|
+
},
|
|
27
|
+
_a[bs_logger_1.LogContexts.logLevel] = bs_logger_1.LogLevels.trace,
|
|
28
|
+
_a), sys = __assign(__assign({}, ts.sys), { readFile: logger.wrap(compilerHostTraceCtx, 'readFile', memoize(ts.sys.readFile)), readDirectory: memoize(ts.sys.readDirectory), getDirectories: memoize(ts.sys.getDirectories), fileExists: memoize(ts.sys.fileExists), directoryExists: memoize(ts.sys.directoryExists), resolvePath: memoize(ts.sys.resolvePath), realpath: memoize(ts.sys.realpath), getCurrentDirectory: function () { return cwd; }, getNewLine: function () { return '\n'; }, getCanonicalFileName: function (fileName) {
|
|
29
|
+
return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
|
|
30
|
+
} });
|
|
31
|
+
var builderProgram, program, host;
|
|
32
|
+
if (incremental) {
|
|
33
|
+
host = ts.createIncrementalCompilerHost(options, sys);
|
|
34
|
+
builderProgram = ts.createIncrementalProgram({
|
|
35
|
+
rootNames: Object.keys(memoryCache.versions),
|
|
36
|
+
options: options,
|
|
37
|
+
host: host,
|
|
38
|
+
configFileParsingDiagnostics: errors,
|
|
39
|
+
projectReferences: projectReferences,
|
|
40
|
+
});
|
|
41
|
+
program = builderProgram.getProgram();
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
host = __assign(__assign({}, sys), { getSourceFile: function (fileName, languageVersion) {
|
|
45
|
+
var contents = ts.sys.readFile(fileName);
|
|
46
|
+
if (contents === undefined)
|
|
47
|
+
return;
|
|
48
|
+
return ts.createSourceFile(fileName, contents, languageVersion);
|
|
49
|
+
}, getDefaultLibFileName: function () { return ts.getDefaultLibFilePath(options); }, useCaseSensitiveFileNames: function () { return sys.useCaseSensitiveFileNames; } });
|
|
50
|
+
program = ts.createProgram({
|
|
51
|
+
rootNames: Object.keys(memoryCache.versions),
|
|
52
|
+
options: options,
|
|
53
|
+
host: host,
|
|
54
|
+
configFileParsingDiagnostics: errors,
|
|
55
|
+
projectReferences: projectReferences,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
var customTransformers = configs.tsCustomTransformers, updateMemoryCache = function (code, fileName) {
|
|
59
|
+
logger.debug({ fileName: fileName }, "updateMemoryCache(): update memory cache for " + (incremental ? 'incremental program' : 'program'));
|
|
60
|
+
var sourceFile = incremental ? builderProgram.getSourceFile(fileName) : program.getSourceFile(fileName);
|
|
61
|
+
if (!hasOwn.call(memoryCache.versions, fileName)) {
|
|
62
|
+
memoryCache.versions[fileName] = 1;
|
|
63
|
+
}
|
|
64
|
+
if (memoryCache.contents[fileName] !== code) {
|
|
65
|
+
memoryCache.contents[fileName] = code;
|
|
66
|
+
memoryCache.versions[fileName] = (memoryCache.versions[fileName] || 0) + 1;
|
|
67
|
+
}
|
|
68
|
+
if (sourceFile === undefined || sourceFile.text !== code || program.isSourceFileFromExternalLibrary(sourceFile)) {
|
|
69
|
+
var programOptions = {
|
|
70
|
+
rootNames: Object.keys(memoryCache.versions),
|
|
71
|
+
options: options,
|
|
72
|
+
host: host,
|
|
73
|
+
configFileParsingDiagnostics: errors,
|
|
74
|
+
projectReferences: projectReferences,
|
|
75
|
+
};
|
|
76
|
+
if (incremental) {
|
|
77
|
+
builderProgram = ts.createIncrementalProgram(programOptions);
|
|
78
|
+
program = builderProgram.getProgram();
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
program = ts.createProgram(__assign(__assign({}, programOptions), { oldProgram: program }));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
compileFn: function (code, fileName) {
|
|
87
|
+
var normalizedFileName = path_1.normalize(fileName), output = ['', ''];
|
|
88
|
+
logger.debug({ normalizedFileName: normalizedFileName }, "compileFn(): compiling using " + (incremental ? 'incremental program' : 'program'));
|
|
89
|
+
updateMemoryCache(code, normalizedFileName);
|
|
90
|
+
var sourceFile = incremental
|
|
91
|
+
? builderProgram.getSourceFile(normalizedFileName)
|
|
92
|
+
: program.getSourceFile(normalizedFileName);
|
|
93
|
+
if (!sourceFile)
|
|
94
|
+
throw new TypeError("Unable to read file: " + fileName);
|
|
95
|
+
var result = incremental
|
|
96
|
+
? builderProgram.emit(sourceFile, function (path, file, _writeByteOrderMark) {
|
|
97
|
+
output[path.endsWith('.map') ? 1 : 0] = file;
|
|
98
|
+
}, undefined, undefined, customTransformers)
|
|
99
|
+
: program.emit(sourceFile, function (path, file, _writeByteOrderMark) {
|
|
100
|
+
output[path.endsWith('.map') ? 1 : 0] = file;
|
|
101
|
+
}, undefined, undefined, customTransformers);
|
|
102
|
+
if (result.emitSkipped) {
|
|
103
|
+
throw new TypeError(path_1.relative(cwd, fileName) + ": Emit skipped");
|
|
104
|
+
}
|
|
105
|
+
if (output[0] === '') {
|
|
106
|
+
throw new TypeError(messages_1.interpolate("Unable to require `.d.ts` file for file: {{file}}.\nThis is usually the result of a faulty configuration or import. Make sure there is a `.js`, `.json` or another executable extension available alongside `{{file}}`.", {
|
|
107
|
+
file: path_1.basename(normalizedFileName),
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
return output;
|
|
111
|
+
},
|
|
112
|
+
diagnoseFn: function (code, filePath) {
|
|
113
|
+
var normalizedFileName = path_1.normalize(filePath);
|
|
114
|
+
updateMemoryCache(code, normalizedFileName);
|
|
115
|
+
if (configs.shouldReportDiagnostic(normalizedFileName)) {
|
|
116
|
+
logger.debug({ normalizedFileName: normalizedFileName }, "compileFn(): computing diagnostics for " + (incremental ? 'incremental program' : 'program'));
|
|
117
|
+
var sourceFile = program.getSourceFile(normalizedFileName), diagnostics = program.getSemanticDiagnostics(sourceFile).concat(program.getSyntacticDiagnostics(sourceFile));
|
|
118
|
+
configs.raiseDiagnostics(diagnostics, normalizedFileName, logger);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
program: program,
|
|
122
|
+
};
|
|
123
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var path_1 = require("path");
|
|
4
|
+
exports.compileUsingTranspileModule = function (configs, logger) {
|
|
5
|
+
logger.debug('compileUsingTranspileModule(): create typescript compiler');
|
|
6
|
+
return {
|
|
7
|
+
compileFn: function (code, fileName) {
|
|
8
|
+
logger.debug({ fileName: fileName }, 'getOutput(): compiling as isolated module');
|
|
9
|
+
var normalizedFileName = path_1.normalize(fileName), result = configs.compilerModule.transpileModule(code, {
|
|
10
|
+
fileName: normalizedFileName,
|
|
11
|
+
transformers: configs.tsCustomTransformers,
|
|
12
|
+
compilerOptions: configs.typescript.options,
|
|
13
|
+
reportDiagnostics: configs.shouldReportDiagnostic(normalizedFileName),
|
|
14
|
+
});
|
|
15
|
+
if (result.diagnostics && configs.shouldReportDiagnostic(normalizedFileName)) {
|
|
16
|
+
configs.raiseDiagnostics(result.diagnostics, normalizedFileName, logger);
|
|
17
|
+
}
|
|
18
|
+
return [result.outputText, result.sourceMapText];
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { Config } from '@jest/types';
|
|
2
2
|
import { Logger } from 'bs-logger';
|
|
3
3
|
import { CompilerOptions, CustomTransformers, ParsedCommandLine } from 'typescript';
|
|
4
4
|
import { AstTransformerDesc, BabelConfig, BabelJestTransformer, TTypeScript, TsCompiler, TsJestConfig, TsJestGlobalOptions, TsJestHooksMap } from '../types';
|
|
@@ -6,12 +6,11 @@ export declare class ConfigSet {
|
|
|
6
6
|
readonly parentOptions?: TsJestGlobalOptions | undefined;
|
|
7
7
|
get projectPackageJson(): Record<string, any>;
|
|
8
8
|
get projectDependencies(): Record<string, string>;
|
|
9
|
-
get jest():
|
|
9
|
+
get jest(): Config.ProjectConfig;
|
|
10
10
|
get tsJest(): TsJestConfig;
|
|
11
11
|
get typescript(): ParsedCommandLine;
|
|
12
12
|
get tsconfig(): any;
|
|
13
13
|
get versions(): Record<string, string>;
|
|
14
|
-
private static loadConfig;
|
|
15
14
|
get babel(): BabelConfig | undefined;
|
|
16
15
|
get compilerModule(): TTypeScript;
|
|
17
16
|
get babelJestTransformer(): BabelJestTransformer | undefined;
|
|
@@ -28,7 +27,7 @@ export declare class ConfigSet {
|
|
|
28
27
|
get tsJestDigest(): string;
|
|
29
28
|
get cacheKey(): string;
|
|
30
29
|
readonly logger: Logger;
|
|
31
|
-
constructor(jestConfig:
|
|
30
|
+
constructor(jestConfig: Config.ProjectConfig, parentOptions?: TsJestGlobalOptions | undefined, parentLogger?: Logger);
|
|
32
31
|
resolvePath(inputPath: string, { throwIfMissing, nodeResolve }?: {
|
|
33
32
|
throwIfMissing?: boolean;
|
|
34
33
|
nodeResolve?: boolean;
|
|
@@ -52,9 +52,8 @@ var bs_logger_1 = require("bs-logger");
|
|
|
52
52
|
var fs_1 = require("fs");
|
|
53
53
|
var json5 = require("json5");
|
|
54
54
|
var path_1 = require("path");
|
|
55
|
-
var semver = require("semver");
|
|
56
55
|
var __1 = require("..");
|
|
57
|
-
var
|
|
56
|
+
var instance_1 = require("../compiler/instance");
|
|
58
57
|
var transformers_1 = require("../transformers");
|
|
59
58
|
var backports_1 = require("../util/backports");
|
|
60
59
|
var get_package_version_1 = require("../util/get-package-version");
|
|
@@ -74,11 +73,6 @@ exports.IGNORE_DIAGNOSTIC_CODES = [
|
|
|
74
73
|
18002,
|
|
75
74
|
18003,
|
|
76
75
|
];
|
|
77
|
-
var DiagnosticCodes;
|
|
78
|
-
(function (DiagnosticCodes) {
|
|
79
|
-
DiagnosticCodes[DiagnosticCodes["TsJest"] = 151000] = "TsJest";
|
|
80
|
-
DiagnosticCodes[DiagnosticCodes["ConfigModuleOption"] = 151001] = "ConfigModuleOption";
|
|
81
|
-
})(DiagnosticCodes = exports.DiagnosticCodes || (exports.DiagnosticCodes = {}));
|
|
82
76
|
var normalizeRegex = function (pattern) {
|
|
83
77
|
return pattern ? (typeof pattern === 'string' ? pattern : pattern.source) : undefined;
|
|
84
78
|
};
|
|
@@ -141,7 +135,7 @@ var ConfigSet = (function () {
|
|
|
141
135
|
if (fs_1.existsSync(path)) {
|
|
142
136
|
return require(path);
|
|
143
137
|
}
|
|
144
|
-
this.logger.warn(
|
|
138
|
+
this.logger.warn("Unable to find the root of the project where ts-jest has been installed.");
|
|
145
139
|
return {};
|
|
146
140
|
}
|
|
147
141
|
var tsJestRoot = path_1.resolve(__dirname, '..', '..');
|
|
@@ -155,7 +149,7 @@ var ConfigSet = (function () {
|
|
|
155
149
|
return require(pkgPath);
|
|
156
150
|
}
|
|
157
151
|
}
|
|
158
|
-
this.logger.warn(
|
|
152
|
+
this.logger.warn("Unable to find the root of the project where ts-jest has been installed.");
|
|
159
153
|
return {};
|
|
160
154
|
},
|
|
161
155
|
enumerable: true,
|
|
@@ -177,9 +171,10 @@ var ConfigSet = (function () {
|
|
|
177
171
|
});
|
|
178
172
|
Object.defineProperty(ConfigSet.prototype, "jest", {
|
|
179
173
|
get: function () {
|
|
174
|
+
var _a;
|
|
180
175
|
var config = backports_1.backportJestConfig(this.logger, this._jestConfig);
|
|
181
176
|
if (this.parentOptions) {
|
|
182
|
-
var globals =
|
|
177
|
+
var globals = (_a = config.globals) !== null && _a !== void 0 ? _a : {};
|
|
183
178
|
globals['ts-jest'] = __assign(__assign({}, this.parentOptions), globals['ts-jest']);
|
|
184
179
|
}
|
|
185
180
|
this.logger.debug({ jestConfig: config }, 'normalized jest config');
|
|
@@ -191,8 +186,9 @@ var ConfigSet = (function () {
|
|
|
191
186
|
Object.defineProperty(ConfigSet.prototype, "tsJest", {
|
|
192
187
|
get: function () {
|
|
193
188
|
var _this = this;
|
|
189
|
+
var _a, _b, _c;
|
|
194
190
|
var parsedConfig = this.jest;
|
|
195
|
-
var
|
|
191
|
+
var _d = parsedConfig.globals, globals = _d === void 0 ? {} : _d;
|
|
196
192
|
var options = __assign({}, globals['ts-jest']);
|
|
197
193
|
var tsConfigOpt = options.tsConfig;
|
|
198
194
|
var tsConfig;
|
|
@@ -238,7 +234,7 @@ var ConfigSet = (function () {
|
|
|
238
234
|
};
|
|
239
235
|
}
|
|
240
236
|
var diagnostics;
|
|
241
|
-
var
|
|
237
|
+
var _e = options.diagnostics, diagnosticsOpt = _e === void 0 ? true : _e;
|
|
242
238
|
var ignoreList = [exports.IGNORE_DIAGNOSTIC_CODES, process.env.TS_JEST_IGNORE_DIAGNOSTICS];
|
|
243
239
|
if (diagnosticsOpt === true || diagnosticsOpt == null) {
|
|
244
240
|
diagnostics = { ignoreCodes: [], pretty: true, throws: true };
|
|
@@ -264,11 +260,13 @@ var ConfigSet = (function () {
|
|
|
264
260
|
var stringifyContentPathRegex = normalizeRegex(options.stringifyContentPathRegex);
|
|
265
261
|
var res = {
|
|
266
262
|
tsConfig: tsConfig,
|
|
263
|
+
compilerHost: (_a = options.compilerHost) !== null && _a !== void 0 ? _a : false,
|
|
264
|
+
incremental: (_b = options.incremental) !== null && _b !== void 0 ? _b : true,
|
|
267
265
|
packageJson: packageJson,
|
|
268
266
|
babelConfig: babelConfig,
|
|
269
267
|
diagnostics: diagnostics,
|
|
270
268
|
isolatedModules: !!options.isolatedModules,
|
|
271
|
-
compiler: options.compiler
|
|
269
|
+
compiler: (_c = options.compiler) !== null && _c !== void 0 ? _c : 'typescript',
|
|
272
270
|
transformers: transformers,
|
|
273
271
|
stringifyContentPathRegex: stringifyContentPathRegex,
|
|
274
272
|
};
|
|
@@ -299,7 +297,8 @@ var ConfigSet = (function () {
|
|
|
299
297
|
modules.push('@babel/core', 'babel-jest');
|
|
300
298
|
}
|
|
301
299
|
return modules.reduce(function (map, name) {
|
|
302
|
-
|
|
300
|
+
var _a;
|
|
301
|
+
map[name] = (_a = get_package_version_1.getPackageVersion(name)) !== null && _a !== void 0 ? _a : '-';
|
|
303
302
|
return map;
|
|
304
303
|
}, { 'ts-jest': __1.version });
|
|
305
304
|
},
|
|
@@ -325,7 +324,7 @@ var ConfigSet = (function () {
|
|
|
325
324
|
return function (diagnostics, filePath, logger) {
|
|
326
325
|
if (logger === void 0) { logger = _this.logger; }
|
|
327
326
|
var filteredDiagnostics = filterDiagnostics(diagnostics, filePath);
|
|
328
|
-
if (filteredDiagnostics.length
|
|
327
|
+
if (!filteredDiagnostics.length)
|
|
329
328
|
return;
|
|
330
329
|
var error = createTsError(filteredDiagnostics);
|
|
331
330
|
var importantCategories = [DiagnosticCategory.Warning, DiagnosticCategory.Error];
|
|
@@ -338,19 +337,6 @@ var ConfigSet = (function () {
|
|
|
338
337
|
enumerable: true,
|
|
339
338
|
configurable: true
|
|
340
339
|
});
|
|
341
|
-
ConfigSet.loadConfig = function (base) {
|
|
342
|
-
var _a = importer_1.importer.babelCore(messages_1.ImportReasons.BabelJest), OptionManager = _a.OptionManager, loadPartialConfig = _a.loadPartialConfig, version = _a.version;
|
|
343
|
-
if (version && semver.satisfies(version, '>=6 <7')) {
|
|
344
|
-
delete base.cwd;
|
|
345
|
-
}
|
|
346
|
-
if (typeof loadPartialConfig === 'function') {
|
|
347
|
-
var partialConfig = loadPartialConfig(base);
|
|
348
|
-
if (partialConfig) {
|
|
349
|
-
return partialConfig.options;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return new OptionManager().init(base);
|
|
353
|
-
};
|
|
354
340
|
Object.defineProperty(ConfigSet.prototype, "babel", {
|
|
355
341
|
get: function () {
|
|
356
342
|
var babelConfig = this.tsJest.babelConfig;
|
|
@@ -372,16 +358,15 @@ var ConfigSet = (function () {
|
|
|
372
358
|
else if (babelConfig.kind === 'inline') {
|
|
373
359
|
base = __assign(__assign({}, base), babelConfig.value);
|
|
374
360
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
return config;
|
|
361
|
+
this.logger.debug({ babelConfig: base }, 'normalized babel config via ts-jest option');
|
|
362
|
+
return base;
|
|
378
363
|
},
|
|
379
364
|
enumerable: true,
|
|
380
365
|
configurable: true
|
|
381
366
|
});
|
|
382
367
|
Object.defineProperty(ConfigSet.prototype, "compilerModule", {
|
|
383
368
|
get: function () {
|
|
384
|
-
return importer_1.importer.typescript(
|
|
369
|
+
return importer_1.importer.typescript("Using \"ts-jest\" requires this package to be installed.", this.tsJest.compiler);
|
|
385
370
|
},
|
|
386
371
|
enumerable: true,
|
|
387
372
|
configurable: true
|
|
@@ -392,14 +377,14 @@ var ConfigSet = (function () {
|
|
|
392
377
|
if (!babel)
|
|
393
378
|
return;
|
|
394
379
|
this.logger.debug('creating babel-jest transformer');
|
|
395
|
-
return importer_1.importer.babelJest(
|
|
380
|
+
return importer_1.importer.babelJest("Using \"babel-jest\" requires this package to be installed.").createTransformer(babel);
|
|
396
381
|
},
|
|
397
382
|
enumerable: true,
|
|
398
383
|
configurable: true
|
|
399
384
|
});
|
|
400
385
|
Object.defineProperty(ConfigSet.prototype, "tsCompiler", {
|
|
401
386
|
get: function () {
|
|
402
|
-
return
|
|
387
|
+
return instance_1.createCompiler(this);
|
|
403
388
|
},
|
|
404
389
|
enumerable: true,
|
|
405
390
|
configurable: true
|
|
@@ -440,7 +425,8 @@ var ConfigSet = (function () {
|
|
|
440
425
|
if (filePath && !shouldReportDiagnostic(filePath))
|
|
441
426
|
return [];
|
|
442
427
|
return diagnostics.filter(function (diagnostic) {
|
|
443
|
-
|
|
428
|
+
var _a;
|
|
429
|
+
if (((_a = diagnostic.file) === null || _a === void 0 ? void 0 : _a.fileName) && !shouldReportDiagnostic(diagnostic.file.fileName)) {
|
|
444
430
|
return false;
|
|
445
431
|
}
|
|
446
432
|
return ignoreCodes.indexOf(diagnostic.code) === -1;
|
|
@@ -529,7 +515,6 @@ var ConfigSet = (function () {
|
|
|
529
515
|
inlineSources: true,
|
|
530
516
|
declaration: false,
|
|
531
517
|
noEmit: false,
|
|
532
|
-
outDir: '$$ts-jest$$',
|
|
533
518
|
removeComments: false,
|
|
534
519
|
out: undefined,
|
|
535
520
|
outFile: undefined,
|
|
@@ -537,7 +522,6 @@ var ConfigSet = (function () {
|
|
|
537
522
|
declarationDir: undefined,
|
|
538
523
|
declarationMap: undefined,
|
|
539
524
|
emitDeclarationOnly: undefined,
|
|
540
|
-
incremental: undefined,
|
|
541
525
|
sourceRoot: undefined,
|
|
542
526
|
tsBuildInfoFile: undefined,
|
|
543
527
|
};
|
|
@@ -563,13 +547,6 @@ var ConfigSet = (function () {
|
|
|
563
547
|
enumerable: true,
|
|
564
548
|
configurable: true
|
|
565
549
|
});
|
|
566
|
-
Object.defineProperty(ConfigSet.prototype, "isDoctoring", {
|
|
567
|
-
get: function () {
|
|
568
|
-
return !!process.env.TS_JEST_DOCTOR;
|
|
569
|
-
},
|
|
570
|
-
enumerable: true,
|
|
571
|
-
configurable: true
|
|
572
|
-
});
|
|
573
550
|
Object.defineProperty(ConfigSet.prototype, "tsJestDigest", {
|
|
574
551
|
get: function () {
|
|
575
552
|
return __1.digest;
|
|
@@ -659,7 +636,7 @@ var ConfigSet = (function () {
|
|
|
659
636
|
if ('module' in forcedOptions &&
|
|
660
637
|
moduleValue !== forcedOptions.module &&
|
|
661
638
|
!(finalOptions.esModuleInterop || finalOptions.allowSyntheticDefaultImports)) {
|
|
662
|
-
result.errors.push(this.makeDiagnostic(
|
|
639
|
+
result.errors.push(this.makeDiagnostic(151001, "If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.", {
|
|
663
640
|
category: ts.DiagnosticCategory.Message,
|
|
664
641
|
}));
|
|
665
642
|
if (!('allowSyntheticDefaultImports' in config.compilerOptions)) {
|
|
@@ -714,7 +691,7 @@ var ConfigSet = (function () {
|
|
|
714
691
|
catch (_) { }
|
|
715
692
|
}
|
|
716
693
|
if (throwIfMissing && !fs_1.existsSync(path)) {
|
|
717
|
-
throw new Error(messages_1.interpolate(
|
|
694
|
+
throw new Error(messages_1.interpolate("File not found: {{inputPath}} (resolved as: {{resolvedPath}})", { inputPath: inputPath, resolvedPath: path }));
|
|
718
695
|
}
|
|
719
696
|
this.logger.debug({ fromPath: inputPath, toPath: path }, 'resolved path from', inputPath, 'to', path);
|
|
720
697
|
return path;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { Config } from '@jest/types';
|
|
2
2
|
export interface TsJestPresets {
|
|
3
|
-
transform:
|
|
3
|
+
transform: Config.InitialOptions['transform'];
|
|
4
4
|
testMatch?: string[];
|
|
5
5
|
moduleFileExtensions?: string[];
|
|
6
6
|
}
|
|
7
7
|
export interface CreateJestPresetOptions {
|
|
8
8
|
allowJs?: boolean;
|
|
9
9
|
}
|
|
10
|
-
export declare function createJestPreset({ allowJs }?: CreateJestPresetOptions, from?:
|
|
10
|
+
export declare function createJestPreset({ allowJs }?: CreateJestPresetOptions, from?: Config.InitialOptions): TsJestPresets;
|
|
@@ -27,11 +27,11 @@ exports.pathsToModuleNameMapper = function (mapping, _a) {
|
|
|
27
27
|
var pattern = void 0;
|
|
28
28
|
var toPaths = mapping[fromPath];
|
|
29
29
|
if (toPaths.length === 0) {
|
|
30
|
-
logger.warn(messages_1.interpolate(
|
|
30
|
+
logger.warn(messages_1.interpolate("Not mapping \"{{path}}\" because it has no target.", { path: fromPath }));
|
|
31
31
|
continue;
|
|
32
32
|
}
|
|
33
33
|
else if (toPaths.length > 1) {
|
|
34
|
-
logger.warn(messages_1.interpolate(
|
|
34
|
+
logger.warn(messages_1.interpolate("Mapping only to first target of \"{{path}}\" because it has more than one ({{count}}).", {
|
|
35
35
|
path: fromPath,
|
|
36
36
|
count: toPaths.length,
|
|
37
37
|
}));
|
|
@@ -47,7 +47,7 @@ exports.pathsToModuleNameMapper = function (mapping, _a) {
|
|
|
47
47
|
jestMap[pattern] = "" + prefix + target.replace(/\*/g, '$1');
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
|
-
logger.warn(messages_1.interpolate(
|
|
50
|
+
logger.warn(messages_1.interpolate("Not mapping \"{{path}}\" because it has more than one star (`*`).", { path: fromPath }));
|
|
51
51
|
continue;
|
|
52
52
|
}
|
|
53
53
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare const createJestPreset: typeof createJestPresetCore;
|
|
|
7
7
|
export declare const pathsToModuleNameMapper: (mapping: import("typescript").MapLike<string[]>, { prefix }?: {
|
|
8
8
|
prefix?: string | undefined;
|
|
9
9
|
}) => {
|
|
10
|
-
[key: string]: string;
|
|
10
|
+
[key: string]: string | string[];
|
|
11
11
|
} | undefined;
|
|
12
12
|
export declare const version: string;
|
|
13
13
|
export declare const digest: string;
|
package/dist/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var testing_1 = require("./util/testing");
|
|
|
33
33
|
var version_checkers_1 = require("./util/version-checkers");
|
|
34
34
|
var warn = logger_1.rootLogger.child((_a = {}, _a[bs_logger_1.LogContexts.logLevel] = bs_logger_1.LogLevels.warn, _a));
|
|
35
35
|
var helperMoved = function (name, helper) {
|
|
36
|
-
return warn.wrap(messages_1.interpolate(
|
|
36
|
+
return warn.wrap(messages_1.interpolate("The `{{helper}}` helper has been moved to `ts-jest/utils`. Use `import { {{helper}} } from 'ts-jest/utils'` instead.", { helper: name }), helper);
|
|
37
37
|
};
|
|
38
38
|
exports.mocked = helperMoved('mocked', testing_1.mocked);
|
|
39
39
|
exports.createJestPreset = helperMoved('createJestPreset', create_jest_preset_1.createJestPreset);
|
|
@@ -21,20 +21,21 @@ var __spread = (this && this.__spread) || function () {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
var bs_logger_1 = require("bs-logger");
|
|
24
|
-
var HOIST_METHODS = ['mock', 'unmock', 'enableAutomock', 'disableAutomock'];
|
|
24
|
+
var HOIST_METHODS = ['mock', 'unmock', 'enableAutomock', 'disableAutomock', 'deepUnmock'];
|
|
25
25
|
exports.name = 'hoisting-jest-mock';
|
|
26
26
|
exports.version = 1;
|
|
27
27
|
function factory(cs) {
|
|
28
28
|
var logger = cs.logger.child({ namespace: 'ts-hoisting' });
|
|
29
29
|
var ts = cs.compilerModule;
|
|
30
|
+
function shouldHoistExpression(expression) {
|
|
31
|
+
return (ts.isCallExpression(expression) &&
|
|
32
|
+
ts.isPropertyAccessExpression(expression.expression) &&
|
|
33
|
+
HOIST_METHODS.includes(expression.expression.name.text) &&
|
|
34
|
+
((ts.isIdentifier(expression.expression.expression) && expression.expression.expression.text === 'jest') ||
|
|
35
|
+
shouldHoistExpression(expression.expression.expression)));
|
|
36
|
+
}
|
|
30
37
|
function shouldHoistNode(node) {
|
|
31
|
-
return
|
|
32
|
-
ts.isCallExpression(node.expression) &&
|
|
33
|
-
ts.isPropertyAccessExpression(node.expression.expression) &&
|
|
34
|
-
ts.isIdentifier(node.expression.expression.expression) &&
|
|
35
|
-
node.expression.expression.expression.text === 'jest' &&
|
|
36
|
-
ts.isIdentifier(node.expression.expression.name) &&
|
|
37
|
-
HOIST_METHODS.includes(node.expression.expression.name.text));
|
|
38
|
+
return ts.isExpressionStatement(node) && shouldHoistExpression(node.expression);
|
|
38
39
|
}
|
|
39
40
|
function createVisitor(ctx, _) {
|
|
40
41
|
var level = 0;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { TransformOptions, TransformedSource, Transformer } from '@jest/transform/build/types';
|
|
2
|
+
import { Config } from '@jest/types';
|
|
3
3
|
import { ConfigSet } from './config/config-set';
|
|
4
4
|
import { TsJestGlobalOptions } from './types';
|
|
5
|
-
export declare class TsJestTransformer implements
|
|
6
|
-
|
|
7
|
-
readonly
|
|
8
|
-
readonly
|
|
9
|
-
readonly options: TsJestGlobalOptions;
|
|
5
|
+
export declare class TsJestTransformer implements Transformer {
|
|
6
|
+
private readonly logger;
|
|
7
|
+
private readonly id;
|
|
8
|
+
private readonly options;
|
|
10
9
|
constructor(baseOptions?: TsJestGlobalOptions);
|
|
11
|
-
configsFor(jestConfig:
|
|
12
|
-
process(input: string, filePath:
|
|
10
|
+
configsFor(jestConfig: Config.ProjectConfig | string): ConfigSet;
|
|
11
|
+
process(input: string, filePath: Config.Path, jestConfig: Config.ProjectConfig, transformOptions?: TransformOptions): TransformedSource | string;
|
|
13
12
|
getCacheKey(fileContent: string, filePath: string, jestConfigStr: string, transformOptions?: {
|
|
14
13
|
instrument?: boolean;
|
|
15
14
|
rootDir?: string;
|
|
@@ -18,7 +18,16 @@ var jsonable_value_1 = require("./util/jsonable-value");
|
|
|
18
18
|
var logger_1 = require("./util/logger");
|
|
19
19
|
var messages_1 = require("./util/messages");
|
|
20
20
|
var sha1_1 = require("./util/sha1");
|
|
21
|
-
|
|
21
|
+
var INSPECT_CUSTOM = util_1.inspect.custom || 'inspect';
|
|
22
|
+
function checkDefinitionFile(filePath) {
|
|
23
|
+
return filePath.endsWith('.d.ts');
|
|
24
|
+
}
|
|
25
|
+
function checkJsFile(filePath) {
|
|
26
|
+
return !checkDefinitionFile(filePath) && /\.jsx?$/.test(filePath);
|
|
27
|
+
}
|
|
28
|
+
function checkTsFile(filePath) {
|
|
29
|
+
return !checkDefinitionFile(filePath) && /\.tsx?$/.test(filePath);
|
|
30
|
+
}
|
|
22
31
|
var TsJestTransformer = (function () {
|
|
23
32
|
function TsJestTransformer(baseOptions) {
|
|
24
33
|
if (baseOptions === void 0) { baseOptions = {}; }
|
|
@@ -30,13 +39,6 @@ var TsJestTransformer = (function () {
|
|
|
30
39
|
});
|
|
31
40
|
this.logger.debug({ baseOptions: baseOptions }, 'created new transformer');
|
|
32
41
|
}
|
|
33
|
-
Object.defineProperty(TsJestTransformer, "lastTransformerId", {
|
|
34
|
-
get: function () {
|
|
35
|
-
return TsJestTransformer._lastTransformerId;
|
|
36
|
-
},
|
|
37
|
-
enumerable: true,
|
|
38
|
-
configurable: true
|
|
39
|
-
});
|
|
40
42
|
Object.defineProperty(TsJestTransformer, "_nextTransformerId", {
|
|
41
43
|
get: function () {
|
|
42
44
|
return ++TsJestTransformer._lastTransformerId;
|
|
@@ -44,7 +46,7 @@ var TsJestTransformer = (function () {
|
|
|
44
46
|
enumerable: true,
|
|
45
47
|
configurable: true
|
|
46
48
|
});
|
|
47
|
-
TsJestTransformer.prototype[
|
|
49
|
+
TsJestTransformer.prototype[INSPECT_CUSTOM] = function () {
|
|
48
50
|
return "[object TsJestTransformer<#" + this.id + ">]";
|
|
49
51
|
};
|
|
50
52
|
TsJestTransformer.prototype.configsFor = function (jestConfig) {
|
|
@@ -79,14 +81,7 @@ var TsJestTransformer = (function () {
|
|
|
79
81
|
TsJestTransformer.prototype.process = function (input, filePath, jestConfig, transformOptions) {
|
|
80
82
|
this.logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'processing', filePath);
|
|
81
83
|
var result;
|
|
82
|
-
var source = input;
|
|
83
|
-
var configs = this.configsFor(jestConfig);
|
|
84
|
-
var hooks = configs.hooks;
|
|
85
|
-
var stringify = configs.shouldStringifyContent(filePath);
|
|
86
|
-
var babelJest = stringify ? undefined : configs.babelJestTransformer;
|
|
87
|
-
var isDefinitionFile = filePath.endsWith('.d.ts');
|
|
88
|
-
var isJsFile = !isDefinitionFile && /\.jsx?$/.test(filePath);
|
|
89
|
-
var isTsFile = isDefinitionFile || /\.tsx?$/.test(filePath);
|
|
84
|
+
var source = input, configs = this.configsFor(jestConfig), hooks = configs.hooks, stringify = configs.shouldStringifyContent(filePath), babelJest = stringify ? undefined : configs.babelJestTransformer, isDefinitionFile = checkDefinitionFile(filePath), isJsFile = checkJsFile(filePath), isTsFile = checkTsFile(filePath);
|
|
90
85
|
if (stringify) {
|
|
91
86
|
result = "module.exports=" + JSON.stringify(source);
|
|
92
87
|
}
|
|
@@ -94,14 +89,14 @@ var TsJestTransformer = (function () {
|
|
|
94
89
|
result = '';
|
|
95
90
|
}
|
|
96
91
|
else if (!configs.typescript.options.allowJs && isJsFile) {
|
|
97
|
-
this.logger.warn({ fileName: filePath }, messages_1.interpolate(
|
|
92
|
+
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 }));
|
|
98
93
|
result = source;
|
|
99
94
|
}
|
|
100
95
|
else if (isJsFile || isTsFile) {
|
|
101
96
|
result = configs.tsCompiler.compile(source, filePath);
|
|
102
97
|
}
|
|
103
98
|
else {
|
|
104
|
-
var message = babelJest ?
|
|
99
|
+
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.";
|
|
105
100
|
this.logger.warn({ fileName: filePath }, messages_1.interpolate(message, { path: filePath }));
|
|
106
101
|
result = source;
|
|
107
102
|
}
|
|
@@ -123,6 +118,9 @@ var TsJestTransformer = (function () {
|
|
|
123
118
|
this.logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'computing cache key for', filePath);
|
|
124
119
|
var configs = this.configsFor(jestConfigStr);
|
|
125
120
|
var _a = transformOptions.instrument, instrument = _a === void 0 ? false : _a, _b = transformOptions.rootDir, rootDir = _b === void 0 ? configs.rootDir : _b;
|
|
121
|
+
if (configs.tsCompiler.diagnose && (checkJsFile(filePath) || checkTsFile(filePath))) {
|
|
122
|
+
configs.tsCompiler.diagnose(fileContent, filePath);
|
|
123
|
+
}
|
|
126
124
|
return sha1_1.sha1(configs.cacheKey, '\x00', rootDir, '\x00', "instrument:" + (instrument ? 'on' : 'off'), '\x00', fileContent, '\x00', filePath);
|
|
127
125
|
};
|
|
128
126
|
TsJestTransformer._configSetsIndex = [];
|