How to use babel-jest

Comprehensive babel-jest code examples:

How to use babel-jest.process:

35
36
37
38
39
40
41
42
43
44
...babelJestTransformer,
// otherwise we have some cache issues
createTransformer: undefined,
process: (src, filename, config, transformOptions) => {
  if (shouldBabelize(filename)) {
    return babelJestTransformer.process(
      src,
      filename,
      config,
      transformOptions,

How to use babel-jest.default:

118
119
120
121
122
123
124
125
126
127
128
}


function processFile (fileContent, filePath, config) {
  let processedContent = String(erbTransformer(fileContent, filePath, config))
  if (config.babelConfig) {
    const babelTransformer = babelJest.default.createTransformer(config.babelConfig)
    const transformOptions = { config: process.cwd() }
    processedContent = babelTransformer.process(processedContent, filePath, transformOptions).code
  }
  return processedContent

How to use babel-jest.createTransformer:

25
26
27
28
29
30
31
32
33
34
35
  if (/^typescript$|tsx?$/.test(lang)) {
    return transformer || require('./transformers/typescript')(lang)
  } else if (/^coffee$|coffeescript$/.test(lang)) {
    return transformer || coffeescriptTransformer
  } else {
    return transformer || babelTransformer.createTransformer()
  }
}


function processScript(scriptPart, filePath, config) {