Skip to content
Closed
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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ transfers.
Bun, TypeScript, Hono, `bun:sqlite`. No build step for the web page
(`public/index.html` is served as-is).

## Run it

```sh
bun install
bun run dev
```

`bun run dev` serves the web page and API on http://localhost:3200 (set
`PORT` to use another port). Demo data is seeded into `splitbill.sqlite`
on first run.

The CLI reads the same database:

```sh
bun run src/cli.ts groups
bun run src/cli.ts balances <group>
bun run src/cli.ts export <group>
```

## Layout

```
Expand Down
40 changes: 40 additions & 0 deletions tests/readme.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { join } from "node:path";

const root = join(import.meta.dir, "..");
const readme = readFileSync(join(root, "README.md"), "utf8");
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
const server = readFileSync(join(root, "src/server.ts"), "utf8");
const cli = readFileSync(join(root, "src/cli.ts"), "utf8");

function runItSection(): string {
const start = readme.indexOf("\n## Run it\n");
if (start === -1) return "";
const rest = readme.slice(start + 1);
const next = rest.indexOf("\n## ", 1);
return next === -1 ? rest : rest.slice(0, next);
}

describe("README Run it", () => {
test("Run it section lists install, dev and URL", () => {
const section = runItSection();
expect(section).not.toBe("");
expect(section).toContain("bun install");
expect(section).toContain("bun run dev");
expect(section).toContain("http://localhost:3200");
});

test("Run it section has a CLI example", () => {
expect(runItSection()).toContain("bun run src/cli.ts groups");
expect(readme).toContain("balances <group>");
expect(readme).toContain("export <group>");
expect(cli).toContain("splitbill balances <group-id>");
expect(cli).toContain("splitbill export <group-id>");
});

test("Run it commands match package.json and server default port", () => {
expect(pkg.scripts.dev).toBe("bun run src/server.ts");
expect(server).toContain("process.env.PORT ?? 3200");
});
});
Loading