cloudflare / workers-sdk

⛅️ Home to Wrangler, the CLI for Cloudflare Workers®
https://developers.cloudflare.com/workers/
Apache License 2.0
2.42k stars 594 forks source link

🐛 BUG: Vitest cannot call fetch() on WorkerEntrypoint #6020

Closed hhoughgg closed 3 weeks ago

hhoughgg commented 3 weeks ago

EDIT: Just realized this is the same issue as: https://github.com/cloudflare/workers-sdk/issues/5726

Which Cloudflare product(s) does this pertain to?

Workers Vitest Integration

What version(s) of the tool(s) are you using?

1.5.0 [vitest], 0.3.0 [vitest-workers-pool]

What version of Node are you using?

v20.13.1

What operating system and version are you using?

Sonoma 14.5

Describe the Bug

Observed behavior

Error: Handler does not export a fetch() function. When using SELF with vitest and WorkerEntrypoint

Expected behavior

Vitest should work with WorkerEntrypoint not just export default fetch.

Steps to reproduce

Does not work:

export default class extends WorkerEntrypoint<Env> {
  async fetch(request: Request) { return app.fetch(request, this.env, this.ctx)}
}

Works:

export default {
  async fetch(request: Request): Promise<Response> { return app.fetch(request) }
}

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

hhoughgg commented 3 weeks ago

I believe this was fixed here https://github.com/cloudflare/workers-sdk/pull/5916 on vitest 0.4.4