Skip to content

Commit 700b0e4

Browse files
committed
docs(vitest-integrations): known issues for isolated storage
1 parent 0139666 commit 700b0e4

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/content/docs/workers/testing/vitest-integration/known-issues.mdx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,40 @@ Dynamic `import()` statements do not work inside `export default { ... }` handle
2626

2727
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.
2828

29-
### Durable Objects and `isolatedStorage`
29+
### WebSockets
3030

3131
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.
3232

33-
### Returning non-primitive values from RPC methods
33+
### Isolated storage
3434

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 setting), follow these patterns to avoid issues:
36+
37+
- Await All Storage Operations
38+
39+
Always `await` all `Promise`s that read or write to storage services.
40+
41+
- Explicit Resource Disposal
42+
43+
If the RPC methods return non-primitive values (such as objects or classes extending `RpcTarget`), use the `using` keyword to explicitly signal when resources can be disposed. 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.
44+
45+
```ts
46+
using result = await stub.getCounter();
47+
```
48+
49+
- Consume Response Bodies
50+
51+
When making requests (e.g., via `fetch` or `R2.get()`), consume the entire response body, even if you aren't asserting its content. For example:
52+
53+
```ts
54+
test('check if file exists', async () => {
55+
await env.R2.put('file', 'hello-world');
56+
const response = await env.R2.get('file');
57+
58+
expect(response).not.toBe(null);
59+
// Consume the response body even if you are not asserting it
60+
await response.text()
61+
});
62+
```
3663

3764
### Module resolution
3865

0 commit comments

Comments
 (0)