loro/crates/loro-wasm/tests/compatibility.test.ts

94 lines
2.7 KiB
TypeScript
Raw Normal View History

2024-05-10 03:06:17 +00:00
import { describe, expect, it } from "vitest";
import {
Delta,
getType,
ListDiff,
Loro,
LoroEventBatch,
LoroList,
LoroMap,
LoroText,
MapDiff,
TextDiff,
} from "../bundler/index";
2024-05-10 03:06:17 +00:00
import * as OLD from "loro-crdt-old";
// TODO: This is skip because we know it will fail for the current version as we've introduced BREAKING CHANGES on the serialization format
2024-05-21 07:18:02 +00:00
describe("compatibility", () => {
2024-05-10 03:06:17 +00:00
it("basic forward compatibility on exportFrom", () => {
const docA = new Loro();
docA.getText("text").insert(0, "123");
docA.getMap("map").set("key", 123);
docA.getMap("map").set("key", "123");
docA.getList("list").insert(0, 1);
docA.getList("list").insert(0, "1");
// TODO: rename
// const t = docA.getTree("tree");
// const node = t.createNode();
// t.createNode(node.id, 0);
2024-05-10 03:06:17 +00:00
const bytes = docA.exportFrom();
// @ts-ignore
2024-05-10 03:06:17 +00:00
const docB = new OLD.Loro();
docB.import(bytes);
expect(docA.toJSON()).toStrictEqual(docB.toJSON());
});
it("basic forward compatibility on exportSnapshot", () => {
// @ts-ignore
2024-05-10 03:06:17 +00:00
const docA = new Loro();
docA.getText("text").insert(0, "123");
docA.getMap("map").set("key", 123);
docA.getMap("map").set("key", "123");
docA.getList("list").insert(0, 1);
docA.getList("list").insert(0, "1");
// const t = docA.getTree("tree");
// const node = t.createNode();
// t.createNode(node.id, 0);
2024-05-10 03:06:17 +00:00
const bytes = docA.exportSnapshot();
// @ts-ignore
2024-05-10 03:06:17 +00:00
const docB = new OLD.Loro();
docB.import(bytes);
expect(docA.toJSON()).toStrictEqual(docB.toJSON());
});
it("basic backward compatibility on exportSnapshot", () => {
// @ts-ignore
2024-05-10 03:06:17 +00:00
const docA = new OLD.Loro();
docA.getText("text").insert(0, "123");
docA.getMap("map").set("key", 123);
docA.getMap("map").set("key", "123");
docA.getList("list").insert(0, 1);
docA.getList("list").insert(0, "1");
// const t = docA.getTree("tree");
// const node = t.createNode();
// t.createNode(node.id);
2024-05-10 03:06:17 +00:00
const bytes = docA.exportSnapshot();
const docB = new Loro();
docB.import(bytes);
expect(docA.toJSON()).toStrictEqual(docB.toJSON());
});
it("basic backward compatibility on exportSnapshot", () => {
// @ts-ignore
2024-05-10 03:06:17 +00:00
const docA = new OLD.Loro();
docA.getText("text").insert(0, "123");
docA.getMap("map").set("key", 123);
docA.getMap("map").set("key", "123");
docA.getList("list").insert(0, 1);
docA.getList("list").insert(0, "1");
// const t = docA.getTree("tree");
// const node = t.createNode();
// t.createNode(node.id);
2024-05-10 03:06:17 +00:00
const bytes = docA.exportSnapshot();
const docB = new Loro();
docB.import(bytes);
expect(docA.toJSON()).toStrictEqual(docB.toJSON());
});
});