thoov / mock-socket

Javascript mocking library for WebSockets and Socket.IO
MIT License
800 stars 119 forks source link

Export `CloseEvent` #380

Closed regseb closed 1 year ago

regseb commented 1 year ago

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;
Atrue commented 1 year ago

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