Created
July 18, 2016 16:18
-
-
Save cakesmith/82b858ded3fd5203864d2c0bba9c1795 to your computer and use it in GitHub Desktop.
jest preprocessor script for babel 5.x.x
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
// jest-babel.js | |
// | |
// usage (package.json): | |
// "jest": { | |
// "scriptPreprocessor": "jest-babel.js" | |
// } | |
// | |
var path = require('path'); | |
var babel = require('babel-core'); | |
var hostPackagePath = path.resolve(require('process').cwd(), 'package.json'); | |
var hostPackageInfo = require(hostPackagePath); | |
var config = { | |
stage: 0, | |
retainLines: true, | |
auxiliaryCommentBefore: 'istanbul ignore next', | |
}; | |
var configOverrides = hostPackageInfo['jest-babel'] || {}; | |
Object.keys(configOverrides).forEach(function(key) { | |
config[key] = configOverrides[key]; | |
}); | |
function process(src, filename) { | |
if (!babel.canCompile(filename, config.extensions)) { | |
return src; | |
} | |
config.filename = filename; | |
return babel.transform(src, config).code; | |
} | |
module.exports = { | |
process: process | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment