Skip to content
/ jest Public
forked from jestjs/jest

Commit

Permalink
Configure babel cwd to be project rootDir
Browse files Browse the repository at this point in the history
  • Loading branch information
bradfordlemley committed Feb 3, 2019
1 parent 0dc6df1 commit 51d008c
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 3 deletions.
1 change: 0 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

module.exports = {
babelrcRoots: ['examples/*'],
plugins: [
['@babel/plugin-transform-modules-commonjs', {allowTopLevelThis: true}],
'@babel/plugin-transform-strict-mode',
Expand Down
6 changes: 6 additions & 0 deletions e2e/global-setup/projects.jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ module.exports = {
globalSetup: '<rootDir>/setup.js',
rootDir: path.resolve(__dirname, './project-1'),
testMatch: ['<rootDir>/**/*.test.js'],
transform: {
'\\.js$': require.resolve('./transform'),
},
transformIgnorePatterns: ['/node_modules/', '/packages/'],
},
{
displayName: 'project-2',
globalSetup: '<rootDir>/setup.js',
rootDir: path.resolve(__dirname, './project-2'),
testMatch: ['<rootDir>/**/*.test.js'],
transform: {
'\\.js$': require.resolve('./transform'),
},
transformIgnorePatterns: ['/node_modules/', '/packages/'],
},
],
Expand Down
8 changes: 8 additions & 0 deletions e2e/global-setup/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
const babelJest = require('babel-jest');

/* use higher-level babel.config.js */

module.exports = babelJest.createTransformer({
rootMode: 'upward',
});
1 change: 1 addition & 0 deletions e2e/multi-project-babel/bar/.babelrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
module.exports = {
presets: ['@babel/preset-flow'],
};
1 change: 1 addition & 0 deletions e2e/multi-project-babel/bar/bar.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
module.exports = (text: string) => text;
1 change: 1 addition & 0 deletions e2e/multi-project-babel/foo/.babelrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
module.exports = {
presets: ['@babel/preset-flow'],
};
1 change: 1 addition & 0 deletions e2e/multi-project-babel/foo/foo.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
module.exports = (text: string) => text;
6 changes: 4 additions & 2 deletions packages/babel-jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const createTransformer = (options: any): Transformer => {
configString: string,
{config, instrument, rootDir}: {config: ProjectConfig} & CacheKeyOptions,
): string {
const babelOptions = loadBabelConfig(config.cwd, filename);
const babelOptions = loadBabelConfig(config.rootDir, filename);
const configPath = [
babelOptions.config || '',
babelOptions.babelrc || '',
Expand Down Expand Up @@ -85,7 +85,9 @@ const createTransformer = (options: any): Transformer => {
config: ProjectConfig,
transformOptions?: TransformOptions,
): string | TransformedSource {
const babelOptions = {...loadBabelConfig(config.cwd, filename).options};
const babelOptions = {
...loadBabelConfig(config.rootDir, filename).options,
};

if (transformOptions && transformOptions.instrument) {
babelOptions.auxiliaryCommentBefore = ' istanbul ignore next ';
Expand Down
16 changes: 16 additions & 0 deletions packages/jest-runtime/src/__tests__/test_root/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
plugins: [
['@babel/plugin-transform-modules-commonjs', {allowTopLevelThis: true}],
'@babel/plugin-transform-strict-mode',
],
presets: [
[
'@babel/preset-env',
{
shippedProposals: true,
targets: {node: 6},
},
],
'@babel/preset-flow',
],
};

0 comments on commit 51d008c

Please sign in to comment.