Skip to content

[experimental] WebSocketNetworkFrame cannot be initialized with WebSocket(Client|Server)ConnectionProtocol implementations #2707

@christoph-fricke

Description

@christoph-fricke

This issue has come up while migrating @msw/playwright to the new network source architecture.

Description

When constructing an implementation of the WebSocketNetworkFrame, it requires a WebSocketClientConnection and WebSocketServerConnection connection. This results in errors when providing WebSocket(Client|Server)ConnectionProtocol implementations.

const frame = new PlaywrightWebSocketNetworkFrame({
  connection: {
    client: new PlaywrightWebSocketClientConnection(route),
    server: new PlaywrightWebSocketServerConnection(route),
    info: { protocols: [] },
  },
})
  • client: Type 'PlaywrightWebSocketClientConnection' is missing the following properties from type 'WebSocketClientConnection': socket, transport, [kEmitter$1]
  • server: Type 'PlaywrightWebSocketServerConnection' is missing the following properties from type 'WebSocketServerConnection': client, transport, createConnection, mockCloseController, and 7 more.

Furthermore, it results in errors when passing protocol implementations to webSockerHandler.run(...).

Proposed Solution

As pointed out here, this seems to be a bug since WebSocket(Client|Server)ConnectionProtocol is the intended way for working with WebSocketNetworkFrame.

I'm getting the WebSocketConnectionData from the Interceptors as-is, but that's a mistake. That type is a narrower type than what the frame should care about.

We should probably annotate that connection option as WebSocketHandlerConnection from WebSocketHandler.ts, which contains the broader WebSocketClientConnectionProtocol.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions