loro/crates/loro-wasm/deno_tests/basic.test.ts
Zixuan Chen 9b60d01be2
fix: define the fork behavior when the doc is detached (#537)
* fix: define the fork behavior when the doc is detached

* chore: add release note
2024-11-04 22:34:33 +08:00

30 lines
1.3 KiB
TypeScript

import init, { initSync, LoroDoc } from "../web/loro_wasm.js";
import { expect } from "npm:expect";
await init();
Deno.test("basic", () => {
const doc = new LoroDoc();
doc.getText("text").insert(0, "Hello, world!");
expect(doc.getText("text").toString()).toBe("Hello, world!");
});
Deno.test("fork when detached", () => {
const doc = new LoroDoc();
doc.setPeerId("0");
doc.getText("text").insert(0, "Hello, world!");
doc.checkout([{ peer: "0", counter: 5 }]);
const newDoc = doc.fork();
newDoc.setPeerId("1");
newDoc.getText("text").insert(6, " Alice!");
// ┌───────────────┐ ┌───────────────┐
// │ Hello, │◀─┬──│ world! │
// └───────────────┘ │ └───────────────┘
// │
// │ ┌───────────────┐
// └──│ Alice! │
// └───────────────┘
doc.import(newDoc.export({ mode: "update" }));
doc.checkoutToLatest();
console.log(doc.getText("text").toString()); // "Hello, world! Alice!"
});