Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up pnpm
uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093
with:
version: 11.5.2
version: 11.27.1

- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
],
"author": "Artem Zakharchenko <kettanaito@gmail.com>",
"license": "MIT",
"packageManager": "pnpm@11.27.1",
"peerDependencies": {
"msw": ">=2.14.1"
"msw": ">=3"
},
"publishConfig": {
"access": "public"
Expand All @@ -39,17 +40,17 @@
"url": "git+https://github.com/mswjs/cloudflare.git"
},
"dependencies": {
"@mswjs/interceptors": "^0.41.6"
"@mswjs/interceptors": "^0.45.5"
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.14.9",
"@cloudflare/workers-types": "^4.20260424.1",
"@epic-web/test-server": "^0.1.6",
"@ossjs/release": "^0.11.2",
"msw": "^2.14.6",
"publint": "^0.3.18",
"tsdown": "^0.21.10",
"msw": "https://pkg.pr.new/msw@2692",
"publint": "^0.3.24",
"tsdown": "^0.23.0",
"typescript": "^6.0.3",
"vitest": "^4.1.5"
}
}
}
1,703 changes: 826 additions & 877 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
allowBuilds:
esbuild: true
msw: true
msw@https://pkg.pr.new/msw@2692: true
sharp: true
workerd: true
minimumReleaseAgeExclude:
- '@mswjs/interceptors@0.45.5'
- 'rettime@0.11.12'
14 changes: 8 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { bypass, ws } from 'msw'
import { ws } from 'msw/ws'
import { bypass } from 'msw/utils/bypass'
import {
defineNetwork,
InterceptorSource,
Expand All @@ -9,10 +10,11 @@ import { FetchInterceptor } from '@mswjs/interceptors/fetch'
import {
WebSocketInterceptor,
type WebSocketData,
type WebSocketConnectionEventData,
type WebSocketServerEventMap,
type WebSocketClientEventMap,
type WebSocketClientConnectionProtocol,
type WebSocketServerConnectionProtocol,
type WebSocketClientHandle,
type WebSocketServerHandle,
} from '@mswjs/interceptors/WebSocket'

export function setupNetwork() {
Expand All @@ -29,7 +31,7 @@ export function setupNetwork() {
const connectionUrl = resolveWebSocketUrl(url)
const [client, server] = Object.values(new WebSocketPair())

const connection = {
const connection: WebSocketConnectionEventData = {
client: new CloudflareWebSocketClientConnection({
url: connectionUrl,
socket: server,
Expand Down Expand Up @@ -71,7 +73,7 @@ export function setupNetwork() {
return network
}

class CloudflareWebSocketClientConnection implements WebSocketClientConnectionProtocol {
class CloudflareWebSocketClientConnection implements WebSocketClientHandle {
#socket: WebSocket

public id: string
Expand Down Expand Up @@ -116,7 +118,7 @@ class CloudflareWebSocketClientConnection implements WebSocketClientConnectionPr
}
}

class CloudflareWebSocketServerConnection implements WebSocketServerConnectionProtocol {
class CloudflareWebSocketServerConnection implements WebSocketServerHandle {
#url: string
#pendingSocket: PromiseWithResolvers<WebSocket>

Expand Down
2 changes: 1 addition & 1 deletion tests/fetch/fetch.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { env, exports } from 'cloudflare:workers'
import { createExecutionContext } from 'cloudflare:test'
import { http, HttpResponse } from 'msw'
import { http, HttpResponse } from 'msw/http'
import { setupNetwork } from '@msw/cloudflare'
import worker from './worker'

Expand Down
2 changes: 1 addition & 1 deletion tests/websocket/websocket.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { inject } from 'vitest'
import { env } from 'cloudflare:workers'
import { createExecutionContext } from 'cloudflare:test'
import { ws } from 'msw'
import { ws } from 'msw/ws'
import { setupNetwork } from '@msw/cloudflare'
import worker from './worker'

Expand Down
Loading