ts-jest 29.3.2 → 29.3.4
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 +21 -0
- package/dist/cli/config/init.js +103 -128
- package/dist/cli/config/migrate.js +113 -156
- package/dist/cli/help.js +14 -42
- package/dist/cli/helpers/presets.js +7 -8
- package/dist/cli/index.js +47 -101
- package/dist/config/paths-to-module-name-mapper.js +37 -61
- package/dist/constants.js +1 -5
- package/dist/index.js +2 -2
- package/dist/legacy/compiler/compiler-utils.js +5 -5
- package/dist/legacy/compiler/ts-compiler.js +194 -213
- package/dist/legacy/compiler/ts-jest-compiler.js +9 -9
- package/dist/legacy/config/config-set.js +298 -298
- package/dist/legacy/index.js +2 -4
- package/dist/legacy/ts-jest-transformer.js +134 -201
- package/dist/presets/all-presets.js +2 -2
- package/dist/presets/create-jest-preset.js +101 -139
- package/dist/transformers/hoist-jest.js +30 -43
- package/dist/transpilers/typescript/transpile-module.js +69 -98
- package/dist/types.d.ts +2 -2
- package/dist/types.js +1 -1
- package/dist/utils/backports.js +26 -28
- package/dist/utils/get-package-version.js +2 -2
- package/dist/utils/importer.js +53 -108
- package/dist/utils/json.js +2 -2
- package/dist/utils/jsonable-value.js +20 -27
- package/dist/utils/logger.js +11 -15
- package/dist/utils/memoize.js +11 -17
- package/dist/utils/messages.js +2 -3
- package/dist/utils/sha1.js +7 -11
- package/dist/utils/ts-error.js +19 -35
- package/package.json +19 -19
- package/tsconfig.base.json +20 -0
- package/sonar-project.properties +0 -16
package/.ts-jest-digest
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
dfc4e7710788a7a7f79e90e8d15aee27450846bd
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [29.3.4](https://github.com/kulshekhar/ts-jest/compare/v29.3.3...v29.3.4) (2025-05-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* fix: fix `TsJestTransformerOptions` type ([3b11e29](https://github.com/kulshekhar/ts-jest/commit/3b11e29)), closes [#4247](https://github.com/kulshekhar/ts-jest/issues/4247)
|
|
7
|
+
* fix(cli): fix wrong path for preset creator fns ([249eb2c](https://github.com/kulshekhar/ts-jest/commit/249eb2c))
|
|
8
|
+
* fix(config): disable `rewriteRelativeImportExtensions` always ([9b1f472](https://github.com/kulshekhar/ts-jest/commit/9b1f472)), closes [#4855](https://github.com/kulshekhar/ts-jest/issues/4855)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## [29.3.3](https://github.com/kulshekhar/ts-jest/compare/v29.3.2...v29.3.3) (2025-05-14)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* fix(cli): init config with preset creator functions ([cdd3039](https://github.com/kulshekhar/ts-jest/commit/cdd3039)), closes [#4840](https://github.com/kulshekhar/ts-jest/issues/4840)
|
|
18
|
+
* fix(config): disable `isolatedDeclarations` ([5d6b35f](https://github.com/kulshekhar/ts-jest/commit/5d6b35f)), closes [#4847](https://github.com/kulshekhar/ts-jest/issues/4847)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
1
22
|
## [29.3.2](https://github.com/kulshekhar/ts-jest/compare/v29.3.1...v29.3.2) (2025-04-12)
|
|
2
23
|
|
|
3
24
|
|
package/dist/cli/config/init.js
CHANGED
|
@@ -4,81 +4,28 @@
|
|
|
4
4
|
* ...and I saw a merged PR with `jest --init` tool!
|
|
5
5
|
* TODO: see what's the best path for this
|
|
6
6
|
*/
|
|
7
|
-
var __assign = (this && this.__assign) || function () {
|
|
8
|
-
__assign = Object.assign || function(t) {
|
|
9
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
10
|
-
s = arguments[i];
|
|
11
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
12
|
-
t[p] = s[p];
|
|
13
|
-
}
|
|
14
|
-
return t;
|
|
15
|
-
};
|
|
16
|
-
return __assign.apply(this, arguments);
|
|
17
|
-
};
|
|
18
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
19
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
20
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
21
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
22
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
23
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
24
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
28
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
29
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
30
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
31
|
-
function step(op) {
|
|
32
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
33
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
34
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
35
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
36
|
-
switch (op[0]) {
|
|
37
|
-
case 0: case 1: t = op; break;
|
|
38
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
39
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
40
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
41
|
-
default:
|
|
42
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
43
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
44
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
45
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
46
|
-
if (t[2]) _.ops.pop();
|
|
47
|
-
_.trys.pop(); continue;
|
|
48
|
-
}
|
|
49
|
-
op = body.call(thisArg, _);
|
|
50
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
51
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
55
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
56
|
-
if (!m) return o;
|
|
57
|
-
var i = m.call(o), r, ar = [], e;
|
|
58
|
-
try {
|
|
59
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
60
|
-
}
|
|
61
|
-
catch (error) { e = { error: error }; }
|
|
62
|
-
finally {
|
|
63
|
-
try {
|
|
64
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
65
|
-
}
|
|
66
|
-
finally { if (e) throw e.error; }
|
|
67
|
-
}
|
|
68
|
-
return ar;
|
|
69
|
-
};
|
|
70
7
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
71
8
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
72
9
|
};
|
|
73
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
74
11
|
exports.help = exports.run = void 0;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
12
|
+
const fs_1 = require("fs");
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const ejs_1 = __importDefault(require("ejs"));
|
|
15
|
+
const json5_1 = require("json5");
|
|
16
|
+
const create_jest_preset_1 = require("../../presets/create-jest-preset");
|
|
17
|
+
const JEST_CONFIG_EJS_TEMPLATE = `const { <%= presetCreatorFn %> } = require("ts-jest");
|
|
18
|
+
|
|
19
|
+
const tsJestTransformCfg = <%= presetCreatorFn %>(<%- transformOpts %>).transform;
|
|
20
|
+
|
|
21
|
+
/** @type {import("jest").Config} **/
|
|
22
|
+
<%= exportKind %> {
|
|
23
|
+
testEnvironment: "<%= testEnvironment %>",
|
|
24
|
+
transform: {
|
|
25
|
+
...tsJestTransformCfg,
|
|
26
|
+
},
|
|
27
|
+
};`;
|
|
28
|
+
const ensureOnlyUsingDoubleQuotes = (str) => {
|
|
82
29
|
return str
|
|
83
30
|
.replace(/"'(.*?)'"/g, '"$1"')
|
|
84
31
|
.replace(/'ts-jest'/g, '"ts-jest"')
|
|
@@ -87,77 +34,105 @@ var ensureOnlyUsingDoubleQuotes = function (str) {
|
|
|
87
34
|
/**
|
|
88
35
|
* @internal
|
|
89
36
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
37
|
+
const run = async (args /* , logger: Logger */) => {
|
|
38
|
+
const { tsconfig: askedTsconfig, force, jsdom, js: jsFilesProcessor, babel: shouldPostProcessWithBabel } = args;
|
|
39
|
+
const file = args._[0]?.toString() ?? 'jest.config.js';
|
|
40
|
+
const filePath = (0, path_1.join)(process.cwd(), file);
|
|
41
|
+
const name = (0, path_1.basename)(file);
|
|
42
|
+
const isPackageJsonConfig = name === 'package.json';
|
|
43
|
+
const isJestConfigFileExisted = (0, fs_1.existsSync)(filePath);
|
|
44
|
+
const pkgFile = isPackageJsonConfig ? filePath : (0, path_1.join)(process.cwd(), 'package.json');
|
|
45
|
+
const isPackageJsonExisted = isPackageJsonConfig || (0, fs_1.existsSync)(pkgFile);
|
|
46
|
+
const tsconfig = askedTsconfig === 'tsconfig.json' ? undefined : askedTsconfig;
|
|
47
|
+
const pkgJsonContent = isPackageJsonExisted ? JSON.parse((0, fs_1.readFileSync)(pkgFile, 'utf8')) : {};
|
|
48
|
+
if (shouldPostProcessWithBabel) {
|
|
49
|
+
console.warn(`The option --babel is deprecated and will be removed in the next major version.` +
|
|
50
|
+
` Please specify 'js' option value (see more with npx ts-jest help) if you wish 'ts-jest' to process 'js' with TypeScript API or Babel.`);
|
|
51
|
+
}
|
|
52
|
+
if (isPackageJsonConfig && !isJestConfigFileExisted) {
|
|
53
|
+
throw new Error(`File ${file} does not exists.`);
|
|
54
|
+
}
|
|
55
|
+
else if (!isPackageJsonConfig && isJestConfigFileExisted && !force) {
|
|
56
|
+
throw new Error(`Configuration file ${file} already exists.`);
|
|
57
|
+
}
|
|
58
|
+
if (!isPackageJsonConfig && !name.endsWith('.js')) {
|
|
59
|
+
throw new TypeError(`Configuration file ${file} must be a .js file or the package.json.`);
|
|
60
|
+
}
|
|
61
|
+
if (isPackageJsonExisted && pkgJsonContent.jest) {
|
|
62
|
+
if (force && !isPackageJsonConfig) {
|
|
63
|
+
delete pkgJsonContent.jest;
|
|
64
|
+
(0, fs_1.writeFileSync)(pkgFile, JSON.stringify(pkgJsonContent, undefined, ' '));
|
|
116
65
|
}
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
delete pkgJsonContent.jest;
|
|
120
|
-
(0, fs_1.writeFileSync)(pkgFile, JSON.stringify(pkgJsonContent, undefined, ' '));
|
|
121
|
-
}
|
|
122
|
-
else if (!force) {
|
|
123
|
-
throw new Error("A Jest configuration is already set in ".concat(pkgFile, "."));
|
|
124
|
-
}
|
|
66
|
+
else if (!force) {
|
|
67
|
+
throw new Error(`A Jest configuration is already set in ${pkgFile}.`);
|
|
125
68
|
}
|
|
126
|
-
|
|
69
|
+
}
|
|
70
|
+
let body;
|
|
71
|
+
const transformOpts = tsconfig
|
|
72
|
+
? { tsconfig: `${(0, json5_1.stringify)(tsconfig)}` }
|
|
73
|
+
: undefined;
|
|
74
|
+
let transformConfig;
|
|
75
|
+
if (isPackageJsonConfig) {
|
|
127
76
|
if (jsFilesProcessor === 'babel' || shouldPostProcessWithBabel) {
|
|
128
|
-
transformConfig = (0, create_jest_preset_1.createJsWithBabelPreset)(
|
|
77
|
+
transformConfig = (0, create_jest_preset_1.createJsWithBabelPreset)(transformOpts);
|
|
129
78
|
}
|
|
130
79
|
else if (jsFilesProcessor === 'ts') {
|
|
131
|
-
transformConfig = (0, create_jest_preset_1.createJsWithTsPreset)(
|
|
80
|
+
transformConfig = (0, create_jest_preset_1.createJsWithTsPreset)(transformOpts);
|
|
132
81
|
}
|
|
133
82
|
else {
|
|
134
|
-
transformConfig = (0, create_jest_preset_1.createDefaultPreset)(
|
|
83
|
+
transformConfig = (0, create_jest_preset_1.createDefaultPreset)(transformOpts);
|
|
84
|
+
}
|
|
85
|
+
body = ensureOnlyUsingDoubleQuotes(JSON.stringify({
|
|
86
|
+
...pkgJsonContent,
|
|
87
|
+
jest: transformConfig,
|
|
88
|
+
}, undefined, ' '));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
let presetCreatorFn;
|
|
92
|
+
if (jsFilesProcessor === 'babel' || shouldPostProcessWithBabel) {
|
|
93
|
+
presetCreatorFn = 'createJsWithBabelPreset';
|
|
135
94
|
}
|
|
136
|
-
if (
|
|
137
|
-
|
|
95
|
+
else if (jsFilesProcessor === 'ts') {
|
|
96
|
+
presetCreatorFn = 'createJsWithTsPreset';
|
|
138
97
|
}
|
|
139
98
|
else {
|
|
140
|
-
|
|
141
|
-
body = ejs_1.default.render(constants_1.JEST_CONFIG_EJS_TEMPLATE, {
|
|
142
|
-
exportKind: pkgJsonContent.type === 'module' ? 'export default' : 'module.exports =',
|
|
143
|
-
testEnvironment: jsdom ? 'jsdom' : 'node',
|
|
144
|
-
transformPattern: transformPattern,
|
|
145
|
-
transformValue: ensureOnlyUsingDoubleQuotes((0, json5_1.stringify)(transformValue)),
|
|
146
|
-
});
|
|
99
|
+
presetCreatorFn = 'createDefaultPreset';
|
|
147
100
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
101
|
+
body = ejs_1.default.render(JEST_CONFIG_EJS_TEMPLATE, {
|
|
102
|
+
exportKind: pkgJsonContent.type === 'module' ? 'export default' : 'module.exports =',
|
|
103
|
+
testEnvironment: jsdom ? 'jsdom' : 'node',
|
|
104
|
+
presetCreatorFn,
|
|
105
|
+
transformOpts: transformOpts ? ensureOnlyUsingDoubleQuotes(JSON.stringify(transformOpts, null, 2)) : undefined,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
(0, fs_1.writeFileSync)(filePath, body);
|
|
109
|
+
process.stderr.write(`
|
|
110
|
+
Jest configuration written to "${filePath}".
|
|
111
|
+
`);
|
|
112
|
+
};
|
|
153
113
|
exports.run = run;
|
|
154
114
|
/**
|
|
155
115
|
* @internal
|
|
156
116
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
117
|
+
const help = async () => {
|
|
118
|
+
process.stdout.write(`
|
|
119
|
+
Usage:
|
|
120
|
+
ts-jest config:init [options] [<config-file>]
|
|
121
|
+
|
|
122
|
+
Arguments:
|
|
123
|
+
<config-file> Can be a js or json Jest config file. If it is a
|
|
124
|
+
package.json file, the configuration will be read from
|
|
125
|
+
the "jest" property.
|
|
126
|
+
Default: jest.config.js
|
|
127
|
+
|
|
128
|
+
Options:
|
|
129
|
+
--force Discard any existing Jest config
|
|
130
|
+
--js ts|babel Process '.js' files with ts-jest if 'ts' or with
|
|
131
|
+
babel-jest if 'babel'
|
|
132
|
+
--no-jest-preset Disable the use of Jest presets
|
|
133
|
+
--tsconfig <file> Path to the tsconfig.json file
|
|
134
|
+
--babel Enable using Babel to process 'js' resulted content from 'ts-jest' processing
|
|
135
|
+
--jsdom Use 'jsdom' as test environment instead of 'node'
|
|
136
|
+
`);
|
|
137
|
+
};
|
|
163
138
|
exports.help = help;
|
|
@@ -1,181 +1,128 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
-
if (!m) return o;
|
|
52
|
-
var i = m.call(o), r, ar = [], e;
|
|
53
|
-
try {
|
|
54
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
-
}
|
|
56
|
-
catch (error) { e = { error: error }; }
|
|
57
|
-
finally {
|
|
58
|
-
try {
|
|
59
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
-
}
|
|
61
|
-
finally { if (e) throw e.error; }
|
|
62
|
-
}
|
|
63
|
-
return ar;
|
|
64
|
-
};
|
|
65
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
66
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
67
4
|
};
|
|
68
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
69
6
|
exports.help = exports.run = void 0;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const bs_logger_1 = require("bs-logger");
|
|
10
|
+
const fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
|
|
11
|
+
const json5_1 = require("json5");
|
|
12
|
+
const create_jest_preset_1 = require("../../presets/create-jest-preset");
|
|
13
|
+
const backports_1 = require("../../utils/backports");
|
|
14
|
+
const presets_1 = require("../helpers/presets");
|
|
15
|
+
const migrateGlobalConfigToTransformConfig = (transformConfig, globalsTsJestConfig) => {
|
|
79
16
|
if (transformConfig) {
|
|
80
|
-
return Object.entries(transformConfig).reduce(
|
|
81
|
-
|
|
82
|
-
var _c = __read(currentValue, 2), key = _c[0], transformOptions = _c[1];
|
|
17
|
+
return Object.entries(transformConfig).reduce((previousValue, currentValue) => {
|
|
18
|
+
const [key, transformOptions] = currentValue;
|
|
83
19
|
if (typeof transformOptions === 'string' && transformOptions.includes('ts-jest')) {
|
|
84
|
-
return
|
|
20
|
+
return {
|
|
21
|
+
...previousValue,
|
|
22
|
+
[key]: globalsTsJestConfig ? ['ts-jest', globalsTsJestConfig] : 'ts-jest',
|
|
23
|
+
};
|
|
85
24
|
}
|
|
86
|
-
return
|
|
25
|
+
return {
|
|
26
|
+
...previousValue,
|
|
27
|
+
[key]: transformOptions,
|
|
28
|
+
};
|
|
87
29
|
}, {});
|
|
88
30
|
}
|
|
89
31
|
return {};
|
|
90
32
|
};
|
|
91
|
-
|
|
33
|
+
const migratePresetToTransformConfig = (transformConfig, preset, globalsTsJestConfig) => {
|
|
92
34
|
if (preset) {
|
|
93
|
-
|
|
35
|
+
const transformConfigFromPreset = preset.name === "ts-jest/presets/js-with-ts" /* JestPresetNames.jsWithTs */
|
|
94
36
|
? (0, create_jest_preset_1.createJsWithTsPreset)(globalsTsJestConfig)
|
|
95
37
|
: preset.name === "ts-jest/presets/js-with-babel" /* JestPresetNames.jsWIthBabel */
|
|
96
38
|
? (0, create_jest_preset_1.createJsWithBabelPreset)(globalsTsJestConfig)
|
|
97
39
|
: (0, create_jest_preset_1.createDefaultPreset)(globalsTsJestConfig);
|
|
98
|
-
return
|
|
40
|
+
return {
|
|
41
|
+
...transformConfig,
|
|
42
|
+
...transformConfigFromPreset.transform,
|
|
43
|
+
};
|
|
99
44
|
}
|
|
100
45
|
return transformConfig;
|
|
101
46
|
};
|
|
102
47
|
/**
|
|
103
48
|
* @internal
|
|
104
49
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
actualConfig =
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
50
|
+
const run = async (args /* , logger: Logger*/) => {
|
|
51
|
+
const nullLogger = (0, bs_logger_1.createLogger)({ targets: [] });
|
|
52
|
+
const file = args._[0]?.toString();
|
|
53
|
+
const filePath = (0, path_1.resolve)(process.cwd(), file);
|
|
54
|
+
if (!(0, fs_1.existsSync)(filePath)) {
|
|
55
|
+
throw new Error(`Configuration file ${file} does not exists.`);
|
|
56
|
+
}
|
|
57
|
+
const name = (0, path_1.basename)(file);
|
|
58
|
+
const isPackage = name === 'package.json';
|
|
59
|
+
if (!/\.(js|json)$/.test(name)) {
|
|
60
|
+
throw new TypeError(`Configuration file ${file} must be a JavaScript or JSON file.`);
|
|
61
|
+
}
|
|
62
|
+
let actualConfig = require(filePath);
|
|
63
|
+
if (isPackage) {
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
+
actualConfig = actualConfig.jest;
|
|
66
|
+
}
|
|
67
|
+
if (!actualConfig)
|
|
68
|
+
actualConfig = {};
|
|
69
|
+
// migrate
|
|
70
|
+
// first we backport our options
|
|
71
|
+
const migratedConfig = (0, backports_1.backportJestConfig)(nullLogger, actualConfig);
|
|
72
|
+
let preset;
|
|
73
|
+
if (migratedConfig.preset) {
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
+
preset = presets_1.allPresets[migratedConfig.preset] ?? presets_1.allPresets["ts-jest/presets/default" /* JestPresetNames.default */];
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
if (args.js) {
|
|
79
|
+
preset = args.js === 'babel' ? presets_1.allPresets["ts-jest/presets/js-with-babel" /* JestPresetNames.jsWIthBabel */] : presets_1.allPresets["ts-jest/presets/js-with-ts" /* JestPresetNames.jsWithTs */];
|
|
131
80
|
}
|
|
132
81
|
else {
|
|
133
|
-
|
|
134
|
-
preset = args.js === 'babel' ? presets_1.allPresets["ts-jest/presets/js-with-babel" /* JestPresetNames.jsWIthBabel */] : presets_1.allPresets["ts-jest/presets/js-with-ts" /* JestPresetNames.jsWithTs */];
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
preset = presets_1.allPresets["ts-jest/presets/default" /* JestPresetNames.default */];
|
|
138
|
-
}
|
|
82
|
+
preset = presets_1.allPresets["ts-jest/presets/default" /* JestPresetNames.default */];
|
|
139
83
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
84
|
+
}
|
|
85
|
+
// check the extensions
|
|
86
|
+
if (migratedConfig.moduleFileExtensions?.length && preset) {
|
|
87
|
+
const presetValue = dedupSort(preset.value.moduleFileExtensions ?? []).join('::');
|
|
88
|
+
const migratedValue = dedupSort(migratedConfig.moduleFileExtensions).join('::');
|
|
89
|
+
if (presetValue === migratedValue) {
|
|
90
|
+
delete migratedConfig.moduleFileExtensions;
|
|
147
91
|
}
|
|
148
|
-
|
|
149
|
-
|
|
92
|
+
}
|
|
93
|
+
// there is a testRegex, remove our testMatch
|
|
94
|
+
if (typeof migratedConfig.testRegex === 'string' || migratedConfig.testRegex?.length) {
|
|
95
|
+
delete migratedConfig.testMatch;
|
|
96
|
+
}
|
|
97
|
+
// check the testMatch
|
|
98
|
+
else if (migratedConfig.testMatch?.length && preset) {
|
|
99
|
+
const presetValue = dedupSort(preset.value.testMatch ?? []).join('::');
|
|
100
|
+
const migratedValue = dedupSort(migratedConfig.testMatch).join('::');
|
|
101
|
+
if (presetValue === migratedValue) {
|
|
150
102
|
delete migratedConfig.testMatch;
|
|
151
103
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
process.stderr.write("\nMigrated Jest configuration:\n");
|
|
175
|
-
process.stdout.write("".concat(prefix).concat(stringify(migratedConfig, undefined, ' '), "\n"));
|
|
176
|
-
return [2 /*return*/];
|
|
177
|
-
});
|
|
178
|
-
}); };
|
|
104
|
+
}
|
|
105
|
+
const globalsTsJestConfig = migratedConfig.globals?.['ts-jest'];
|
|
106
|
+
migratedConfig.transform = migrateGlobalConfigToTransformConfig(migratedConfig.transform, globalsTsJestConfig);
|
|
107
|
+
migratedConfig.transform = migratePresetToTransformConfig(migratedConfig.transform, preset, globalsTsJestConfig);
|
|
108
|
+
cleanupConfig(actualConfig);
|
|
109
|
+
cleanupConfig(migratedConfig);
|
|
110
|
+
const before = (0, fast_json_stable_stringify_1.default)(actualConfig);
|
|
111
|
+
const after = (0, fast_json_stable_stringify_1.default)(migratedConfig);
|
|
112
|
+
if (after === before) {
|
|
113
|
+
process.stderr.write(`
|
|
114
|
+
No migration needed for given Jest configuration
|
|
115
|
+
`);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const stringify = file.endsWith('.json') ? JSON.stringify : json5_1.stringify;
|
|
119
|
+
const prefix = file.endsWith('.json') ? '"jest": ' : 'module.exports = ';
|
|
120
|
+
// output new config
|
|
121
|
+
process.stderr.write(`
|
|
122
|
+
Migrated Jest configuration:
|
|
123
|
+
`);
|
|
124
|
+
process.stdout.write(`${prefix}${stringify(migratedConfig, undefined, ' ')}\n`);
|
|
125
|
+
};
|
|
179
126
|
exports.run = run;
|
|
180
127
|
function cleanupConfig(config) {
|
|
181
128
|
if (config.globals) {
|
|
@@ -202,16 +149,26 @@ function cleanupConfig(config) {
|
|
|
202
149
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
203
150
|
function dedupSort(arr) {
|
|
204
151
|
return arr
|
|
205
|
-
.filter(
|
|
206
|
-
.sort(
|
|
152
|
+
.filter((s, i, a) => a.findIndex((e) => s.toString() === e.toString()) === i)
|
|
153
|
+
.sort((a, b) => (a.toString() > b.toString() ? 1 : a.toString() < b.toString() ? -1 : 0));
|
|
207
154
|
}
|
|
208
155
|
/**
|
|
209
156
|
* @internal
|
|
210
157
|
*/
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
158
|
+
const help = async () => {
|
|
159
|
+
process.stdout.write(`
|
|
160
|
+
Usage:
|
|
161
|
+
ts-jest config:migrate [options] <config-file>
|
|
162
|
+
|
|
163
|
+
Arguments:
|
|
164
|
+
<config-file> Can be a js or json Jest config file. If it is a
|
|
165
|
+
package.json file, the configuration will be read from
|
|
166
|
+
the "jest" property.
|
|
167
|
+
|
|
168
|
+
Options:
|
|
169
|
+
--js ts|babel Process .js files with ts-jest if 'ts' or with
|
|
170
|
+
babel-jest if 'babel'
|
|
171
|
+
--no-jest-preset Disable the use of Jest presets
|
|
172
|
+
`);
|
|
173
|
+
};
|
|
217
174
|
exports.help = help;
|