mirror of
https://github.com/typesense/typesense.git
synced 2025-05-17 12:12:35 +08:00
- add cli entrypoint with version and help commands - set up command structure using commander.js - add signal handlers for SIGINT and SIGTERM - add integration tests for command behavior - use package version from package.json
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { exec } from "node:child_process";
|
|
import path from "node:path";
|
|
import { promisify } from "node:util";
|
|
|
|
import { beforeAll, describe, expect, test } from "vitest";
|
|
|
|
import { getPackageInfo } from "../src/utils/package-info";
|
|
|
|
const execAsync = promisify(exec);
|
|
const CLI_PATH = path.resolve("./dist/index.js");
|
|
|
|
describe("CLI Integration", () => {
|
|
beforeAll(async () => {
|
|
// Build the CLI before running tests
|
|
await execAsync("pnpm build");
|
|
});
|
|
|
|
test("displays version with -v flag", async () => {
|
|
const { stdout } = await execAsync(`node ${CLI_PATH} -v`);
|
|
expect(stdout.trim()).toBe(getPackageInfo().version);
|
|
});
|
|
|
|
test("displays help with no arguments", async () => {
|
|
const { stdout } = await execAsync(`node ${CLI_PATH}`);
|
|
expect(stdout).toContain("Typesense CLI");
|
|
expect(stdout).toContain("Utilities for Typesense");
|
|
});
|
|
|
|
test("displays help with --help flag", async () => {
|
|
const { stdout } = await execAsync(`node ${CLI_PATH} --help`);
|
|
expect(stdout).toContain("Typesense CLI");
|
|
expect(stdout).toContain("Utilities for Typesense");
|
|
});
|
|
|
|
test("displays version with --version flag", async () => {
|
|
const { stdout } = await execAsync(`node ${CLI_PATH} --version`);
|
|
expect(stdout.trim()).toBe(getPackageInfo().version);
|
|
});
|
|
|
|
test("handles invalid commands", async () => {
|
|
await expect(
|
|
execAsync(`node ${CLI_PATH} invalid-command`),
|
|
).rejects.toThrow();
|
|
});
|
|
});
|