Skip to report

Mocked WebSocket connections gain a browser logger

Follow MSW’s WebSocket logging from new core utilities into browser setup, and the connection callback options that browser and Node setup now share.

mswjs/msw #2112 · PR by kettanaito · Merged

mswjs/msw 64b6a82e..3ed3d497

base and head as given

  • WebSocket logging utilities entered the core
  • Browser workers now use WebSocket logging utilities
  • WebSocket handler connection events use a revised interface
files changed
16
in a component
9
lines in components
474
components
6
public routes changed
0
schema statements
0
new dependencies
0
excluded by role
7
Based on 9 of 9 eligible changed files

WebSocket traffic logging

Added
Before
WebSocket traffic logging did not exist
After
Mocked browser sockets log traffic

Browser-based mocked WebSocket connections now log opening, closure, errors, and message direction. Message logs include a truncated public payload and byte length, distinguishing handler-originated traffic from actual socket traffic.

In favour

  • In favour: Logs mocked socket traffic absent from browser developer tools
  • In favour: Includes payload previews and byte lengths for logged messages

Against

  • Against: Proxy-wrapped send methods add work to mocked message delivery
Files changed in 6 components. Dependencies shown: 1 new, 11 unchanged
unchanged · 11new · 1

1 new dependency between components — WebSocket Core → Logging Utilities

What else could behave differently

13 components · 37 files

These components import changed code, directly or through other files. A traced dependency is a place to review, not a confirmed runtime failure.

Reached 3

ComponentSymbolCited atFilesReached by
Core Handlerssrc/core/handlers/Body changed src/core/utils/logging/getTimestamp.ts:8-1722 direct
Trace path

Shortest component path from the changed symbol:

  1. Logging Utilities
  2. Core Handlers

Later steps follow file imports; they do not prove this symbol is called.

src/core/Signature changed 1 of 3 changed symbols reaching itsrc/core/handlers/WebSocketHandler.ts:15-1742 direct · 2 at two steps
Trace path

Shortest component path from the changed symbol:

  1. Core Handlers
  2. src/core/

Later steps follow file imports; they do not prove this symbol is called.

src/core/utils/internal/Body changed src/core/utils/logging/getTimestamp.ts:8-171none direct · 1 at two steps
Trace path

Shortest component path from the changed symbol:

  1. Logging Utilities
  2. Core Handlers
  3. src/core/utils/internal/

Later steps follow file imports; they do not prove this symbol is called.

Ranked lower 10

ComponentFilesReached by
src/core/utils/11 direct
src/core/ws/33 direct
src/browser/setupWorker/22 direct
src/node/54 direct · 1 at two steps
src/browser/11 direct
src/browser/utils/3none direct · 3 at two steps
src/native/11 direct
src/iife/1none direct · 1 at two steps
src/browser/setupWorker/start/11none direct · 11 at two steps
src/browser/setupWorker/stop/2none direct · 2 at two steps

Statements 3

getTimestamp's body changed and reached 2 handler files. 2
src/core/utils/logging/getTimestamp.ts:8-17
WebSocketHandlerEventMap's signature changed among 6 of 9 names in its file and reached 4 core files. 22
src/core/handlers/WebSocketHandler.ts:15-17
getTimestamp's body changed and reached 1 internal utility file. 1
src/core/utils/logging/getTimestamp.ts:8-17

15 reached files belong to no component — tests, docs and config.

Routes, schema, dependencies

No public URL, no migration and no new package.

Inspect components, files and symbols

Component

Core HandlersModified
src/core/handlers/

1 file · 60 lines

exports, 8 dependents

The handler exports added kSender and removed kDefaultPrevented.
Core UtilitiesModified
src/core/utils/

1 file · 68 lines

5 dependents

WebSocket CoreModified
src/core/ws/

4 files · 307 lines

4 dependents

WebSocket exports added attachWebSocketLogger, getMessageLength, getPublicData, logConnectionOpen, logIncomingClientMessage, logIncomingMockedClientMessage, logIncomingServerMessage, logOutgoingClientMessage, logOutgoingMockedClientMessage, and truncateMessage.
Worker SetupModified
src/browser/setupWorker/

1 file · 21 lines

4 dependents

NodeModified
src/node/

1 file · 8 lines

1 dependent

Logging UtilitiesModified
src/core/utils/logging/

1 file · 10 lines

2 dependents

File

Core Handlerssrc/core/handlers/
src/core/handlers/WebSocketHandler.ts

+21 −39

Core Utilitiessrc/core/utils/
src/core/utils/handleWebSocketEvent.ts

+39 −29

WebSocket Coresrc/core/ws/
src/core/ws/utils/attachWebSocketLogger.ts

+262 −0

WebSocket Coresrc/core/ws/
src/core/ws/utils/getMessageLength.ts

+19 −0

WebSocket Coresrc/core/ws/
src/core/ws/utils/getPublicData.ts

+17 −0

WebSocket Coresrc/core/ws/
src/core/ws/utils/truncateMessage.ts

+9 −0

Worker Setupsrc/browser/setupWorker/
src/browser/setupWorker/setupWorker.ts

+19 −2

Nodesrc/node/
src/node/SetupServerCommonApi.ts

+6 −2

Logging Utilitiessrc/core/utils/logging/
src/core/utils/logging/getTimestamp.ts

+2 −8

Function

imports what changeddownstream of it, one mark per step

WebSocketHandler()src/core/handlers/WebSocketHandler.ts

reaches 6 components

WebSocketHandler's signature changed among 6 of 9 names in its file and reached 1 utility file. 1
src/core/handlers/WebSocketHandler.ts:27-71
WebSocketHandler's signature changed among 6 of 9 names in its file and reached 2 worker setup files. 2
src/core/handlers/WebSocketHandler.ts:27-71
WebSocketHandler's signature changed among 6 of 9 names in its file and reached 5 Node files. 41
src/core/handlers/WebSocketHandler.ts:27-71
WebSocketHandler's signature changed among 6 of 9 names in its file and reached 3 browser utility files. 3
src/core/handlers/WebSocketHandler.ts:27-71
WebSocketHandler's signature changed among 6 of 9 names in its file and reached 11 worker start files. 11
src/core/handlers/WebSocketHandler.ts:27-71
WebSocketHandler's signature changed among 6 of 9 names in its file and reached 2 worker stop files. 2
src/core/handlers/WebSocketHandler.ts:27-71

Diff

Core Handlerssrc/core/handlers/
src/core/handlers/WebSocketHandler.ts

2–2, 9–9, 16–16 and 10 more spans

Core Utilitiessrc/core/utils/
src/core/utils/handleWebSocketEvent.ts

1–1, 3–3, 6–12 and 6 more spans

WebSocket Coresrc/core/ws/
src/core/ws/utils/attachWebSocketLogger.ts

1–262

WebSocket Coresrc/core/ws/
src/core/ws/utils/getMessageLength.ts

1–19

WebSocket Coresrc/core/ws/
src/core/ws/utils/getPublicData.ts

1–17

WebSocket Coresrc/core/ws/
src/core/ws/utils/truncateMessage.ts

1–9

Worker Setupsrc/browser/setupWorker/
src/browser/setupWorker/setupWorker.ts

27–27, 183–199, 201–201

Nodesrc/node/
src/node/SetupServerCommonApi.ts

88–93

Logging Utilitiessrc/core/utils/logging/
src/core/utils/logging/getTimestamp.ts

10–10, 13–13

Analysis scope

521 → 6
  1. 521
    files at head
  2. 24
    components
  3. 6
    changed by this change

Where the new files landed

4 new files
New fileBelongs toUsed byCallsServes
src/core/ws/4 new files
WebSocket Corebase frame
Worker Setup
src/core/utils/internal/Logging Utilitiessrc/core/utils/request/

4 added files carry no component — 4 test.

6components changed
8reached, not changed
0components added/removed
3dependencies added between components
0dependencies removed between components
0files moved to another path

16 files changed, 21 claims stated. 13 components reached in total.

naming: “model

narrative: “model

analyzer 0.2.0, config v1.9.0-phase8

Every line above is derived from 64b6a82e..3ed3d497 and nothing else.