@depup/ts-jest 29.4.6-depup.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/.lintstagedrc +4 -0
- package/.ts-jest-digest +1 -0
- package/CHANGELOG.md +2025 -0
- package/CONTRIBUTING.md +121 -0
- package/LICENSE.md +21 -0
- package/README.md +33 -0
- package/TROUBLESHOOTING.md +3 -0
- package/changes.json +18 -0
- package/cli.js +3 -0
- package/dist/cli/config/init.d.ts +6 -0
- package/dist/cli/config/init.js +139 -0
- package/dist/cli/config/migrate.d.ts +1 -0
- package/dist/cli/config/migrate.js +177 -0
- package/dist/cli/help.d.ts +1 -0
- package/dist/cli/help.js +25 -0
- package/dist/cli/helpers/presets.d.ts +1 -0
- package/dist/cli/helpers/presets.js +41 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +63 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +18 -0
- package/dist/config/paths-to-module-name-mapper.d.ts +9 -0
- package/dist/config/paths-to-module-name-mapper.js +52 -0
- package/dist/config/types.d.ts +2 -0
- package/dist/config/types.js +2 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.js +22 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +31 -0
- package/dist/legacy/compiler/compiler-utils.d.ts +8 -0
- package/dist/legacy/compiler/compiler-utils.js +32 -0
- package/dist/legacy/compiler/index.d.ts +2 -0
- package/dist/legacy/compiler/index.js +18 -0
- package/dist/legacy/compiler/ts-compiler.d.ts +27 -0
- package/dist/legacy/compiler/ts-compiler.js +434 -0
- package/dist/legacy/compiler/ts-jest-compiler.d.ts +8 -0
- package/dist/legacy/compiler/ts-jest-compiler.js +18 -0
- package/dist/legacy/config/config-set.d.ts +36 -0
- package/dist/legacy/config/config-set.js +622 -0
- package/dist/legacy/index.d.ts +6 -0
- package/dist/legacy/index.js +6 -0
- package/dist/legacy/ts-jest-transformer.d.ts +28 -0
- package/dist/legacy/ts-jest-transformer.js +293 -0
- package/dist/presets/all-presets.d.ts +15 -0
- package/dist/presets/all-presets.js +42 -0
- package/dist/presets/create-jest-preset.d.ts +18 -0
- package/dist/presets/create-jest-preset.js +180 -0
- package/dist/raw-compiler-options.d.ts +556 -0
- package/dist/raw-compiler-options.js +2 -0
- package/dist/transformers/hoist-jest.d.ts +9 -0
- package/dist/transformers/hoist-jest.js +111 -0
- package/dist/transpilers/typescript/transpile-module.d.ts +8 -0
- package/dist/transpilers/typescript/transpile-module.js +174 -0
- package/dist/types.d.ts +282 -0
- package/dist/types.js +3 -0
- package/dist/utils/backports.d.ts +1 -0
- package/dist/utils/backports.js +118 -0
- package/dist/utils/diagnostics.d.ts +5 -0
- package/dist/utils/diagnostics.js +8 -0
- package/dist/utils/get-package-version.d.ts +1 -0
- package/dist/utils/get-package-version.js +14 -0
- package/dist/utils/importer.d.ts +1 -0
- package/dist/utils/importer.js +146 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/json.d.ts +2 -0
- package/dist/utils/json.js +16 -0
- package/dist/utils/jsonable-value.d.ts +10 -0
- package/dist/utils/jsonable-value.js +29 -0
- package/dist/utils/logger.d.ts +1 -0
- package/dist/utils/logger.js +20 -0
- package/dist/utils/memoize.d.ts +1 -0
- package/dist/utils/memoize.js +60 -0
- package/dist/utils/messages.d.ts +1 -0
- package/dist/utils/messages.js +21 -0
- package/dist/utils/normalize-slashes.d.ts +1 -0
- package/dist/utils/normalize-slashes.js +9 -0
- package/dist/utils/sha1.d.ts +1 -0
- package/dist/utils/sha1.js +38 -0
- package/dist/utils/ts-error.d.ts +1 -0
- package/dist/utils/ts-error.js +37 -0
- package/jest-preset.js +1 -0
- package/legacy.js +1 -0
- package/package.json +167 -0
- package/preprocessor.js +7 -0
- package/presets/default/jest-preset.js +1 -0
- package/presets/default-esm/jest-preset.js +1 -0
- package/presets/default-esm-legacy/jest-preset.js +1 -0
- package/presets/default-legacy/jest-preset.js +1 -0
- package/presets/index.d.ts +3 -0
- package/presets/index.js +3 -0
- package/presets/js-with-babel/jest-preset.js +1 -0
- package/presets/js-with-babel-esm/jest-preset.js +1 -0
- package/presets/js-with-babel-esm-legacy/jest-preset.js +1 -0
- package/presets/js-with-babel-legacy/jest-preset.js +1 -0
- package/presets/js-with-ts/jest-preset.js +1 -0
- package/presets/js-with-ts-esm/jest-preset.js +1 -0
- package/presets/js-with-ts-esm-legacy/jest-preset.js +1 -0
- package/presets/js-with-ts-legacy/jest-preset.js +1 -0
- package/tsconfig.base.json +20 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TsJestTransformer = exports.CACHE_KEY_EL_SEPARATOR = void 0;
|
|
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) => {
|
|
19
|
+
return path_1.default.normalize(filePath).split(path_1.default.sep).includes('node_modules');
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
exports.CACHE_KEY_EL_SEPARATOR = '\x00';
|
|
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) {
|
|
39
|
+
this.transformerOptions = transformerOptions;
|
|
40
|
+
this._logger = utils_1.rootLogger.child({ namespace: 'ts-jest-transformer' });
|
|
41
|
+
/**
|
|
42
|
+
* For some unknown reasons, `this` is undefined in `getCacheKey` and `process`
|
|
43
|
+
* when running Jest in ESM mode
|
|
44
|
+
*/
|
|
45
|
+
this.getCacheKey = this.getCacheKey.bind(this);
|
|
46
|
+
this.getCacheKeyAsync = this.getCacheKeyAsync.bind(this);
|
|
47
|
+
this.process = this.process.bind(this);
|
|
48
|
+
this.processAsync = this.processAsync.bind(this);
|
|
49
|
+
this._logger.debug('created new transformer');
|
|
50
|
+
process.env.TS_JEST = '1';
|
|
51
|
+
}
|
|
52
|
+
_configsFor(transformOptions) {
|
|
53
|
+
const { config, cacheFS } = transformOptions;
|
|
54
|
+
const ccs = TsJestTransformer._cachedConfigSets.find((cs) => cs.jestConfig.value === config);
|
|
55
|
+
let configSet;
|
|
56
|
+
if (ccs) {
|
|
57
|
+
this._transformCfgStr = ccs.transformerCfgStr;
|
|
58
|
+
this._compiler = ccs.compiler;
|
|
59
|
+
this._depGraphs = ccs.depGraphs;
|
|
60
|
+
this._watchMode = ccs.watchMode;
|
|
61
|
+
configSet = ccs.configSet;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// try to look-it up by stringified version
|
|
65
|
+
const serializedJestCfg = (0, utils_1.stringify)(config);
|
|
66
|
+
const serializedCcs = TsJestTransformer._cachedConfigSets.find((cs) => cs.jestConfig.serialized === serializedJestCfg);
|
|
67
|
+
if (serializedCcs) {
|
|
68
|
+
// update the object so that we can find it later
|
|
69
|
+
// this happens because jest first calls getCacheKey with stringified version of
|
|
70
|
+
// the config, and then it calls the transformer with the proper object
|
|
71
|
+
serializedCcs.jestConfig.value = config;
|
|
72
|
+
this._transformCfgStr = serializedCcs.transformerCfgStr;
|
|
73
|
+
this._compiler = serializedCcs.compiler;
|
|
74
|
+
this._depGraphs = serializedCcs.depGraphs;
|
|
75
|
+
this._watchMode = serializedCcs.watchMode;
|
|
76
|
+
configSet = serializedCcs.configSet;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// create the new record in the index
|
|
80
|
+
this._logger.info('no matching config-set found, creating a new one');
|
|
81
|
+
if (config.globals?.['ts-jest']) {
|
|
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 */);
|
|
83
|
+
}
|
|
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;
|
|
98
|
+
configSet = this._createConfigSet(migratedConfig);
|
|
99
|
+
const jest = { ...migratedConfig };
|
|
100
|
+
// we need to remove some stuff from jest config
|
|
101
|
+
// this which does not depend on config
|
|
102
|
+
jest.cacheDirectory = undefined; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
103
|
+
this._transformCfgStr = `${new utils_1.JsonableValue(jest).serialized}${configSet.cacheSuffix}`;
|
|
104
|
+
this._createCompiler(configSet, cacheFS);
|
|
105
|
+
this._watchMode = process.argv.includes('--watch');
|
|
106
|
+
TsJestTransformer._cachedConfigSets.push({
|
|
107
|
+
jestConfig: new utils_1.JsonableValue(config),
|
|
108
|
+
configSet,
|
|
109
|
+
transformerCfgStr: this._transformCfgStr,
|
|
110
|
+
compiler: this._compiler,
|
|
111
|
+
depGraphs: this._depGraphs,
|
|
112
|
+
watchMode: this._watchMode,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return configSet;
|
|
117
|
+
}
|
|
118
|
+
_createConfigSet(config) {
|
|
119
|
+
return new config_set_1.ConfigSet(config);
|
|
120
|
+
}
|
|
121
|
+
_createCompiler(configSet, cacheFS) {
|
|
122
|
+
this._compiler = new compiler_1.TsJestCompiler(configSet, cacheFS);
|
|
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 = {
|
|
130
|
+
code: this.processWithTs(sourceText, sourcePath, transformOptions).code,
|
|
131
|
+
};
|
|
132
|
+
if (babelJest) {
|
|
133
|
+
this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
|
|
134
|
+
// do not instrument here, jest will do it anyway afterwards
|
|
135
|
+
result = babelJest.process(result.code, sourcePath, {
|
|
136
|
+
...transformOptions,
|
|
137
|
+
instrument: false,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
|
|
141
|
+
return result;
|
|
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,
|
|
162
|
+
});
|
|
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);
|
|
175
|
+
if (shouldStringifyContent) {
|
|
176
|
+
// handles here what we should simply stringify
|
|
177
|
+
result = {
|
|
178
|
+
code: `module.exports=${(0, utils_1.stringify)(sourceText)}`,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
else if (isDefinitionFile) {
|
|
182
|
+
// do not try to compile declaration files
|
|
183
|
+
result = {
|
|
184
|
+
code: '',
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
else if (isJsFile || isTsFile) {
|
|
188
|
+
if (isJsFile && isNodeModule(sourcePath)) {
|
|
189
|
+
const transpiledResult = typescript_1.default.transpileModule(sourceText, {
|
|
190
|
+
compilerOptions: {
|
|
191
|
+
...configs.parsedTsConfig.options,
|
|
192
|
+
module: transformOptions.supportsStaticESM && transformOptions.transformerConfig.useESM
|
|
193
|
+
? typescript_1.default.ModuleKind.ESNext
|
|
194
|
+
: typescript_1.default.ModuleKind.CommonJS,
|
|
195
|
+
},
|
|
196
|
+
fileName: sourcePath,
|
|
197
|
+
});
|
|
198
|
+
result = {
|
|
199
|
+
code: (0, compiler_utils_1.updateOutput)(transpiledResult.outputText, sourcePath, transpiledResult.sourceMapText),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
// transpile TS code (source maps are included)
|
|
204
|
+
result = this._compiler.getCompiledOutput(sourceText, sourcePath, {
|
|
205
|
+
depGraphs: this._depGraphs,
|
|
206
|
+
supportsStaticESM: transformOptions.supportsStaticESM,
|
|
207
|
+
watchMode: this._watchMode,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
// we should not get called for files with other extension than js[x], ts[x] and d.ts,
|
|
213
|
+
// TypeScript will bail if we try to compile, and if it was to call babel, users can
|
|
214
|
+
// define the transform value with `babel-jest` for this extension instead
|
|
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 */;
|
|
216
|
+
this._logger.warn({ fileName: sourcePath }, (0, messages_1.interpolate)(message, { path: sourcePath }));
|
|
217
|
+
result = {
|
|
218
|
+
code: sourceText,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
runTsJestHook(sourcePath, sourceText, transformOptions, compiledOutput) {
|
|
224
|
+
let hooksFile = process.env.TS_JEST_HOOKS;
|
|
225
|
+
let hooks;
|
|
226
|
+
/* istanbul ignore next (cover by e2e) */
|
|
227
|
+
if (hooksFile) {
|
|
228
|
+
hooksFile = path_1.default.resolve(this._configsFor(transformOptions).cwd, hooksFile);
|
|
229
|
+
hooks = importer_1.importer.tryTheseOr(hooksFile, {});
|
|
230
|
+
}
|
|
231
|
+
// This is not supposed to be a public API but we keep it as some people use it
|
|
232
|
+
if (hooks?.afterProcess) {
|
|
233
|
+
this._logger.debug({ fileName: sourcePath, hookName: 'afterProcess' }, 'calling afterProcess hook');
|
|
234
|
+
const newResult = hooks.afterProcess([sourceText, sourcePath, transformOptions.config, transformOptions], compiledOutput);
|
|
235
|
+
if (newResult) {
|
|
236
|
+
return newResult;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return compiledOutput;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Jest uses this to cache the compiled version of a file
|
|
243
|
+
*
|
|
244
|
+
* @see https://github.com/facebook/jest/blob/v23.5.0/packages/jest-runtime/src/script_transformer.js#L61-L90
|
|
245
|
+
*
|
|
246
|
+
* @public
|
|
247
|
+
*/
|
|
248
|
+
getCacheKey(fileContent, filePath, transformOptions) {
|
|
249
|
+
const configs = this._configsFor(transformOptions);
|
|
250
|
+
this._logger.debug({ fileName: filePath, transformOptions }, 'computing cache key for', filePath);
|
|
251
|
+
// we do not instrument, ensure it is false all the time
|
|
252
|
+
const { supportsStaticESM, instrument = false } = transformOptions;
|
|
253
|
+
const constructingCacheKeyElements = [
|
|
254
|
+
this._transformCfgStr,
|
|
255
|
+
exports.CACHE_KEY_EL_SEPARATOR,
|
|
256
|
+
configs.rootDir,
|
|
257
|
+
exports.CACHE_KEY_EL_SEPARATOR,
|
|
258
|
+
`instrument:${instrument ? 'on' : 'off'}`,
|
|
259
|
+
exports.CACHE_KEY_EL_SEPARATOR,
|
|
260
|
+
`supportsStaticESM:${supportsStaticESM ? 'on' : 'off'}`,
|
|
261
|
+
exports.CACHE_KEY_EL_SEPARATOR,
|
|
262
|
+
fileContent,
|
|
263
|
+
exports.CACHE_KEY_EL_SEPARATOR,
|
|
264
|
+
filePath,
|
|
265
|
+
];
|
|
266
|
+
if (!configs.isolatedModules && configs.tsCacheDir) {
|
|
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);
|
|
270
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
271
|
+
resolvedModuleNames = this._depGraphs
|
|
272
|
+
.get(filePath)
|
|
273
|
+
.resolvedModuleNames.filter((moduleName) => (0, fs_1.existsSync)(moduleName));
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
this._logger.debug({ fileName: filePath, transformOptions }, 'getting resolved modules from TypeScript API for', filePath);
|
|
277
|
+
resolvedModuleNames = this._compiler.getResolvedModules(fileContent, filePath, transformOptions.cacheFS);
|
|
278
|
+
this._depGraphs.set(filePath, {
|
|
279
|
+
fileContent,
|
|
280
|
+
resolvedModuleNames,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
resolvedModuleNames.forEach((moduleName) => {
|
|
284
|
+
constructingCacheKeyElements.push(exports.CACHE_KEY_EL_SEPARATOR, moduleName, exports.CACHE_KEY_EL_SEPARATOR, (0, fs_1.statSync)(moduleName).mtimeMs.toString());
|
|
285
|
+
});
|
|
286
|
+
}
|
|
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
|
+
}
|
|
293
|
+
exports.TsJestTransformer = TsJestTransformer;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const allPresets: {
|
|
2
|
+
readonly defaults: import("..").DefaultPreset;
|
|
3
|
+
readonly defaultsLegacy: import("..").DefaultLegacyPreset;
|
|
4
|
+
readonly defaultsESM: import("..").DefaultEsmPreset;
|
|
5
|
+
readonly defaultsESMLegacy: import("..").DefaultEsmLegacyPreset;
|
|
6
|
+
readonly jsWithTs: import("..").JsWithTsPreset;
|
|
7
|
+
readonly jsWithTsLegacy: import("..").JsWithTsLegacyPreset;
|
|
8
|
+
readonly jsWithTsESM: import("..").JsWithTsEsmPreset;
|
|
9
|
+
readonly jsWithTsESMLegacy: import("..").JsWithTsEsmLegacyPreset;
|
|
10
|
+
readonly jsWithBabel: import("..").JsWithBabelPreset;
|
|
11
|
+
readonly jsWithBabelLegacy: import("..").JsWithBabelLegacyPreset;
|
|
12
|
+
readonly jsWithBabelESM: import("..").JsWithBabelEsmPreset;
|
|
13
|
+
readonly jsWithBabelESMLegacy: import("..").JsWithBabelEsmLegacyPreset;
|
|
14
|
+
};
|
|
15
|
+
export default allPresets;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const create_jest_preset_1 = require("./create-jest-preset");
|
|
4
|
+
const allPresets = {
|
|
5
|
+
get defaults() {
|
|
6
|
+
return (0, create_jest_preset_1.createDefaultPreset)();
|
|
7
|
+
},
|
|
8
|
+
get defaultsLegacy() {
|
|
9
|
+
return (0, create_jest_preset_1.createDefaultLegacyPreset)();
|
|
10
|
+
},
|
|
11
|
+
get defaultsESM() {
|
|
12
|
+
return (0, create_jest_preset_1.createDefaultEsmPreset)();
|
|
13
|
+
},
|
|
14
|
+
get defaultsESMLegacy() {
|
|
15
|
+
return (0, create_jest_preset_1.createDefaultEsmLegacyPreset)();
|
|
16
|
+
},
|
|
17
|
+
get jsWithTs() {
|
|
18
|
+
return (0, create_jest_preset_1.createJsWithTsPreset)();
|
|
19
|
+
},
|
|
20
|
+
get jsWithTsLegacy() {
|
|
21
|
+
return (0, create_jest_preset_1.createJsWithTsLegacyPreset)();
|
|
22
|
+
},
|
|
23
|
+
get jsWithTsESM() {
|
|
24
|
+
return (0, create_jest_preset_1.createJsWithTsEsmPreset)();
|
|
25
|
+
},
|
|
26
|
+
get jsWithTsESMLegacy() {
|
|
27
|
+
return (0, create_jest_preset_1.createJsWithTsEsmLegacyPreset)();
|
|
28
|
+
},
|
|
29
|
+
get jsWithBabel() {
|
|
30
|
+
return (0, create_jest_preset_1.createJsWithBabelPreset)();
|
|
31
|
+
},
|
|
32
|
+
get jsWithBabelLegacy() {
|
|
33
|
+
return (0, create_jest_preset_1.createJsWithBabelLegacyPreset)();
|
|
34
|
+
},
|
|
35
|
+
get jsWithBabelESM() {
|
|
36
|
+
return (0, create_jest_preset_1.createJsWithBabelEsmPreset)();
|
|
37
|
+
},
|
|
38
|
+
get jsWithBabelESMLegacy() {
|
|
39
|
+
return (0, create_jest_preset_1.createJsWithBabelEsmLegacyPreset)();
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
exports.default = allPresets;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Config } from '@jest/types';
|
|
2
|
+
import { DefaultEsmLegacyPreset, DefaultEsmPreset, DefaultEsmTransformOptions, DefaultLegacyPreset, DefaultPreset, DefaultTransformOptions, JsWithBabelEsmLegacyPreset, JsWithBabelEsmPreset, JsWithBabelEsmTransformOptions, JsWithBabelLegacyPreset, JsWithBabelPreset, JsWithBabelTransformerOptions, JsWithTsEsmLegacyPreset, JsWithTsEsmPreset, JsWithTsEsmTransformOptions, JsWithTsLegacyPreset, JsWithTsPreset, JsWithTsTransformOptions, TsJestPresets } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated use other functions below instead
|
|
5
|
+
*/
|
|
6
|
+
export declare function createJestPreset(legacy?: boolean, allowJs?: boolean, extraOptions?: Config.InitialOptions): TsJestPresets;
|
|
7
|
+
export declare function createDefaultPreset(tsJestTransformOptions?: DefaultTransformOptions): DefaultPreset;
|
|
8
|
+
export declare function createDefaultLegacyPreset(tsJestTransformOptions?: DefaultTransformOptions): DefaultLegacyPreset;
|
|
9
|
+
export declare function createJsWithTsPreset(tsJestTransformOptions?: JsWithTsTransformOptions): JsWithTsPreset;
|
|
10
|
+
export declare function createJsWithTsLegacyPreset(tsJestTransformOptions?: JsWithTsTransformOptions): JsWithTsLegacyPreset;
|
|
11
|
+
export declare function createJsWithBabelPreset(tsJestTransformOptions?: JsWithBabelTransformerOptions): JsWithBabelPreset;
|
|
12
|
+
export declare function createJsWithBabelLegacyPreset(tsJestTransformOptions?: JsWithBabelTransformerOptions): JsWithBabelLegacyPreset;
|
|
13
|
+
export declare function createDefaultEsmPreset(tsJestTransformOptions?: DefaultEsmTransformOptions): DefaultEsmPreset;
|
|
14
|
+
export declare function createDefaultEsmLegacyPreset(tsJestTransformOptions?: DefaultEsmTransformOptions): DefaultEsmLegacyPreset;
|
|
15
|
+
export declare function createJsWithTsEsmPreset(tsJestTransformOptions?: JsWithTsEsmTransformOptions): JsWithTsEsmPreset;
|
|
16
|
+
export declare function createJsWithTsEsmLegacyPreset(tsJestTransformOptions?: JsWithTsEsmTransformOptions): JsWithTsEsmLegacyPreset;
|
|
17
|
+
export declare function createJsWithBabelEsmPreset(tsJestTransformOptions?: JsWithBabelEsmTransformOptions): JsWithBabelEsmPreset;
|
|
18
|
+
export declare function createJsWithBabelEsmLegacyPreset(tsJestTransformOptions?: JsWithBabelEsmTransformOptions): JsWithBabelEsmLegacyPreset;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createJestPreset = createJestPreset;
|
|
4
|
+
exports.createDefaultPreset = createDefaultPreset;
|
|
5
|
+
exports.createDefaultLegacyPreset = createDefaultLegacyPreset;
|
|
6
|
+
exports.createJsWithTsPreset = createJsWithTsPreset;
|
|
7
|
+
exports.createJsWithTsLegacyPreset = createJsWithTsLegacyPreset;
|
|
8
|
+
exports.createJsWithBabelPreset = createJsWithBabelPreset;
|
|
9
|
+
exports.createJsWithBabelLegacyPreset = createJsWithBabelLegacyPreset;
|
|
10
|
+
exports.createDefaultEsmPreset = createDefaultEsmPreset;
|
|
11
|
+
exports.createDefaultEsmLegacyPreset = createDefaultEsmLegacyPreset;
|
|
12
|
+
exports.createJsWithTsEsmPreset = createJsWithTsEsmPreset;
|
|
13
|
+
exports.createJsWithTsEsmLegacyPreset = createJsWithTsEsmLegacyPreset;
|
|
14
|
+
exports.createJsWithBabelEsmPreset = createJsWithBabelEsmPreset;
|
|
15
|
+
exports.createJsWithBabelEsmLegacyPreset = createJsWithBabelEsmLegacyPreset;
|
|
16
|
+
const constants_1 = require("../constants");
|
|
17
|
+
const utils_1 = require("../utils");
|
|
18
|
+
const logger = utils_1.rootLogger.child({ namespace: 'jest-preset' });
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated use other functions below instead
|
|
21
|
+
*/
|
|
22
|
+
function createJestPreset(legacy = false, allowJs = false, extraOptions = {}) {
|
|
23
|
+
logger.debug({ allowJs }, 'creating jest presets', allowJs ? 'handling' : 'not handling', 'JavaScript files');
|
|
24
|
+
const { extensionsToTreatAsEsm, moduleFileExtensions, testMatch } = extraOptions;
|
|
25
|
+
const supportESM = extensionsToTreatAsEsm?.length;
|
|
26
|
+
const tsJestTransformOptions = supportESM ? { useESM: true } : {};
|
|
27
|
+
return {
|
|
28
|
+
...(extensionsToTreatAsEsm ? { extensionsToTreatAsEsm } : undefined),
|
|
29
|
+
...(moduleFileExtensions ? { moduleFileExtensions } : undefined),
|
|
30
|
+
...(testMatch ? { testMatch } : undefined),
|
|
31
|
+
transform: {
|
|
32
|
+
...extraOptions.transform,
|
|
33
|
+
[allowJs ? (supportESM ? '^.+\\.m?[tj]sx?$' : '^.+\\.[tj]sx?$') : '^.+\\.tsx?$']: legacy
|
|
34
|
+
? ['ts-jest/legacy', tsJestTransformOptions]
|
|
35
|
+
: ['ts-jest', tsJestTransformOptions],
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function createDefaultPreset(tsJestTransformOptions = {}) {
|
|
40
|
+
logger.debug('creating default CJS Jest preset');
|
|
41
|
+
return {
|
|
42
|
+
transform: {
|
|
43
|
+
[constants_1.TS_TRANSFORM_PATTERN]: ['ts-jest', tsJestTransformOptions],
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function createDefaultLegacyPreset(tsJestTransformOptions = {}) {
|
|
48
|
+
logger.debug('creating default CJS Jest preset');
|
|
49
|
+
return {
|
|
50
|
+
transform: {
|
|
51
|
+
[constants_1.TS_TRANSFORM_PATTERN]: ['ts-jest/legacy', tsJestTransformOptions],
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function createJsWithTsPreset(tsJestTransformOptions = {}) {
|
|
56
|
+
logger.debug('creating Js with Ts CJS Jest preset');
|
|
57
|
+
return {
|
|
58
|
+
transform: {
|
|
59
|
+
[constants_1.TS_JS_TRANSFORM_PATTERN]: ['ts-jest', tsJestTransformOptions],
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function createJsWithTsLegacyPreset(tsJestTransformOptions = {}) {
|
|
64
|
+
logger.debug('creating Js with Ts CJS Jest preset');
|
|
65
|
+
return {
|
|
66
|
+
transform: {
|
|
67
|
+
[constants_1.TS_JS_TRANSFORM_PATTERN]: ['ts-jest/legacy', tsJestTransformOptions],
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function createJsWithBabelPreset(tsJestTransformOptions = {}) {
|
|
72
|
+
logger.debug('creating JS with Babel CJS Jest preset');
|
|
73
|
+
return {
|
|
74
|
+
transform: {
|
|
75
|
+
[constants_1.JS_TRANSFORM_PATTERN]: 'babel-jest',
|
|
76
|
+
[constants_1.TS_TRANSFORM_PATTERN]: ['ts-jest', tsJestTransformOptions],
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function createJsWithBabelLegacyPreset(tsJestTransformOptions = {}) {
|
|
81
|
+
logger.debug('creating JS with Babel CJS Jest preset');
|
|
82
|
+
return {
|
|
83
|
+
transform: {
|
|
84
|
+
[constants_1.JS_TRANSFORM_PATTERN]: 'babel-jest',
|
|
85
|
+
[constants_1.TS_TRANSFORM_PATTERN]: ['ts-jest/legacy', tsJestTransformOptions],
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function createDefaultEsmPreset(tsJestTransformOptions = {}) {
|
|
90
|
+
logger.debug('creating default ESM Jest preset');
|
|
91
|
+
return {
|
|
92
|
+
extensionsToTreatAsEsm: [...constants_1.TS_EXT_TO_TREAT_AS_ESM],
|
|
93
|
+
transform: {
|
|
94
|
+
[constants_1.ESM_TS_TRANSFORM_PATTERN]: [
|
|
95
|
+
'ts-jest',
|
|
96
|
+
{
|
|
97
|
+
...tsJestTransformOptions,
|
|
98
|
+
useESM: true,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function createDefaultEsmLegacyPreset(tsJestTransformOptions = {}) {
|
|
105
|
+
logger.debug('creating default ESM Jest preset');
|
|
106
|
+
return {
|
|
107
|
+
extensionsToTreatAsEsm: [...constants_1.TS_EXT_TO_TREAT_AS_ESM],
|
|
108
|
+
transform: {
|
|
109
|
+
[constants_1.ESM_TS_TRANSFORM_PATTERN]: [
|
|
110
|
+
'ts-jest/legacy',
|
|
111
|
+
{
|
|
112
|
+
...tsJestTransformOptions,
|
|
113
|
+
useESM: true,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function createJsWithTsEsmPreset(tsJestTransformOptions = {}) {
|
|
120
|
+
logger.debug('creating Js with Ts ESM Jest preset');
|
|
121
|
+
return {
|
|
122
|
+
extensionsToTreatAsEsm: [...constants_1.JS_EXT_TO_TREAT_AS_ESM, ...constants_1.TS_EXT_TO_TREAT_AS_ESM],
|
|
123
|
+
transform: {
|
|
124
|
+
[constants_1.ESM_TS_JS_TRANSFORM_PATTERN]: [
|
|
125
|
+
'ts-jest',
|
|
126
|
+
{
|
|
127
|
+
...tsJestTransformOptions,
|
|
128
|
+
useESM: true,
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function createJsWithTsEsmLegacyPreset(tsJestTransformOptions = {}) {
|
|
135
|
+
logger.debug('creating Js with Ts ESM Jest preset');
|
|
136
|
+
return {
|
|
137
|
+
extensionsToTreatAsEsm: [...constants_1.JS_EXT_TO_TREAT_AS_ESM, ...constants_1.TS_EXT_TO_TREAT_AS_ESM],
|
|
138
|
+
transform: {
|
|
139
|
+
[constants_1.ESM_TS_JS_TRANSFORM_PATTERN]: [
|
|
140
|
+
'ts-jest/legacy',
|
|
141
|
+
{
|
|
142
|
+
...tsJestTransformOptions,
|
|
143
|
+
useESM: true,
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function createJsWithBabelEsmPreset(tsJestTransformOptions = {}) {
|
|
150
|
+
logger.debug('creating JS with Babel ESM Jest preset');
|
|
151
|
+
return {
|
|
152
|
+
extensionsToTreatAsEsm: [...constants_1.JS_EXT_TO_TREAT_AS_ESM, ...constants_1.TS_EXT_TO_TREAT_AS_ESM],
|
|
153
|
+
transform: {
|
|
154
|
+
[constants_1.ESM_JS_TRANSFORM_PATTERN]: 'babel-jest',
|
|
155
|
+
[constants_1.ESM_TS_TRANSFORM_PATTERN]: [
|
|
156
|
+
'ts-jest',
|
|
157
|
+
{
|
|
158
|
+
...tsJestTransformOptions,
|
|
159
|
+
useESM: true,
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function createJsWithBabelEsmLegacyPreset(tsJestTransformOptions = {}) {
|
|
166
|
+
logger.debug('creating JS with Babel ESM Jest preset');
|
|
167
|
+
return {
|
|
168
|
+
extensionsToTreatAsEsm: [...constants_1.JS_EXT_TO_TREAT_AS_ESM, ...constants_1.TS_EXT_TO_TREAT_AS_ESM],
|
|
169
|
+
transform: {
|
|
170
|
+
[constants_1.ESM_JS_TRANSFORM_PATTERN]: 'babel-jest',
|
|
171
|
+
[constants_1.ESM_TS_TRANSFORM_PATTERN]: [
|
|
172
|
+
'ts-jest/legacy',
|
|
173
|
+
{
|
|
174
|
+
...tsJestTransformOptions,
|
|
175
|
+
useESM: true,
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|