ts-jest 26.4.1 → 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 +20 -0
- package/dist/compiler/instance.d.ts +2 -1
- package/dist/compiler/instance.js +6 -5
- package/dist/compiler/language-service.js +5 -15
- package/dist/compiler/transpiler.js +3 -3
- package/dist/config/config-set.d.ts +19 -7
- package/dist/config/config-set.js +286 -580
- package/dist/constants.d.ts +2 -1
- package/dist/constants.js +1 -3
- package/dist/index.d.ts +1 -114
- package/dist/index.js +3 -54
- package/dist/ts-jest-transformer.d.ts +5 -8
- package/dist/ts-jest-transformer.js +47 -52
- package/dist/types.d.ts +7 -0
- package/dist/utils/json.d.ts +2 -1
- package/dist/utils/jsonable-value.d.ts +10 -1
- package/package.json +4 -3
- package/presets/index.js +20 -1
- package/utils/index.d.ts +3 -1
- package/utils/index.js +15 -1
- package/dist/presets/index.d.ts +0 -339
- package/dist/presets/index.js +0 -18
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.js +0 -9
|
@@ -49,29 +49,26 @@ 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 = void 0;
|
|
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
|
|
61
|
+
var hoist_jest_1 = require("../transformers/hoist-jest");
|
|
63
62
|
var backports_1 = require("../utils/backports");
|
|
64
|
-
var get_package_version_1 = require("../utils/get-package-version");
|
|
65
63
|
var importer_1 = require("../utils/importer");
|
|
66
64
|
var json_1 = require("../utils/json");
|
|
67
|
-
var jsonable_value_1 = require("../utils/jsonable-value");
|
|
68
65
|
var logger_1 = require("../utils/logger");
|
|
69
66
|
var memoize_1 = require("../utils/memoize");
|
|
70
67
|
var messages_1 = require("../utils/messages");
|
|
71
68
|
var normalize_slashes_1 = require("../utils/normalize-slashes");
|
|
72
69
|
var sha1_1 = require("../utils/sha1");
|
|
73
70
|
var ts_error_1 = require("../utils/ts-error");
|
|
74
|
-
|
|
71
|
+
exports.MY_DIGEST = fs_1.readFileSync(path_1.resolve(__dirname, '..', '..', '.ts-jest-digest'), 'utf8');
|
|
75
72
|
exports.IGNORE_DIAGNOSTIC_CODES = [
|
|
76
73
|
6059,
|
|
77
74
|
18002,
|
|
@@ -119,543 +116,201 @@ var toDiagnosticCodeList = function (items, into) {
|
|
|
119
116
|
return into;
|
|
120
117
|
};
|
|
121
118
|
var ConfigSet = (function () {
|
|
122
|
-
function ConfigSet(jestConfig,
|
|
119
|
+
function ConfigSet(jestConfig, parentLogger) {
|
|
123
120
|
var _a;
|
|
124
|
-
|
|
125
|
-
this.
|
|
126
|
-
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();
|
|
127
154
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (!matchablePatterns.length) {
|
|
148
|
-
matchablePatterns.push.apply(matchablePatterns, __spread(constants_1.DEFAULT_JEST_TEST_MATCH));
|
|
149
|
-
}
|
|
150
|
-
var stringPatterns = matchablePatterns.filter(function (pattern) { return typeof pattern === 'string'; });
|
|
151
|
-
var isMatch = jest_util_1.globsToMatcher(stringPatterns);
|
|
152
|
-
return function (fileName) {
|
|
153
|
-
return matchablePatterns.some(function (pattern) { return (typeof pattern === 'string' ? isMatch(fileName) : pattern.test(fileName)); });
|
|
154
|
-
};
|
|
155
|
-
},
|
|
156
|
-
enumerable: false,
|
|
157
|
-
configurable: true
|
|
158
|
-
});
|
|
159
|
-
Object.defineProperty(ConfigSet.prototype, "tsJest", {
|
|
160
|
-
get: function () {
|
|
161
|
-
var _this = this;
|
|
162
|
-
var _a, _b, _c, _d, _e, _f;
|
|
163
|
-
var parsedConfig = this.jest;
|
|
164
|
-
var _g = parsedConfig.globals, globals = _g === void 0 ? {} : _g;
|
|
165
|
-
var options = __assign({}, globals['ts-jest']);
|
|
166
|
-
var tsConfig = this.getInlineOrFileConfigOpt((_b = (_a = options.tsConfig) !== null && _a !== void 0 ? _a : options.tsconfig) !== null && _b !== void 0 ? _b : true);
|
|
167
|
-
var packageJson = this.getInlineOrFileConfigOpt((_c = options.packageJson) !== null && _c !== void 0 ? _c : true);
|
|
168
|
-
var transformers = Object.create(null);
|
|
169
|
-
var astTransformers = options.astTransformers;
|
|
170
|
-
if (astTransformers) {
|
|
171
|
-
if (Array.isArray(astTransformers)) {
|
|
172
|
-
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");
|
|
173
|
-
transformers = {
|
|
174
|
-
before: astTransformers.map(function (transformerPath) { return ({
|
|
175
|
-
path: _this.resolvePath(transformerPath, { nodeResolve: true }),
|
|
176
|
-
}); }),
|
|
177
|
-
};
|
|
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 })));
|
|
178
174
|
}
|
|
179
175
|
else {
|
|
180
|
-
|
|
181
|
-
transformers = {
|
|
182
|
-
before: astTransformers.before.map(function (transformer) {
|
|
183
|
-
return typeof transformer === 'string'
|
|
184
|
-
? {
|
|
185
|
-
path: _this.resolvePath(transformer, { nodeResolve: true }),
|
|
186
|
-
}
|
|
187
|
-
: __assign(__assign({}, transformer), { path: _this.resolvePath(transformer.path, { nodeResolve: true }) });
|
|
188
|
-
}),
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
if (astTransformers.after) {
|
|
192
|
-
transformers = __assign(__assign({}, transformers), { after: astTransformers.after.map(function (transformer) {
|
|
193
|
-
return typeof transformer === 'string'
|
|
194
|
-
? {
|
|
195
|
-
path: _this.resolvePath(transformer, { nodeResolve: true }),
|
|
196
|
-
}
|
|
197
|
-
: __assign(__assign({}, transformer), { path: _this.resolvePath(transformer.path, { nodeResolve: true }) });
|
|
198
|
-
}) });
|
|
199
|
-
}
|
|
200
|
-
if (astTransformers.afterDeclarations) {
|
|
201
|
-
transformers = __assign(__assign({}, transformers), { afterDeclarations: astTransformers.afterDeclarations.map(function (transformer) {
|
|
202
|
-
return typeof transformer === 'string'
|
|
203
|
-
? {
|
|
204
|
-
path: _this.resolvePath(transformer, { nodeResolve: true }),
|
|
205
|
-
}
|
|
206
|
-
: __assign(__assign({}, transformer), { path: _this.resolvePath(transformer.path, { nodeResolve: true }) });
|
|
207
|
-
}) });
|
|
208
|
-
}
|
|
176
|
+
this._babelConfig = __assign(__assign({}, baseBabelCfg), json5.parse(fs_1.readFileSync(options.babelConfig, 'utf-8')));
|
|
209
177
|
}
|
|
210
178
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
var diagnosticsOpt = (_d = options.diagnostics) !== null && _d !== void 0 ? _d : true;
|
|
214
|
-
var ignoreList = __spread(exports.IGNORE_DIAGNOSTIC_CODES);
|
|
215
|
-
if (typeof diagnosticsOpt === 'object') {
|
|
216
|
-
var ignoreCodes = diagnosticsOpt.ignoreCodes;
|
|
217
|
-
if (ignoreCodes) {
|
|
218
|
-
Array.isArray(ignoreCodes) ? ignoreList.push.apply(ignoreList, __spread(ignoreCodes)) : ignoreList.push(ignoreCodes);
|
|
219
|
-
}
|
|
220
|
-
diagnostics = {
|
|
221
|
-
pretty: (_e = diagnosticsOpt.pretty) !== null && _e !== void 0 ? _e : true,
|
|
222
|
-
ignoreCodes: toDiagnosticCodeList(ignoreList),
|
|
223
|
-
pathRegex: normalizeRegex(diagnosticsOpt.pathRegex),
|
|
224
|
-
throws: !diagnosticsOpt.warnOnly,
|
|
225
|
-
};
|
|
179
|
+
else if (typeof options.babelConfig === 'object') {
|
|
180
|
+
this._babelConfig = __assign(__assign({}, baseBabelCfg), options.babelConfig);
|
|
226
181
|
}
|
|
227
182
|
else {
|
|
228
|
-
|
|
229
|
-
ignoreCodes: diagnosticsOpt ? toDiagnosticCodeList(ignoreList) : [],
|
|
230
|
-
pretty: true,
|
|
231
|
-
throws: diagnosticsOpt,
|
|
232
|
-
};
|
|
183
|
+
this._babelConfig = baseBabelCfg;
|
|
233
184
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
Object.defineProperty(ConfigSet.prototype, "parsedTsConfig", {
|
|
252
|
-
get: function () {
|
|
253
|
-
return this._parsedTsConfig;
|
|
254
|
-
},
|
|
255
|
-
enumerable: false,
|
|
256
|
-
configurable: true
|
|
257
|
-
});
|
|
258
|
-
Object.defineProperty(ConfigSet.prototype, "versions", {
|
|
259
|
-
get: function () {
|
|
260
|
-
var modules = ['jest', this.tsJest.compiler];
|
|
261
|
-
if (this.tsJest.babelConfig) {
|
|
262
|
-
modules.push('@babel/core', 'babel-jest');
|
|
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);
|
|
263
202
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
},
|
|
270
|
-
enumerable: false,
|
|
271
|
-
configurable: true
|
|
272
|
-
});
|
|
273
|
-
Object.defineProperty(ConfigSet.prototype, "_parsedTsConfig", {
|
|
274
|
-
get: function () {
|
|
275
|
-
var tsConfig = this.tsJest.tsConfig;
|
|
276
|
-
var configFilePath = (tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.kind) === 'file' ? tsConfig.value : undefined;
|
|
277
|
-
var result = this.readTsConfig((tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.kind) === 'inline' ? tsConfig.value : undefined, configFilePath, tsConfig == null);
|
|
278
|
-
this.raiseDiagnostics(result.errors, configFilePath);
|
|
279
|
-
this.logger.debug({ tsconfig: result }, 'normalized typescript config');
|
|
280
|
-
return result;
|
|
281
|
-
},
|
|
282
|
-
enumerable: false,
|
|
283
|
-
configurable: true
|
|
284
|
-
});
|
|
285
|
-
Object.defineProperty(ConfigSet.prototype, "raiseDiagnostics", {
|
|
286
|
-
get: function () {
|
|
287
|
-
var _this = this;
|
|
288
|
-
var _a = this, createTsError = _a.createTsError, filterDiagnostics = _a.filterDiagnostics, throws = _a.tsJest.diagnostics.throws, DiagnosticCategory = _a.compilerModule.DiagnosticCategory;
|
|
289
|
-
return function (diagnostics, filePath, logger) {
|
|
290
|
-
if (logger === void 0) { logger = _this.logger; }
|
|
291
|
-
var filteredDiagnostics = filterDiagnostics(diagnostics, filePath);
|
|
292
|
-
if (!filteredDiagnostics.length)
|
|
293
|
-
return;
|
|
294
|
-
var error = createTsError(filteredDiagnostics);
|
|
295
|
-
var importantCategories = [DiagnosticCategory.Warning, DiagnosticCategory.Error];
|
|
296
|
-
if (throws && filteredDiagnostics.some(function (d) { return importantCategories.includes(d.category); })) {
|
|
297
|
-
throw error;
|
|
298
|
-
}
|
|
299
|
-
logger.warn({ error: error }, error.message);
|
|
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,
|
|
300
208
|
};
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
var babelConfig = this.tsJest.babelConfig;
|
|
308
|
-
if (babelConfig == null) {
|
|
309
|
-
this.logger.debug('babel is disabled');
|
|
310
|
-
return undefined;
|
|
311
|
-
}
|
|
312
|
-
var base = { cwd: this.cwd };
|
|
313
|
-
if (babelConfig.kind === 'file') {
|
|
314
|
-
if (babelConfig.value) {
|
|
315
|
-
if (path_1.extname(babelConfig.value) === '.js') {
|
|
316
|
-
base = __assign(__assign({}, base), require(babelConfig.value));
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
base = __assign(__assign({}, base), json5.parse(fs_1.readFileSync(babelConfig.value, 'utf8')));
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
else if (babelConfig.kind === 'inline') {
|
|
324
|
-
base = __assign(__assign({}, base), babelConfig.value);
|
|
325
|
-
}
|
|
326
|
-
this.logger.debug({ babelConfig: base }, 'normalized babel config via ts-jest option');
|
|
327
|
-
return base;
|
|
328
|
-
},
|
|
329
|
-
enumerable: false,
|
|
330
|
-
configurable: true
|
|
331
|
-
});
|
|
332
|
-
Object.defineProperty(ConfigSet.prototype, "compilerModule", {
|
|
333
|
-
get: function () {
|
|
334
|
-
return importer_1.importer.typescript("Using \"ts-jest\" requires this package to be installed.", this.tsJest.compiler);
|
|
335
|
-
},
|
|
336
|
-
enumerable: false,
|
|
337
|
-
configurable: true
|
|
338
|
-
});
|
|
339
|
-
Object.defineProperty(ConfigSet.prototype, "babelJestTransformer", {
|
|
340
|
-
get: function () {
|
|
341
|
-
var babel = this.babel;
|
|
342
|
-
if (!babel)
|
|
343
|
-
return undefined;
|
|
344
|
-
this.logger.debug('creating babel-jest transformer');
|
|
345
|
-
return importer_1.importer.babelJest("Using \"babel-jest\" requires this package to be installed.").createTransformer(babel);
|
|
346
|
-
},
|
|
347
|
-
enumerable: false,
|
|
348
|
-
configurable: true
|
|
349
|
-
});
|
|
350
|
-
Object.defineProperty(ConfigSet.prototype, "tsCompiler", {
|
|
351
|
-
get: function () {
|
|
352
|
-
return instance_1.createCompilerInstance(this);
|
|
353
|
-
},
|
|
354
|
-
enumerable: false,
|
|
355
|
-
configurable: true
|
|
356
|
-
});
|
|
357
|
-
Object.defineProperty(ConfigSet.prototype, "astTransformers", {
|
|
358
|
-
get: function () {
|
|
359
|
-
var astTransformers = {
|
|
360
|
-
before: __spread(transformers_1.internals.map(function (transformer) { return ({
|
|
361
|
-
transformModule: transformer,
|
|
362
|
-
}); })),
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
this._diagnostics = {
|
|
212
|
+
ignoreCodes: diagnosticsOpt ? toDiagnosticCodeList(ignoreList) : [],
|
|
213
|
+
pretty: true,
|
|
214
|
+
throws: diagnosticsOpt,
|
|
363
215
|
};
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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);
|
|
376
237
|
})),
|
|
377
238
|
};
|
|
378
239
|
}
|
|
379
|
-
if (transformers.after) {
|
|
380
|
-
astTransformers = __assign(__assign({}, astTransformers), { after: transformers.after.map(function (transformer) {
|
|
381
|
-
return typeof transformer === 'string'
|
|
382
|
-
? {
|
|
383
|
-
transformModule: require(transformer),
|
|
384
|
-
}
|
|
385
|
-
: {
|
|
386
|
-
transformModule: require(transformer.path),
|
|
387
|
-
options: transformer.options,
|
|
388
|
-
};
|
|
389
|
-
}) });
|
|
390
|
-
}
|
|
391
|
-
if (transformers.afterDeclarations) {
|
|
392
|
-
astTransformers = __assign(__assign({}, astTransformers), { afterDeclarations: transformers.afterDeclarations.map(function (transformer) {
|
|
393
|
-
return typeof transformer === 'string'
|
|
394
|
-
? {
|
|
395
|
-
transformModule: require(transformer),
|
|
396
|
-
}
|
|
397
|
-
: {
|
|
398
|
-
transformModule: require(transformer.path),
|
|
399
|
-
options: transformer.options,
|
|
400
|
-
};
|
|
401
|
-
}) });
|
|
402
|
-
}
|
|
403
|
-
return astTransformers;
|
|
404
|
-
},
|
|
405
|
-
enumerable: false,
|
|
406
|
-
configurable: true
|
|
407
|
-
});
|
|
408
|
-
Object.defineProperty(ConfigSet.prototype, "tsCustomTransformers", {
|
|
409
|
-
get: function () {
|
|
410
|
-
var _this = this;
|
|
411
|
-
var customTransformers = {
|
|
412
|
-
before: this.astTransformers.before.map(function (t) { return t.transformModule.factory(_this, t.options); }),
|
|
413
|
-
};
|
|
414
|
-
if (this.astTransformers.after) {
|
|
415
|
-
customTransformers = __assign(__assign({}, customTransformers), { after: this.astTransformers.after.map(function (t) { return t.transformModule.factory(_this, t.options); }) });
|
|
416
|
-
}
|
|
417
|
-
if (this.astTransformers.afterDeclarations) {
|
|
418
|
-
customTransformers = __assign(__assign({}, customTransformers), { afterDeclarations: this.astTransformers.afterDeclarations.map(function (t) {
|
|
419
|
-
return t.transformModule.factory(_this, t.options);
|
|
420
|
-
}) });
|
|
421
|
-
}
|
|
422
|
-
return customTransformers;
|
|
423
|
-
},
|
|
424
|
-
enumerable: false,
|
|
425
|
-
configurable: true
|
|
426
|
-
});
|
|
427
|
-
Object.defineProperty(ConfigSet.prototype, "hooks", {
|
|
428
|
-
get: function () {
|
|
429
|
-
var hooksFile = process.env.TS_JEST_HOOKS;
|
|
430
|
-
if (hooksFile) {
|
|
431
|
-
hooksFile = path_1.resolve(this.cwd, hooksFile);
|
|
432
|
-
return importer_1.importer.tryTheseOr(hooksFile, {});
|
|
433
|
-
}
|
|
434
|
-
return {};
|
|
435
|
-
},
|
|
436
|
-
enumerable: false,
|
|
437
|
-
configurable: true
|
|
438
|
-
});
|
|
439
|
-
Object.defineProperty(ConfigSet.prototype, "filterDiagnostics", {
|
|
440
|
-
get: function () {
|
|
441
|
-
var _a = this, ignoreCodes = _a.tsJest.diagnostics.ignoreCodes, shouldReportDiagnostic = _a.shouldReportDiagnostic;
|
|
442
|
-
return function (diagnostics, filePath) {
|
|
443
|
-
if (filePath && !shouldReportDiagnostic(filePath))
|
|
444
|
-
return [];
|
|
445
|
-
return diagnostics.filter(function (diagnostic) {
|
|
446
|
-
var _a;
|
|
447
|
-
if (((_a = diagnostic.file) === null || _a === void 0 ? void 0 : _a.fileName) && !shouldReportDiagnostic(diagnostic.file.fileName)) {
|
|
448
|
-
return false;
|
|
449
|
-
}
|
|
450
|
-
return !ignoreCodes.includes(diagnostic.code);
|
|
451
|
-
});
|
|
452
|
-
};
|
|
453
|
-
},
|
|
454
|
-
enumerable: false,
|
|
455
|
-
configurable: true
|
|
456
|
-
});
|
|
457
|
-
Object.defineProperty(ConfigSet.prototype, "shouldReportDiagnostic", {
|
|
458
|
-
get: function () {
|
|
459
|
-
var pathRegex = this.tsJest.diagnostics.pathRegex;
|
|
460
|
-
if (pathRegex) {
|
|
461
|
-
var regex_1 = new RegExp(pathRegex);
|
|
462
|
-
return function (file) { return regex_1.test(file); };
|
|
463
|
-
}
|
|
464
|
-
else {
|
|
465
|
-
return function () { return true; };
|
|
466
|
-
}
|
|
467
|
-
},
|
|
468
|
-
enumerable: false,
|
|
469
|
-
configurable: true
|
|
470
|
-
});
|
|
471
|
-
Object.defineProperty(ConfigSet.prototype, "shouldStringifyContent", {
|
|
472
|
-
get: function () {
|
|
473
|
-
var stringifyContentPathRegex = this.tsJest.stringifyContentPathRegex;
|
|
474
|
-
if (stringifyContentPathRegex) {
|
|
475
|
-
var regex_2 = new RegExp(stringifyContentPathRegex);
|
|
476
|
-
return function (file) { return regex_2.test(file); };
|
|
477
|
-
}
|
|
478
240
|
else {
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
enumerable: false,
|
|
504
|
-
configurable: true
|
|
505
|
-
});
|
|
506
|
-
Object.defineProperty(ConfigSet.prototype, "tsCacheDir", {
|
|
507
|
-
get: function () {
|
|
508
|
-
if (!this.jest.cache) {
|
|
509
|
-
logger.debug('file caching disabled');
|
|
510
|
-
return undefined;
|
|
511
|
-
}
|
|
512
|
-
var cacheSuffix = sha1_1.sha1(json_1.stringify({
|
|
513
|
-
version: this.compilerModule.version,
|
|
514
|
-
digest: this.tsJestDigest,
|
|
515
|
-
compiler: this.tsJest.compiler,
|
|
516
|
-
compilerOptions: this.parsedTsConfig.options,
|
|
517
|
-
isolatedModules: this.tsJest.isolatedModules,
|
|
518
|
-
diagnostics: this.tsJest.diagnostics,
|
|
519
|
-
}));
|
|
520
|
-
var res = path_1.join(this.jest.cacheDirectory, 'ts-jest', cacheSuffix.substr(0, 2), cacheSuffix.substr(2));
|
|
521
|
-
logger.debug({ cacheDirectory: res }, 'will use file caching');
|
|
522
|
-
return res;
|
|
523
|
-
},
|
|
524
|
-
enumerable: false,
|
|
525
|
-
configurable: true
|
|
526
|
-
});
|
|
527
|
-
Object.defineProperty(ConfigSet.prototype, "overriddenCompilerOptions", {
|
|
528
|
-
get: function () {
|
|
529
|
-
var options = {
|
|
530
|
-
sourceMap: true,
|
|
531
|
-
inlineSourceMap: false,
|
|
532
|
-
inlineSources: true,
|
|
533
|
-
declaration: false,
|
|
534
|
-
noEmit: false,
|
|
535
|
-
removeComments: false,
|
|
536
|
-
out: undefined,
|
|
537
|
-
outFile: undefined,
|
|
538
|
-
composite: undefined,
|
|
539
|
-
declarationDir: undefined,
|
|
540
|
-
declarationMap: undefined,
|
|
541
|
-
emitDeclarationOnly: undefined,
|
|
542
|
-
sourceRoot: undefined,
|
|
543
|
-
tsBuildInfoFile: undefined,
|
|
544
|
-
};
|
|
545
|
-
if (!this.tsJest.babelConfig) {
|
|
546
|
-
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
|
+
}
|
|
547
265
|
}
|
|
548
|
-
return options;
|
|
549
|
-
},
|
|
550
|
-
enumerable: false,
|
|
551
|
-
configurable: true
|
|
552
|
-
});
|
|
553
|
-
Object.defineProperty(ConfigSet.prototype, "rootDir", {
|
|
554
|
-
get: function () {
|
|
555
|
-
return path_1.normalize(this.jest.rootDir || this.cwd);
|
|
556
|
-
},
|
|
557
|
-
enumerable: false,
|
|
558
|
-
configurable: true
|
|
559
|
-
});
|
|
560
|
-
Object.defineProperty(ConfigSet.prototype, "cwd", {
|
|
561
|
-
get: function () {
|
|
562
|
-
return path_1.normalize(this.jest.cwd || process.cwd());
|
|
563
|
-
},
|
|
564
|
-
enumerable: false,
|
|
565
|
-
configurable: true
|
|
566
|
-
});
|
|
567
|
-
Object.defineProperty(ConfigSet.prototype, "tsJestDigest", {
|
|
568
|
-
get: function () {
|
|
569
|
-
return __1.digest;
|
|
570
|
-
},
|
|
571
|
-
enumerable: false,
|
|
572
|
-
configurable: true
|
|
573
|
-
});
|
|
574
|
-
Object.defineProperty(ConfigSet.prototype, "jsonValue", {
|
|
575
|
-
get: function () {
|
|
576
|
-
var jest = __assign({}, this.jest);
|
|
577
|
-
var globals = (jest.globals = __assign({}, jest.globals));
|
|
578
|
-
jest.name = undefined;
|
|
579
|
-
jest.cacheDirectory = undefined;
|
|
580
|
-
delete globals['ts-jest'];
|
|
581
|
-
return new jsonable_value_1.JsonableValue({
|
|
582
|
-
digest: this.tsJestDigest,
|
|
583
|
-
transformers: Object.values(this.astTransformers)
|
|
584
|
-
.reduce(function (acc, val) { return acc.concat(val); }, [])
|
|
585
|
-
.map(function (_a) {
|
|
586
|
-
var transformModule = _a.transformModule;
|
|
587
|
-
return transformModule.name + "@" + transformModule.version;
|
|
588
|
-
}),
|
|
589
|
-
jest: jest,
|
|
590
|
-
tsJest: this.tsJest,
|
|
591
|
-
babel: this.babel,
|
|
592
|
-
tsconfig: {
|
|
593
|
-
options: this.parsedTsConfig.options,
|
|
594
|
-
raw: this.parsedTsConfig.raw,
|
|
595
|
-
},
|
|
596
|
-
});
|
|
597
|
-
},
|
|
598
|
-
enumerable: false,
|
|
599
|
-
configurable: true
|
|
600
|
-
});
|
|
601
|
-
Object.defineProperty(ConfigSet.prototype, "cacheKey", {
|
|
602
|
-
get: function () {
|
|
603
|
-
return this.jsonValue.serialized;
|
|
604
|
-
},
|
|
605
|
-
enumerable: false,
|
|
606
|
-
configurable: true
|
|
607
|
-
});
|
|
608
|
-
ConfigSet.prototype.makeDiagnostic = function (code, messageText, options) {
|
|
609
|
-
if (options === void 0) { options = {}; }
|
|
610
|
-
var _a = options.category, category = _a === void 0 ? this.compilerModule.DiagnosticCategory.Warning : _a, file = options.file, start = options.start, length = options.length;
|
|
611
|
-
return {
|
|
612
|
-
code: code,
|
|
613
|
-
messageText: messageText,
|
|
614
|
-
category: category,
|
|
615
|
-
file: file,
|
|
616
|
-
start: start,
|
|
617
|
-
length: length,
|
|
618
|
-
};
|
|
619
|
-
};
|
|
620
|
-
ConfigSet.prototype.getInlineOrFileConfigOpt = function (configOpt) {
|
|
621
|
-
if (typeof configOpt === 'string' || configOpt === true) {
|
|
622
|
-
return {
|
|
623
|
-
kind: 'file',
|
|
624
|
-
value: typeof configOpt === 'string' ? this.resolvePath(configOpt) : undefined,
|
|
625
|
-
};
|
|
626
266
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
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;
|
|
632
280
|
}
|
|
633
|
-
|
|
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;
|
|
634
292
|
};
|
|
635
|
-
ConfigSet.prototype.
|
|
293
|
+
ConfigSet.prototype._readTsConfig = function (compilerOptions, resolvedConfigFile) {
|
|
636
294
|
var e_2, _a;
|
|
637
295
|
var _b;
|
|
638
296
|
var config = { compilerOptions: Object.create(null) };
|
|
639
297
|
var basePath = normalize_slashes_1.normalizeSlashes(this.rootDir);
|
|
640
|
-
var configFileName;
|
|
641
298
|
var ts = this.compilerModule;
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
return { errors: [result_1.error], fileNames: [], options: {} };
|
|
651
|
-
}
|
|
652
|
-
config = result_1.config;
|
|
653
|
-
basePath = normalize_slashes_1.normalizeSlashes(path_1.dirname(configFileName));
|
|
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: {} };
|
|
654
307
|
}
|
|
308
|
+
config = result_1.config;
|
|
309
|
+
basePath = normalize_slashes_1.normalizeSlashes(path_1.dirname(configFileName));
|
|
655
310
|
}
|
|
656
311
|
config.compilerOptions = __assign(__assign({}, config.compilerOptions), compilerOptions);
|
|
657
312
|
var result = ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, configFileName);
|
|
658
|
-
var forcedOptions = this.
|
|
313
|
+
var forcedOptions = this._overriddenCompilerOptions;
|
|
659
314
|
var finalOptions = result.options;
|
|
660
315
|
if (finalOptions.target === undefined) {
|
|
661
316
|
finalOptions.target = ts.ScriptTarget.ES5;
|
|
@@ -668,9 +323,14 @@ var ConfigSet = (function () {
|
|
|
668
323
|
if ('module' in forcedOptions &&
|
|
669
324
|
moduleValue !== forcedOptions.module &&
|
|
670
325
|
!(finalOptions.esModuleInterop || finalOptions.allowSyntheticDefaultImports)) {
|
|
671
|
-
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.",
|
|
672
329
|
category: ts.DiagnosticCategory.Message,
|
|
673
|
-
|
|
330
|
+
file: undefined,
|
|
331
|
+
start: undefined,
|
|
332
|
+
length: undefined,
|
|
333
|
+
});
|
|
674
334
|
if (!('allowSyntheticDefaultImports' in config.compilerOptions)) {
|
|
675
335
|
finalOptions.allowSyntheticDefaultImports = true;
|
|
676
336
|
}
|
|
@@ -699,17 +359,123 @@ var ConfigSet = (function () {
|
|
|
699
359
|
}
|
|
700
360
|
var nodeJsVer = process.version;
|
|
701
361
|
var compilationTarget = result.options.target;
|
|
702
|
-
if (!this.
|
|
362
|
+
if (!this._babelConfig &&
|
|
703
363
|
((nodeJsVer.startsWith('v10') && compilationTarget > typescript_1.ScriptTarget.ES2018) ||
|
|
704
364
|
(nodeJsVer.startsWith('v12') && compilationTarget > typescript_1.ScriptTarget.ES2019))) {
|
|
705
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", {
|
|
706
366
|
nodeJsVer: process.version,
|
|
707
367
|
compilationTarget: (_b = config.compilerOptions.target) !== null && _b !== void 0 ? _b : TARGET_TO_VERSION_MAPPING[compilationTarget],
|
|
708
368
|
});
|
|
709
|
-
logger.warn(message);
|
|
369
|
+
this.logger.warn(message);
|
|
710
370
|
}
|
|
711
371
|
return result;
|
|
712
372
|
};
|
|
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
|
+
};
|
|
713
479
|
ConfigSet.prototype.resolvePath = function (inputPath, _a) {
|
|
714
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;
|
|
715
481
|
var path = inputPath;
|
|
@@ -742,78 +508,18 @@ var ConfigSet = (function () {
|
|
|
742
508
|
this.logger.debug({ fromPath: inputPath, toPath: path }, 'resolved path from', inputPath, 'to', path);
|
|
743
509
|
return path;
|
|
744
510
|
};
|
|
745
|
-
ConfigSet.prototype.toJSON = function () {
|
|
746
|
-
return this.jsonValue.value;
|
|
747
|
-
};
|
|
748
|
-
__decorate([
|
|
749
|
-
memoize_1.Memoize()
|
|
750
|
-
], ConfigSet.prototype, "jest", null);
|
|
751
|
-
__decorate([
|
|
752
|
-
memoize_1.Memoize()
|
|
753
|
-
], ConfigSet.prototype, "isTestFile", null);
|
|
754
|
-
__decorate([
|
|
755
|
-
memoize_1.Memoize()
|
|
756
|
-
], ConfigSet.prototype, "tsJest", null);
|
|
757
|
-
__decorate([
|
|
758
|
-
memoize_1.Memoize()
|
|
759
|
-
], ConfigSet.prototype, "versions", null);
|
|
760
|
-
__decorate([
|
|
761
|
-
memoize_1.Memoize()
|
|
762
|
-
], ConfigSet.prototype, "_parsedTsConfig", null);
|
|
763
|
-
__decorate([
|
|
764
|
-
memoize_1.Memoize()
|
|
765
|
-
], ConfigSet.prototype, "raiseDiagnostics", null);
|
|
766
|
-
__decorate([
|
|
767
|
-
memoize_1.Memoize()
|
|
768
|
-
], ConfigSet.prototype, "babel", null);
|
|
769
|
-
__decorate([
|
|
770
|
-
memoize_1.Memoize()
|
|
771
|
-
], ConfigSet.prototype, "compilerModule", null);
|
|
772
|
-
__decorate([
|
|
773
|
-
memoize_1.Memoize()
|
|
774
|
-
], ConfigSet.prototype, "babelJestTransformer", null);
|
|
775
511
|
__decorate([
|
|
776
512
|
memoize_1.Memoize()
|
|
777
513
|
], ConfigSet.prototype, "tsCompiler", null);
|
|
778
514
|
__decorate([
|
|
779
515
|
memoize_1.Memoize()
|
|
780
|
-
], ConfigSet.prototype, "
|
|
781
|
-
__decorate([
|
|
782
|
-
memoize_1.Memoize()
|
|
783
|
-
], ConfigSet.prototype, "tsCustomTransformers", null);
|
|
516
|
+
], ConfigSet.prototype, "tsJestDigest", null);
|
|
784
517
|
__decorate([
|
|
785
518
|
memoize_1.Memoize()
|
|
786
519
|
], ConfigSet.prototype, "hooks", null);
|
|
787
520
|
__decorate([
|
|
788
521
|
memoize_1.Memoize()
|
|
789
|
-
], ConfigSet.prototype, "
|
|
790
|
-
__decorate([
|
|
791
|
-
memoize_1.Memoize()
|
|
792
|
-
], ConfigSet.prototype, "shouldReportDiagnostic", null);
|
|
793
|
-
__decorate([
|
|
794
|
-
memoize_1.Memoize()
|
|
795
|
-
], ConfigSet.prototype, "shouldStringifyContent", null);
|
|
796
|
-
__decorate([
|
|
797
|
-
memoize_1.Memoize()
|
|
798
|
-
], ConfigSet.prototype, "createTsError", null);
|
|
799
|
-
__decorate([
|
|
800
|
-
memoize_1.Memoize()
|
|
801
|
-
], ConfigSet.prototype, "tsCacheDir", null);
|
|
802
|
-
__decorate([
|
|
803
|
-
memoize_1.Memoize()
|
|
804
|
-
], ConfigSet.prototype, "overriddenCompilerOptions", null);
|
|
805
|
-
__decorate([
|
|
806
|
-
memoize_1.Memoize()
|
|
807
|
-
], ConfigSet.prototype, "rootDir", null);
|
|
808
|
-
__decorate([
|
|
809
|
-
memoize_1.Memoize()
|
|
810
|
-
], ConfigSet.prototype, "cwd", null);
|
|
811
|
-
__decorate([
|
|
812
|
-
memoize_1.Memoize()
|
|
813
|
-
], ConfigSet.prototype, "tsJestDigest", null);
|
|
814
|
-
__decorate([
|
|
815
|
-
memoize_1.Memoize()
|
|
816
|
-
], ConfigSet.prototype, "jsonValue", null);
|
|
522
|
+
], ConfigSet.prototype, "isTestFile", null);
|
|
817
523
|
return ConfigSet;
|
|
818
524
|
}());
|
|
819
525
|
exports.ConfigSet = ConfigSet;
|