Skip to content

Commit f46d26a

Browse files
committed
test: accept ws RawData buffer arrays in e2e helper
1 parent 9d5b786 commit f46d26a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/loro-websocket/tests/e2e.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, it, expect, beforeAll, afterAll } from "vitest";
22
import { WebSocket, WebSocketServer } from "ws";
3+
import type { RawData } from "ws";
34
import getPort from "get-port";
45
import { SimpleServer } from "../src/server/simple-server";
56
import { LoroWebsocketClient, ClientStatus } from "../src/client";
@@ -1127,8 +1128,13 @@ async function waitUntil(
11271128
throw new Error("Condition not met within timeout");
11281129
}
11291130

1130-
function toUint8Array(data: Buffer | ArrayBuffer | ArrayBufferView | string): Uint8Array {
1131+
function toUint8Array(data: RawData | string): Uint8Array {
11311132
if (typeof data === "string") return new TextEncoder().encode(data);
1133+
if (Array.isArray(data)) {
1134+
// RawData can be Buffer[] when `ws` aggregates chunks
1135+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1136+
return toUint8Array(Buffer.concat(data as Buffer[]));
1137+
}
11321138
if (data instanceof ArrayBuffer) return new Uint8Array(data);
11331139
if (ArrayBuffer.isView(data)) return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
11341140
// Buffer from ws in Node

0 commit comments

Comments
 (0)