Last active
November 15, 2019 06:31
-
-
Save loklaan/3b4990f0f66a0103f34029829009e417 to your computer and use it in GitHub Desktop.
Rolling your own babel-jest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Up to you how to let Jest consume this config. I ended up stringifying the export and supplying it to a terminal command. | |
*/ | |
const path = require('path') | |
module.exports = { | |
transform: path.resolve(__dirname, './my-babel-jest.js') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
We can recreate what babel-jest does, but skip using .babelrc for any configuration of presets. | |
*/ | |
const babelJest = require('babel-jest'); | |
const es2015Preset = require('babel-preset-es2015'); | |
const reactPreset = require('babel-preset-react'); | |
const stage2Preset = require('babel-preset-stage-1'); | |
const createBabelJestTransformer = babelJest.createTransformer; // Undocumented feature AFAIK | |
module.exports = createBabelJestTransformer({ | |
presets: [ es2015Preset, stage2Preset, reactPreset ] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to use
transform
, rather than deprecatedscriptPreprocessor
.