MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / expectRejected

Function expectRejected

packages/server/test/ws-auth.e2e.test.ts:184–206  ·  view source on GitHub ↗

* Asserts the upgrade is rejected (the socket errors/closes without ever * opening, so no `server_hello` is received). Resolves on the first `error` or * `close`; rejects if the socket opens or nothing happens within the timeout.

(url: string, opts?: ConnectOptions)

Source from the content-addressed store, hash-verified

182 * `close`; rejects if the socket opens or nothing happens within the timeout.
183 */
184function expectRejected(url: string, opts?: ConnectOptions): Promise<void> {
185 return new Promise((resolve, reject) => {
186 const ws = new WebSocket(url, opts?.protocols, { headers: opts?.headers });
187 const done = (err?: Error): void => {
188 clearTimeout(t);
189 ws.removeAllListeners();
190 try {
191 ws.terminate();
192 } catch {
193 // ignore
194 }
195 if (err !== undefined) reject(err);
196 else resolve();
197 };
198 const t = setTimeout(
199 () => done(new Error('connection was not rejected within timeout')),
200 1500,
201 );
202 ws.once('open', () => done(new Error('connection unexpectedly opened')));
203 ws.once('error', () => done());
204 ws.once('close', () => done());
205 });
206}
207
208describe('ws upgrade auth', () => {
209 it('accepts a valid bearer subprotocol and echoes it', async () => {

Callers 1

Calls 2

doneFunction · 0.70
onceMethod · 0.65

Tested by

no test coverage detected