@@ -21,7 +21,8 @@ const localLoroPackage = path.join(repoRoot, "crates/loro-wasm");
2121const loroPackageSpec = normalizeLoroPackageSpec (
2222 process . env . LORO_SMOKE_PACKAGE ?? `file:${ localLoroPackage } ` ,
2323) ;
24- const smokeMode = process . env . LORO_SMOKE_MODE ?? "default" ;
24+ const expectedSmokeJson = { map : { text : "mergeable-smoke" } } ;
25+ const expectedSmokeJsonLiteral = JSON . stringify ( expectedSmokeJson ) ;
2526
2627function normalizeLoroPackageSpec ( spec ) {
2728 if ( spec === "loro-crdt" || spec . startsWith ( "loro-crdt@" ) ) {
@@ -31,43 +32,33 @@ function normalizeLoroPackageSpec(spec) {
3132 return spec ;
3233}
3334
34- const sharedApp = ( importPath ) => {
35- if ( smokeMode === "json" ) {
36- return `import { LoroDoc } from "${ importPath } ";
37-
38- const doc = new LoroDoc();
39- doc.getText("t").insert(0, "hi");
35+ function loroSmokeBody ( { renderToDom = true } = { } ) {
36+ return `const doc = new Loro();
37+ const map = doc.getMap("map");
38+ const text = map.ensureMergeableText("text");
39+ text.insert(0, "mergeable-smoke");
4040const value = doc.toJSON();
41+ const expected = ${ expectedSmokeJsonLiteral } ;
4142
42- if (value.t !== "hi" || Object.keys (value).length !== 1 ) {
43+ if (JSON.stringify (value) !== JSON.stringify(expected) ) {
4344 throw new Error(\`Unexpected Loro JSON: \${JSON.stringify(value)}\`);
4445}
4546
46- console.log(value);
4747globalThis.__LORO_JSON_SMOKE__ = value;
48- const app = document.getElementById("app");
48+ globalThis.__LORO_SMOKE__ = value.map.text;
49+ ${ renderToDom
50+ ? `const app = document.getElementById("app");
4951if (app) {
5052 app.textContent = JSON.stringify(value);
5153}
52- ` ;
53- }
54-
55- return `import { LoroDoc } from "${ importPath } ";
56-
57- const doc = new LoroDoc();
58- const text = doc.getText("text");
59- text.insert(0, "bundler-smoke");
60-
61- const value = doc.toJSON().text;
62- if (value !== "bundler-smoke") {
63- throw new Error(\`Unexpected Loro value: \${value}\`);
54+ `
55+ : "" } `;
6456}
6557
66- globalThis.__LORO_SMOKE__ = value;
67- const app = document.getElementById("app");
68- if (app) {
69- app.textContent = value;
70- }
58+ const sharedApp = ( importPath ) => {
59+ return `import { Loro } from "${ importPath } ";
60+
61+ ${ loroSmokeBody ( ) }
7162` ;
7263} ;
7364
@@ -85,6 +76,15 @@ const html = `<!doctype html>
8576` ;
8677
8778const cases = {
79+ "vitest-node" : {
80+ description : "Vitest Node runtime with bare loro-crdt import" ,
81+ dependencies : { } ,
82+ devDependencies : {
83+ vitest : "3.2.6" ,
84+ } ,
85+ setup : setupVitestNode ,
86+ command : [ "pnpm" , "exec" , "vitest" , "run" ] ,
87+ } ,
8888 vite5 : viteCase ( "vite5" , "vite" , "^5.4.21" ) ,
8989 vite6 : viteCase ( "vite6" , "vite" , "^6.4.2" ) ,
9090 vite7 : viteCase ( "vite7" , "vite" , "^7.3.2" ) ,
@@ -356,6 +356,22 @@ async function setupBasic(dir, importPath) {
356356 await writeFile ( path . join ( dir , "src/main.js" ) , sharedApp ( importPath ) ) ;
357357}
358358
359+ async function setupVitestNode ( dir ) {
360+ await writeFile (
361+ path . join ( dir , "loro.test.ts" ) ,
362+ `import { describe, expect, it } from "vitest";
363+ import { Loro } from "loro-crdt";
364+
365+ describe("loro-crdt", () => {
366+ it("runs the mergeable text smoke test", () => {
367+ ${ loroSmokeBody ( { renderToDom : false } ) . replaceAll ( "\n" , "\n " ) }
368+ expect(value).toStrictEqual(${ expectedSmokeJsonLiteral } );
369+ });
370+ });
371+ ` ,
372+ ) ;
373+ }
374+
359375async function setupVite ( dir ) {
360376 await setupBasic ( dir , "loro-crdt" ) ;
361377 await writeFile (
@@ -374,25 +390,13 @@ async function setupViteWebMirror(dir) {
374390 await writeFile ( path . join ( dir , "index.html" ) , html ) ;
375391 await writeFile (
376392 path . join ( dir , "src/main.js" ) ,
377- `import init, { LoroDoc } from "loro-crdt/web";
393+ `import init, { Loro } from "loro-crdt/web";
378394import wasmUrl from "loro-crdt/web/loro_wasm_bg.wasm?url";
379395import * as mirror from "loro-mirror";
380396
381397await init(wasmUrl);
382- const doc = new LoroDoc();
383- doc.getText("t").insert(0, "hi");
384- const value = doc.toJSON();
385-
386- if (value.t !== "hi" || Object.keys(value).length !== 1) {
387- throw new Error(\`Unexpected Loro JSON: \${JSON.stringify(value)}\`);
388- }
389-
390- globalThis.__LORO_JSON_SMOKE__ = value;
398+ ${ loroSmokeBody ( ) }
391399globalThis.__LORO_MIRROR_KEYS__ = Object.keys(mirror);
392- const app = document.getElementById("app");
393- if (app) {
394- app.textContent = JSON.stringify(value);
395- }
396400` ,
397401 ) ;
398402 await writeViteWasmConfig ( dir ) ;
@@ -545,35 +549,14 @@ export default function Page() {
545549 ) ;
546550 await writeFile (
547551 path . join ( dir , "components/Smoke.jsx" ) ,
548- smokeMode === "json"
549- ? `"use client";
552+ `"use client";
550553
551- import { LoroDoc } from "${ importPath } ";
554+ import { Loro } from "${ importPath } ";
552555
553556export default function Smoke() {
554- const doc = new LoroDoc();
555- doc.getText("t").insert(0, "hi");
556- const value = doc.toJSON();
557-
558- if (value.t !== "hi" || Object.keys(value).length !== 1) {
559- throw new Error(\`Unexpected Loro JSON: \${JSON.stringify(value)}\`);
560- }
561-
562- console.log(value);
563- globalThis.__LORO_JSON_SMOKE__ = value;
557+ ${ loroSmokeBody ( { renderToDom : false } ) . replaceAll ( "\n" , "\n " ) }
564558 return <main>{JSON.stringify(value)}</main>;
565559}
566- `
567- : `"use client";
568-
569- import { LoroDoc } from "${ importPath } ";
570-
571- export default function Smoke() {
572- const doc = new LoroDoc();
573- const text = doc.getText("text");
574- text.insert(0, "bundler-smoke");
575- return <main>{doc.toJSON().text}</main>;
576- }
577560` ,
578561 ) ;
579562 await writeFile (
@@ -661,7 +644,9 @@ async function runCase(name, testCase) {
661644 if ( testCase . afterBuild ) {
662645 await testCase . afterBuild ( dir ) ;
663646 }
664- await inspectOutput ( dir , testCase . inspect ) ;
647+ if ( testCase . inspect ) {
648+ await inspectOutput ( dir , testCase . inspect ) ;
649+ }
665650 console . log ( `[${ name } ] ok` ) ;
666651}
667652
0 commit comments