SuperWSTest (v3.0.0) extends supertest with WebSocket testing capabilities, allowing you to test WebSocket endpoints alongside HTTP endpoints using the same request-like API. It integrates seamlessly with supertest and provides methods like .ws(), .expectText(), .expectJson(), and .close(). The package ships TypeScript types, supports both local and remote servers, auto-closes connections via server.close, and offers scoped instances for parallel test isolation. Unlike raw ws integration, it provides a supertest-compatible fluent API with built-in message filtering and expectations.
npm install superwstestNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Tests a WebSocket echo server using SuperWSTest's fluent API: connect, expect initial message, send, expect echo, close.
Add afterEach(() => request.closeAll()); in your test suite for remote servers.
Use const request = baseRequest.scoped(); and afterEach(() => request.closeAll()); for each describe block.
Upgrade to v3 and review the options parameter in .expectText() and .expectJson().
Use require('superwstest').default, or switch to ES module imports.Ensure you import default from 'superwstest', not from 'supertest' alone. Use import request from 'superwstest' and then request(server).ws(...).
Recreate the server in beforeEach, not before the test suite. For remote servers, use a URL string instead of a server object.
Ensure server.listen is called before test, and add await before request(...).ws(...). Also check WebSocket path matches server.
Check server's websocket path and options. Add .expectConnection() or ensure server is listening.