Skip to content

Commit

Permalink
Add support for Babel 7 in babel-jest (#3271)
Browse files Browse the repository at this point in the history
* Add support for Babel 7 in babel-jest

* Fix Flow enforcing string literals on require()

* Update index.js
  • Loading branch information
niieani authored and cpojer committed Apr 11, 2017
1 parent 87f61ee commit 706ce99
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/babel-jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const jestPreset = require('babel-preset-jest');
const path = require('path');

const BABELRC_FILENAME = '.babelrc';
const BABELRC_JS_FILENAME = '.babelrc.js';
const THIS_FILE = fs.readFileSync(__filename);

const cache = Object.create(null);
Expand All @@ -39,6 +40,12 @@ const getBabelRC = (filename, {useCache}) => {
cache[directory] = fs.readFileSync(configFilePath, 'utf8');
break;
}
const configJsFilePath = path.join(directory, BABELRC_JS_FILENAME);
if (fs.existsSync(configJsFilePath)) {
// $FlowFixMe
cache[directory] = JSON.stringify(require(configJsFilePath));
break;
}
}
paths.forEach(directoryPath => {
cache[directoryPath] = cache[directory];
Expand Down Expand Up @@ -91,7 +98,7 @@ const createTransformer = (options: any) => {
babel = require('babel-core');
}

if (!babel.util.canCompile(filename)) {
if (babel.util && !babel.util.canCompile(filename)) {
return src;
}

Expand Down

0 comments on commit 706ce99

Please sign in to comment.