-
-
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
@vitest/web-worker error when using jsDOM environment #7023
Comments
This is because The workaround I found is to set import workerpool from 'workerpool/src/worker';
const getSquare = (x: number) => {
return x * x;
};
workerpool.add({
getSquare,
}); |
Hello Hiroshi, thanks for the response, I tried out the changes you mentioned in my vs code env but it doesn't seem to work for me, it is now throwing a new error, I am attaching the same for your reference, it would be great if you can look into this and try replicating in a vs code environment. Also, you mentioned that the workerpool package is in cjs and that is not being transformed by Vitest. Builiding on that context do you think that getting an esm build of the workerpool package will fix the issue all-together, if it is at all possible to verify it once, I would really appreciate the help. |
I'm not sure what you mean. Downloading and locally running this #7023 (comment) is working for me. If you have a different error, can you provide a reproduction for that? |
Hello Hiroshi, I am not being able to create a new reproduction of the error, the screen snip I attached above is what I am facing in the current set up itself. Anyways, lets keep that aside, I wanted to check with you that if we get the esm module support from the workerpool library will it solve the issue without having to do these work arounds. Let me know what you think about this. |
Yes. If |
Describe the bug
I am trying to run test cases in my application which needs both web-workers and DOM for successfully running the test case. As we know jsDOM environment doesn't have the support for web-workers so I figured I would use the @vitest/web-workers for adding the support for the same.
Now, in theory I don't see any problem with this but when I am trying to run the test suites, I am getting a dynamic error like this:
Here as you can see, the error is originating from Object.worker.send in workerpool->worker.js and is looking for postMessage().
Now, logically it should go ahead an hit the postMessage() in the vitest/web-workers scope, but somehow we can see that it goes to the jsDOM's scope of window.postMessage().
If the scope is dedicated globally in the context of web-workers, it might solve the issue.
Reproduction
Here is the link to the minimal reproduction repo on gitHub: repository
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: