Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const path = require('path');
const chalk = require('chalk');
const { createTransformer: babelTransFormer } = require('babel-jest');
const { createTransformer: tsTransFormer } = require('ts-jest');
const getBabelCommonConfig = require('../lib/getBabelCommonConfig');
const tsJest = tsTransFormer({
tsConfig: path.join(__dirname, '../lib/tests/tsconfig.test.json'),
});
const babelJest = babelTransFormer(getBabelCommonConfig());
module.exports = {
process(src, filePath) {
const isTypeScript = filePath.endsWith('.ts') || filePath.endsWith('.tsx');
const isJavaScript = filePath.endsWith('.js') || filePath.endsWith('.jsx');
if (isTypeScript) {
src = tsJest.process(src, filePath, { moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'] });
} else if (isJavaScript) {
src = babelJest.process(src, filePath, { moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'] });
} else {
console.log(
chalk.red('File not match type:'),
const babelOptions = {
presets: ['env', 'react'],
plugins: ['require-context-hook'],
};
module.exports = require('ts-jest').createTransformer({ babelConfig: babelOptions });
const getTsJestConfig = function getTsJestConfig(config) {
const createTransformer = require('ts-jest').createTransformer
const tr = createTransformer()
const { typescript } = tr.configsFor(config)
return { compilerOptions: typescript.options }
}