title: babel-jest doesn't handle ES6 within modules
body: <p>I am trying to set up Jest on a React based project which uses ES6 modules. However I seem to be having issues with ES6 modules, I am using babel-jest and believe I have this set up properly (Jest detects it automatically).</p>
  
  <p>Jest doesn't seem to have a problem using ES6 imports however as soon as it hits on an import statement within one of the imported modules it chokes. It's as if it is only transpiling the initial test script and not any of the imported modules. I have tried various configurations and tried searching Google with no luck. Running tests without any imports works fine.</p>
  
  <p>Here is the error:</p>
  
  <pre><code>({"Object.&lt;anonymous&gt;":function(module,exports,require,__dirname,__filename,global,jest){import Predications from './predications';
                                                                                           ^^^^^^
  SyntaxError: Unexpected token import
  </code></pre>
  
  <p>Here are the relevant bits of config:</p>
  
  <p>jest.conf.json</p>
  
  <pre><code>{
    "testRegex": "\/test\/spec\/.*\\.js$",
  }
  </code></pre>
  
  <p>.babelrc</p>
  
  <pre><code>{
    "presets": ["es2015", "stage-0", "react"]
  }
  </code></pre>
  
  <p>Test script</p>
  
  <pre><code>import React from 'react';
  import { mount, shallow } from 'enzyme';
  import Slider from 'react-slick';
  import Carousel from '../../client/components/carousel/carousel.js'; // test chokes on when I include this module
  
  describe('carousel component', () =&gt; {
    it('is a test test case', () =&gt; {
      expect(1 + 2).toEqual(3);
    });
  });
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>As suggested, I have tried running the test without jest.conf.js, however the testRegex is needed in order for Jest to find my tests, I tried moving tests to the default test directory and they still fail.</p>
  
  <p>I would like to clarify that tests themselves are running fine, the issue seems to be where one of my imported modules uses ES6, in my example above, if I don't import my carousel component the test runs fine, as soon as I import that the test chokes on the import statement within that file. It seems as though the imported modules are not getting transpiled.</p>
  
  <p><strong>Update #2</strong></p>
  
  <p>After some investigation it appears the issue is that babel is not transpiling ES6 within node_modules. I have created an example repo to demonstrate this here: <a href="https://github.com/jamiedust/babel-jest-example" rel="noreferrer">https://github.com/jamiedust/babel-jest-example</a></p>
  
  <p>I understand that third party modules should be handling their own transpiling, however we have a number of modules which are hosted on our own npm registry and are re-used between projects, in these cases Webpack handles transpiling, for the Jest tests we need these node_modules to be transpiled by Babel, or a way of leveraging our webpack set up to do this for us.</p>
  
  <p><strong>Solution</strong></p>
  
  <p>Add the following config in package.json (or Jest config file).</p>
  
  <pre><code>"jest": {
    "transformIgnorePatterns": [
      "/node_modules/(?!test-component).+\\.js$"
    ]
  }
  </code></pre>