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
Copy file name to clipboardExpand all lines: src/content/docs/workers/testing/vitest-integration/known-issues.mdx
+38-3Lines changed: 38 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,13 +26,48 @@ Dynamic `import()` statements do not work inside `export default { ... }` handle
26
26
27
27
Durable Object alarms are not reset between test runs and do not respect isolated storage. Ensure you delete or run all alarms with [`runDurableObjectAlarm()`](/workers/testing/vitest-integration/test-apis/#durable-objects) scheduled in each test before finishing the test.
28
28
29
-
### Durable Objects and `isolatedStorage`
29
+
### WebSockets
30
30
31
31
Using WebSockets with Durable Objects with the [`isolatedStorage`](/workers/testing/vitest-integration/isolation-and-concurrency) flag turned on is not supported. You must set `isolatedStorage: false` in your `vitest.config.ts` file.
32
32
33
-
### Returning non-primitive values from RPC methods
33
+
### Isolated storage
34
34
35
-
In order to return non-primitive values (objects or classes extending `RpcTarget`, for instance) from RPC methods, you must use the `using` keyword. Refer to [https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle#explicit-resource-management](https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle#explicit-resource-management) for more details. An [example test](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-pool-workers-examples/rpc/test/unit.test.ts#L155) is included in the `workers-sdk` repository.
35
+
When the `isolatedStorage` flag is enabled (the default), the test runner will undo any writes to the storage at the end of the test as detailed in the [isolation and concurrency documentation](/workers/testing/vitest-integration/isolation-and-concurrency/). However, Cloudflare recommends that you consider the following actions to avoid any common issues:
36
+
37
+
## Await all storage operations
38
+
39
+
Always `await` all `Promise`s that read or write to storage services.
40
+
41
+
```ts
42
+
// Example: Seed data
43
+
beforeAll(async () => {
44
+
awaitenv.KV.put('message', 'test message');
45
+
awaitenv.R2.put('file', 'hello-world');
46
+
});
47
+
```
48
+
49
+
## Explicitly signal resource disposal
50
+
51
+
When calling RPC methods of a Service Worker or Durable Object that return non-primitive values (such as objects or classes extending `RpcTarget`), use the `using` keyword to explicitly signal when resources can be disposed of. See [this example test](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-pool-workers-examples/rpc/test/unit.test.ts#L155) and refer to [explicit-resource-management](/workers/runtime-apis/rpc/lifecycle#explicit-resource-management) for more details.
52
+
53
+
```ts
54
+
usingresult=awaitstub.getCounter();
55
+
```
56
+
57
+
## Consume response bodies
58
+
59
+
When making requests via `fetch` or `R2.get()`, consume the entire response body, even if you are not asserting its content. For example:
60
+
61
+
```ts
62
+
test('check if file exists', async () => {
63
+
awaitenv.R2.put('file', 'hello-world');
64
+
const response =awaitenv.R2.get('file');
65
+
66
+
expect(response).not.toBe(null);
67
+
// Consume the response body even if you are not asserting it
0 commit comments