Any ideas how to get worker constructors into Vitest?
Trying to create an object using a constructor from the worker. However the worker types only specify interfaces, leading to the error in the screenshot.
I've tried to use the
vitest/packages/web-worker
package from https://github.com/vitest-dev/vitest/tree/main/packages/web-worker
And set up vitest.config.js
like so:
However I'm not able to use any of the types from worker runtime it seems.
I'm trying to mock an EmailMessage
replicating the actual thing here: https://github.com/webbertakken/email-worker/blob/526b020af8bcefcd9ecfeb81eb264e8d826b633a/test/helpers/createEmailMessage.ts#L20
Any ideas?2 Replies
Hey! 👋 You may want to look at https://miniflare.dev/testing/vitest instead of
@vitest/web-worker
for specifically unit testing Cloudflare Workers.Excellent. That was exactly what I was looking for. Thank you!