-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Durable Objects] Add docs & changelog for eviction helpers in vitest #31686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
apeacock1991
wants to merge
1
commit into
production
Choose a base branch
from
apeacock/do-eviction
base: production
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+306
−1
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/content/changelog/workers/2026-06-25-durable-object-eviction-test-helpers.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| --- | ||
| title: Test Durable Object eviction with new cloudflare:test helpers | ||
| description: evictDurableObject and evictAllDurableObjects let you test how Durable Objects behave across evictions in your Vitest tests. | ||
| products: | ||
| - durable-objects | ||
| - workers | ||
| date: 2026-06-25 | ||
| --- | ||
|
|
||
| The `@cloudflare/vitest-pool-workers` package now includes `evictDurableObject` and `evictAllDurableObjects` test helpers, exported from `cloudflare:test`. | ||
|
|
||
| These helpers let you test how a Durable Object behaves across evictions, simulating the production lifecycle where an idle Durable Object can be evicted from memory. | ||
|
|
||
| For more context, refer to [Lifecycle of a Durable Object](/durable-objects/concepts/durable-object-lifecycle/). | ||
|
|
||
| ```ts | ||
| import { evictDurableObject, evictAllDurableObjects } from "cloudflare:test"; | ||
| import { env } from "cloudflare:workers"; | ||
|
|
||
| const id = env.COUNTER.idFromName("my-counter"); | ||
| const stub = env.COUNTER.get(id); | ||
|
|
||
| // Evict the Durable Object instance pointed to by a specific stub | ||
| await evictDurableObject(stub); | ||
|
|
||
| // Close WebSockets instead of hibernating them | ||
| await evictDurableObject(stub, { webSockets: "close" }); | ||
|
|
||
| // Evict all currently-running Durable Objects in evictable namespaces | ||
| await evictAllDurableObjects(); | ||
| ``` | ||
|
|
||
| These helpers are available in `@cloudflare/vitest-pool-workers@0.16.20` and later. | ||
|
|
||
| Learn more in the [Test APIs reference](/workers/testing/vitest-integration/test-apis/#durable-objects) and the [Testing Durable Objects guide](/durable-objects/examples/testing-with-durable-objects/#testing-eviction). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.