The WebSockets specification defines two classes: WebSocket and CloseEvent. These two classes don't exist in Node.
Mock Socket already exports WebSocket. CloseEvent should also be exported to use it as polyfill in Node.
import { WebSocket, CloseEvent, Server } from 'mock-socket';
const server = new Server('ws://localhost:8080', { mock: false });
globalThis.WebSocket = WebSocket;
globalThis.CloseEvent = CloseEvent;
This package is not a polyfill, it's a mocking library for the WebSocket. If you have any issues running tests you can open a new issue/PR with the details
The WebSockets specification defines two classes:
WebSocket
andCloseEvent
. These two classes don't exist in Node. Mock Socket already exportsWebSocket
.CloseEvent
should also be exported to use it as polyfill in Node.