swissquote / crafty

The task runner that binds them all
https://swissquote.github.io/crafty/
Apache License 2.0
30 stars 12 forks source link

"Error: act(...) is not supported in production builds of React" with jest.config.mjs generated by crafty v1.24.0 #2281

Closed denuko closed 6 months ago

denuko commented 6 months ago

Hello! After upgrading to crafty v1.24.0 and generating files with crafty ide, the following issue is happening specifically with jest.config.mjs:

After generating and using the jest.config.mjs in IntelliJ integrated test run, the following error occurs

Error: act(...) is not supported in production builds of React.

    at Object.<anonymous>.exports.unstable_act (/home/dkasidia/workspace/securities-retail-paid-prices-plugin/server-war/src/main/frontend/node_modules/react/cjs/react.production.min.js:23:393)

I reproduced that with crafty v1.24.0 and the newly generated jest.config.mjs. The test run was working fine with previous jest.config.js (generated by older crafty version).

I tried to add NODE_ENV=test in the configuration so that it's appended to the jest command, but it was not effective. MicrosoftTeams-image (27)

I did some console.log in jest.config.mjs to check NODE_ENV. Initially it's test, then changes to production after initialize() MicrosoftTeams-image (28)

Could you please look into that? Thanks!

onigoetz commented 6 months ago

Hi, thanks for the report

Crafty needs to set the environment variable for builds, and indeed, tests have different needs than builds.

I hardcoded

// Crafty configures its own environment for builds
// tests have different needs
process.env.NODE_ENV = "test";

right after initialize I will release this soon but you can add it to your file in the meantime

onigoetz commented 6 months ago

Released Released in https://github.com/swissquote/crafty/releases/tag/v1.25.0

denuko commented 6 months ago

I tried the new release and it works great! Thanks a lot!

onigoetz commented 6 months ago

awesome, happy it works :)