You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are three arguments to fetch: the incoming Request, the environment, and an ExecutionContext. The request is usually constructed per-test (and is a primary input to the code under test), the context is also created per-test using the createExecutionContext function exported from cloudflare:test. The lifecycle of these are clear and understandable.
The environment, on the other hand, is a global, imported from cloudflare:test and reused across all tests. While storage (like KV) is reset between tests, the env object is not, nor is it frozen. Mutations from one test affect all others that run afterwards.
I would like a function (tentatively and unimaginatively) named createEnvironment. This function can be used to create an environment for each test, where mutations have a clear lifecycle.
I've needed this several times myself. An official API here would make things much easier! Please also consider taking relevant Miniflare workerOptions here as parameters. It would be great to be able to override these on a per-test basis rather than being restricted to just a single global implementation in vitest.config.mts.
Describe the solution
There are three arguments to
fetch
: the incomingRequest
, the environment, and anExecutionContext
. The request is usually constructed per-test (and is a primary input to the code under test), the context is also created per-test using thecreateExecutionContext
function exported fromcloudflare:test
. The lifecycle of these are clear and understandable.The environment, on the other hand, is a global, imported from
cloudflare:test
and reused across all tests. While storage (like KV) is reset between tests, the env object is not, nor is it frozen. Mutations from one test affect all others that run afterwards.I would like a function (tentatively and unimaginatively) named
createEnvironment
. This function can be used to create an environment for each test, where mutations have a clear lifecycle.The text was updated successfully, but these errors were encountered: