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/dist/legacy/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
const ts_jest_transformer_1 = require("./ts-jest-transformer");
|
|
4
4
|
exports.default = {
|
|
5
|
-
createTransformer:
|
|
6
|
-
return new ts_jest_transformer_1.TsJestTransformer(tsJestConfig);
|
|
7
|
-
},
|
|
5
|
+
createTransformer: (tsJestConfig) => new ts_jest_transformer_1.TsJestTransformer(tsJestConfig),
|
|
8
6
|
};
|
|
@@ -1,104 +1,42 @@
|
|
|
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
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
66
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
-
if (ar || !(i in from)) {
|
|
68
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
-
ar[i] = from[i];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
|
-
};
|
|
74
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
75
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
76
4
|
};
|
|
77
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
78
6
|
exports.TsJestTransformer = exports.CACHE_KEY_EL_SEPARATOR = void 0;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
10
|
+
const constants_1 = require("../constants");
|
|
11
|
+
const utils_1 = require("../utils");
|
|
12
|
+
const importer_1 = require("../utils/importer");
|
|
13
|
+
const messages_1 = require("../utils/messages");
|
|
14
|
+
const sha1_1 = require("../utils/sha1");
|
|
15
|
+
const compiler_1 = require("./compiler");
|
|
16
|
+
const compiler_utils_1 = require("./compiler/compiler-utils");
|
|
17
|
+
const config_set_1 = require("./config/config-set");
|
|
18
|
+
const isNodeModule = (filePath) => {
|
|
91
19
|
return path_1.default.normalize(filePath).split(path_1.default.sep).includes('node_modules');
|
|
92
20
|
};
|
|
93
21
|
/**
|
|
94
22
|
* @internal
|
|
95
23
|
*/
|
|
96
24
|
exports.CACHE_KEY_EL_SEPARATOR = '\x00';
|
|
97
|
-
|
|
98
|
-
|
|
25
|
+
class TsJestTransformer {
|
|
26
|
+
transformerOptions;
|
|
27
|
+
/**
|
|
28
|
+
* cache ConfigSet between test runs
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
static _cachedConfigSets = [];
|
|
33
|
+
_logger;
|
|
34
|
+
_compiler;
|
|
35
|
+
_transformCfgStr;
|
|
36
|
+
_depGraphs = new Map();
|
|
37
|
+
_watchMode = false;
|
|
38
|
+
constructor(transformerOptions) {
|
|
99
39
|
this.transformerOptions = transformerOptions;
|
|
100
|
-
this._depGraphs = new Map();
|
|
101
|
-
this._watchMode = false;
|
|
102
40
|
this._logger = utils_1.rootLogger.child({ namespace: 'ts-jest-transformer' });
|
|
103
41
|
/**
|
|
104
42
|
* For some unknown reasons, `this` is undefined in `getCacheKey` and `process`
|
|
@@ -111,11 +49,10 @@ var TsJestTransformer = /** @class */ (function () {
|
|
|
111
49
|
this._logger.debug('created new transformer');
|
|
112
50
|
process.env.TS_JEST = '1';
|
|
113
51
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
var configSet;
|
|
52
|
+
_configsFor(transformOptions) {
|
|
53
|
+
const { config, cacheFS } = transformOptions;
|
|
54
|
+
const ccs = TsJestTransformer._cachedConfigSets.find((cs) => cs.jestConfig.value === config);
|
|
55
|
+
let configSet;
|
|
119
56
|
if (ccs) {
|
|
120
57
|
this._transformCfgStr = ccs.transformerCfgStr;
|
|
121
58
|
this._compiler = ccs.compiler;
|
|
@@ -125,8 +62,8 @@ var TsJestTransformer = /** @class */ (function () {
|
|
|
125
62
|
}
|
|
126
63
|
else {
|
|
127
64
|
// try to look-it up by stringified version
|
|
128
|
-
|
|
129
|
-
|
|
65
|
+
const serializedJestCfg = (0, utils_1.stringify)(config);
|
|
66
|
+
const serializedCcs = TsJestTransformer._cachedConfigSets.find((cs) => cs.jestConfig.serialized === serializedJestCfg);
|
|
130
67
|
if (serializedCcs) {
|
|
131
68
|
// update the object so that we can find it later
|
|
132
69
|
// this happens because jest first calls getCacheKey with stringified version of
|
|
@@ -141,24 +78,34 @@ var TsJestTransformer = /** @class */ (function () {
|
|
|
141
78
|
else {
|
|
142
79
|
// create the new record in the index
|
|
143
80
|
this._logger.info('no matching config-set found, creating a new one');
|
|
144
|
-
if (
|
|
81
|
+
if (config.globals?.['ts-jest']) {
|
|
145
82
|
this._logger.warn("Define `ts-jest` config under `globals` is deprecated. Please do\ntransform: {\n <transform_regex>: ['ts-jest', { /* ts-jest config goes here in Jest */ }],\n},\nSee more at https://kulshekhar.github.io/ts-jest/docs/getting-started/presets#advanced" /* Deprecations.GlobalsTsJestConfigOption */);
|
|
146
83
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
?
|
|
84
|
+
const jestGlobalsConfig = config.globals ?? {};
|
|
85
|
+
const tsJestGlobalsConfig = jestGlobalsConfig['ts-jest'] ?? {};
|
|
86
|
+
const migratedConfig = this.transformerOptions
|
|
87
|
+
? {
|
|
88
|
+
...config,
|
|
89
|
+
globals: {
|
|
90
|
+
...jestGlobalsConfig,
|
|
91
|
+
'ts-jest': {
|
|
92
|
+
...tsJestGlobalsConfig,
|
|
93
|
+
...this.transformerOptions,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
: config;
|
|
151
98
|
configSet = this._createConfigSet(migratedConfig);
|
|
152
|
-
|
|
99
|
+
const jest = { ...migratedConfig };
|
|
153
100
|
// we need to remove some stuff from jest config
|
|
154
101
|
// this which does not depend on config
|
|
155
|
-
|
|
156
|
-
this._transformCfgStr =
|
|
102
|
+
jest.cacheDirectory = undefined; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
103
|
+
this._transformCfgStr = `${new utils_1.JsonableValue(jest).serialized}${configSet.cacheSuffix}`;
|
|
157
104
|
this._createCompiler(configSet, cacheFS);
|
|
158
105
|
this._watchMode = process.argv.includes('--watch');
|
|
159
106
|
TsJestTransformer._cachedConfigSets.push({
|
|
160
107
|
jestConfig: new utils_1.JsonableValue(config),
|
|
161
|
-
configSet
|
|
108
|
+
configSet,
|
|
162
109
|
transformerCfgStr: this._transformCfgStr,
|
|
163
110
|
compiler: this._compiler,
|
|
164
111
|
depGraphs: this._depGraphs,
|
|
@@ -167,73 +114,68 @@ var TsJestTransformer = /** @class */ (function () {
|
|
|
167
114
|
}
|
|
168
115
|
}
|
|
169
116
|
return configSet;
|
|
170
|
-
}
|
|
171
|
-
|
|
117
|
+
}
|
|
118
|
+
_createConfigSet(config) {
|
|
172
119
|
return new config_set_1.ConfigSet(config);
|
|
173
|
-
}
|
|
174
|
-
|
|
120
|
+
}
|
|
121
|
+
_createCompiler(configSet, cacheFS) {
|
|
175
122
|
this._compiler = new compiler_1.TsJestCompiler(configSet, cacheFS);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
this._logger.debug({ fileName: sourcePath, transformOptions
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
123
|
+
}
|
|
124
|
+
process(sourceText, sourcePath, transformOptions) {
|
|
125
|
+
this._logger.debug({ fileName: sourcePath, transformOptions }, 'processing', sourcePath);
|
|
126
|
+
const configs = this._configsFor(transformOptions);
|
|
127
|
+
const shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
|
|
128
|
+
const babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
|
|
129
|
+
let result = {
|
|
183
130
|
code: this.processWithTs(sourceText, sourcePath, transformOptions).code,
|
|
184
131
|
};
|
|
185
132
|
if (babelJest) {
|
|
186
133
|
this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
|
|
187
134
|
// do not instrument here, jest will do it anyway afterwards
|
|
188
|
-
result = babelJest.process(result.code, sourcePath,
|
|
135
|
+
result = babelJest.process(result.code, sourcePath, {
|
|
136
|
+
...transformOptions,
|
|
137
|
+
instrument: false,
|
|
138
|
+
});
|
|
189
139
|
}
|
|
190
140
|
result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
|
|
191
141
|
return result;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
|
|
213
|
-
return [4 /*yield*/, babelJest.processAsync(result.code, sourcePath, __assign(__assign({}, transformOptions), { instrument: false }))];
|
|
214
|
-
case 1:
|
|
215
|
-
// do not instrument here, jest will do it anyway afterwards
|
|
216
|
-
result = _b.sent();
|
|
217
|
-
_b.label = 2;
|
|
218
|
-
case 2:
|
|
219
|
-
result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
|
|
220
|
-
return [2 /*return*/, result];
|
|
221
|
-
}
|
|
142
|
+
}
|
|
143
|
+
async processAsync(sourceText, sourcePath, transformOptions) {
|
|
144
|
+
this._logger.debug({ fileName: sourcePath, transformOptions }, 'processing', sourcePath);
|
|
145
|
+
const configs = this._configsFor(transformOptions);
|
|
146
|
+
const shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
|
|
147
|
+
const babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
|
|
148
|
+
let result;
|
|
149
|
+
const processWithTsResult = this.processWithTs(sourceText, sourcePath, transformOptions);
|
|
150
|
+
result = {
|
|
151
|
+
code: processWithTsResult.code,
|
|
152
|
+
};
|
|
153
|
+
if (processWithTsResult.diagnostics?.length) {
|
|
154
|
+
throw configs.createTsError(processWithTsResult.diagnostics);
|
|
155
|
+
}
|
|
156
|
+
if (babelJest) {
|
|
157
|
+
this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
|
|
158
|
+
// do not instrument here, jest will do it anyway afterwards
|
|
159
|
+
result = await babelJest.processAsync(result.code, sourcePath, {
|
|
160
|
+
...transformOptions,
|
|
161
|
+
instrument: false,
|
|
222
162
|
});
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
163
|
+
}
|
|
164
|
+
result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
processWithTs(sourceText, sourcePath, transformOptions) {
|
|
168
|
+
let result;
|
|
169
|
+
const configs = this._configsFor(transformOptions);
|
|
170
|
+
const shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
|
|
171
|
+
const babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
|
|
172
|
+
const isDefinitionFile = sourcePath.endsWith(constants_1.DECLARATION_TYPE_EXT);
|
|
173
|
+
const isJsFile = constants_1.JS_JSX_REGEX.test(sourcePath);
|
|
174
|
+
const isTsFile = !isDefinitionFile && constants_1.TS_TSX_REGEX.test(sourcePath);
|
|
233
175
|
if (shouldStringifyContent) {
|
|
234
176
|
// handles here what we should simply stringify
|
|
235
177
|
result = {
|
|
236
|
-
code:
|
|
178
|
+
code: `module.exports=${(0, utils_1.stringify)(sourceText)}`,
|
|
237
179
|
};
|
|
238
180
|
}
|
|
239
181
|
else if (isDefinitionFile) {
|
|
@@ -244,10 +186,13 @@ var TsJestTransformer = /** @class */ (function () {
|
|
|
244
186
|
}
|
|
245
187
|
else if (isJsFile || isTsFile) {
|
|
246
188
|
if (isJsFile && isNodeModule(sourcePath)) {
|
|
247
|
-
|
|
248
|
-
compilerOptions:
|
|
189
|
+
const transpiledResult = typescript_1.default.transpileModule(sourceText, {
|
|
190
|
+
compilerOptions: {
|
|
191
|
+
...configs.parsedTsConfig.options,
|
|
192
|
+
module: transformOptions.supportsStaticESM && transformOptions.transformerConfig.useESM
|
|
249
193
|
? typescript_1.default.ModuleKind.ESNext
|
|
250
|
-
: typescript_1.default.ModuleKind.CommonJS
|
|
194
|
+
: typescript_1.default.ModuleKind.CommonJS,
|
|
195
|
+
},
|
|
251
196
|
fileName: sourcePath,
|
|
252
197
|
});
|
|
253
198
|
result = {
|
|
@@ -267,32 +212,32 @@ var TsJestTransformer = /** @class */ (function () {
|
|
|
267
212
|
// we should not get called for files with other extension than js[x], ts[x] and d.ts,
|
|
268
213
|
// TypeScript will bail if we try to compile, and if it was to call babel, users can
|
|
269
214
|
// define the transform value with `babel-jest` for this extension instead
|
|
270
|
-
|
|
215
|
+
const message = babelJest ? "Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore. If you still want Babel to process it, add another entry to the `transform` option with value `babel-jest` which key matches this type of files." /* Errors.GotUnknownFileTypeWithBabel */ : "Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore." /* Errors.GotUnknownFileTypeWithoutBabel */;
|
|
271
216
|
this._logger.warn({ fileName: sourcePath }, (0, messages_1.interpolate)(message, { path: sourcePath }));
|
|
272
217
|
result = {
|
|
273
218
|
code: sourceText,
|
|
274
219
|
};
|
|
275
220
|
}
|
|
276
221
|
return result;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
222
|
+
}
|
|
223
|
+
runTsJestHook(sourcePath, sourceText, transformOptions, compiledOutput) {
|
|
224
|
+
let hooksFile = process.env.TS_JEST_HOOKS;
|
|
225
|
+
let hooks;
|
|
281
226
|
/* istanbul ignore next (cover by e2e) */
|
|
282
227
|
if (hooksFile) {
|
|
283
228
|
hooksFile = path_1.default.resolve(this._configsFor(transformOptions).cwd, hooksFile);
|
|
284
229
|
hooks = importer_1.importer.tryTheseOr(hooksFile, {});
|
|
285
230
|
}
|
|
286
231
|
// This is not supposed to be a public API but we keep it as some people use it
|
|
287
|
-
if (hooks
|
|
232
|
+
if (hooks?.afterProcess) {
|
|
288
233
|
this._logger.debug({ fileName: sourcePath, hookName: 'afterProcess' }, 'calling afterProcess hook');
|
|
289
|
-
|
|
234
|
+
const newResult = hooks.afterProcess([sourceText, sourcePath, transformOptions.config, transformOptions], compiledOutput);
|
|
290
235
|
if (newResult) {
|
|
291
236
|
return newResult;
|
|
292
237
|
}
|
|
293
238
|
}
|
|
294
239
|
return compiledOutput;
|
|
295
|
-
}
|
|
240
|
+
}
|
|
296
241
|
/**
|
|
297
242
|
* Jest uses this to cache the compiled version of a file
|
|
298
243
|
*
|
|
@@ -300,61 +245,49 @@ var TsJestTransformer = /** @class */ (function () {
|
|
|
300
245
|
*
|
|
301
246
|
* @public
|
|
302
247
|
*/
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
this._logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'computing cache key for', filePath);
|
|
248
|
+
getCacheKey(fileContent, filePath, transformOptions) {
|
|
249
|
+
const configs = this._configsFor(transformOptions);
|
|
250
|
+
this._logger.debug({ fileName: filePath, transformOptions }, 'computing cache key for', filePath);
|
|
307
251
|
// we do not instrument, ensure it is false all the time
|
|
308
|
-
|
|
309
|
-
|
|
252
|
+
const { supportsStaticESM, instrument = false } = transformOptions;
|
|
253
|
+
const constructingCacheKeyElements = [
|
|
310
254
|
this._transformCfgStr,
|
|
311
255
|
exports.CACHE_KEY_EL_SEPARATOR,
|
|
312
256
|
configs.rootDir,
|
|
313
257
|
exports.CACHE_KEY_EL_SEPARATOR,
|
|
314
|
-
|
|
258
|
+
`instrument:${instrument ? 'on' : 'off'}`,
|
|
315
259
|
exports.CACHE_KEY_EL_SEPARATOR,
|
|
316
|
-
|
|
260
|
+
`supportsStaticESM:${supportsStaticESM ? 'on' : 'off'}`,
|
|
317
261
|
exports.CACHE_KEY_EL_SEPARATOR,
|
|
318
262
|
fileContent,
|
|
319
263
|
exports.CACHE_KEY_EL_SEPARATOR,
|
|
320
264
|
filePath,
|
|
321
265
|
];
|
|
322
266
|
if (!configs.isolatedModules && configs.tsCacheDir) {
|
|
323
|
-
|
|
324
|
-
if (
|
|
325
|
-
this._logger.debug({ fileName: filePath, transformOptions
|
|
267
|
+
let resolvedModuleNames;
|
|
268
|
+
if (this._depGraphs.get(filePath)?.fileContent === fileContent) {
|
|
269
|
+
this._logger.debug({ fileName: filePath, transformOptions }, 'getting resolved modules from disk caching or memory caching for', filePath);
|
|
326
270
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
327
271
|
resolvedModuleNames = this._depGraphs
|
|
328
272
|
.get(filePath)
|
|
329
|
-
.resolvedModuleNames.filter(
|
|
273
|
+
.resolvedModuleNames.filter((moduleName) => (0, fs_1.existsSync)(moduleName));
|
|
330
274
|
}
|
|
331
275
|
else {
|
|
332
|
-
this._logger.debug({ fileName: filePath, transformOptions
|
|
276
|
+
this._logger.debug({ fileName: filePath, transformOptions }, 'getting resolved modules from TypeScript API for', filePath);
|
|
333
277
|
resolvedModuleNames = this._compiler.getResolvedModules(fileContent, filePath, transformOptions.cacheFS);
|
|
334
278
|
this._depGraphs.set(filePath, {
|
|
335
|
-
fileContent
|
|
336
|
-
resolvedModuleNames
|
|
279
|
+
fileContent,
|
|
280
|
+
resolvedModuleNames,
|
|
337
281
|
});
|
|
338
282
|
}
|
|
339
|
-
resolvedModuleNames.forEach(
|
|
283
|
+
resolvedModuleNames.forEach((moduleName) => {
|
|
340
284
|
constructingCacheKeyElements.push(exports.CACHE_KEY_EL_SEPARATOR, moduleName, exports.CACHE_KEY_EL_SEPARATOR, (0, fs_1.statSync)(moduleName).mtimeMs.toString());
|
|
341
285
|
});
|
|
342
286
|
}
|
|
343
|
-
return
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
return
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
};
|
|
352
|
-
/**
|
|
353
|
-
* cache ConfigSet between test runs
|
|
354
|
-
*
|
|
355
|
-
* @internal
|
|
356
|
-
*/
|
|
357
|
-
TsJestTransformer._cachedConfigSets = [];
|
|
358
|
-
return TsJestTransformer;
|
|
359
|
-
}());
|
|
287
|
+
return (0, sha1_1.sha1)(...constructingCacheKeyElements);
|
|
288
|
+
}
|
|
289
|
+
async getCacheKeyAsync(sourceText, sourcePath, transformOptions) {
|
|
290
|
+
return Promise.resolve(this.getCacheKey(sourceText, sourcePath, transformOptions));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
360
293
|
exports.TsJestTransformer = TsJestTransformer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const create_jest_preset_1 = require("./create-jest-preset");
|
|
4
|
+
const allPresets = {
|
|
5
5
|
get defaults() {
|
|
6
6
|
return (0, create_jest_preset_1.createDefaultPreset)();
|
|
7
7
|
},
|