Move ser/deser logic to JS

This commit is contained in:
Andras Schmelczer 2025-01-05 20:49:38 +00:00
parent 7e045caab1
commit e43a13648b
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
7 changed files with 59 additions and 17 deletions

View file

@ -0,0 +1,18 @@
import init, { base64ToBytes } from "sync_lib";
import fs from "fs";
describe("deserialize", () => {
it("should serialize a Uint8Array to a base64 string", async () => {
const wasmBin = fs.readFileSync(
"../backend/sync_lib/pkg/sync_lib_bg.wasm"
);
await init({ module_or_path: wasmBin });
const base64 = "SGVsbG8=";
const jsResult = base64ToBytes(base64);
const expected = new Uint8Array([72, 101, 108, 108, 111]);
expect(jsResult).toEqual(expected);
const rustResult = base64ToBytes(base64);
expect(jsResult).toEqual(rustResult);
});
});