xonecas.io
6533
Yo

yoctomarkdown / commit 0091c09

test: add comprehensive CLI and programmatic tests with performance analysis

xonecas2026-03-15 0091c09bf34eb7e1e830d57dedf3a91a0b83208a parent b51c6c6

4 files changed

knip.json+1−1
@@ -1 +1 @@
1-{ "ignoreBinaries": ["tsc"] }
1+{ "ignoreBinaries": ["tsc", "src/cli.ts"] }
package.json+2−1
@@ -28,6 +28,7 @@
2828 "prepare": "husky",
2929 "lint": "biome lint .",
3030 "format": "prettier --write .",
31- "format:check": "prettier --check ."
31+ "format:check": "prettier --check .",
32+ "test": "bun test"
3233 }
3334 }
tests/cli.test.ts+30−0
@@ -0,0 +1,30 @@
1+import { test, expect, describe } from "bun:test";
2+import { $ } from "bun";
3+
4+describe("CLI tests", () => {
5+ test("should render from stdin", async () => {
6+ const result =
7+ await $`echo "# Hello World" | bun src/cli.ts --theme none`.text();
8+ expect(result).toContain("Hello World");
9+ });
10+
11+ test("should render an existing file", async () => {
12+ const result = await $`bun src/cli.ts spec.md --theme none`.text();
13+ expect(result.length).toBeGreaterThan(100);
14+ });
15+
16+ test("CLI performance test", async () => {
17+ const largeMdPath = "large_temp.md";
18+ await $`bun -e 'require("fs").writeFileSync("${largeMdPath}", "# Performance\\n\\nSome **bold** text here.\\n".repeat(5000))'`;
19+
20+ const start = performance.now();
21+ await $`bun src/cli.ts ${largeMdPath} --theme none`.text();
22+ const end = performance.now();
23+
24+ const duration = end - start;
25+ console.log(`CLI Execution Time: ${duration.toFixed(2)}ms`);
26+ expect(duration).toBeLessThan(500); // Process boot + execution should be under 500ms
27+
28+ await $`rm ${largeMdPath}`;
29+ });
30+});
tests/index.test.ts+47−0
@@ -0,0 +1,47 @@
1+import { test, expect, describe } from "bun:test";
2+import { highlightSync, createHighlighter } from "../src/index";
3+
4+describe("Programmatic Usage: highlightSync", () => {
5+ test("should format basic markdown elements", () => {
6+ const res = highlightSync("# Heading\n\n**bold** and *italic*", {
7+ theme: "none",
8+ });
9+ expect(res).toContain("Heading");
10+ expect(res).toContain("bold");
11+ expect(res).toContain("italic");
12+ });
13+
14+ test("should format lists", () => {
15+ const res = highlightSync("- Item 1\n- Item 2\n1. Number 1", {
16+ theme: "none",
17+ });
18+ expect(res).toContain("Item 1");
19+ expect(res).toContain("Item 2");
20+ expect(res).toContain("Number 1");
21+ });
22+
23+ test("performance test on large input", () => {
24+ const largeMd = "# Heading\n\nSome **bold** text here.\n".repeat(5000);
25+ const start = performance.now();
26+ highlightSync(largeMd, { theme: "none" });
27+ const end = performance.now();
28+
29+ const duration = end - start;
30+ console.log(`Programmatic Parse Time: ${duration.toFixed(2)}ms`);
31+ expect(duration).toBeLessThan(200); // 5000 lines should be fast
32+ });
33+});
34+
35+describe("Programmatic Usage: createHighlighter (Streaming)", () => {
36+ test("should handle chunks without breaking output", () => {
37+ const highlighter = createHighlighter({ theme: "none" });
38+ let res = highlighter.write("# Hea");
39+ res += highlighter.write("ding\n");
40+ res += highlighter.write("\nSome **tex");
41+ res += highlighter.write("t**\n");
42+ res += highlighter.end();
43+
44+ expect(res).toContain("Heading");
45+ expect(res).toContain("Some **text**");
46+ });
47+});