Skip to content

Instantly share code, notes, and snippets.

@loklaan
Last active November 15, 2019 06:31
Show Gist options
  • Save loklaan/3b4990f0f66a0103f34029829009e417 to your computer and use it in GitHub Desktop.
Save loklaan/3b4990f0f66a0103f34029829009e417 to your computer and use it in GitHub Desktop.
Rolling your own babel-jest
/*
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')
}
/*
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 ]
});
@loklaan
Copy link
Author

loklaan commented Mar 8, 2017

Updated to use transform, rather than deprecated scriptPreprocessor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment