Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
- name: Run tests
run: bun run test

- name: Run integration tests
run: bun run test:integration

- name: Typecheck
run: bun run typecheck

Expand Down
157 changes: 152 additions & 5 deletions bun.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"clean": "rm -rf dist packages/app/dist packages/opentui/dist",
"build": "cd packages/opentui && bun run build && cd ../app && bun run build",
"test": "cd packages/opentui && bun test",
"test:integration": "cd packages/app && bun run test:integration",
"typecheck": "cd packages/opentui && bun run typecheck && cd ../app && bun run typecheck && cd ../pi && bun run typecheck",
"pack:check": "cd packages/opentui && bun run pack:check && cd ../app && bun run pack:check && cd ../pi && bun run pack:check",
"smoke:pi": "cd packages/pi && bun run smoke:pi",
Expand All @@ -28,6 +29,7 @@
"oxfmt": "^0.44.0",
"oxlint": "^1.59.0",
"simple-git-hooks": "^2.13.1",
"tuistory": "^0.3.0",
"typescript": "^5.9.3"
},
"simple-git-hooks": {
Expand Down
2 changes: 2 additions & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"build:lib": "tsc -p tsconfig.build.json",
"build:cli": "bun build src/cli.tsx --outdir dist --target=bun && chmod +x dist/cli.js",
"check": "bun run format:check && bun run lint && bun run typecheck",
"test:integration": "bun test test/integration",
"pack:check": "bun run build && npm pack --dry-run --ignore-scripts",
"prepack": "bun run build",
"prepublishOnly": "bun run lint && bun run typecheck",
Expand All @@ -70,6 +71,7 @@
"@types/react": "^19.2.14",
"oxfmt": "^0.44.0",
"oxlint": "^1.59.0",
"tuistory": "^0.3.0",
"typescript": "^5.9.3"
},
"engines": {
Expand Down
82 changes: 82 additions & 0 deletions packages/app/test/integration/cli.integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { afterEach, expect, test } from "bun:test";
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
import type { Session } from "tuistory";
import { closeSessionSafely, getScreenText, launchTermdraw, waitForChrome } from "./helpers";

const sessions: Session[] = [];

afterEach(async () => {
while (sessions.length > 0) {
const session = sessions.pop();
if (session) {
await closeSessionSafely(session);
}
}
});

test("termdraw launches with the full chrome visible", async () => {
const session = await launchTermdraw();
sessions.push(session);

const text = await waitForChrome(session);

expect(text.includes("Select")).toBe(true);
expect(text.includes("Box")).toBe(true);
expect(text.includes("Line")).toBe(true);
expect(text.includes("Brush")).toBe(true);
expect(text.includes("Text")).toBe(true);
expect(text.includes("Ctrl+Q") || text.includes("Ctrl+S")).toBe(true);
});

test("Ctrl+Q cancels and exits cleanly", async () => {
const session = await launchTermdraw();
sessions.push(session);

await waitForChrome(session);
await session.press(["ctrl", "q"]);
await session.waitIdle({ timeout: 1_000 });

const output = session.readAll();
expect(output.includes("Drawing cancelled.")).toBe(true);
expect(session.isDead).toBe(true);
});

test("saving with --output writes a file after drawing and saving", async () => {
const tempDir = mkdtempSync(join(tmpdir(), "termdraw-tuistory-"));
const outputPath = join(tempDir, "drawing.txt");

try {
const session = await launchTermdraw(["--output", outputPath]);
sessions.push(session);

await waitForChrome(session);
await session.press("t");
await session.press(["ctrl", "s"]);
await session.waitIdle({ timeout: 1_500 });

expect(session.isDead).toBe(true);
expect(existsSync(outputPath)).toBe(true);

const saved = readFileSync(outputPath, "utf8");
expect(saved.endsWith("\n")).toBe(true);

const output = session.readAll();
expect(output.includes(`Saved drawing to ${outputPath}`)).toBe(true);
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
});

test("tool hotkeys update the visible palette state", async () => {
const session = await launchTermdraw();
sessions.push(session);

await waitForChrome(session);
await session.press("t");

const text = await getScreenText(session);
expect(text.includes("No border")).toBe(true);
expect(text.includes("Double")).toBe(true);
});
40 changes: 40 additions & 0 deletions packages/app/test/integration/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { launchTerminal, type Session } from "tuistory";

const TERM_COLS = 120;
const TERM_ROWS = 36;

export async function launchTermdraw(args: string[] = []): Promise<Session> {
return launchTerminal({
command: "bun",
args: ["run", "src/cli.tsx", ...args],
cwd: new URL("../..", import.meta.url).pathname,
cols: TERM_COLS,
rows: TERM_ROWS,
waitForDataTimeout: 10_000,
env: {
CI: process.env.CI,
NO_COLOR: "1",
},
});
}

export async function getScreenText(session: Session): Promise<string> {
return session.text({
timeout: 5_000,
trimEnd: true,
});
}

export async function waitForChrome(session: Session): Promise<string> {
return session.waitForText(/Select|Box|Line|Brush|Text/, {
timeout: 10_000,
});
}

export async function closeSessionSafely(session: Session): Promise<void> {
try {
session.close();
} catch {
// best effort cleanup in tests
}
}