strothj / react-app-rewire-typescript-babel-preset

Add TypeScript support to Create React App using @babel/preset-typescript
https://react-app-rewire-typescript-babel-preset.netlify.com
MIT License
52 stars 6 forks source link

Unable to configure Babel for Jest #18

Closed lee-reinhardt closed 6 years ago

lee-reinhardt commented 6 years ago

This rewire is working really great for me, thanks for maintaining it. The only issue I cannot solve is how to load additional Babel presets/plugins when running Jest.

When looking through the source, it looks like this is explicitly disabled -- in rewireBabelTransform.js:

const transformer = babelJest.createTransformer({
  presets: [path.resolve(__dirname, "rewirePreset")],
  babelrc: false
});

I see no way to override or change this behavior aside from patching the source in node_modules. I'm not the only person that's been tripped up by this: https://github.com/timarney/react-app-rewired/issues/250#issuecomment-393466807.

Would it be possible to change this option, or at least make it configurable in some way? Perhaps there's a good reason it's like this, but it was an unexpected limitation.

strothj commented 6 years ago

I believe I was referencing the original source from the react-scripts v2 package and that’s how it was there. I don’t know of any issues that would be caused by removing that.

I’m currently away from a computer. Do you know if react-app-rewired removes that normally?

lee-reinhardt commented 6 years ago

It is indeed disabled like this in CRA react-scripts@next source here. This makes sense since they want little-to-no custom config.

However, in react-app-rewired@next this setting is flipped to true, source here. (Changed in this commit a year ago, surfaced from this issue)

If you're OK with this change, I can submit a PR to change it plus some docs that describe how to ensure your Babel plugins are loaded for Babel Jest.

strothj commented 6 years ago

Yes, that would be awesome thank you.

If you don’t mind me asking, which Babel plugins were you looking to enable in jest?

lee-reinhardt commented 6 years ago

The one that forced me down this path of debugging was js-lingui. And then to a lesser degree, emotion. It's easier to live without emotion's plugin, since it's mostly about perf optimizations. The js-lingui plugins are technically optional, but required for the way I want to use it.

I'll submit a PR shortly.