Код: Выделить всё
type CloseMessage = {
code: number,
reason: Buffer,
};
describe('Signalling Endpoint Protocol', () => {
let app: FastifyInstance;
let ws: WebSocket;
beforeEach(async () => {
app = await buildApp();
await app.ready();
ws = await app.injectWS('/signal', {
headers: {
authorization: `Bearer ${MOCK_TOKEN}`,
'sec-websocket-protocol': SIGNALLING_PROTOCOL,
}
});
});
afterEach(async () => {
await app.close();
ws?.terminate();
});
it('disconnects if the client sends malformed JSON', async () => {
const { promise, resolve } = Promise.withResolvers();
ws.once('close', (code, reason) => {
resolve({ code, reason });
});
ws.send('fgsfds'); // Invalid JSON
const { code } = await promise;
// prints, but wrongly attributed to a different test
// (the one that normally comes after this one)
console.log(`awaited code ${code}`);
expect(code).toBe(WebSocketStatus.INVALID_FRAME_PAYLOAD_DATA);
expect(ws.readyState).toBe(WebSocket.CLOSED);
console.log("tests are done");
// runs to here, then times out
});
});
Есть идеи, почему это происходит? Я использую Fastify 5.4.0, @Fastify/WebSocket 11.2.0, узел 22.13.1 и Vitest 3.2.4.
Подробнее здесь: https://stackoverflow.com/questions/797 ... t-but-also
Мобильная версия