99 lines
3.2 KiB
TypeScript
99 lines
3.2 KiB
TypeScript
/**
|
|
* Project template tools tests
|
|
*/
|
|
|
|
import { describe, test, expect, beforeEach, afterEach } from "bun:test";
|
|
import { registerProjectTemplateTools } from "../../../../src/tools/programming/projectTemplate.js";
|
|
import { callTool } from "../../../helpers/tool-helper.js";
|
|
import { createTempDir } from "../../../helpers/test-utils.js";
|
|
import { existsSync, readFileSync } from "fs";
|
|
import { join } from "path";
|
|
|
|
describe("Project Template Tools", () => {
|
|
let testContext: ReturnType<typeof createTempDir>;
|
|
|
|
beforeEach(() => {
|
|
testContext = createTempDir();
|
|
registerProjectTemplateTools();
|
|
});
|
|
|
|
afterEach(() => {
|
|
testContext.cleanup();
|
|
});
|
|
|
|
test("should create Vite + Vue3 project", async () => {
|
|
const projectName = "test-vue-project";
|
|
const projectPath = join(testContext.tempDir, projectName);
|
|
|
|
const result = await callTool("project_template_create", {
|
|
name: projectName,
|
|
path: testContext.tempDir,
|
|
});
|
|
|
|
expect(result.content[0].text).toContain("created successfully");
|
|
expect(existsSync(join(projectPath, "package.json"))).toBe(true);
|
|
expect(existsSync(join(projectPath, "vite.config.ts"))).toBe(true);
|
|
expect(existsSync(join(projectPath, "src", "main.ts"))).toBe(true);
|
|
expect(existsSync(join(projectPath, "src", "App.vue"))).toBe(true);
|
|
});
|
|
|
|
test("should create project with Pinia", async () => {
|
|
const projectName = "test-vue-pinia";
|
|
const projectPath = join(testContext.tempDir, projectName);
|
|
|
|
await callTool("project_template_create", {
|
|
name: projectName,
|
|
path: testContext.tempDir,
|
|
usePinia: true,
|
|
});
|
|
|
|
const packageJson = JSON.parse(
|
|
readFileSync(join(projectPath, "package.json"), "utf-8")
|
|
);
|
|
expect(packageJson.dependencies.pinia).toBeDefined();
|
|
});
|
|
|
|
test("should create fullstack project", async () => {
|
|
const projectName = "test-fullstack";
|
|
const projectPath = join(testContext.tempDir, projectName);
|
|
|
|
const result = await callTool("project_template_create_fullstack", {
|
|
name: projectName,
|
|
path: testContext.tempDir,
|
|
});
|
|
|
|
expect(result.content[0].text).toContain("created successfully");
|
|
expect(existsSync(join(projectPath, "frontend", "package.json"))).toBe(
|
|
true
|
|
);
|
|
expect(existsSync(join(projectPath, "backend", "package.json"))).toBe(true);
|
|
expect(existsSync(join(projectPath, "backend", "src", "index.ts"))).toBe(
|
|
true
|
|
);
|
|
});
|
|
|
|
test("should list available templates", async () => {
|
|
const result = await callTool("project_template_list", {});
|
|
|
|
expect(result.content[0].text).toContain("Available project templates");
|
|
expect(result.content[0].text).toContain("Vite + Vue3");
|
|
expect(result.content[0].text).toContain("Fullstack");
|
|
});
|
|
|
|
test("should handle existing directory error", async () => {
|
|
const projectName = "existing-project";
|
|
const projectPath = join(testContext.tempDir, projectName);
|
|
|
|
// Create directory first
|
|
const { mkdirSync } = await import("fs");
|
|
mkdirSync(projectPath, { recursive: true });
|
|
|
|
const result = await callTool("project_template_create", {
|
|
name: projectName,
|
|
path: testContext.tempDir,
|
|
});
|
|
|
|
expect(result.content[0].text).toContain("already exists");
|
|
});
|
|
});
|