Skip to content

Jest test cases are failing #4

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

Open
kvpasupuleti opened this issue Feb 23, 2022 · 1 comment
Open

Jest test cases are failing #4

kvpasupuleti opened this issue Feb 23, 2022 · 1 comment
Labels
needs repro Indicates that this issue needs a reproduction before further steps can be taken support Indicates a request for help / clarification

Comments

@kvpasupuleti
Copy link

Hey @dominique-mueller , great work on the package. And it's really of good help for CRA.

  1. I am using CRA, TypeScript, Craco (To override webpack) and Jest.
  2. I could achieve working with Comlink seamlessly by your workaround.
  3. My class that will use this syntax worker-loader!../Somefolder/worker.ts will be exported initially with the app.

So, while running Jest tests, all my tests are getting failed because of this.

I am getting this error while running Jest tests

Cannot find module 'worker-loader!../Somefolder/worker.ts' from 'src/xxx/xxx/xxx/xxx/index.ts'

I have followed this solution. This has resolved this issue, but I got another issue like this

TypeError: ep.addEventListener is not a function

The above issue is reported in Comlink, but I think that's for another reason.

How could I get this working? Any ideas?

@dominique-mueller dominique-mueller added needs repro Indicates that this issue needs a reproduction before further steps can be taken support Indicates a request for help / clarification labels Feb 24, 2022
@dominique-mueller
Copy link
Owner

Regarding the broken imports: Jest within CRA does not rely on Webpack, thus the Webpack-specific loader syntax won't work. Now, when you use the exact webpack override config (README) you don't actually need the worker-loader! prefix as long as the worker file ends with .worker.ts|js. That at least might solve the issue of broken imports in Jest.

I am not sure when it comes to testing, however. This repo does explicitely not contain that aspect, and I haven't had the chance to explore it deeper. Because Jest runs on jsdom and not within an actual browser, Workers itself won't work and chances are that related APIs might not be available. Jest requires lots of mocking, and so might your Worker usage. You can see in the App.test.tsx file how I've simply mocked away the workers so that the tests at least pass (https://github.com/dominique-mueller/create-react-app-typescript-web-worker-setup/blob/main/src/App.test.tsx#L5). But that of course is not a real solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Indicates that this issue needs a reproduction before further steps can be taken support Indicates a request for help / clarification
Projects
None yet
Development

No branches or pull requests

2 participants