Skip to content

Commit a56438d

Browse files
committed
Merge branch 'main' into beta
2 parents 28bd0fc + 3a7a97f commit a56438d

4 files changed

Lines changed: 34 additions & 20 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ afterAll(() => {
5353
network.disable()
5454
})
5555

56-
it('', async () => {
56+
it('responds with the user id', async () => {
5757
network.use(
5858
http.get('https://api.example.com/user', () => {
5959
return HttpResponse.json({ id: 1, name: 'John Maverick' })

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@cloudflare/vitest-pool-workers": "^0.14.9",
3737
"@cloudflare/workers-types": "^4.20260424.1",
3838
"@epic-web/test-server": "^0.1.6",
39-
"msw": "^2.14.2",
39+
"msw": "^2.14.6",
4040
"publint": "^0.3.18",
4141
"tsdown": "^0.21.10",
4242
"typescript": "^6.0.3",

pnpm-lock.yaml

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/fetch/fetch.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { env } from 'cloudflare:workers'
1+
import { env, exports } from 'cloudflare:workers'
22
import { createExecutionContext } from 'cloudflare:test'
33
import { http, HttpResponse } from 'msw'
44
import { setupNetwork } from '@msw/cloudflare'
@@ -35,3 +35,17 @@ it('intercepts a fetch request made in a worker', async () => {
3535
expect.soft(response.status).toBe(200)
3636
await expect.soft(response.json()).resolves.toEqual({ mocked: true })
3737
})
38+
39+
it('intercepts a fetch request in a worker used as "exports.default.fetch"', async () => {
40+
network.use(
41+
http.get('http://localhost/resource', () => {
42+
return HttpResponse.json({ mocked: true })
43+
}),
44+
)
45+
46+
const ctx = createExecutionContext()
47+
const response = await exports.default.fetch('http://localhost/')
48+
49+
expect.soft(response.status).toBe(200)
50+
await expect.soft(response.json()).resolves.toEqual({ mocked: true })
51+
})

0 commit comments

Comments
 (0)