Skip to content
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

Jest cannot find module '@react-three/cannon' #419

Open
dmnkb opened this issue Oct 27, 2022 · 4 comments
Open

Jest cannot find module '@react-three/cannon' #419

dmnkb opened this issue Oct 27, 2022 · 4 comments

Comments

@dmnkb
Copy link

dmnkb commented Oct 27, 2022

Although I'm not perfectly sure if this is more of a jest issue than a cannon one, I'd like to try to start here. When writing a unit test covering cases in a file that imports cannon, all tests fail due to not being able to find the module '@react-three/cannon'. What's strange about this, is, that this is the only module jest is having problems with. For instance, fiber and postprocessing are working perfectly fine. Maybe there is a way to resolve this issue. Please see the screenshot for reference and thank you in advance!

image

@tedsecretsource
Copy link

I'm having the same problem in both Jest and Vitest

image

@isaac-mason
Copy link
Member

isaac-mason commented Jan 11, 2023

This could be caused by @react-three/cannon only being distributed as esm / not having a main defined in package.json? I'll try and find some time to look into.

Jest by default only supports cjs. I'm not sure about vitest. If that's the case, @react-three/cannon and @pmndrs/cannon-worker-api could have a cjs distribution for better compatibility.

Jest does have experimental support for esm that could help: https://jestjs.io/docs/ecmascript-modules


It's worth noting though that @react-three/cannon runs cannon-es inside a web worker. Many test environments, e.g. regular jsdom, don't support web workers. There are some libraries out there that may solve this (e.g. https://github.com/developit/jsdom-worker#readme, from a quick search), but I don't have any experience with them and can't comment on whether they'll work for @react-three/cannon.

@tedsecretsource
Copy link

Thanks for the background, very helpful! Note that we're not hoping to test @react-three/cannon itself but rather test other components that have a @react-three/cannon dependency. Based on what you said, @isaac-mason, it sounds like maybe the solution is to mock @react-three/cannon?

@vinod-luminar
Copy link

Hi @tedsecretsource,
Are able to test components with @react-three/cannon . It will be helpful for me if you can share your approach.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants