mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 19:32:27 +00:00
22 lines
812 B
TypeScript
22 lines
812 B
TypeScript
import { Buffer } from "node:buffer";
|
|
import { describe, expect, it } from "vitest";
|
|
import { rawDataToString } from "./ws.js";
|
|
|
|
describe("rawDataToString", () => {
|
|
it("returns string input unchanged", () => {
|
|
expect(rawDataToString("hello" as unknown as Parameters<typeof rawDataToString>[0])).toBe(
|
|
"hello",
|
|
);
|
|
});
|
|
|
|
it("decodes Buffer, Buffer[] and ArrayBuffer inputs", () => {
|
|
expect(rawDataToString(Buffer.from("hello"))).toBe("hello");
|
|
expect(rawDataToString([Buffer.from("he"), Buffer.from("llo")])).toBe("hello");
|
|
expect(rawDataToString(Uint8Array.from([104, 101, 108, 108, 111]).buffer)).toBe("hello");
|
|
});
|
|
|
|
it("falls back to string coercion for other raw data shapes", () => {
|
|
expect(rawDataToString(Uint8Array.from([1, 2, 3]) as never)).toBe("1,2,3");
|
|
});
|
|
});
|