Workers SDK Issue Reports

← Back to Dashboard

#7077 🐛 BUG: Can't mock env when authoring a WorkerEntrypoint

Recommendation:KEEP OPEN
Difficulty:medium
Reasoning:

Valid bug: createExecutionContext() returns incompatible type for WorkerEntrypoint constructor. No fix in PRs or changelog. 2 users confirmed issue over 15 months. Blocks testing RPC-based workers.

Suggested Action:

Keep open for engineering work - needs ExecutionContext fix or envMock utility

Analysis Report

Issue Review: cloudflare/workers-sdk#7077

Summary

Cannot mock env when instantiating a WorkerEntrypoint class in vitest-pool-workers tests.

Findings

  • Created: 2024-10-23
  • Updated: 2025-10-30
  • Version: 0.4.14 -> 0.12.6 (current)
  • Component: vitest-pool-workers
  • Labels: bug, vitest
  • Comments: 2 (community users confirming the issue)

Key Evidence

  • Issue remains open with no merged PRs referencing it
  • Not mentioned in vitest-pool-workers changelog
  • Two additional users (2025-01-13 and 2025-04-01) confirmed they face the same issue
  • The core problem: createExecutionContext() returns something that can't be passed to WorkerEntrypoint constructor
  • Error: TypeError: Failed to construct 'WorkerEntrypoint': constructor parameter 1 is not of type 'ExecutionContext'
  • This is a valid bug affecting users who want to test RPC-based workers using WorkerEntrypoint class pattern
  • The reporter also requests an envMock utility similar to fetchMock

Recommendation

Status: KEEP OPEN

Reasoning: This is a legitimate feature gap/bug in the vitest-pool-workers package. The WorkerEntrypoint pattern is a valid and promoted way to create Cloudflare Workers, especially for RPC functionality. The inability to mock env bindings when testing WorkerEntrypoint classes limits the testability of such workers. Community engagement (2 additional users confirming) shows this affects real-world use cases.

Action: Keep open as a valid enhancement/bug. This requires implementation work to either:

  1. Make createExecutionContext() return a proper ExecutionContext compatible with WorkerEntrypoint
  2. Provide an alternative testing approach for WorkerEntrypoint classes
  3. Add an envMock utility as suggested by the reporter

Suggested Comment

N/A - Issue should remain open for engineering work.

Notes & Feedback (0)

No notes yet.

Add Note