ts-jest 26.3.0 → 26.4.2
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 +52 -0
- package/README.md +0 -1
- package/dist/cli/config/init.d.ts +0 -5
- package/dist/cli/config/init.js +3 -18
- package/dist/cli/config/migrate.js +11 -41
- package/dist/cli/help.js +1 -7
- package/dist/cli/helpers/presets.js +5 -11
- package/dist/cli/index.js +11 -12
- package/dist/compiler/instance.d.ts +2 -1
- package/dist/compiler/instance.js +8 -27
- package/dist/compiler/language-service.js +11 -62
- package/dist/compiler/transpiler.js +5 -10
- package/dist/config/config-set.d.ts +19 -26
- package/dist/config/config-set.js +305 -727
- package/dist/config/paths-to-module-name-mapper.d.ts +1 -1
- package/dist/config/paths-to-module-name-mapper.js +13 -12
- package/dist/constants.d.ts +2 -1
- package/dist/constants.js +1 -22
- package/dist/index.d.ts +4 -120
- package/dist/index.js +9 -87
- package/dist/{config → presets}/create-jest-preset.d.ts +2 -1
- package/dist/{config → presets}/create-jest-preset.js +1 -1
- package/dist/transformers/hoist-jest.js +48 -73
- package/dist/transformers/index.js +20 -4
- package/dist/transformers/path-mapping.d.ts +3 -0
- package/dist/transformers/path-mapping.js +121 -0
- package/dist/ts-jest-transformer.d.ts +5 -22
- package/dist/ts-jest-transformer.js +54 -103
- package/dist/types.d.ts +14 -90
- package/dist/{util → utils}/backports.d.ts +0 -0
- package/dist/{util → utils}/backports.js +4 -11
- package/dist/{util → utils}/get-package-version.d.ts +0 -0
- package/dist/{util → utils}/get-package-version.js +0 -3
- package/dist/{util → utils}/importer.d.ts +0 -0
- package/dist/{util → utils}/importer.js +4 -29
- package/dist/utils/json.d.ts +2 -0
- package/dist/{util → utils}/json.js +0 -14
- package/dist/utils/jsonable-value.d.ts +10 -0
- package/dist/{util → utils}/jsonable-value.js +1 -4
- package/dist/{util → utils}/logger.d.ts +0 -0
- package/dist/{util → utils}/logger.js +0 -4
- package/dist/{util → utils}/memoize.d.ts +0 -0
- package/dist/{util → utils}/memoize.js +0 -8
- package/dist/{util → utils}/messages.d.ts +0 -0
- package/dist/{util → utils}/messages.js +0 -4
- package/dist/{util → utils}/normalize-slashes.d.ts +0 -0
- package/dist/{util → utils}/normalize-slashes.js +0 -3
- package/dist/{util → utils}/sha1.d.ts +0 -0
- package/dist/{util → utils}/sha1.js +0 -10
- package/dist/{util → utils}/testing.d.ts +1 -1
- package/dist/{util → utils}/testing.js +0 -0
- package/dist/{util → utils}/ts-error.d.ts +0 -0
- package/dist/{util → utils}/ts-error.js +2 -12
- package/dist/{util → utils}/version-checkers.d.ts +0 -0
- package/dist/{util → utils}/version-checkers.js +5 -8
- package/jest-preset.js +1 -1
- package/package.json +8 -7
- package/presets/index.js +4 -4
- package/utils/index.d.ts +3 -1
- package/utils/index.js +15 -1
- package/dist/util/index.d.ts +0 -3
- package/dist/util/index.js +0 -9
- package/dist/util/json.d.ts +0 -1
- package/dist/util/jsonable-value.d.ts +0 -1
- package/presets/create.js +0 -1
- package/presets/index.d.ts +0 -5
|
@@ -49,45 +49,31 @@ var __spread = (this && this.__spread) || function () {
|
|
|
49
49
|
};
|
|
50
50
|
var _a;
|
|
51
51
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
-
exports.ConfigSet = exports.TS_JEST_OUT_DIR = exports.IGNORE_DIAGNOSTIC_CODES = exports.
|
|
52
|
+
exports.ConfigSet = exports.TS_JEST_OUT_DIR = exports.IGNORE_DIAGNOSTIC_CODES = exports.MY_DIGEST = void 0;
|
|
53
53
|
var bs_logger_1 = require("bs-logger");
|
|
54
54
|
var fs_1 = require("fs");
|
|
55
55
|
var jest_util_1 = require("jest-util");
|
|
56
56
|
var json5 = require("json5");
|
|
57
57
|
var path_1 = require("path");
|
|
58
58
|
var typescript_1 = require("typescript");
|
|
59
|
-
var __1 = require("..");
|
|
60
59
|
var instance_1 = require("../compiler/instance");
|
|
61
60
|
var constants_1 = require("../constants");
|
|
62
|
-
var
|
|
63
|
-
var backports_1 = require("../
|
|
64
|
-
var
|
|
65
|
-
var
|
|
66
|
-
var
|
|
67
|
-
var
|
|
68
|
-
var
|
|
69
|
-
var
|
|
70
|
-
var
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
var ts_error_1 = require("../util/ts-error");
|
|
74
|
-
var logger = logger_1.rootLogger.child({ namespace: 'config' });
|
|
75
|
-
/**
|
|
76
|
-
* @internal
|
|
77
|
-
*/
|
|
78
|
-
// this regex MUST match nothing, it's the goal ;-)
|
|
79
|
-
exports.MATCH_NOTHING = /a^/;
|
|
80
|
-
/**
|
|
81
|
-
* @internal
|
|
82
|
-
*/
|
|
61
|
+
var hoist_jest_1 = require("../transformers/hoist-jest");
|
|
62
|
+
var backports_1 = require("../utils/backports");
|
|
63
|
+
var importer_1 = require("../utils/importer");
|
|
64
|
+
var json_1 = require("../utils/json");
|
|
65
|
+
var logger_1 = require("../utils/logger");
|
|
66
|
+
var memoize_1 = require("../utils/memoize");
|
|
67
|
+
var messages_1 = require("../utils/messages");
|
|
68
|
+
var normalize_slashes_1 = require("../utils/normalize-slashes");
|
|
69
|
+
var sha1_1 = require("../utils/sha1");
|
|
70
|
+
var ts_error_1 = require("../utils/ts-error");
|
|
71
|
+
exports.MY_DIGEST = fs_1.readFileSync(path_1.resolve(__dirname, '..', '..', '.ts-jest-digest'), 'utf8');
|
|
83
72
|
exports.IGNORE_DIAGNOSTIC_CODES = [
|
|
84
73
|
6059,
|
|
85
74
|
18002,
|
|
86
75
|
18003,
|
|
87
76
|
];
|
|
88
|
-
/**
|
|
89
|
-
* @internal
|
|
90
|
-
*/
|
|
91
77
|
exports.TS_JEST_OUT_DIR = '$$ts-jest$$';
|
|
92
78
|
var TARGET_TO_VERSION_MAPPING = (_a = {},
|
|
93
79
|
_a[typescript_1.ScriptTarget.ES2018] = 'es2018',
|
|
@@ -98,25 +84,14 @@ var TARGET_TO_VERSION_MAPPING = (_a = {},
|
|
|
98
84
|
var normalizeRegex = function (pattern) {
|
|
99
85
|
return pattern ? (typeof pattern === 'string' ? pattern : pattern.source) : undefined;
|
|
100
86
|
};
|
|
101
|
-
var toDiagnosticCode = function (code) {
|
|
102
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
103
|
-
return code ? parseInt(("" + code).trim().replace(/^TS/, ''), 10) || undefined : undefined;
|
|
104
|
-
};
|
|
87
|
+
var toDiagnosticCode = function (code) { var _a; return code ? (_a = parseInt(("" + code).trim().replace(/^TS/, ''), 10)) !== null && _a !== void 0 ? _a : undefined : undefined; };
|
|
105
88
|
var toDiagnosticCodeList = function (items, into) {
|
|
106
89
|
var e_1, _a;
|
|
107
90
|
if (into === void 0) { into = []; }
|
|
108
|
-
if (!Array.isArray(items))
|
|
109
|
-
items = [items];
|
|
110
91
|
try {
|
|
111
92
|
for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
112
93
|
var item = items_1_1.value;
|
|
113
|
-
if (
|
|
114
|
-
continue;
|
|
115
|
-
if (Array.isArray(item)) {
|
|
116
|
-
toDiagnosticCodeList(item, into);
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
else if (typeof item === 'string') {
|
|
94
|
+
if (typeof item === 'string') {
|
|
120
95
|
var children = item.trim().split(/\s*,\s*/g);
|
|
121
96
|
if (children.length > 1) {
|
|
122
97
|
toDiagnosticCodeList(children, into);
|
|
@@ -140,641 +115,207 @@ var toDiagnosticCodeList = function (items, into) {
|
|
|
140
115
|
}
|
|
141
116
|
return into;
|
|
142
117
|
};
|
|
143
|
-
var ConfigSet =
|
|
144
|
-
function ConfigSet(jestConfig,
|
|
118
|
+
var ConfigSet = (function () {
|
|
119
|
+
function ConfigSet(jestConfig, parentLogger) {
|
|
145
120
|
var _a;
|
|
146
|
-
|
|
147
|
-
this.
|
|
148
|
-
this.
|
|
121
|
+
var _b, _c, _d, _e;
|
|
122
|
+
this.jestConfig = jestConfig;
|
|
123
|
+
this.parentLogger = parentLogger;
|
|
124
|
+
this.customTransformers = Object.create(null);
|
|
125
|
+
this._overriddenCompilerOptions = {
|
|
126
|
+
sourceMap: true,
|
|
127
|
+
inlineSourceMap: false,
|
|
128
|
+
inlineSources: true,
|
|
129
|
+
declaration: false,
|
|
130
|
+
noEmit: false,
|
|
131
|
+
removeComments: false,
|
|
132
|
+
out: undefined,
|
|
133
|
+
outFile: undefined,
|
|
134
|
+
composite: undefined,
|
|
135
|
+
declarationDir: undefined,
|
|
136
|
+
declarationMap: undefined,
|
|
137
|
+
emitDeclarationOnly: undefined,
|
|
138
|
+
sourceRoot: undefined,
|
|
139
|
+
tsBuildInfoFile: undefined,
|
|
140
|
+
};
|
|
141
|
+
this.logger = this.parentLogger
|
|
142
|
+
? this.parentLogger.child((_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'config', _a))
|
|
143
|
+
: logger_1.rootLogger.child({ namespace: 'config' });
|
|
144
|
+
this.cwd = path_1.normalize((_b = this.jestConfig.cwd) !== null && _b !== void 0 ? _b : process.cwd());
|
|
145
|
+
this.rootDir = path_1.normalize((_c = this.jestConfig.rootDir) !== null && _c !== void 0 ? _c : this.cwd);
|
|
146
|
+
var tsJestCfg = this.jestConfig.globals && this.jestConfig.globals['ts-jest'];
|
|
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.", (_d = options.compiler) !== null && _d !== void 0 ? _d : 'typescript');
|
|
149
|
+
this.isolatedModules = (_e = options.isolatedModules) !== null && _e !== void 0 ? _e : false;
|
|
150
|
+
this.logger.debug({ compilerModule: this.compilerModule }, 'normalized compiler module config via ts-jest option');
|
|
151
|
+
this._backportJestCfg();
|
|
152
|
+
this._setupTsJestCfg(options);
|
|
153
|
+
this._resolveTsCacheDir();
|
|
149
154
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
* @internal
|
|
170
|
-
*/
|
|
171
|
-
get: function () {
|
|
172
|
-
var matchablePatterns = __spread(this.jest.testMatch, this.jest.testRegex).filter(function (pattern) {
|
|
173
|
-
/**
|
|
174
|
-
* jest config testRegex doesn't always deliver the correct RegExp object
|
|
175
|
-
* See https://github.com/facebook/jest/issues/9778
|
|
176
|
-
*/
|
|
177
|
-
return pattern instanceof RegExp || typeof pattern === 'string';
|
|
178
|
-
});
|
|
179
|
-
if (!matchablePatterns.length) {
|
|
180
|
-
matchablePatterns.push.apply(matchablePatterns, __spread(constants_1.DEFAULT_JEST_TEST_MATCH));
|
|
181
|
-
}
|
|
182
|
-
var stringPatterns = matchablePatterns.filter(function (pattern) { return typeof pattern === 'string'; });
|
|
183
|
-
var isMatch = jest_util_1.globsToMatcher(stringPatterns);
|
|
184
|
-
return function (fileName) {
|
|
185
|
-
return matchablePatterns.some(function (pattern) { return (typeof pattern === 'string' ? isMatch(fileName) : pattern.test(fileName)); });
|
|
186
|
-
};
|
|
187
|
-
},
|
|
188
|
-
enumerable: false,
|
|
189
|
-
configurable: true
|
|
190
|
-
});
|
|
191
|
-
Object.defineProperty(ConfigSet.prototype, "tsJest", {
|
|
192
|
-
/**
|
|
193
|
-
* @internal
|
|
194
|
-
*/
|
|
195
|
-
get: function () {
|
|
196
|
-
var _this = this;
|
|
197
|
-
var _a, _b, _c;
|
|
198
|
-
var parsedConfig = this.jest;
|
|
199
|
-
var _d = parsedConfig.globals, globals = _d === void 0 ? {} : _d;
|
|
200
|
-
var options = __assign({}, globals['ts-jest']);
|
|
201
|
-
// tsconfig
|
|
202
|
-
var tsConfigOpt = (_b = (_a = options.tsConfig) !== null && _a !== void 0 ? _a : options.tsconfig) !== null && _b !== void 0 ? _b : true;
|
|
203
|
-
var tsConfig;
|
|
204
|
-
if (typeof tsConfigOpt === 'string' || tsConfigOpt === true) {
|
|
205
|
-
tsConfig = {
|
|
206
|
-
kind: 'file',
|
|
207
|
-
value: typeof tsConfigOpt === 'string' ? this.resolvePath(tsConfigOpt) : undefined,
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
else if (typeof tsConfigOpt === 'object') {
|
|
211
|
-
tsConfig = {
|
|
212
|
-
kind: 'inline',
|
|
213
|
-
value: tsConfigOpt,
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
// packageJson
|
|
217
|
-
var packageJsonOpt = options.packageJson;
|
|
218
|
-
var packageJson;
|
|
219
|
-
if (typeof packageJsonOpt === 'string' || packageJsonOpt == null || packageJsonOpt === true) {
|
|
220
|
-
packageJson = {
|
|
221
|
-
kind: 'file',
|
|
222
|
-
value: typeof packageJsonOpt === 'string' ? this.resolvePath(packageJsonOpt) : undefined,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
else if (typeof packageJsonOpt === 'object') {
|
|
226
|
-
packageJson = {
|
|
227
|
-
kind: 'inline',
|
|
228
|
-
value: packageJsonOpt,
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
// transformers
|
|
232
|
-
var transformers = Object.create(null);
|
|
233
|
-
var astTransformers = options.astTransformers;
|
|
234
|
-
if (astTransformers) {
|
|
235
|
-
if (Array.isArray(astTransformers)) {
|
|
236
|
-
this.logger.warn("The configuration for astTransformers as string[] is deprecated and will be removed in ts-jest 27. Please define your custom AST transformers in a form of an object. More information you can check online documentation https://kulshekhar.github.io/ts-jest/user/config/astTransformers" /* AstTransformerArrayConfig */);
|
|
237
|
-
transformers = {
|
|
238
|
-
before: astTransformers.map(function (transformerPath) { return _this.resolvePath(transformerPath, { nodeResolve: true }); }),
|
|
239
|
-
};
|
|
155
|
+
ConfigSet.prototype._backportJestCfg = function () {
|
|
156
|
+
var config = backports_1.backportJestConfig(this.logger, this.jestConfig);
|
|
157
|
+
this.logger.debug({ jestConfig: config }, 'normalized jest config');
|
|
158
|
+
this._jestCfg = config;
|
|
159
|
+
};
|
|
160
|
+
ConfigSet.prototype._setupTsJestCfg = function (options) {
|
|
161
|
+
var _this = this;
|
|
162
|
+
var _a, _b, _c;
|
|
163
|
+
if (options.packageJson) {
|
|
164
|
+
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
|
+
}
|
|
166
|
+
if (!options.babelConfig) {
|
|
167
|
+
this.logger.debug('babel is disabled');
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
var baseBabelCfg = { cwd: this.cwd };
|
|
171
|
+
if (typeof options.babelConfig === 'string') {
|
|
172
|
+
if (path_1.extname(options.babelConfig) === '.js') {
|
|
173
|
+
this._babelConfig = __assign(__assign({}, baseBabelCfg), require(this.resolvePath(options.babelConfig, { nodeResolve: true })));
|
|
240
174
|
}
|
|
241
175
|
else {
|
|
242
|
-
|
|
243
|
-
transformers = {
|
|
244
|
-
before: astTransformers.before.map(function (transformerPath) {
|
|
245
|
-
return _this.resolvePath(transformerPath, { nodeResolve: true });
|
|
246
|
-
}),
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
if (astTransformers.after) {
|
|
250
|
-
transformers = __assign(__assign({}, transformers), { after: astTransformers.after.map(function (transformerPath) {
|
|
251
|
-
return _this.resolvePath(transformerPath, { nodeResolve: true });
|
|
252
|
-
}) });
|
|
253
|
-
}
|
|
254
|
-
if (astTransformers.afterDeclarations) {
|
|
255
|
-
transformers = __assign(__assign({}, transformers), { afterDeclarations: astTransformers.afterDeclarations.map(function (transformerPath) {
|
|
256
|
-
return _this.resolvePath(transformerPath, { nodeResolve: true });
|
|
257
|
-
}) });
|
|
258
|
-
}
|
|
176
|
+
this._babelConfig = __assign(__assign({}, baseBabelCfg), json5.parse(fs_1.readFileSync(options.babelConfig, 'utf-8')));
|
|
259
177
|
}
|
|
260
178
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
var babelConfig;
|
|
264
|
-
if (typeof babelConfigOpt === 'string' || babelConfigOpt === true) {
|
|
265
|
-
babelConfig = {
|
|
266
|
-
kind: 'file',
|
|
267
|
-
value: babelConfigOpt === true ? undefined : this.resolvePath(babelConfigOpt),
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
else if (babelConfigOpt) {
|
|
271
|
-
babelConfig = {
|
|
272
|
-
kind: 'inline',
|
|
273
|
-
value: babelConfigOpt,
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
// diagnostics
|
|
277
|
-
var diagnostics;
|
|
278
|
-
var _e = options.diagnostics, diagnosticsOpt = _e === void 0 ? true : _e;
|
|
279
|
-
// messy list of stuff to ignore (will be casted later)
|
|
280
|
-
var ignoreList = [exports.IGNORE_DIAGNOSTIC_CODES, process.env.TS_JEST_IGNORE_DIAGNOSTICS];
|
|
281
|
-
if (diagnosticsOpt === true || diagnosticsOpt == null) {
|
|
282
|
-
diagnostics = { ignoreCodes: [], pretty: true, throws: true };
|
|
283
|
-
}
|
|
284
|
-
else if (diagnosticsOpt === false) {
|
|
285
|
-
diagnostics = {
|
|
286
|
-
throws: false,
|
|
287
|
-
pretty: true,
|
|
288
|
-
ignoreCodes: [],
|
|
289
|
-
pathRegex: exports.MATCH_NOTHING.source,
|
|
290
|
-
};
|
|
179
|
+
else if (typeof options.babelConfig === 'object') {
|
|
180
|
+
this._babelConfig = __assign(__assign({}, baseBabelCfg), options.babelConfig);
|
|
291
181
|
}
|
|
292
182
|
else {
|
|
293
|
-
|
|
294
|
-
diagnostics = {
|
|
295
|
-
pretty: diagnosticsOpt.pretty == null ? true : !!diagnosticsOpt.pretty,
|
|
296
|
-
ignoreCodes: [],
|
|
297
|
-
pathRegex: normalizeRegex(diagnosticsOpt.pathRegex),
|
|
298
|
-
throws: !diagnosticsOpt.warnOnly,
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
// now we clean and flatten the list
|
|
302
|
-
diagnostics.ignoreCodes = toDiagnosticCodeList(ignoreList);
|
|
303
|
-
// stringifyContentPathRegex option
|
|
304
|
-
var stringifyContentPathRegex = normalizeRegex(options.stringifyContentPathRegex);
|
|
305
|
-
// parsed options
|
|
306
|
-
var res = {
|
|
307
|
-
tsConfig: tsConfig,
|
|
308
|
-
packageJson: packageJson,
|
|
309
|
-
babelConfig: babelConfig,
|
|
310
|
-
diagnostics: diagnostics,
|
|
311
|
-
isolatedModules: !!options.isolatedModules,
|
|
312
|
-
compiler: (_c = options.compiler) !== null && _c !== void 0 ? _c : 'typescript',
|
|
313
|
-
transformers: transformers,
|
|
314
|
-
stringifyContentPathRegex: stringifyContentPathRegex,
|
|
315
|
-
};
|
|
316
|
-
this.logger.debug({ tsJestConfig: res }, 'normalized ts-jest config');
|
|
317
|
-
return res;
|
|
318
|
-
},
|
|
319
|
-
enumerable: false,
|
|
320
|
-
configurable: true
|
|
321
|
-
});
|
|
322
|
-
Object.defineProperty(ConfigSet.prototype, "parsedTsConfig", {
|
|
323
|
-
/**
|
|
324
|
-
* @internal
|
|
325
|
-
*/
|
|
326
|
-
get: function () {
|
|
327
|
-
return this._parsedTsConfig;
|
|
328
|
-
},
|
|
329
|
-
enumerable: false,
|
|
330
|
-
configurable: true
|
|
331
|
-
});
|
|
332
|
-
Object.defineProperty(ConfigSet.prototype, "versions", {
|
|
333
|
-
/**
|
|
334
|
-
* Use by e2e, don't mark as internal
|
|
335
|
-
*/
|
|
336
|
-
get: function () {
|
|
337
|
-
var modules = ['jest', this.tsJest.compiler];
|
|
338
|
-
if (this.tsJest.babelConfig) {
|
|
339
|
-
modules.push('@babel/core', 'babel-jest');
|
|
183
|
+
this._babelConfig = baseBabelCfg;
|
|
340
184
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
var
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
this.
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
configurable: true
|
|
365
|
-
});
|
|
366
|
-
Object.defineProperty(ConfigSet.prototype, "raiseDiagnostics", {
|
|
367
|
-
/**
|
|
368
|
-
* @internal
|
|
369
|
-
*/
|
|
370
|
-
get: function () {
|
|
371
|
-
var _this = this;
|
|
372
|
-
var _a = this, createTsError = _a.createTsError, filterDiagnostics = _a.filterDiagnostics, throws = _a.tsJest.diagnostics.throws, DiagnosticCategory = _a.compilerModule.DiagnosticCategory;
|
|
373
|
-
return function (diagnostics, filePath, logger) {
|
|
374
|
-
if (logger === void 0) { logger = _this.logger; }
|
|
375
|
-
var filteredDiagnostics = filterDiagnostics(diagnostics, filePath);
|
|
376
|
-
if (!filteredDiagnostics.length)
|
|
377
|
-
return;
|
|
378
|
-
var error = createTsError(filteredDiagnostics);
|
|
379
|
-
// only throw if `warnOnly` and it is a warning or error
|
|
380
|
-
var importantCategories = [DiagnosticCategory.Warning, DiagnosticCategory.Error];
|
|
381
|
-
if (throws && filteredDiagnostics.some(function (d) { return importantCategories.includes(d.category); })) {
|
|
382
|
-
throw error;
|
|
383
|
-
}
|
|
384
|
-
logger.warn({ error: error }, error.message);
|
|
185
|
+
this.logger.debug({ babelConfig: this._babelConfig }, 'normalized babel config via ts-jest option');
|
|
186
|
+
}
|
|
187
|
+
if (!this._babelConfig) {
|
|
188
|
+
this._overriddenCompilerOptions.module = this.compilerModule.ModuleKind.CommonJS;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
this._babelJestTransformers = importer_1.importer
|
|
192
|
+
.babelJest("Using \"babel-jest\" requires this package to be installed.")
|
|
193
|
+
.createTransformer(this._babelConfig);
|
|
194
|
+
this.logger.debug('created babel-jest transformer');
|
|
195
|
+
}
|
|
196
|
+
var diagnosticsOpt = (_a = options.diagnostics) !== null && _a !== void 0 ? _a : true;
|
|
197
|
+
var ignoreList = __spread(exports.IGNORE_DIAGNOSTIC_CODES);
|
|
198
|
+
if (typeof diagnosticsOpt === 'object') {
|
|
199
|
+
var ignoreCodes = diagnosticsOpt.ignoreCodes;
|
|
200
|
+
if (ignoreCodes) {
|
|
201
|
+
Array.isArray(ignoreCodes) ? ignoreList.push.apply(ignoreList, __spread(ignoreCodes)) : ignoreList.push(ignoreCodes);
|
|
202
|
+
}
|
|
203
|
+
this._diagnostics = {
|
|
204
|
+
pretty: (_b = diagnosticsOpt.pretty) !== null && _b !== void 0 ? _b : true,
|
|
205
|
+
ignoreCodes: toDiagnosticCodeList(ignoreList),
|
|
206
|
+
pathRegex: normalizeRegex(diagnosticsOpt.pathRegex),
|
|
207
|
+
throws: !diagnosticsOpt.warnOnly,
|
|
385
208
|
};
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
* @internal
|
|
393
|
-
*/
|
|
394
|
-
get: function () {
|
|
395
|
-
var babelConfig = this.tsJest.babelConfig;
|
|
396
|
-
if (babelConfig == null) {
|
|
397
|
-
this.logger.debug('babel is disabled');
|
|
398
|
-
return undefined;
|
|
399
|
-
}
|
|
400
|
-
var base = { cwd: this.cwd };
|
|
401
|
-
if (babelConfig.kind === 'file') {
|
|
402
|
-
if (babelConfig.value) {
|
|
403
|
-
if (path_1.extname(babelConfig.value) === '.js') {
|
|
404
|
-
base = __assign(__assign({}, base), require(babelConfig.value));
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
base = __assign(__assign({}, base), json5.parse(fs_1.readFileSync(babelConfig.value, 'utf8')));
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
else if (babelConfig.kind === 'inline') {
|
|
412
|
-
base = __assign(__assign({}, base), babelConfig.value);
|
|
413
|
-
}
|
|
414
|
-
this.logger.debug({ babelConfig: base }, 'normalized babel config via ts-jest option');
|
|
415
|
-
return base;
|
|
416
|
-
},
|
|
417
|
-
enumerable: false,
|
|
418
|
-
configurable: true
|
|
419
|
-
});
|
|
420
|
-
Object.defineProperty(ConfigSet.prototype, "compilerModule", {
|
|
421
|
-
/**
|
|
422
|
-
* This API can be used by custom transformers
|
|
423
|
-
*/
|
|
424
|
-
get: function () {
|
|
425
|
-
return importer_1.importer.typescript("Using \"ts-jest\" requires this package to be installed." /* TsJest */, this.tsJest.compiler);
|
|
426
|
-
},
|
|
427
|
-
enumerable: false,
|
|
428
|
-
configurable: true
|
|
429
|
-
});
|
|
430
|
-
Object.defineProperty(ConfigSet.prototype, "babelJestTransformer", {
|
|
431
|
-
/**
|
|
432
|
-
* @internal
|
|
433
|
-
*/
|
|
434
|
-
get: function () {
|
|
435
|
-
var babel = this.babel;
|
|
436
|
-
if (!babel)
|
|
437
|
-
return undefined;
|
|
438
|
-
this.logger.debug('creating babel-jest transformer');
|
|
439
|
-
return importer_1.importer.babelJest("Using \"babel-jest\" requires this package to be installed." /* BabelJest */).createTransformer(babel);
|
|
440
|
-
},
|
|
441
|
-
enumerable: false,
|
|
442
|
-
configurable: true
|
|
443
|
-
});
|
|
444
|
-
Object.defineProperty(ConfigSet.prototype, "tsCompiler", {
|
|
445
|
-
get: function () {
|
|
446
|
-
return instance_1.createCompilerInstance(this);
|
|
447
|
-
},
|
|
448
|
-
enumerable: false,
|
|
449
|
-
configurable: true
|
|
450
|
-
});
|
|
451
|
-
Object.defineProperty(ConfigSet.prototype, "astTransformers", {
|
|
452
|
-
/**
|
|
453
|
-
* @internal
|
|
454
|
-
*/
|
|
455
|
-
get: function () {
|
|
456
|
-
var astTransformers = {
|
|
457
|
-
before: __spread(transformers_1.internals),
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
this._diagnostics = {
|
|
212
|
+
ignoreCodes: diagnosticsOpt ? toDiagnosticCodeList(ignoreList) : [],
|
|
213
|
+
pretty: true,
|
|
214
|
+
throws: diagnosticsOpt,
|
|
458
215
|
};
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
216
|
+
}
|
|
217
|
+
this.logger.debug({ diagnostics: this._diagnostics }, 'normalized diagnostics config via ts-jest option');
|
|
218
|
+
if (options.tsConfig) {
|
|
219
|
+
this.logger.warn("The option `tsConfig` is deprecated and will be removed in ts-jest 27, use `tsconfig` instead");
|
|
220
|
+
}
|
|
221
|
+
var tsconfigOpt = (_c = options.tsConfig) !== null && _c !== void 0 ? _c : options.tsconfig;
|
|
222
|
+
var configFilePath = typeof tsconfigOpt === 'string' ? this.resolvePath(tsconfigOpt) : undefined;
|
|
223
|
+
this.parsedTsConfig = this._readTsConfig(typeof tsconfigOpt === 'object' ? tsconfigOpt : undefined, configFilePath);
|
|
224
|
+
this.raiseDiagnostics(this.parsedTsConfig.errors, configFilePath);
|
|
225
|
+
this.logger.debug({ tsconfig: this.parsedTsConfig }, 'normalized typescript config via ts-jest option');
|
|
226
|
+
var astTransformers = options.astTransformers;
|
|
227
|
+
this.customTransformers = {
|
|
228
|
+
before: [hoist_jest_1.factory(this)],
|
|
229
|
+
};
|
|
230
|
+
if (astTransformers) {
|
|
231
|
+
if (Array.isArray(astTransformers)) {
|
|
232
|
+
this.logger.warn("The configuration for astTransformers as string[] is deprecated and will be removed in ts-jest 27. Please define your custom AST transformers in a form of an object. More information you can check online documentation https://kulshekhar.github.io/ts-jest/user/config/astTransformers");
|
|
233
|
+
this.customTransformers = {
|
|
234
|
+
before: __spread(this.customTransformers.before, astTransformers.map(function (transformer) {
|
|
235
|
+
var transformerPath = _this.resolvePath(transformer, { nodeResolve: true });
|
|
236
|
+
return require(transformerPath).factory(_this);
|
|
237
|
+
})),
|
|
463
238
|
};
|
|
464
239
|
}
|
|
465
|
-
if (transformers.after) {
|
|
466
|
-
astTransformers = __assign(__assign({}, astTransformers), { after: transformers.after.map(function (transformerFilePath) { return require(transformerFilePath); }) });
|
|
467
|
-
}
|
|
468
|
-
if (transformers.afterDeclarations) {
|
|
469
|
-
astTransformers = __assign(__assign({}, astTransformers), { afterDeclarations: transformers.afterDeclarations.map(function (transformerFilePath) {
|
|
470
|
-
return require(transformerFilePath);
|
|
471
|
-
}) });
|
|
472
|
-
}
|
|
473
|
-
return astTransformers;
|
|
474
|
-
},
|
|
475
|
-
enumerable: false,
|
|
476
|
-
configurable: true
|
|
477
|
-
});
|
|
478
|
-
Object.defineProperty(ConfigSet.prototype, "tsCustomTransformers", {
|
|
479
|
-
/**
|
|
480
|
-
* @internal
|
|
481
|
-
*/
|
|
482
|
-
get: function () {
|
|
483
|
-
var _this = this;
|
|
484
|
-
var customTransformers = {
|
|
485
|
-
before: this.astTransformers.before.map(function (t) { return t.factory(_this); }),
|
|
486
|
-
};
|
|
487
|
-
if (this.astTransformers.after) {
|
|
488
|
-
customTransformers = __assign(__assign({}, customTransformers), { after: this.astTransformers.after.map(function (t) { return t.factory(_this); }) });
|
|
489
|
-
}
|
|
490
|
-
if (this.astTransformers.afterDeclarations) {
|
|
491
|
-
customTransformers = __assign(__assign({}, customTransformers), { afterDeclarations: this.astTransformers.afterDeclarations.map(function (t) { return t.factory(_this); }) });
|
|
492
|
-
}
|
|
493
|
-
return customTransformers;
|
|
494
|
-
},
|
|
495
|
-
enumerable: false,
|
|
496
|
-
configurable: true
|
|
497
|
-
});
|
|
498
|
-
Object.defineProperty(ConfigSet.prototype, "hooks", {
|
|
499
|
-
/**
|
|
500
|
-
* @internal
|
|
501
|
-
*/
|
|
502
|
-
get: function () {
|
|
503
|
-
var hooksFile = process.env.TS_JEST_HOOKS;
|
|
504
|
-
if (hooksFile) {
|
|
505
|
-
hooksFile = path_1.resolve(this.cwd, hooksFile);
|
|
506
|
-
return importer_1.importer.tryTheseOr(hooksFile, {});
|
|
507
|
-
}
|
|
508
|
-
return {};
|
|
509
|
-
},
|
|
510
|
-
enumerable: false,
|
|
511
|
-
configurable: true
|
|
512
|
-
});
|
|
513
|
-
Object.defineProperty(ConfigSet.prototype, "filterDiagnostics", {
|
|
514
|
-
/**
|
|
515
|
-
* @internal
|
|
516
|
-
*/
|
|
517
|
-
get: function () {
|
|
518
|
-
var _a = this, ignoreCodes = _a.tsJest.diagnostics.ignoreCodes, shouldReportDiagnostic = _a.shouldReportDiagnostic;
|
|
519
|
-
return function (diagnostics, filePath) {
|
|
520
|
-
if (filePath && !shouldReportDiagnostic(filePath))
|
|
521
|
-
return [];
|
|
522
|
-
return diagnostics.filter(function (diagnostic) {
|
|
523
|
-
var _a;
|
|
524
|
-
if (((_a = diagnostic.file) === null || _a === void 0 ? void 0 : _a.fileName) && !shouldReportDiagnostic(diagnostic.file.fileName)) {
|
|
525
|
-
return false;
|
|
526
|
-
}
|
|
527
|
-
return !ignoreCodes.includes(diagnostic.code);
|
|
528
|
-
});
|
|
529
|
-
};
|
|
530
|
-
},
|
|
531
|
-
enumerable: false,
|
|
532
|
-
configurable: true
|
|
533
|
-
});
|
|
534
|
-
Object.defineProperty(ConfigSet.prototype, "shouldReportDiagnostic", {
|
|
535
|
-
/**
|
|
536
|
-
* @internal
|
|
537
|
-
*/
|
|
538
|
-
get: function () {
|
|
539
|
-
var pathRegex = this.tsJest.diagnostics.pathRegex;
|
|
540
|
-
if (pathRegex) {
|
|
541
|
-
var regex_1 = new RegExp(pathRegex);
|
|
542
|
-
return function (file) { return regex_1.test(file); };
|
|
543
|
-
}
|
|
544
|
-
else {
|
|
545
|
-
return function () { return true; };
|
|
546
|
-
}
|
|
547
|
-
},
|
|
548
|
-
enumerable: false,
|
|
549
|
-
configurable: true
|
|
550
|
-
});
|
|
551
|
-
Object.defineProperty(ConfigSet.prototype, "shouldStringifyContent", {
|
|
552
|
-
/**
|
|
553
|
-
* @internal
|
|
554
|
-
*/
|
|
555
|
-
get: function () {
|
|
556
|
-
var stringifyContentPathRegex = this.tsJest.stringifyContentPathRegex;
|
|
557
|
-
if (stringifyContentPathRegex) {
|
|
558
|
-
var regex_2 = new RegExp(stringifyContentPathRegex);
|
|
559
|
-
return function (file) { return regex_2.test(file); };
|
|
560
|
-
}
|
|
561
240
|
else {
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
return new ts_error_1.TSError(diagnosticText, diagnosticCodes);
|
|
587
|
-
};
|
|
588
|
-
},
|
|
589
|
-
enumerable: false,
|
|
590
|
-
configurable: true
|
|
591
|
-
});
|
|
592
|
-
Object.defineProperty(ConfigSet.prototype, "tsCacheDir", {
|
|
593
|
-
/**
|
|
594
|
-
* @internal
|
|
595
|
-
*/
|
|
596
|
-
get: function () {
|
|
597
|
-
if (!this.jest.cache) {
|
|
598
|
-
logger.debug('file caching disabled');
|
|
599
|
-
return undefined;
|
|
600
|
-
}
|
|
601
|
-
var cacheSuffix = sha1_1.sha1(json_1.stringify({
|
|
602
|
-
version: this.compilerModule.version,
|
|
603
|
-
digest: this.tsJestDigest,
|
|
604
|
-
compiler: this.tsJest.compiler,
|
|
605
|
-
compilerOptions: this.parsedTsConfig.options,
|
|
606
|
-
isolatedModules: this.tsJest.isolatedModules,
|
|
607
|
-
diagnostics: this.tsJest.diagnostics,
|
|
608
|
-
}));
|
|
609
|
-
var res = path_1.join(this.jest.cacheDirectory, 'ts-jest', cacheSuffix.substr(0, 2), cacheSuffix.substr(2));
|
|
610
|
-
logger.debug({ cacheDirectory: res }, 'will use file caching');
|
|
611
|
-
return res;
|
|
612
|
-
},
|
|
613
|
-
enumerable: false,
|
|
614
|
-
configurable: true
|
|
615
|
-
});
|
|
616
|
-
Object.defineProperty(ConfigSet.prototype, "overriddenCompilerOptions", {
|
|
617
|
-
/**
|
|
618
|
-
* @internal
|
|
619
|
-
*/
|
|
620
|
-
get: function () {
|
|
621
|
-
var options = {
|
|
622
|
-
// we handle sourcemaps this way and not another
|
|
623
|
-
sourceMap: true,
|
|
624
|
-
inlineSourceMap: false,
|
|
625
|
-
inlineSources: true,
|
|
626
|
-
// we don't want to create declaration files
|
|
627
|
-
declaration: false,
|
|
628
|
-
noEmit: false,
|
|
629
|
-
// else istanbul related will be dropped
|
|
630
|
-
removeComments: false,
|
|
631
|
-
// to clear out else it's buggy
|
|
632
|
-
out: undefined,
|
|
633
|
-
outFile: undefined,
|
|
634
|
-
composite: undefined,
|
|
635
|
-
declarationDir: undefined,
|
|
636
|
-
declarationMap: undefined,
|
|
637
|
-
emitDeclarationOnly: undefined,
|
|
638
|
-
sourceRoot: undefined,
|
|
639
|
-
tsBuildInfoFile: undefined,
|
|
640
|
-
};
|
|
641
|
-
// force the module kind if not piping babel-jest
|
|
642
|
-
if (!this.tsJest.babelConfig) {
|
|
643
|
-
// commonjs is required for jest
|
|
644
|
-
options.module = this.compilerModule.ModuleKind.CommonJS;
|
|
241
|
+
var resolveTransformers = function (transformers) {
|
|
242
|
+
return transformers.map(function (transformer) {
|
|
243
|
+
var transformerPath;
|
|
244
|
+
if (typeof transformer === 'string') {
|
|
245
|
+
transformerPath = _this.resolvePath(transformer, { nodeResolve: true });
|
|
246
|
+
return require(transformerPath).factory(_this);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
transformerPath = _this.resolvePath(transformer.path, { nodeResolve: true });
|
|
250
|
+
return require(transformerPath).factory(_this, transformer.options);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
if (astTransformers.before) {
|
|
255
|
+
this.customTransformers = {
|
|
256
|
+
before: __spread(this.customTransformers.before, resolveTransformers(astTransformers.before)),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
if (astTransformers.after) {
|
|
260
|
+
this.customTransformers = __assign(__assign({}, this.customTransformers), { after: resolveTransformers(astTransformers.after) });
|
|
261
|
+
}
|
|
262
|
+
if (astTransformers.afterDeclarations) {
|
|
263
|
+
this.customTransformers = __assign(__assign({}, this.customTransformers), { afterDeclarations: resolveTransformers(astTransformers.afterDeclarations) });
|
|
264
|
+
}
|
|
645
265
|
}
|
|
646
|
-
|
|
647
|
-
},
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
/**
|
|
673
|
-
* Use by e2e, don't mark as internal
|
|
674
|
-
*/
|
|
675
|
-
get: function () {
|
|
676
|
-
return __1.digest;
|
|
677
|
-
},
|
|
678
|
-
enumerable: false,
|
|
679
|
-
configurable: true
|
|
680
|
-
});
|
|
681
|
-
Object.defineProperty(ConfigSet.prototype, "jsonValue", {
|
|
682
|
-
/**
|
|
683
|
-
* @internal
|
|
684
|
-
*/
|
|
685
|
-
get: function () {
|
|
686
|
-
var jest = __assign({}, this.jest);
|
|
687
|
-
var globals = (jest.globals = __assign({}, jest.globals));
|
|
688
|
-
// we need to remove some stuff from jest config
|
|
689
|
-
// this which does not depend on config
|
|
690
|
-
jest.name = undefined;
|
|
691
|
-
jest.cacheDirectory = undefined;
|
|
692
|
-
// we do not need this since its normalized version is in tsJest
|
|
693
|
-
delete globals['ts-jest'];
|
|
694
|
-
return new jsonable_value_1.JsonableValue({
|
|
695
|
-
digest: this.tsJestDigest,
|
|
696
|
-
transformers: Object.values(this.astTransformers)
|
|
697
|
-
.reduce(function (acc, val) { return acc.concat(val); }, [])
|
|
698
|
-
.map(function (t) { return t.name + "@" + t.version; }),
|
|
699
|
-
jest: jest,
|
|
700
|
-
tsJest: this.tsJest,
|
|
701
|
-
babel: this.babel,
|
|
702
|
-
tsconfig: {
|
|
703
|
-
options: this.parsedTsConfig.options,
|
|
704
|
-
raw: this.parsedTsConfig.raw,
|
|
705
|
-
},
|
|
706
|
-
});
|
|
707
|
-
},
|
|
708
|
-
enumerable: false,
|
|
709
|
-
configurable: true
|
|
710
|
-
});
|
|
711
|
-
Object.defineProperty(ConfigSet.prototype, "cacheKey", {
|
|
712
|
-
/**
|
|
713
|
-
* @internal
|
|
714
|
-
*/
|
|
715
|
-
get: function () {
|
|
716
|
-
return this.jsonValue.serialized;
|
|
717
|
-
},
|
|
718
|
-
enumerable: false,
|
|
719
|
-
configurable: true
|
|
720
|
-
});
|
|
721
|
-
/**
|
|
722
|
-
* @internal
|
|
723
|
-
*/
|
|
724
|
-
ConfigSet.prototype.makeDiagnostic = function (code, messageText, options) {
|
|
725
|
-
if (options === void 0) { options = {}; }
|
|
726
|
-
var _a = options.category, category = _a === void 0 ? this.compilerModule.DiagnosticCategory.Warning : _a, file = options.file, start = options.start, length = options.length;
|
|
727
|
-
return {
|
|
728
|
-
code: code,
|
|
729
|
-
messageText: messageText,
|
|
730
|
-
category: category,
|
|
731
|
-
file: file,
|
|
732
|
-
start: start,
|
|
733
|
-
length: length,
|
|
734
|
-
};
|
|
266
|
+
}
|
|
267
|
+
this.logger.debug({ customTransformers: this.customTransformers }, 'normalized custom AST transformers via ts-jest option');
|
|
268
|
+
if (options.stringifyContentPathRegex) {
|
|
269
|
+
this._stringifyContentRegExp =
|
|
270
|
+
typeof options.stringifyContentPathRegex === 'string'
|
|
271
|
+
? new RegExp(normalizeRegex(options.stringifyContentPathRegex))
|
|
272
|
+
: options.stringifyContentPathRegex;
|
|
273
|
+
this.logger.debug({ stringifyContentPathRegex: this._stringifyContentRegExp }, 'normalized stringifyContentPathRegex config via ts-jest option');
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
ConfigSet.prototype._resolveTsCacheDir = function () {
|
|
277
|
+
if (!this._jestCfg.cache) {
|
|
278
|
+
this.logger.debug('file caching disabled');
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
var cacheSuffix = sha1_1.sha1(json_1.stringify({
|
|
282
|
+
version: this.compilerModule.version,
|
|
283
|
+
digest: this.tsJestDigest,
|
|
284
|
+
compilerModule: this.compilerModule,
|
|
285
|
+
compilerOptions: this.parsedTsConfig.options,
|
|
286
|
+
isolatedModules: this.isolatedModules,
|
|
287
|
+
diagnostics: this._diagnostics,
|
|
288
|
+
}));
|
|
289
|
+
var res = path_1.join(this._jestCfg.cacheDirectory, 'ts-jest', cacheSuffix.substr(0, 2), cacheSuffix.substr(2));
|
|
290
|
+
this.logger.debug({ cacheDirectory: res }, 'will use file caching');
|
|
291
|
+
this.tsCacheDir = res;
|
|
735
292
|
};
|
|
736
|
-
|
|
737
|
-
* Load TypeScript configuration. Returns the parsed TypeScript config and
|
|
738
|
-
* any `tsConfig` options specified in ts-jest tsConfig
|
|
739
|
-
*
|
|
740
|
-
* @internal
|
|
741
|
-
*/
|
|
742
|
-
ConfigSet.prototype.readTsConfig = function (compilerOptions, resolvedConfigFile, noProject) {
|
|
293
|
+
ConfigSet.prototype._readTsConfig = function (compilerOptions, resolvedConfigFile) {
|
|
743
294
|
var e_2, _a;
|
|
744
295
|
var _b;
|
|
745
296
|
var config = { compilerOptions: Object.create(null) };
|
|
746
297
|
var basePath = normalize_slashes_1.normalizeSlashes(this.rootDir);
|
|
747
|
-
var configFileName;
|
|
748
298
|
var ts = this.compilerModule;
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
}
|
|
761
|
-
config = result_1.config;
|
|
762
|
-
basePath = normalize_slashes_1.normalizeSlashes(path_1.dirname(configFileName));
|
|
763
|
-
}
|
|
299
|
+
var configFileName = resolvedConfigFile
|
|
300
|
+
? normalize_slashes_1.normalizeSlashes(resolvedConfigFile)
|
|
301
|
+
: ts.findConfigFile(normalize_slashes_1.normalizeSlashes(this.rootDir), ts.sys.fileExists);
|
|
302
|
+
if (configFileName) {
|
|
303
|
+
this.logger.debug({ tsConfigFileName: configFileName }, 'readTsConfig(): reading', configFileName);
|
|
304
|
+
var result_1 = ts.readConfigFile(configFileName, ts.sys.readFile);
|
|
305
|
+
if (result_1.error) {
|
|
306
|
+
return { errors: [result_1.error], fileNames: [], options: {} };
|
|
307
|
+
}
|
|
308
|
+
config = result_1.config;
|
|
309
|
+
basePath = normalize_slashes_1.normalizeSlashes(path_1.dirname(configFileName));
|
|
764
310
|
}
|
|
765
|
-
// Override default configuration options `ts-jest` requires.
|
|
766
311
|
config.compilerOptions = __assign(__assign({}, config.compilerOptions), compilerOptions);
|
|
767
|
-
// parse json, merge config extending others, ...
|
|
768
312
|
var result = ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, configFileName);
|
|
769
|
-
var forcedOptions = this.
|
|
313
|
+
var forcedOptions = this._overriddenCompilerOptions;
|
|
770
314
|
var finalOptions = result.options;
|
|
771
|
-
// Target ES5 output by default (instead of ES3).
|
|
772
315
|
if (finalOptions.target === undefined) {
|
|
773
316
|
finalOptions.target = ts.ScriptTarget.ES5;
|
|
774
317
|
}
|
|
775
|
-
// check the module interoperability
|
|
776
318
|
var target = finalOptions.target;
|
|
777
|
-
// compute the default if not set
|
|
778
319
|
var defaultModule = [ts.ScriptTarget.ES3, ts.ScriptTarget.ES5].includes(target)
|
|
779
320
|
? ts.ModuleKind.CommonJS
|
|
780
321
|
: ts.ModuleKind.ESNext;
|
|
@@ -782,20 +323,22 @@ var ConfigSet = /** @class */ (function () {
|
|
|
782
323
|
if ('module' in forcedOptions &&
|
|
783
324
|
moduleValue !== forcedOptions.module &&
|
|
784
325
|
!(finalOptions.esModuleInterop || finalOptions.allowSyntheticDefaultImports)) {
|
|
785
|
-
result.errors.push(
|
|
326
|
+
result.errors.push({
|
|
327
|
+
code: 151001,
|
|
328
|
+
messageText: "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.",
|
|
786
329
|
category: ts.DiagnosticCategory.Message,
|
|
787
|
-
|
|
788
|
-
|
|
330
|
+
file: undefined,
|
|
331
|
+
start: undefined,
|
|
332
|
+
length: undefined,
|
|
333
|
+
});
|
|
789
334
|
if (!('allowSyntheticDefaultImports' in config.compilerOptions)) {
|
|
790
335
|
finalOptions.allowSyntheticDefaultImports = true;
|
|
791
336
|
}
|
|
792
337
|
}
|
|
793
|
-
// Make sure when allowJs is enabled, outDir is required to have when using allowJs: true
|
|
794
338
|
if (finalOptions.allowJs && !finalOptions.outDir) {
|
|
795
339
|
finalOptions.outDir = exports.TS_JEST_OUT_DIR;
|
|
796
340
|
}
|
|
797
341
|
try {
|
|
798
|
-
// ensure undefined are removed and other values are overridden
|
|
799
342
|
for (var _c = __values(Object.keys(forcedOptions)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
800
343
|
var key = _d.value;
|
|
801
344
|
var val = forcedOptions[key];
|
|
@@ -814,27 +357,125 @@ var ConfigSet = /** @class */ (function () {
|
|
|
814
357
|
}
|
|
815
358
|
finally { if (e_2) throw e_2.error; }
|
|
816
359
|
}
|
|
817
|
-
/**
|
|
818
|
-
* See https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping
|
|
819
|
-
* Every time this page is updated, we also need to update here. Here we only show warning message for Node LTS versions
|
|
820
|
-
*/
|
|
821
360
|
var nodeJsVer = process.version;
|
|
822
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
823
361
|
var compilationTarget = result.options.target;
|
|
824
|
-
if (!this.
|
|
362
|
+
if (!this._babelConfig &&
|
|
825
363
|
((nodeJsVer.startsWith('v10') && compilationTarget > typescript_1.ScriptTarget.ES2018) ||
|
|
826
364
|
(nodeJsVer.startsWith('v12') && compilationTarget > typescript_1.ScriptTarget.ES2019))) {
|
|
827
|
-
var message = messages_1.interpolate("There is a mismatch between your NodeJs version {{nodeJsVer}} and your TypeScript target {{compilationTarget}}. This might lead to some unexpected errors when running tests with `ts-jest`. To fix this, you can check https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping"
|
|
365
|
+
var message = messages_1.interpolate("There is a mismatch between your NodeJs version {{nodeJsVer}} and your TypeScript target {{compilationTarget}}. This might lead to some unexpected errors when running tests with `ts-jest`. To fix this, you can check https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping", {
|
|
828
366
|
nodeJsVer: process.version,
|
|
829
367
|
compilationTarget: (_b = config.compilerOptions.target) !== null && _b !== void 0 ? _b : TARGET_TO_VERSION_MAPPING[compilationTarget],
|
|
830
368
|
});
|
|
831
|
-
logger.warn(message);
|
|
369
|
+
this.logger.warn(message);
|
|
832
370
|
}
|
|
833
371
|
return result;
|
|
834
372
|
};
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
373
|
+
Object.defineProperty(ConfigSet.prototype, "tsCompiler", {
|
|
374
|
+
get: function () {
|
|
375
|
+
return instance_1.createCompilerInstance(this);
|
|
376
|
+
},
|
|
377
|
+
enumerable: false,
|
|
378
|
+
configurable: true
|
|
379
|
+
});
|
|
380
|
+
Object.defineProperty(ConfigSet.prototype, "babelConfig", {
|
|
381
|
+
get: function () {
|
|
382
|
+
return this._babelConfig;
|
|
383
|
+
},
|
|
384
|
+
enumerable: false,
|
|
385
|
+
configurable: true
|
|
386
|
+
});
|
|
387
|
+
Object.defineProperty(ConfigSet.prototype, "babelJestTransformer", {
|
|
388
|
+
get: function () {
|
|
389
|
+
return this._babelJestTransformers;
|
|
390
|
+
},
|
|
391
|
+
enumerable: false,
|
|
392
|
+
configurable: true
|
|
393
|
+
});
|
|
394
|
+
Object.defineProperty(ConfigSet.prototype, "tsJestDigest", {
|
|
395
|
+
get: function () {
|
|
396
|
+
return exports.MY_DIGEST;
|
|
397
|
+
},
|
|
398
|
+
enumerable: false,
|
|
399
|
+
configurable: true
|
|
400
|
+
});
|
|
401
|
+
Object.defineProperty(ConfigSet.prototype, "hooks", {
|
|
402
|
+
get: function () {
|
|
403
|
+
var hooksFile = process.env.TS_JEST_HOOKS;
|
|
404
|
+
if (hooksFile) {
|
|
405
|
+
hooksFile = path_1.resolve(this.cwd, hooksFile);
|
|
406
|
+
return importer_1.importer.tryTheseOr(hooksFile, {});
|
|
407
|
+
}
|
|
408
|
+
return {};
|
|
409
|
+
},
|
|
410
|
+
enumerable: false,
|
|
411
|
+
configurable: true
|
|
412
|
+
});
|
|
413
|
+
Object.defineProperty(ConfigSet.prototype, "isTestFile", {
|
|
414
|
+
get: function () {
|
|
415
|
+
var matchablePatterns = __spread(this._jestCfg.testMatch, this._jestCfg.testRegex).filter(function (pattern) {
|
|
416
|
+
return pattern instanceof RegExp || typeof pattern === 'string';
|
|
417
|
+
});
|
|
418
|
+
if (!matchablePatterns.length) {
|
|
419
|
+
matchablePatterns.push.apply(matchablePatterns, __spread(constants_1.DEFAULT_JEST_TEST_MATCH));
|
|
420
|
+
}
|
|
421
|
+
var stringPatterns = matchablePatterns.filter(function (pattern) { return typeof pattern === 'string'; });
|
|
422
|
+
var isMatch = jest_util_1.globsToMatcher(stringPatterns);
|
|
423
|
+
return function (fileName) {
|
|
424
|
+
return matchablePatterns.some(function (pattern) { return (typeof pattern === 'string' ? isMatch(fileName) : pattern.test(fileName)); });
|
|
425
|
+
};
|
|
426
|
+
},
|
|
427
|
+
enumerable: false,
|
|
428
|
+
configurable: true
|
|
429
|
+
});
|
|
430
|
+
ConfigSet.prototype.shouldStringifyContent = function (filePath) {
|
|
431
|
+
return this._stringifyContentRegExp ? this._stringifyContentRegExp.test(filePath) : false;
|
|
432
|
+
};
|
|
433
|
+
ConfigSet.prototype.raiseDiagnostics = function (diagnostics, filePath, logger) {
|
|
434
|
+
var _this = this;
|
|
435
|
+
var ignoreCodes = this._diagnostics.ignoreCodes;
|
|
436
|
+
var DiagnosticCategory = this.compilerModule.DiagnosticCategory;
|
|
437
|
+
var filteredDiagnostics = filePath && !this.shouldReportDiagnostics(filePath)
|
|
438
|
+
? []
|
|
439
|
+
: diagnostics.filter(function (diagnostic) {
|
|
440
|
+
var _a;
|
|
441
|
+
if (((_a = diagnostic.file) === null || _a === void 0 ? void 0 : _a.fileName) && !_this.shouldReportDiagnostics(diagnostic.file.fileName)) {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
return !ignoreCodes.includes(diagnostic.code);
|
|
445
|
+
});
|
|
446
|
+
if (!filteredDiagnostics.length)
|
|
447
|
+
return;
|
|
448
|
+
var error = this._createTsError(filteredDiagnostics);
|
|
449
|
+
var importantCategories = [DiagnosticCategory.Warning, DiagnosticCategory.Error];
|
|
450
|
+
if (this._diagnostics.throws && filteredDiagnostics.some(function (d) { return importantCategories.includes(d.category); })) {
|
|
451
|
+
throw error;
|
|
452
|
+
}
|
|
453
|
+
logger ? logger.warn({ error: error }, error.message) : this.logger.warn({ error: error }, error.message);
|
|
454
|
+
};
|
|
455
|
+
ConfigSet.prototype.shouldReportDiagnostics = function (filePath) {
|
|
456
|
+
var pathRegex = this._diagnostics.pathRegex;
|
|
457
|
+
if (pathRegex) {
|
|
458
|
+
var regex = new RegExp(pathRegex);
|
|
459
|
+
return regex.test(filePath);
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
return true;
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
ConfigSet.prototype._createTsError = function (diagnostics) {
|
|
466
|
+
var _this = this;
|
|
467
|
+
var formatDiagnostics = this._diagnostics.pretty
|
|
468
|
+
? this.compilerModule.formatDiagnosticsWithColorAndContext
|
|
469
|
+
: this.compilerModule.formatDiagnostics;
|
|
470
|
+
var diagnosticHost = {
|
|
471
|
+
getNewLine: function () { return '\n'; },
|
|
472
|
+
getCurrentDirectory: function () { return _this.cwd; },
|
|
473
|
+
getCanonicalFileName: function (path) { return path; },
|
|
474
|
+
};
|
|
475
|
+
var diagnosticText = formatDiagnostics(diagnostics, diagnosticHost);
|
|
476
|
+
var diagnosticCodes = diagnostics.map(function (x) { return x.code; });
|
|
477
|
+
return new ts_error_1.TSError(diagnosticText, diagnosticCodes);
|
|
478
|
+
};
|
|
838
479
|
ConfigSet.prototype.resolvePath = function (inputPath, _a) {
|
|
839
480
|
var _b = _a === void 0 ? {} : _a, _c = _b.throwIfMissing, throwIfMissing = _c === void 0 ? true : _c, _d = _b.nodeResolve, nodeResolve = _d === void 0 ? false : _d;
|
|
840
481
|
var path = inputPath;
|
|
@@ -862,86 +503,23 @@ var ConfigSet = /** @class */ (function () {
|
|
|
862
503
|
catch (_) { }
|
|
863
504
|
}
|
|
864
505
|
if (throwIfMissing && !fs_1.existsSync(path)) {
|
|
865
|
-
throw new Error(messages_1.interpolate("File not found: {{inputPath}} (resolved as: {{resolvedPath}})"
|
|
506
|
+
throw new Error(messages_1.interpolate("File not found: {{inputPath}} (resolved as: {{resolvedPath}})", { inputPath: inputPath, resolvedPath: path }));
|
|
866
507
|
}
|
|
867
508
|
this.logger.debug({ fromPath: inputPath, toPath: path }, 'resolved path from', inputPath, 'to', path);
|
|
868
509
|
return path;
|
|
869
510
|
};
|
|
870
|
-
/**
|
|
871
|
-
* @internal
|
|
872
|
-
*/
|
|
873
|
-
ConfigSet.prototype.toJSON = function () {
|
|
874
|
-
return this.jsonValue.value;
|
|
875
|
-
};
|
|
876
|
-
__decorate([
|
|
877
|
-
memoize_1.Memoize()
|
|
878
|
-
], ConfigSet.prototype, "jest", null);
|
|
879
|
-
__decorate([
|
|
880
|
-
memoize_1.Memoize()
|
|
881
|
-
], ConfigSet.prototype, "isTestFile", null);
|
|
882
|
-
__decorate([
|
|
883
|
-
memoize_1.Memoize()
|
|
884
|
-
], ConfigSet.prototype, "tsJest", null);
|
|
885
|
-
__decorate([
|
|
886
|
-
memoize_1.Memoize()
|
|
887
|
-
], ConfigSet.prototype, "versions", null);
|
|
888
|
-
__decorate([
|
|
889
|
-
memoize_1.Memoize()
|
|
890
|
-
], ConfigSet.prototype, "_parsedTsConfig", null);
|
|
891
|
-
__decorate([
|
|
892
|
-
memoize_1.Memoize()
|
|
893
|
-
], ConfigSet.prototype, "raiseDiagnostics", null);
|
|
894
|
-
__decorate([
|
|
895
|
-
memoize_1.Memoize()
|
|
896
|
-
], ConfigSet.prototype, "babel", null);
|
|
897
|
-
__decorate([
|
|
898
|
-
memoize_1.Memoize()
|
|
899
|
-
], ConfigSet.prototype, "compilerModule", null);
|
|
900
|
-
__decorate([
|
|
901
|
-
memoize_1.Memoize()
|
|
902
|
-
], ConfigSet.prototype, "babelJestTransformer", null);
|
|
903
511
|
__decorate([
|
|
904
512
|
memoize_1.Memoize()
|
|
905
513
|
], ConfigSet.prototype, "tsCompiler", null);
|
|
906
514
|
__decorate([
|
|
907
515
|
memoize_1.Memoize()
|
|
908
|
-
], ConfigSet.prototype, "
|
|
909
|
-
__decorate([
|
|
910
|
-
memoize_1.Memoize()
|
|
911
|
-
], ConfigSet.prototype, "tsCustomTransformers", null);
|
|
516
|
+
], ConfigSet.prototype, "tsJestDigest", null);
|
|
912
517
|
__decorate([
|
|
913
518
|
memoize_1.Memoize()
|
|
914
519
|
], ConfigSet.prototype, "hooks", null);
|
|
915
520
|
__decorate([
|
|
916
521
|
memoize_1.Memoize()
|
|
917
|
-
], ConfigSet.prototype, "
|
|
918
|
-
__decorate([
|
|
919
|
-
memoize_1.Memoize()
|
|
920
|
-
], ConfigSet.prototype, "shouldReportDiagnostic", null);
|
|
921
|
-
__decorate([
|
|
922
|
-
memoize_1.Memoize()
|
|
923
|
-
], ConfigSet.prototype, "shouldStringifyContent", null);
|
|
924
|
-
__decorate([
|
|
925
|
-
memoize_1.Memoize()
|
|
926
|
-
], ConfigSet.prototype, "createTsError", null);
|
|
927
|
-
__decorate([
|
|
928
|
-
memoize_1.Memoize()
|
|
929
|
-
], ConfigSet.prototype, "tsCacheDir", null);
|
|
930
|
-
__decorate([
|
|
931
|
-
memoize_1.Memoize()
|
|
932
|
-
], ConfigSet.prototype, "overriddenCompilerOptions", null);
|
|
933
|
-
__decorate([
|
|
934
|
-
memoize_1.Memoize()
|
|
935
|
-
], ConfigSet.prototype, "rootDir", null);
|
|
936
|
-
__decorate([
|
|
937
|
-
memoize_1.Memoize()
|
|
938
|
-
], ConfigSet.prototype, "cwd", null);
|
|
939
|
-
__decorate([
|
|
940
|
-
memoize_1.Memoize()
|
|
941
|
-
], ConfigSet.prototype, "tsJestDigest", null);
|
|
942
|
-
__decorate([
|
|
943
|
-
memoize_1.Memoize()
|
|
944
|
-
], ConfigSet.prototype, "jsonValue", null);
|
|
522
|
+
], ConfigSet.prototype, "isTestFile", null);
|
|
945
523
|
return ConfigSet;
|
|
946
524
|
}());
|
|
947
525
|
exports.ConfigSet = ConfigSet;
|