pradel / create-react-app-esbuild

Use esbuild in your create-react-app for faster compilation, development and tests
MIT License
561 stars 34 forks source link

Async Jest tests run into issue #18

Open jordan-cote opened 3 years ago

jordan-cote commented 3 years ago

Hi, thanks for this project! I'm having an issue I can't seem to fix: all my Jest tests are passing BUT as soon as there is some async in there, it stops working, having a ReferenceError: regeneratorRuntime is not defined.

script in package.json: craco test

Here is my craco.config.js:

const CracoEsbuildPlugin = require('craco-esbuild');

module.exports = {
  plugins: [{
    plugin: CracoEsbuildPlugin, options: {
      esbuildLoaderOptions: {
        loader: 'jsx',
        target: 'es2015',
      }
    }
  }]
};

Error: image

And when I run it with a Jest configuration (with Babel) there is no issue. Any leads? Thanks!

edit: I dug into the issue and the case is well documented for Babel, needing to add polyfill and/or regenerator. But having low experience with esbuild, I don't know how the polyfills work, especially with create-react-app-esbuild as a wrapper.

jordan-cote commented 3 years ago

Update: running with the jest script after installing esbuild-jest(by putting esbuild-jest as transform in jest.config.js) seems to be working. Although this is a quick fix, this must mean there is indeed a bug with this craco. Ideally I would only have to run craco test and it should work.

Let me know if you need more info 👍

pradel commented 3 years ago

I would be curious to see this one, do you have a reproducible example so I can fix the issue?

jordan-cote commented 3 years ago

I would be curious to see this one, do you have a reproducible example so I can fix the issue?

Semester's over in a few days, then I should be able to give you a minimal project to reproduce this, sure