creatrip-agent-rules-builder
Version:
Unified converter for AI coding agent rules across Cursor, Windsurf, and Claude
104 lines (87 loc) • 3.21 kB
text/typescript
import * as fs from "fs";
import * as path from "path";
import { generateCursorRules } from "../src/generators/cursor";
import { generateWindsurfRules } from "../src/generators/windsurf";
import { generateClaudeRules } from "../src/generators/claude";
import { ParsedContent } from "../src/types";
describe("Generators", () => {
const testOutputDir = path.join(__dirname, "temp-output");
const originalCwd = process.cwd();
beforeEach(() => {
// 테스트용 임시 디렉토리 생성
if (!fs.existsSync(testOutputDir)) {
fs.mkdirSync(testOutputDir, { recursive: true });
}
process.chdir(testOutputDir);
});
afterEach(() => {
// 원래 디렉토리로 복원 및 정리
process.chdir(originalCwd);
if (fs.existsSync(testOutputDir)) {
fs.rmSync(testOutputDir, { recursive: true, force: true });
}
});
const mockParsedContent: ParsedContent = {
rules: "# Test Rules\n- Rule 1\n- Rule 2",
config: {
cursor: {
globs: ["*.ts", "*.tsx"],
description: "Test cursor rules",
},
},
};
describe("generateCursorRules", () => {
it("should generate cursor rules with frontmatter", () => {
generateCursorRules(mockParsedContent, testOutputDir);
const filePath = path.join(
testOutputDir,
".cursor",
"rules",
"rules.mdc"
);
expect(fs.existsSync(filePath)).toBe(true);
const content = fs.readFileSync(filePath, "utf8");
expect(content).toContain("---");
expect(content).toContain("description: Test cursor rules");
expect(content).toContain("globs: *.ts,*.tsx");
expect(content).toContain("# Test Rules");
});
it("should generate cursor rules with default frontmatter when no config", () => {
const noConfigContent: ParsedContent = {
rules: "# Simple Rules",
config: {},
};
generateCursorRules(noConfigContent, testOutputDir);
const filePath = path.join(
testOutputDir,
".cursor",
"rules",
"rules.mdc"
);
const content = fs.readFileSync(filePath, "utf8");
expect(content).toContain("---");
expect(content).toContain("description: ");
expect(content).toContain("globs: ");
expect(content).toContain("alwaysApply: false");
expect(content).toContain("# Simple Rules");
});
});
describe("generateWindsurfRules", () => {
it("should generate windsurf rules file", () => {
generateWindsurfRules(mockParsedContent, testOutputDir);
const filePath = path.join(testOutputDir, ".windsurfrules");
expect(fs.existsSync(filePath)).toBe(true);
const content = fs.readFileSync(filePath, "utf8");
expect(content).toBe("# Test Rules\n- Rule 1\n- Rule 2");
});
});
describe("generateClaudeRules", () => {
it("should generate claude rules file", () => {
generateClaudeRules(mockParsedContent, testOutputDir);
const filePath = path.join(testOutputDir, "CLAUDE.md");
expect(fs.existsSync(filePath)).toBe(true);
const content = fs.readFileSync(filePath, "utf8");
expect(content).toBe("# Test Rules\n- Rule 1\n- Rule 2");
});
});
});