refactor: init 命令使用 CommandError
This commit is contained in:
@@ -3,6 +3,7 @@ import { existsSync } from "node:fs";
|
||||
import { mkdir, rm, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { runInit } from "../../src/commands/init.ts";
|
||||
import { CommandError } from "../../src/cli/errors.ts";
|
||||
|
||||
const TMP_DIR = join(import.meta.dir, "__tmp_init_test__");
|
||||
|
||||
@@ -57,9 +58,13 @@ describe("runInit", () => {
|
||||
expect(content).toBe("自定义内容");
|
||||
});
|
||||
|
||||
it("不支持的工具名抛出错误", async () => {
|
||||
await expect(runInit(TMP_DIR, ["unknown-tool"])).rejects.toThrow(
|
||||
"不支持的工具",
|
||||
);
|
||||
it("不支持的工具名抛出 CommandError", async () => {
|
||||
try {
|
||||
await runInit(TMP_DIR, ["unknown-tool"]);
|
||||
expect.unreachable("应抛出错误");
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(CommandError);
|
||||
expect((e as CommandError).message).toContain("不支持的工具: unknown-tool");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user