-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React spring is breaking my tests #555
Comments
node doesn't understand esm, it cannot use imports. it would make sense to use the cjs for testing. i think this is how you'd do it with any other library, or how do you normally get around es-modules? |
This should work to make sure Jest picks up the CJS bundles instead of ESM
The way it normally works is probably that Jest uses the |
@drcmda I'm not quite sure about it, but for all other library it works fine. |
@jacobrask Hey, thanks for the solution. I'm quite confused why jest works fine with other libs such as material-ui, but doesn't with react-spring |
Are you sure they serve evergreen-esm, though? Many popular libs (like React) just ship plain commonjs in a flatbundle, which can't be tree-shaken afterwards. If there's something i can do to make the Node story better i would of course gladly do it, i just don't know where the problem is. edit: Is this the material-ui you're referring to? https://unpkg.com/[email protected]/index.js To me that looks like cjs. |
Wait, so |
@drcmda Nah nevermind, I actually got it now. Is there anything you can do to make cjs the default file instead of esm? Or at least a doc on this would help a lot of people |
require, as i understand it, is commonjs, node's current module standard. es modules define imports via
What @jacobrask said explains the weird behaviour. Due to hooks we are forced to distribute essentially two libs. Previously Jest would just pick up the main field in package.json. @jacobrask do you think there is any solution to this? Otherwise i will make a new section about this in the docs. |
@drcmda Shall I just make a pull request for this bit? |
Yes, that would be great! 😄 |
@drcmda Ok I will have a quick look at the repo and make a PR now |
@WebDeg-Brian I just have the same issue, and I noticed the thread is resent. But with this issue is closed without any PR related? did you fix it? |
Never mind the @jacobrask previews solution it works, I just I had to remove my cache loaders to make it works. |
@drcmda I haven't followed how far the .mjs proposal got, but this problem was basically what .mjs was supposed to solve - .mjs files are ES modules, .js files are commonjs. Maybe long term the components should be re-implemented as wrappers around the hooks and re-integrated into the main bundle? The different targets will still have the same problem though. |
I thought about wrapping hooks with Spring/Transition/Trail classes, too, it would be the best way forward. next major this could perhaps be one of the bigger changes. |
React Spring distributes ES6 by default, which breaks jest tests unless it's imported explicitly using the cjs extension. see pmndrs/react-spring#555
There was a misalignment between the animated props and the non animated ones that causes the area line to use the fill instead of stroke wrongly rendering the line on the chart. We also aligned the animated and not animated props for line and bars. React Spring also distributes ES6 by default, which breaks jest tests unless it's imported explicitly using the cjs extension. see pmndrs/react-spring#555 fix #140
In my case, the order of entries matters. Sub entry should be defined before the parent
|
In case you use Create-React-App (which doesn't support |
@kwrush You really saved my day! Thx! |
There was a misalignment between the animated props and the non animated ones that causes the area line to use the fill instead of stroke wrongly rendering the line on the chart. We also aligned the animated and not animated props for line and bars. React Spring also distributes ES6 by default, which breaks jest tests unless it's imported explicitly using the cjs extension. see pmndrs/react-spring#555 fix opensearch-project#140
@kwrush this was working fine but now it is failing im getting this : |
I'm currently using Jest with enzyme to test my components. My animations work fine on the client, no problems are shown in the console. However, when I run my tests, Jest keeps saying the problem comes from react-spring. Here are the screenshots:
https://cdn.discordapp.com/attachments/103696749012467712/547192480832159765/unknown.png
https://cdn.discordapp.com/attachments/103696749012467712/547192562851643402/unknown.png
I also confirm that because when I remove all the animations my tests work fine. As soon as I import Spring from react-spring the tests started to break :(
I believe this is a strong, and would appreciate if you could fix it as soon as possible. Thank you!
Edit: The problem most likely comes from the renderprops module, since I don't get the problem using hook
Edit again: I've read the this issue on GitHub and tried the workaround but doesn't seem to work. I then also tried to import the cjs file and it works, but it kinda sucks to import a CJS file instead of an actual ESM
The text was updated successfully, but these errors were encountered: