jsmdcui 0.10.1 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  import { afterEach, expect, test } from "bun:test";
2
- import { mkdtempSync, rmSync } from "node:fs";
2
+ import { mkdtempSync, readFileSync, rmSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
- import { createWui } from "../runmd.mjs";
5
+ import { createWui, extractJs } from "../runmd.mjs";
6
6
 
7
7
  const temporaryDirectories = [];
8
8
 
@@ -33,3 +33,22 @@ test("createWui injects the image rule into an existing document head", async ()
33
33
  expect(html.indexOf("max-width: 100%")).toBeLessThan(html.indexOf("</head>"));
34
34
  expect(html.match(/document\.md\.front\.js/g)).toHaveLength(1);
35
35
  });
36
+
37
+ test("bundling mode creates a browser-only front entry", async () => {
38
+ const directory = mkdtempSync(join(tmpdir(), "jsmdcui-wui-bundling-"));
39
+ temporaryDirectories.push(directory);
40
+ const markdownPath = join(directory, "bundle.md");
41
+ const source = "```js front\nexport function pav() { return rpc }\n```";
42
+ const markdown = await extractJs(source, markdownPath, { bundling: true });
43
+ const html = await createWui(markdown, markdownPath, { bundling: true });
44
+ const frontSource = readFileSync(`${markdownPath}.tmpfs.js`, "utf8");
45
+ const installerSource = readFileSync(`${markdownPath}.tmpfi.js`, "utf8");
46
+
47
+ expect(frontSource).toContain("const rpc = wuiRpcClient");
48
+ expect(frontSource).not.toContain("globalThis.process");
49
+ expect(frontSource).not.toContain('import("./bundle.md.front.js")');
50
+ expect(installerSource).toContain('import * as frontMod from "./bundle.md.tmpfs.js"');
51
+ expect(installerSource).toContain("Object.assign(window, frontMod)");
52
+ expect(html).toContain('src="./bundle.md.tmpfi.js"');
53
+ expect(html).not.toContain("bundle.md.front.js");
54
+ });
package/tests/wui.test.js CHANGED
@@ -4,6 +4,9 @@ import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import { readMarkdownInput, writeRuntimeFiles } from "../runmd.mjs";
6
6
 
7
+ const indexEntry = join(import.meta.dir, "..", "src", "index.js");
8
+ const bunBin = Bun.which("bun") || process.argv0;
9
+
7
10
  test("WUI writes the bundled testapp.md when it is missing", async () => {
8
11
  const dir = await mkdtemp(join(tmpdir(), "jsmdcui-wui-"));
9
12
  const mdpath = join(dir, "testapp.md");
@@ -43,3 +46,31 @@ test("generated WUI server falls back to a system port when 3000 is occupied", a
43
46
  await rm(dir, { recursive: true, force: true });
44
47
  }
45
48
  });
49
+
50
+ test("WUI reports an external server before starting it", async () => {
51
+ const dir = await mkdtemp(join(tmpdir(), "jsmdcui-wui-source-report-"));
52
+ const mdpath = join(dir, "external.md");
53
+ const preloadPath = join(dir, "mock-serve.mjs");
54
+ try {
55
+ await writeFile(mdpath, "# External WUI\n");
56
+ await writeFile(
57
+ preloadPath,
58
+ `Bun.serve = () => ({ port: 34567, stop() {} });\n`,
59
+ );
60
+ const result = Bun.spawnSync(
61
+ [bunBin, "--preload", preloadPath, indexEntry, "--wui", mdpath],
62
+ {
63
+ cwd: dir,
64
+ stdout: "pipe",
65
+ stderr: "pipe",
66
+ },
67
+ );
68
+
69
+ expect(result.exitCode).toBe(0);
70
+ const stderr = Bun.stripANSI(result.stderr.toString());
71
+ expect(stderr).toContain("[mdcui] Starting external WUI server:");
72
+ expect(stderr).toContain(`${mdpath}-server.js`);
73
+ } finally {
74
+ await rm(dir, { recursive: true, force: true });
75
+ }
76
+ });