@@ -19,17 +19,17 @@ Install Vitest and the Workers Vitest integration as dev dependencies:
1919<Tabs >
2020<TabItem label = " npm" >
2121``` sh
22- npm i -D vitest@~3.2 .0 @cloudflare/vitest-pool-workers
22+ npm i -D vitest@^4.1 .0 @cloudflare/vitest-pool-workers
2323```
2424</TabItem >
2525<TabItem label = " pnpm" >
2626``` sh
27- pnpm add -D vitest@~3.2 .0 @cloudflare/vitest-pool-workers
27+ pnpm add -D vitest@^4.1 .0 @cloudflare/vitest-pool-workers
2828```
2929</TabItem >
3030<TabItem label = " yarn" >
3131``` sh
32- yarn add -D vitest@~3.2 .0 @cloudflare/vitest-pool-workers
32+ yarn add -D vitest@^4.1 .0 @cloudflare/vitest-pool-workers
3333```
3434</TabItem >
3535</Tabs >
@@ -106,19 +106,18 @@ export default {
106106
107107## Configure Vitest
108108
109- Create a ` vitest.config.ts ` file that uses ` defineWorkersConfig ` :
109+ Create a ` vitest.config.ts ` file that uses the ` cloudflareTest() ` plugin :
110110
111111``` ts title="vitest.config.ts"
112- import { defineWorkersConfig } from " @cloudflare/vitest-pool-workers/config" ;
113-
114- export default defineWorkersConfig ({
115- test: {
116- poolOptions: {
117- workers: {
118- wrangler: { configPath: " ./wrangler.jsonc" },
119- },
120- },
121- },
112+ import { cloudflareTest } from " @cloudflare/vitest-pool-workers" ;
113+ import { defineConfig } from " vitest/config" ;
114+
115+ export default defineConfig ({
116+ plugins: [
117+ cloudflareTest ({
118+ wrangler: { configPath: " ./wrangler.jsonc" },
119+ }),
120+ ],
122121});
123122```
124123
@@ -160,7 +159,7 @@ Create a `test/tsconfig.json` to configure TypeScript for your tests:
160159Create an ` env.d.ts ` file to type the test environment:
161160
162161``` ts title="test/env.d.ts"
163- declare module " cloudflare:test " {
162+ declare module " cloudflare:workers " {
164163 interface ProvidedEnv extends Env {}
165164}
166165```
@@ -169,11 +168,11 @@ declare module "cloudflare:test" {
169168
170169### Unit tests with direct Durable Object access
171170
172- You can get a stub to a Durable Object directly from the ` env ` object provided by ` cloudflare:test ` :
171+ You can get a stub to a Durable Object directly from the ` env ` object provided by ` cloudflare:workers ` :
173172
174173<TypeScriptExample filename = " test/counter.test.ts" >
175174``` ts
176- import { env } from " cloudflare:test " ;
175+ import { env } from " cloudflare:workers " ;
177176import { describe , it , expect , beforeEach } from " vitest" ;
178177
179178describe (" Counter Durable Object" , () => {
@@ -237,18 +236,18 @@ describe("Counter Durable Object", () => {
237236```
238237</TypeScriptExample >
239238
240- ### Integration tests with SELF
239+ ### Integration tests with ` exports `
241240
242- Use the ` SELF ` fetcher to test your Worker's HTTP handler, which routes requests to Durable Objects:
241+ Use ` exports.default.fetch() ` to test your Worker's HTTP handler, which routes requests to Durable Objects:
243242
244243<TypeScriptExample filename = " test/integration.test.ts" >
245244``` ts
246- import { SELF } from " cloudflare:test " ;
245+ import { exports } from " cloudflare:workers " ;
247246import { describe , it , expect } from " vitest" ;
248247
249248describe (" Counter Worker integration" , () => {
250249 it (" should increment via HTTP POST" , async () => {
251- const response = await SELF .fetch (" http://example.com?id=http-test" , {
250+ const response = await exports . default .fetch (" http://example.com?id=http-test" , {
252251 method: " POST" ,
253252 });
254253
@@ -259,22 +258,22 @@ describe("Counter Worker integration", () => {
259258
260259 it (" should get count via HTTP GET" , async () => {
261260 // First increment the counter
262- await SELF .fetch (" http://example.com?id=get-test" , { method: " POST" });
263- await SELF .fetch (" http://example.com?id=get-test" , { method: " POST" });
261+ await exports . default .fetch (" http://example.com?id=get-test" , { method: " POST" });
262+ await exports . default .fetch (" http://example.com?id=get-test" , { method: " POST" });
264263
265264 // Then get the count
266- const response = await SELF .fetch (" http://example.com?id=get-test" );
265+ const response = await exports . default .fetch (" http://example.com?id=get-test" );
267266 const data = await response .json <{ count: number }>();
268267 expect (data .count ).toBe (2 );
269268 });
270269
271270 it (" should use different counters for different IDs" , async () => {
272- await SELF .fetch (" http://example.com?id=counter-a" , { method: " POST" });
273- await SELF .fetch (" http://example.com?id=counter-a" , { method: " POST" });
274- await SELF .fetch (" http://example.com?id=counter-b" , { method: " POST" });
271+ await exports . default .fetch (" http://example.com?id=counter-a" , { method: " POST" });
272+ await exports . default .fetch (" http://example.com?id=counter-a" , { method: " POST" });
273+ await exports . default .fetch (" http://example.com?id=counter-b" , { method: " POST" });
275274
276- const responseA = await SELF .fetch (" http://example.com?id=counter-a" );
277- const responseB = await SELF .fetch (" http://example.com?id=counter-b" );
275+ const responseA = await exports . default .fetch (" http://example.com?id=counter-a" );
276+ const responseB = await exports . default .fetch (" http://example.com?id=counter-b" );
278277
279278 const dataA = await responseA .json <{ count: number }>();
280279 const dataB = await responseB .json <{ count: number }>();
@@ -292,8 +291,8 @@ Use `runInDurableObject()` to access instance properties and storage directly. T
292291
293292<TypeScriptExample filename = " test/direct-access.test.ts" >
294293``` ts
294+ import { env } from " cloudflare:workers" ;
295295import {
296- env ,
297296 runInDurableObject ,
298297 listDurableObjectIds ,
299298} from " cloudflare:test" ;
@@ -349,7 +348,8 @@ Each test automatically gets isolated storage. Durable Objects created in one te
349348
350349<TypeScriptExample filename = " test/isolation.test.ts" >
351350``` ts
352- import { env , listDurableObjectIds } from " cloudflare:test" ;
351+ import { env } from " cloudflare:workers" ;
352+ import { listDurableObjectIds } from " cloudflare:test" ;
353353import { describe , it , expect } from " vitest" ;
354354
355355describe (" Test isolation" , () => {
@@ -382,7 +382,8 @@ SQLite-backed Durable Objects work seamlessly in tests. The SQL API is available
382382
383383<TypeScriptExample filename = " test/sqlite.test.ts" >
384384``` ts
385- import { env , runInDurableObject } from " cloudflare:test" ;
385+ import { env } from " cloudflare:workers" ;
386+ import { runInDurableObject } from " cloudflare:test" ;
386387import { describe , it , expect } from " vitest" ;
387388
388389describe (" SQLite in Durable Objects" , () => {
@@ -421,8 +422,8 @@ Use `runDurableObjectAlarm()` to immediately trigger a scheduled alarm without w
421422
422423<TypeScriptExample filename = " test/alarm.test.ts" >
423424``` ts
425+ import { env } from " cloudflare:workers" ;
424426import {
425- env ,
426427 runInDurableObject ,
427428 runDurableObjectAlarm ,
428429} from " cloudflare:test" ;
0 commit comments