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:
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
setupFiles: ['@vitest/web-worker'],
},
})
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
setupFiles: ['@vitest/web-worker'],
},
})
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
MrBBot
MrBBot•16mo ago
Hey! 👋 You may want to look at https://miniflare.dev/testing/vitest instead of @vitest/web-worker for specifically unit testing Cloudflare Workers.
Webber
Webber•16mo ago
Excellent. That was exactly what I was looking for. Thank you!