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
256 changes: 250 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"README.md"
],
"scripts": {
"build": "tsup src/cli.ts --format esm --out-dir dist --target node20 --clean",
"build": "tsup src/cli.ts src/discord-bot-cli.ts --format esm --out-dir dist --target node20 --clean",
"local": "npm run build && node dist/cli.js",
"dev": "tsx src/cli.ts",
"discord-bot": "tsx src/discord-bot-cli.ts",
"discord-bot:build": "npm run build && node dist/discord-bot-cli.js",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"test:e2e": "bash scripts/docker-e2e-test.sh",
Expand All @@ -34,6 +36,7 @@
},
"dependencies": {
"@clack/prompts": "^1.1.0",
"discord.js": "^14.25.1",
"ws": "^8.19.0"
},
"devDependencies": {
Expand Down
35 changes: 35 additions & 0 deletions src/__tests__/discord-bot.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { describe, it, expect } from "vitest";
import { splitMessage } from "../discord-bot.js";

describe("splitMessage", () => {
it("returns single chunk when text fits", () => {
const result = splitMessage("hello world", 2000);
expect(result).toEqual(["hello world"]);
});

it("splits at newline boundary when possible", () => {
const line = "a".repeat(90);
const text = `${line}\n${line}\n${line}`;
const result = splitMessage(text, 200);
expect(result.length).toBeGreaterThan(1);
// Each chunk should be within limit
for (const chunk of result) {
expect(chunk.length).toBeLessThanOrEqual(200);
}
// Concatenated chunks should equal original (minus stripped newlines)
expect(result.join("\n")).toBe(text);
});

it("hard-splits when no newline is found", () => {
const text = "a".repeat(500);
const result = splitMessage(text, 200);
expect(result.length).toBe(3);
expect(result[0].length).toBe(200);
expect(result[1].length).toBe(200);
expect(result[2].length).toBe(100);
});

it("handles empty string", () => {
expect(splitMessage("", 100)).toEqual([""]);
});
});
Loading
Loading