SnowLuma v2.4.2 source snapshot
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
Publish MCP to npm / Build, test, and publish MCP (push) Waiting to run
Publish SDK to npm / Build, test, and publish SDK (push) Waiting to run
Sync action catalog to docs / sync (push) Waiting to run
Publish UI to npm / Build and publish UI (push) Waiting to run
Build and Release / preflight (push) Waiting to run
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
Publish MCP to npm / Build, test, and publish MCP (push) Waiting to run
Publish SDK to npm / Build, test, and publish SDK (push) Waiting to run
Sync action catalog to docs / sync (push) Waiting to run
Publish UI to npm / Build and publish UI (push) Waiting to run
Build and Release / preflight (push) Waiting to run
This commit is contained in:
commit
fa9c73363d
1367 files changed
+355735
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import type { WebSocket } from '@snowluma/websocket';
|
||||
import { StreamTransportClosedError } from '../src/streaming';
|
||||
import { safeSendAsync } from '../src/network/utils';
|
||||
|
||||
describe('safeSendAsync', () => {
|
||||
it('resolves after a successful WebSocket write callback', async () => {
|
||||
const socket = {
|
||||
readyState: 1,
|
||||
send: vi.fn((_payload: string, callback: (error?: Error | null) => void) => {
|
||||
callback(null);
|
||||
}),
|
||||
} as unknown as WebSocket;
|
||||
|
||||
await expect(safeSendAsync(socket, 'frame')).resolves.toBeUndefined();
|
||||
expect(socket.send).toHaveBeenCalledWith('frame', expect.any(Function));
|
||||
});
|
||||
|
||||
it('rejects when the socket is not open', async () => {
|
||||
const socket = {
|
||||
readyState: 3,
|
||||
send: vi.fn(),
|
||||
} as unknown as WebSocket;
|
||||
|
||||
await expect(safeSendAsync(socket, 'frame')).rejects.toBeInstanceOf(
|
||||
StreamTransportClosedError,
|
||||
);
|
||||
expect(socket.send).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects a synchronous WebSocket send failure', async () => {
|
||||
const socket = {
|
||||
readyState: 1,
|
||||
send: vi.fn(() => {
|
||||
throw new Error('socket gone');
|
||||
}),
|
||||
} as unknown as WebSocket;
|
||||
|
||||
await expect(safeSendAsync(socket, 'frame')).rejects.toBeInstanceOf(
|
||||
StreamTransportClosedError,
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects an asynchronous WebSocket write failure', async () => {
|
||||
const socket = {
|
||||
readyState: 1,
|
||||
send: vi.fn((_payload: string, callback: (error?: Error | null) => void) => {
|
||||
callback(new Error('write failed'));
|
||||
}),
|
||||
} as unknown as WebSocket;
|
||||
|
||||
await expect(safeSendAsync(socket, 'frame')).rejects.toBeInstanceOf(
|
||||
StreamTransportClosedError,
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user