New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add WS support? #2240
Comments
I hope to finally have the time to tackle the decomposition of nock into smaller module as mentioned in #129 (comment). Once we have that we might look into an alternative intercept module that will work with websockets. If anyone knows of prior work for websocket mocking, please share! |
I'm happy to help however I can! |
+1 am Interested in feature |
A good place to start is to discuss a "dream API". Gather your use cases and make up the best possible APIs to make them possible. Then we have something we can work towards. |
I suggest simply adding a pipeline function for the various sub-protocols in websockets or HTTP. Here's an example for a node: import nock from 'nock';
import WebSocket, { createWebSocketStream } from 'ws';
const ws = new WebSocket('wss://echo.websocket.org/', {
origin: 'https://websocket.org',
});
const duplexWebSocket = createWebSocketStream(ws, { encoding: 'utf8' });
// nock will intercept request, check header and pipe to websocket server
nock('https://websocket.org')
.matchHeader('X-MBX-APIKEY', 'foobar')
.pipe(duplexWebSocket);
duplexWebSocket.pipe(process.stdout); With this nock API, we can create any mocking implementation. |
This looks great! How would like to define mocks beyond just headers? |
Context
I love using nock for my HTTP server mocking, and I'd love to use it for a WS project I'm working on. I was hoping it could intercept messages (at least from) the websocket server.
Has the feature been requested before?
This was discussed in #129.
If the feature request is accepted, would you be willing to submit a PR?
Sadly, I don't think I'm skilled enough to implement this on my own, but I'd be willing to help if someone could give me guidance.
The text was updated successfully, but these errors were encountered: