create-react-app-esbuild icon indicating copy to clipboard operation
create-react-app-esbuild copied to clipboard

Async Jest tests run into issue

Open jordan-cote opened this issue 3 years ago • 3 comments

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 avatar Mar 12 '21 20:03 jordan-cote

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 👍

jordan-cote avatar Mar 14 '21 21:03 jordan-cote

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

pradel avatar Apr 28 '21 15:04 pradel

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

jordan-cote avatar Apr 30 '21 08:04 jordan-cote