ts-jest 26.2.0 → 26.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ts-jest-digest +1 -1
- package/CHANGELOG.md +14 -0
- package/dist/cli/config/init.d.ts +5 -0
- package/dist/cli/config/init.js +18 -3
- package/dist/cli/config/migrate.js +40 -10
- package/dist/cli/help.js +7 -1
- package/dist/cli/helpers/presets.js +11 -5
- package/dist/cli/index.js +9 -5
- package/dist/compiler/instance.js +21 -1
- package/dist/compiler/language-service.js +44 -3
- package/dist/compiler/transpiler.js +4 -0
- package/dist/config/config-set.d.ts +19 -0
- package/dist/config/config-set.js +146 -65
- package/dist/config/paths-to-module-name-mapper.js +6 -2
- package/dist/constants.js +19 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +28 -1
- package/dist/transformers/hoist-jest.js +76 -2
- package/dist/transformers/index.js +3 -0
- package/dist/ts-jest-transformer.d.ts +14 -0
- package/dist/ts-jest-transformer.js +47 -3
- package/dist/types.d.ts +87 -0
- package/dist/util/backports.js +11 -4
- package/dist/util/get-package-version.js +3 -0
- package/dist/util/importer.js +29 -4
- package/dist/util/index.js +1 -0
- package/dist/util/json.js +14 -0
- package/dist/util/jsonable-value.js +4 -1
- package/dist/util/logger.js +4 -0
- package/dist/util/memoize.js +8 -0
- package/dist/util/messages.js +4 -0
- package/dist/util/normalize-slashes.js +3 -0
- package/dist/util/sha1.js +10 -0
- package/dist/util/ts-error.js +13 -3
- package/dist/util/version-checkers.js +8 -5
- package/package.json +6 -5
|
@@ -72,12 +72,22 @@ var normalize_slashes_1 = require("../util/normalize-slashes");
|
|
|
72
72
|
var sha1_1 = require("../util/sha1");
|
|
73
73
|
var ts_error_1 = require("../util/ts-error");
|
|
74
74
|
var logger = logger_1.rootLogger.child({ namespace: 'config' });
|
|
75
|
+
/**
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
// this regex MUST match nothing, it's the goal ;-)
|
|
75
79
|
exports.MATCH_NOTHING = /a^/;
|
|
80
|
+
/**
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
76
83
|
exports.IGNORE_DIAGNOSTIC_CODES = [
|
|
77
84
|
6059,
|
|
78
85
|
18002,
|
|
79
86
|
18003,
|
|
80
87
|
];
|
|
88
|
+
/**
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
81
91
|
exports.TS_JEST_OUT_DIR = '$$ts-jest$$';
|
|
82
92
|
var TARGET_TO_VERSION_MAPPING = (_a = {},
|
|
83
93
|
_a[typescript_1.ScriptTarget.ES2018] = 'es2018',
|
|
@@ -89,6 +99,7 @@ var normalizeRegex = function (pattern) {
|
|
|
89
99
|
return pattern ? (typeof pattern === 'string' ? pattern : pattern.source) : undefined;
|
|
90
100
|
};
|
|
91
101
|
var toDiagnosticCode = function (code) {
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
92
103
|
return code ? parseInt(("" + code).trim().replace(/^TS/, ''), 10) || undefined : undefined;
|
|
93
104
|
};
|
|
94
105
|
var toDiagnosticCodeList = function (items, into) {
|
|
@@ -129,61 +140,17 @@ var toDiagnosticCodeList = function (items, into) {
|
|
|
129
140
|
}
|
|
130
141
|
return into;
|
|
131
142
|
};
|
|
132
|
-
var ConfigSet = (function () {
|
|
143
|
+
var ConfigSet = /** @class */ (function () {
|
|
133
144
|
function ConfigSet(jestConfig, parentOptions, parentLogger) {
|
|
134
145
|
var _a;
|
|
135
146
|
this.parentOptions = parentOptions;
|
|
136
147
|
this._jestConfig = jestConfig;
|
|
137
148
|
this.logger = parentLogger ? parentLogger.child((_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'config', _a)) : logger;
|
|
138
149
|
}
|
|
139
|
-
Object.defineProperty(ConfigSet.prototype, "projectPackageJson", {
|
|
140
|
-
get: function () {
|
|
141
|
-
var packageJson = this.tsJest.packageJson;
|
|
142
|
-
if (packageJson) {
|
|
143
|
-
if (packageJson.kind === 'inline') {
|
|
144
|
-
return packageJson.value;
|
|
145
|
-
}
|
|
146
|
-
else if (packageJson.kind === 'file' && packageJson.value) {
|
|
147
|
-
var path = this.resolvePath(packageJson.value);
|
|
148
|
-
if (fs_1.existsSync(path)) {
|
|
149
|
-
return require(path);
|
|
150
|
-
}
|
|
151
|
-
this.logger.warn("Unable to find the root of the project where ts-jest has been installed.");
|
|
152
|
-
return {};
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
var tsJestRoot = path_1.resolve(__dirname, '..', '..');
|
|
156
|
-
var pkgPath = path_1.resolve(tsJestRoot, '..', '..', 'package.json');
|
|
157
|
-
if (fs_1.existsSync(pkgPath)) {
|
|
158
|
-
return require(pkgPath);
|
|
159
|
-
}
|
|
160
|
-
if (fs_1.realpathSync(this.rootDir) === fs_1.realpathSync(tsJestRoot)) {
|
|
161
|
-
pkgPath = path_1.resolve(tsJestRoot, 'package.json');
|
|
162
|
-
if (fs_1.existsSync(pkgPath)) {
|
|
163
|
-
return require(pkgPath);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
this.logger.warn("Unable to find the root of the project where ts-jest has been installed.");
|
|
167
|
-
return {};
|
|
168
|
-
},
|
|
169
|
-
enumerable: false,
|
|
170
|
-
configurable: true
|
|
171
|
-
});
|
|
172
|
-
Object.defineProperty(ConfigSet.prototype, "projectDependencies", {
|
|
173
|
-
get: function () {
|
|
174
|
-
var pkg = this.projectPackageJson;
|
|
175
|
-
var names = Object.keys(__assign(__assign(__assign(__assign({}, pkg.optionalDependencies), pkg.peerDependencies), pkg.devDependencies), pkg.dependencies));
|
|
176
|
-
return names.reduce(function (map, name) {
|
|
177
|
-
var version = get_package_version_1.getPackageVersion(name);
|
|
178
|
-
if (version)
|
|
179
|
-
map[name] = version;
|
|
180
|
-
return map;
|
|
181
|
-
}, {});
|
|
182
|
-
},
|
|
183
|
-
enumerable: false,
|
|
184
|
-
configurable: true
|
|
185
|
-
});
|
|
186
150
|
Object.defineProperty(ConfigSet.prototype, "jest", {
|
|
151
|
+
/**
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
187
154
|
get: function () {
|
|
188
155
|
var _a;
|
|
189
156
|
var config = backports_1.backportJestConfig(this.logger, this._jestConfig);
|
|
@@ -198,8 +165,15 @@ var ConfigSet = (function () {
|
|
|
198
165
|
configurable: true
|
|
199
166
|
});
|
|
200
167
|
Object.defineProperty(ConfigSet.prototype, "isTestFile", {
|
|
168
|
+
/**
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
201
171
|
get: function () {
|
|
202
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
|
+
*/
|
|
203
177
|
return pattern instanceof RegExp || typeof pattern === 'string';
|
|
204
178
|
});
|
|
205
179
|
if (!matchablePatterns.length) {
|
|
@@ -215,12 +189,16 @@ var ConfigSet = (function () {
|
|
|
215
189
|
configurable: true
|
|
216
190
|
});
|
|
217
191
|
Object.defineProperty(ConfigSet.prototype, "tsJest", {
|
|
192
|
+
/**
|
|
193
|
+
* @internal
|
|
194
|
+
*/
|
|
218
195
|
get: function () {
|
|
219
196
|
var _this = this;
|
|
220
197
|
var _a, _b, _c;
|
|
221
198
|
var parsedConfig = this.jest;
|
|
222
199
|
var _d = parsedConfig.globals, globals = _d === void 0 ? {} : _d;
|
|
223
200
|
var options = __assign({}, globals['ts-jest']);
|
|
201
|
+
// tsconfig
|
|
224
202
|
var tsConfigOpt = (_b = (_a = options.tsConfig) !== null && _a !== void 0 ? _a : options.tsconfig) !== null && _b !== void 0 ? _b : true;
|
|
225
203
|
var tsConfig;
|
|
226
204
|
if (typeof tsConfigOpt === 'string' || tsConfigOpt === true) {
|
|
@@ -235,6 +213,7 @@ var ConfigSet = (function () {
|
|
|
235
213
|
value: tsConfigOpt,
|
|
236
214
|
};
|
|
237
215
|
}
|
|
216
|
+
// packageJson
|
|
238
217
|
var packageJsonOpt = options.packageJson;
|
|
239
218
|
var packageJson;
|
|
240
219
|
if (typeof packageJsonOpt === 'string' || packageJsonOpt == null || packageJsonOpt === true) {
|
|
@@ -249,11 +228,12 @@ var ConfigSet = (function () {
|
|
|
249
228
|
value: packageJsonOpt,
|
|
250
229
|
};
|
|
251
230
|
}
|
|
231
|
+
// transformers
|
|
252
232
|
var transformers = Object.create(null);
|
|
253
233
|
var astTransformers = options.astTransformers;
|
|
254
234
|
if (astTransformers) {
|
|
255
235
|
if (Array.isArray(astTransformers)) {
|
|
256
|
-
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");
|
|
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 */);
|
|
257
237
|
transformers = {
|
|
258
238
|
before: astTransformers.map(function (transformerPath) { return _this.resolvePath(transformerPath, { nodeResolve: true }); }),
|
|
259
239
|
};
|
|
@@ -278,6 +258,7 @@ var ConfigSet = (function () {
|
|
|
278
258
|
}
|
|
279
259
|
}
|
|
280
260
|
}
|
|
261
|
+
// babel jest
|
|
281
262
|
var babelConfigOpt = options.babelConfig;
|
|
282
263
|
var babelConfig;
|
|
283
264
|
if (typeof babelConfigOpt === 'string' || babelConfigOpt === true) {
|
|
@@ -292,8 +273,10 @@ var ConfigSet = (function () {
|
|
|
292
273
|
value: babelConfigOpt,
|
|
293
274
|
};
|
|
294
275
|
}
|
|
276
|
+
// diagnostics
|
|
295
277
|
var diagnostics;
|
|
296
278
|
var _e = options.diagnostics, diagnosticsOpt = _e === void 0 ? true : _e;
|
|
279
|
+
// messy list of stuff to ignore (will be casted later)
|
|
297
280
|
var ignoreList = [exports.IGNORE_DIAGNOSTIC_CODES, process.env.TS_JEST_IGNORE_DIAGNOSTICS];
|
|
298
281
|
if (diagnosticsOpt === true || diagnosticsOpt == null) {
|
|
299
282
|
diagnostics = { ignoreCodes: [], pretty: true, throws: true };
|
|
@@ -315,8 +298,11 @@ var ConfigSet = (function () {
|
|
|
315
298
|
throws: !diagnosticsOpt.warnOnly,
|
|
316
299
|
};
|
|
317
300
|
}
|
|
301
|
+
// now we clean and flatten the list
|
|
318
302
|
diagnostics.ignoreCodes = toDiagnosticCodeList(ignoreList);
|
|
303
|
+
// stringifyContentPathRegex option
|
|
319
304
|
var stringifyContentPathRegex = normalizeRegex(options.stringifyContentPathRegex);
|
|
305
|
+
// parsed options
|
|
320
306
|
var res = {
|
|
321
307
|
tsConfig: tsConfig,
|
|
322
308
|
packageJson: packageJson,
|
|
@@ -334,6 +320,9 @@ var ConfigSet = (function () {
|
|
|
334
320
|
configurable: true
|
|
335
321
|
});
|
|
336
322
|
Object.defineProperty(ConfigSet.prototype, "parsedTsConfig", {
|
|
323
|
+
/**
|
|
324
|
+
* @internal
|
|
325
|
+
*/
|
|
337
326
|
get: function () {
|
|
338
327
|
return this._parsedTsConfig;
|
|
339
328
|
},
|
|
@@ -341,6 +330,9 @@ var ConfigSet = (function () {
|
|
|
341
330
|
configurable: true
|
|
342
331
|
});
|
|
343
332
|
Object.defineProperty(ConfigSet.prototype, "versions", {
|
|
333
|
+
/**
|
|
334
|
+
* Use by e2e, don't mark as internal
|
|
335
|
+
*/
|
|
344
336
|
get: function () {
|
|
345
337
|
var modules = ['jest', this.tsJest.compiler];
|
|
346
338
|
if (this.tsJest.babelConfig) {
|
|
@@ -356,10 +348,14 @@ var ConfigSet = (function () {
|
|
|
356
348
|
configurable: true
|
|
357
349
|
});
|
|
358
350
|
Object.defineProperty(ConfigSet.prototype, "_parsedTsConfig", {
|
|
351
|
+
/**
|
|
352
|
+
* @internal
|
|
353
|
+
*/
|
|
359
354
|
get: function () {
|
|
360
355
|
var tsConfig = this.tsJest.tsConfig;
|
|
361
356
|
var configFilePath = (tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.kind) === 'file' ? tsConfig.value : undefined;
|
|
362
357
|
var result = this.readTsConfig((tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.kind) === 'inline' ? tsConfig.value : undefined, configFilePath, tsConfig == null);
|
|
358
|
+
// throw errors if any matching wanted diagnostics
|
|
363
359
|
this.raiseDiagnostics(result.errors, configFilePath);
|
|
364
360
|
this.logger.debug({ tsconfig: result }, 'normalized typescript config');
|
|
365
361
|
return result;
|
|
@@ -368,6 +364,9 @@ var ConfigSet = (function () {
|
|
|
368
364
|
configurable: true
|
|
369
365
|
});
|
|
370
366
|
Object.defineProperty(ConfigSet.prototype, "raiseDiagnostics", {
|
|
367
|
+
/**
|
|
368
|
+
* @internal
|
|
369
|
+
*/
|
|
371
370
|
get: function () {
|
|
372
371
|
var _this = this;
|
|
373
372
|
var _a = this, createTsError = _a.createTsError, filterDiagnostics = _a.filterDiagnostics, throws = _a.tsJest.diagnostics.throws, DiagnosticCategory = _a.compilerModule.DiagnosticCategory;
|
|
@@ -377,6 +376,7 @@ var ConfigSet = (function () {
|
|
|
377
376
|
if (!filteredDiagnostics.length)
|
|
378
377
|
return;
|
|
379
378
|
var error = createTsError(filteredDiagnostics);
|
|
379
|
+
// only throw if `warnOnly` and it is a warning or error
|
|
380
380
|
var importantCategories = [DiagnosticCategory.Warning, DiagnosticCategory.Error];
|
|
381
381
|
if (throws && filteredDiagnostics.some(function (d) { return importantCategories.includes(d.category); })) {
|
|
382
382
|
throw error;
|
|
@@ -388,6 +388,9 @@ var ConfigSet = (function () {
|
|
|
388
388
|
configurable: true
|
|
389
389
|
});
|
|
390
390
|
Object.defineProperty(ConfigSet.prototype, "babel", {
|
|
391
|
+
/**
|
|
392
|
+
* @internal
|
|
393
|
+
*/
|
|
391
394
|
get: function () {
|
|
392
395
|
var babelConfig = this.tsJest.babelConfig;
|
|
393
396
|
if (babelConfig == null) {
|
|
@@ -415,19 +418,25 @@ var ConfigSet = (function () {
|
|
|
415
418
|
configurable: true
|
|
416
419
|
});
|
|
417
420
|
Object.defineProperty(ConfigSet.prototype, "compilerModule", {
|
|
421
|
+
/**
|
|
422
|
+
* This API can be used by custom transformers
|
|
423
|
+
*/
|
|
418
424
|
get: function () {
|
|
419
|
-
return importer_1.importer.typescript("Using \"ts-jest\" requires this package to be installed."
|
|
425
|
+
return importer_1.importer.typescript("Using \"ts-jest\" requires this package to be installed." /* TsJest */, this.tsJest.compiler);
|
|
420
426
|
},
|
|
421
427
|
enumerable: false,
|
|
422
428
|
configurable: true
|
|
423
429
|
});
|
|
424
430
|
Object.defineProperty(ConfigSet.prototype, "babelJestTransformer", {
|
|
431
|
+
/**
|
|
432
|
+
* @internal
|
|
433
|
+
*/
|
|
425
434
|
get: function () {
|
|
426
435
|
var babel = this.babel;
|
|
427
436
|
if (!babel)
|
|
428
437
|
return undefined;
|
|
429
438
|
this.logger.debug('creating babel-jest transformer');
|
|
430
|
-
return importer_1.importer.babelJest("Using \"babel-jest\" requires this package to be installed.").createTransformer(babel);
|
|
439
|
+
return importer_1.importer.babelJest("Using \"babel-jest\" requires this package to be installed." /* BabelJest */).createTransformer(babel);
|
|
431
440
|
},
|
|
432
441
|
enumerable: false,
|
|
433
442
|
configurable: true
|
|
@@ -440,6 +449,9 @@ var ConfigSet = (function () {
|
|
|
440
449
|
configurable: true
|
|
441
450
|
});
|
|
442
451
|
Object.defineProperty(ConfigSet.prototype, "astTransformers", {
|
|
452
|
+
/**
|
|
453
|
+
* @internal
|
|
454
|
+
*/
|
|
443
455
|
get: function () {
|
|
444
456
|
var astTransformers = {
|
|
445
457
|
before: __spread(transformers_1.internals),
|
|
@@ -464,6 +476,9 @@ var ConfigSet = (function () {
|
|
|
464
476
|
configurable: true
|
|
465
477
|
});
|
|
466
478
|
Object.defineProperty(ConfigSet.prototype, "tsCustomTransformers", {
|
|
479
|
+
/**
|
|
480
|
+
* @internal
|
|
481
|
+
*/
|
|
467
482
|
get: function () {
|
|
468
483
|
var _this = this;
|
|
469
484
|
var customTransformers = {
|
|
@@ -481,6 +496,9 @@ var ConfigSet = (function () {
|
|
|
481
496
|
configurable: true
|
|
482
497
|
});
|
|
483
498
|
Object.defineProperty(ConfigSet.prototype, "hooks", {
|
|
499
|
+
/**
|
|
500
|
+
* @internal
|
|
501
|
+
*/
|
|
484
502
|
get: function () {
|
|
485
503
|
var hooksFile = process.env.TS_JEST_HOOKS;
|
|
486
504
|
if (hooksFile) {
|
|
@@ -493,6 +511,9 @@ var ConfigSet = (function () {
|
|
|
493
511
|
configurable: true
|
|
494
512
|
});
|
|
495
513
|
Object.defineProperty(ConfigSet.prototype, "filterDiagnostics", {
|
|
514
|
+
/**
|
|
515
|
+
* @internal
|
|
516
|
+
*/
|
|
496
517
|
get: function () {
|
|
497
518
|
var _a = this, ignoreCodes = _a.tsJest.diagnostics.ignoreCodes, shouldReportDiagnostic = _a.shouldReportDiagnostic;
|
|
498
519
|
return function (diagnostics, filePath) {
|
|
@@ -511,6 +532,9 @@ var ConfigSet = (function () {
|
|
|
511
532
|
configurable: true
|
|
512
533
|
});
|
|
513
534
|
Object.defineProperty(ConfigSet.prototype, "shouldReportDiagnostic", {
|
|
535
|
+
/**
|
|
536
|
+
* @internal
|
|
537
|
+
*/
|
|
514
538
|
get: function () {
|
|
515
539
|
var pathRegex = this.tsJest.diagnostics.pathRegex;
|
|
516
540
|
if (pathRegex) {
|
|
@@ -525,6 +549,9 @@ var ConfigSet = (function () {
|
|
|
525
549
|
configurable: true
|
|
526
550
|
});
|
|
527
551
|
Object.defineProperty(ConfigSet.prototype, "shouldStringifyContent", {
|
|
552
|
+
/**
|
|
553
|
+
* @internal
|
|
554
|
+
*/
|
|
528
555
|
get: function () {
|
|
529
556
|
var stringifyContentPathRegex = this.tsJest.stringifyContentPathRegex;
|
|
530
557
|
if (stringifyContentPathRegex) {
|
|
@@ -539,6 +566,9 @@ var ConfigSet = (function () {
|
|
|
539
566
|
configurable: true
|
|
540
567
|
});
|
|
541
568
|
Object.defineProperty(ConfigSet.prototype, "createTsError", {
|
|
569
|
+
/**
|
|
570
|
+
* @internal
|
|
571
|
+
*/
|
|
542
572
|
get: function () {
|
|
543
573
|
var _this = this;
|
|
544
574
|
var pretty = this.tsJest.diagnostics.pretty;
|
|
@@ -560,6 +590,9 @@ var ConfigSet = (function () {
|
|
|
560
590
|
configurable: true
|
|
561
591
|
});
|
|
562
592
|
Object.defineProperty(ConfigSet.prototype, "tsCacheDir", {
|
|
593
|
+
/**
|
|
594
|
+
* @internal
|
|
595
|
+
*/
|
|
563
596
|
get: function () {
|
|
564
597
|
if (!this.jest.cache) {
|
|
565
598
|
logger.debug('file caching disabled');
|
|
@@ -568,7 +601,6 @@ var ConfigSet = (function () {
|
|
|
568
601
|
var cacheSuffix = sha1_1.sha1(json_1.stringify({
|
|
569
602
|
version: this.compilerModule.version,
|
|
570
603
|
digest: this.tsJestDigest,
|
|
571
|
-
dependencies: this.projectDependencies,
|
|
572
604
|
compiler: this.tsJest.compiler,
|
|
573
605
|
compilerOptions: this.parsedTsConfig.options,
|
|
574
606
|
isolatedModules: this.tsJest.isolatedModules,
|
|
@@ -582,14 +614,21 @@ var ConfigSet = (function () {
|
|
|
582
614
|
configurable: true
|
|
583
615
|
});
|
|
584
616
|
Object.defineProperty(ConfigSet.prototype, "overriddenCompilerOptions", {
|
|
617
|
+
/**
|
|
618
|
+
* @internal
|
|
619
|
+
*/
|
|
585
620
|
get: function () {
|
|
586
621
|
var options = {
|
|
622
|
+
// we handle sourcemaps this way and not another
|
|
587
623
|
sourceMap: true,
|
|
588
624
|
inlineSourceMap: false,
|
|
589
625
|
inlineSources: true,
|
|
626
|
+
// we don't want to create declaration files
|
|
590
627
|
declaration: false,
|
|
591
628
|
noEmit: false,
|
|
629
|
+
// else istanbul related will be dropped
|
|
592
630
|
removeComments: false,
|
|
631
|
+
// to clear out else it's buggy
|
|
593
632
|
out: undefined,
|
|
594
633
|
outFile: undefined,
|
|
595
634
|
composite: undefined,
|
|
@@ -599,7 +638,9 @@ var ConfigSet = (function () {
|
|
|
599
638
|
sourceRoot: undefined,
|
|
600
639
|
tsBuildInfoFile: undefined,
|
|
601
640
|
};
|
|
641
|
+
// force the module kind if not piping babel-jest
|
|
602
642
|
if (!this.tsJest.babelConfig) {
|
|
643
|
+
// commonjs is required for jest
|
|
603
644
|
options.module = this.compilerModule.ModuleKind.CommonJS;
|
|
604
645
|
}
|
|
605
646
|
return options;
|
|
@@ -608,6 +649,9 @@ var ConfigSet = (function () {
|
|
|
608
649
|
configurable: true
|
|
609
650
|
});
|
|
610
651
|
Object.defineProperty(ConfigSet.prototype, "rootDir", {
|
|
652
|
+
/**
|
|
653
|
+
* @internal
|
|
654
|
+
*/
|
|
611
655
|
get: function () {
|
|
612
656
|
return path_1.normalize(this.jest.rootDir || this.cwd);
|
|
613
657
|
},
|
|
@@ -615,6 +659,9 @@ var ConfigSet = (function () {
|
|
|
615
659
|
configurable: true
|
|
616
660
|
});
|
|
617
661
|
Object.defineProperty(ConfigSet.prototype, "cwd", {
|
|
662
|
+
/**
|
|
663
|
+
* @internal
|
|
664
|
+
*/
|
|
618
665
|
get: function () {
|
|
619
666
|
return path_1.normalize(this.jest.cwd || process.cwd());
|
|
620
667
|
},
|
|
@@ -622,6 +669,9 @@ var ConfigSet = (function () {
|
|
|
622
669
|
configurable: true
|
|
623
670
|
});
|
|
624
671
|
Object.defineProperty(ConfigSet.prototype, "tsJestDigest", {
|
|
672
|
+
/**
|
|
673
|
+
* Use by e2e, don't mark as internal
|
|
674
|
+
*/
|
|
625
675
|
get: function () {
|
|
626
676
|
return __1.digest;
|
|
627
677
|
},
|
|
@@ -629,15 +679,19 @@ var ConfigSet = (function () {
|
|
|
629
679
|
configurable: true
|
|
630
680
|
});
|
|
631
681
|
Object.defineProperty(ConfigSet.prototype, "jsonValue", {
|
|
682
|
+
/**
|
|
683
|
+
* @internal
|
|
684
|
+
*/
|
|
632
685
|
get: function () {
|
|
633
686
|
var jest = __assign({}, this.jest);
|
|
634
687
|
var globals = (jest.globals = __assign({}, jest.globals));
|
|
635
|
-
|
|
636
|
-
|
|
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
|
|
637
693
|
delete globals['ts-jest'];
|
|
638
694
|
return new jsonable_value_1.JsonableValue({
|
|
639
|
-
versions: this.versions,
|
|
640
|
-
projectDepVersions: this.projectDependencies,
|
|
641
695
|
digest: this.tsJestDigest,
|
|
642
696
|
transformers: Object.values(this.astTransformers)
|
|
643
697
|
.reduce(function (acc, val) { return acc.concat(val); }, [])
|
|
@@ -655,12 +709,18 @@ var ConfigSet = (function () {
|
|
|
655
709
|
configurable: true
|
|
656
710
|
});
|
|
657
711
|
Object.defineProperty(ConfigSet.prototype, "cacheKey", {
|
|
712
|
+
/**
|
|
713
|
+
* @internal
|
|
714
|
+
*/
|
|
658
715
|
get: function () {
|
|
659
716
|
return this.jsonValue.serialized;
|
|
660
717
|
},
|
|
661
718
|
enumerable: false,
|
|
662
719
|
configurable: true
|
|
663
720
|
});
|
|
721
|
+
/**
|
|
722
|
+
* @internal
|
|
723
|
+
*/
|
|
664
724
|
ConfigSet.prototype.makeDiagnostic = function (code, messageText, options) {
|
|
665
725
|
if (options === void 0) { options = {}; }
|
|
666
726
|
var _a = options.category, category = _a === void 0 ? this.compilerModule.DiagnosticCategory.Warning : _a, file = options.file, start = options.start, length = options.length;
|
|
@@ -673,6 +733,12 @@ var ConfigSet = (function () {
|
|
|
673
733
|
length: length,
|
|
674
734
|
};
|
|
675
735
|
};
|
|
736
|
+
/**
|
|
737
|
+
* Load TypeScript configuration. Returns the parsed TypeScript config and
|
|
738
|
+
* any `tsConfig` options specified in ts-jest tsConfig
|
|
739
|
+
*
|
|
740
|
+
* @internal
|
|
741
|
+
*/
|
|
676
742
|
ConfigSet.prototype.readTsConfig = function (compilerOptions, resolvedConfigFile, noProject) {
|
|
677
743
|
var e_2, _a;
|
|
678
744
|
var _b;
|
|
@@ -681,12 +747,14 @@ var ConfigSet = (function () {
|
|
|
681
747
|
var configFileName;
|
|
682
748
|
var ts = this.compilerModule;
|
|
683
749
|
if (!noProject) {
|
|
750
|
+
// Read project configuration when available.
|
|
684
751
|
configFileName = resolvedConfigFile
|
|
685
752
|
? normalize_slashes_1.normalizeSlashes(resolvedConfigFile)
|
|
686
753
|
: ts.findConfigFile(normalize_slashes_1.normalizeSlashes(this.rootDir), ts.sys.fileExists);
|
|
687
754
|
if (configFileName) {
|
|
688
755
|
this.logger.debug({ tsConfigFileName: configFileName }, 'readTsConfig(): reading', configFileName);
|
|
689
756
|
var result_1 = ts.readConfigFile(configFileName, ts.sys.readFile);
|
|
757
|
+
// Return diagnostics.
|
|
690
758
|
if (result_1.error) {
|
|
691
759
|
return { errors: [result_1.error], fileNames: [], options: {} };
|
|
692
760
|
}
|
|
@@ -694,14 +762,19 @@ var ConfigSet = (function () {
|
|
|
694
762
|
basePath = normalize_slashes_1.normalizeSlashes(path_1.dirname(configFileName));
|
|
695
763
|
}
|
|
696
764
|
}
|
|
765
|
+
// Override default configuration options `ts-jest` requires.
|
|
697
766
|
config.compilerOptions = __assign(__assign({}, config.compilerOptions), compilerOptions);
|
|
767
|
+
// parse json, merge config extending others, ...
|
|
698
768
|
var result = ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, configFileName);
|
|
699
769
|
var forcedOptions = this.overriddenCompilerOptions;
|
|
700
770
|
var finalOptions = result.options;
|
|
771
|
+
// Target ES5 output by default (instead of ES3).
|
|
701
772
|
if (finalOptions.target === undefined) {
|
|
702
773
|
finalOptions.target = ts.ScriptTarget.ES5;
|
|
703
774
|
}
|
|
775
|
+
// check the module interoperability
|
|
704
776
|
var target = finalOptions.target;
|
|
777
|
+
// compute the default if not set
|
|
705
778
|
var defaultModule = [ts.ScriptTarget.ES3, ts.ScriptTarget.ES5].includes(target)
|
|
706
779
|
? ts.ModuleKind.CommonJS
|
|
707
780
|
: ts.ModuleKind.ESNext;
|
|
@@ -709,17 +782,20 @@ var ConfigSet = (function () {
|
|
|
709
782
|
if ('module' in forcedOptions &&
|
|
710
783
|
moduleValue !== forcedOptions.module &&
|
|
711
784
|
!(finalOptions.esModuleInterop || finalOptions.allowSyntheticDefaultImports)) {
|
|
712
|
-
result.errors.push(this.makeDiagnostic(151001
|
|
785
|
+
result.errors.push(this.makeDiagnostic(151001 /* ConfigModuleOption */, "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." /* ConfigNoModuleInterop */, {
|
|
713
786
|
category: ts.DiagnosticCategory.Message,
|
|
714
787
|
}));
|
|
788
|
+
// at least enable synthetic default imports (except if it's set in the input config)
|
|
715
789
|
if (!('allowSyntheticDefaultImports' in config.compilerOptions)) {
|
|
716
790
|
finalOptions.allowSyntheticDefaultImports = true;
|
|
717
791
|
}
|
|
718
792
|
}
|
|
793
|
+
// Make sure when allowJs is enabled, outDir is required to have when using allowJs: true
|
|
719
794
|
if (finalOptions.allowJs && !finalOptions.outDir) {
|
|
720
795
|
finalOptions.outDir = exports.TS_JEST_OUT_DIR;
|
|
721
796
|
}
|
|
722
797
|
try {
|
|
798
|
+
// ensure undefined are removed and other values are overridden
|
|
723
799
|
for (var _c = __values(Object.keys(forcedOptions)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
724
800
|
var key = _d.value;
|
|
725
801
|
var val = forcedOptions[key];
|
|
@@ -738,12 +814,17 @@ var ConfigSet = (function () {
|
|
|
738
814
|
}
|
|
739
815
|
finally { if (e_2) throw e_2.error; }
|
|
740
816
|
}
|
|
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
|
+
*/
|
|
741
821
|
var nodeJsVer = process.version;
|
|
822
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
742
823
|
var compilationTarget = result.options.target;
|
|
743
824
|
if (!this.tsJest.babelConfig &&
|
|
744
825
|
((nodeJsVer.startsWith('v10') && compilationTarget > typescript_1.ScriptTarget.ES2018) ||
|
|
745
826
|
(nodeJsVer.startsWith('v12') && compilationTarget > typescript_1.ScriptTarget.ES2019))) {
|
|
746
|
-
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"
|
|
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" /* MismatchNodeTargetMapping */, {
|
|
747
828
|
nodeJsVer: process.version,
|
|
748
829
|
compilationTarget: (_b = config.compilerOptions.target) !== null && _b !== void 0 ? _b : TARGET_TO_VERSION_MAPPING[compilationTarget],
|
|
749
830
|
});
|
|
@@ -751,6 +832,9 @@ var ConfigSet = (function () {
|
|
|
751
832
|
}
|
|
752
833
|
return result;
|
|
753
834
|
};
|
|
835
|
+
/**
|
|
836
|
+
* @internal
|
|
837
|
+
*/
|
|
754
838
|
ConfigSet.prototype.resolvePath = function (inputPath, _a) {
|
|
755
839
|
var _b = _a === void 0 ? {} : _a, _c = _b.throwIfMissing, throwIfMissing = _c === void 0 ? true : _c, _d = _b.nodeResolve, nodeResolve = _d === void 0 ? false : _d;
|
|
756
840
|
var path = inputPath;
|
|
@@ -778,20 +862,17 @@ var ConfigSet = (function () {
|
|
|
778
862
|
catch (_) { }
|
|
779
863
|
}
|
|
780
864
|
if (throwIfMissing && !fs_1.existsSync(path)) {
|
|
781
|
-
throw new Error(messages_1.interpolate("File not found: {{inputPath}} (resolved as: {{resolvedPath}})"
|
|
865
|
+
throw new Error(messages_1.interpolate("File not found: {{inputPath}} (resolved as: {{resolvedPath}})" /* FileNotFound */, { inputPath: inputPath, resolvedPath: path }));
|
|
782
866
|
}
|
|
783
867
|
this.logger.debug({ fromPath: inputPath, toPath: path }, 'resolved path from', inputPath, 'to', path);
|
|
784
868
|
return path;
|
|
785
869
|
};
|
|
870
|
+
/**
|
|
871
|
+
* @internal
|
|
872
|
+
*/
|
|
786
873
|
ConfigSet.prototype.toJSON = function () {
|
|
787
874
|
return this.jsonValue.value;
|
|
788
875
|
};
|
|
789
|
-
__decorate([
|
|
790
|
-
memoize_1.Memoize()
|
|
791
|
-
], ConfigSet.prototype, "projectPackageJson", null);
|
|
792
|
-
__decorate([
|
|
793
|
-
memoize_1.Memoize()
|
|
794
|
-
], ConfigSet.prototype, "projectDependencies", null);
|
|
795
876
|
__decorate([
|
|
796
877
|
memoize_1.Memoize()
|
|
797
878
|
], ConfigSet.prototype, "jest", null);
|
|
@@ -16,6 +16,8 @@ exports.pathsToModuleNameMapper = void 0;
|
|
|
16
16
|
var bs_logger_1 = require("bs-logger");
|
|
17
17
|
var logger_1 = require("../util/logger");
|
|
18
18
|
var messages_1 = require("../util/messages");
|
|
19
|
+
// we don't need to escape all chars, so commented out is the real one
|
|
20
|
+
// const escapeRegex = (str: string) => str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')
|
|
19
21
|
var escapeRegex = function (str) { return str.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); };
|
|
20
22
|
var logger = logger_1.rootLogger.child((_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'path-mapper', _a));
|
|
21
23
|
exports.pathsToModuleNameMapper = function (mapping, _a) {
|
|
@@ -27,10 +29,12 @@ exports.pathsToModuleNameMapper = function (mapping, _a) {
|
|
|
27
29
|
var fromPath = _e.value;
|
|
28
30
|
var pattern = void 0;
|
|
29
31
|
var toPaths = mapping[fromPath];
|
|
32
|
+
// check that we have only one target path
|
|
30
33
|
if (toPaths.length === 0) {
|
|
31
|
-
logger.warn(messages_1.interpolate("Not mapping \"{{path}}\" because it has no target."
|
|
34
|
+
logger.warn(messages_1.interpolate("Not mapping \"{{path}}\" because it has no target." /* NotMappingPathWithEmptyMap */, { path: fromPath }));
|
|
32
35
|
continue;
|
|
33
36
|
}
|
|
37
|
+
// split with '*'
|
|
34
38
|
var segments = fromPath.split(/\*/g);
|
|
35
39
|
if (segments.length === 1) {
|
|
36
40
|
var paths = toPaths.map(function (target) { return "" + prefix + target; });
|
|
@@ -43,7 +47,7 @@ exports.pathsToModuleNameMapper = function (mapping, _a) {
|
|
|
43
47
|
jestMap[pattern] = paths.length === 1 ? paths[0] : paths;
|
|
44
48
|
}
|
|
45
49
|
else {
|
|
46
|
-
logger.warn(messages_1.interpolate("Not mapping \"{{path}}\" because it has more than one star (`*`)."
|
|
50
|
+
logger.warn(messages_1.interpolate("Not mapping \"{{path}}\" because it has more than one star (`*`)." /* NotMappingMultiStarPath */, { path: fromPath }));
|
|
47
51
|
continue;
|
|
48
52
|
}
|
|
49
53
|
}
|
package/dist/constants.js
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_JEST_TEST_MATCH = exports.JSON_REGEX = exports.JS_JSX_REGEX = exports.TS_TSX_REGEX = exports.EXTENSION_REGEX = exports.LINE_FEED = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
4
7
|
exports.LINE_FEED = '\n';
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
5
11
|
exports.EXTENSION_REGEX = /\.[^.]+$/;
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
6
15
|
exports.TS_TSX_REGEX = /\.tsx?$/;
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
7
19
|
exports.JS_JSX_REGEX = /\.jsx?$/;
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
8
23
|
exports.JSON_REGEX = /\.json$/i;
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
* See https://jestjs.io/docs/en/configuration#testmatch-arraystring
|
|
27
|
+
*/
|
|
9
28
|
exports.DEFAULT_JEST_TEST_MATCH = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'];
|
package/dist/index.d.ts
CHANGED
|
@@ -9,8 +9,11 @@ declare module '@jest/types' {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
+
/** @deprecated */
|
|
12
13
|
export declare const mocked: typeof mockedCore;
|
|
14
|
+
/** @deprecated */
|
|
13
15
|
export declare const createJestPreset: typeof createJestPresetCore;
|
|
16
|
+
/** @deprecated */
|
|
14
17
|
export declare const pathsToModuleNameMapper: (mapping: import("typescript").MapLike<string[]>, { prefix }?: {
|
|
15
18
|
prefix?: string | undefined;
|
|
16
19
|
}) => {
|