How to use the ts-jest.createTransformer function in ts-jest

To help you get started, we’ve selected a few ts-jest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github react-component / rc-tools / scripts / jestPreprocessor.js View on Github external
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:'),
github firstlookmedia / react-scripts / scripts / utils / tsJestBabelTransform.js View on Github external
const babelOptions = {
  presets: ['env', 'react'],
  plugins: ['require-context-hook'],
};

module.exports = require('ts-jest').createTransformer({ babelConfig: babelOptions });
github vuejs / vue-jest / lib / utils.js View on Github external
const getTsJestConfig = function getTsJestConfig(config) {
  const createTransformer = require('ts-jest').createTransformer
  const tr = createTransformer()
  const { typescript } = tr.configsFor(config)
  return { compilerOptions: typescript.options }
}