UNPKG

ccexp

Version:

CLI tool for exploring and managing Claude Code settings and slash commands

204 lines (191 loc) 6.43 kB
import { __toESM, require_usingCtx } from "./usingCtx-BLgT6AjQ.js"; import { k } from "./dist-TTmWmO-C.js"; import "es-toolkit/array"; import "es-toolkit/compat"; import { match } from "ts-pattern"; //#region src/test-fixture-helpers.ts var import_usingCtx = __toESM(require_usingCtx(), 1); /** * Default CLAUDE.md content for testing */ const DEFAULT_CLAUDE_MD = `# CLAUDE.md This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. ## Overview Test project for validating fs-fixture integration. ## Commands - \`bun run test\` - Run tests - \`bun run build\` - Build project `; /** * Default CLAUDE.local.md content for testing */ const DEFAULT_CLAUDE_LOCAL_MD = `# CLAUDE.local.md Local configuration overrides for this project. ## Local Settings - Custom API endpoints - Development-specific configurations `; /** * Default slash command content */ const createSlashCommandContent = (name, description = "") => `# /${name} ${description || `Execute the ${name} command`} ## Usage \`\`\`bash /${name} [options] \`\`\` `; /** * Create a Claude project fixture with typical project structure */ async function createClaudeProjectFixture(options) { const { projectName = "test-project", includeLocal = false, includeCommands = false, additionalFiles = {} } = options || {}; const fileTree = { [projectName]: { "CLAUDE.md": DEFAULT_CLAUDE_MD, "package.json": JSON.stringify({ name: projectName, version: "1.0.0", type: "module" }, null, 2), src: { "index.ts": "export const hello = () => \"Hello, World!\";", "utils.ts": "export const noop = () => {};" }, ...additionalFiles } }; if (includeLocal) { const projectFiles = fileTree[projectName]; projectFiles["CLAUDE.local.md"] = DEFAULT_CLAUDE_LOCAL_MD; } if (includeCommands) { const projectFiles = fileTree[projectName]; projectFiles[".claude"] = { commands: { "test.md": createSlashCommandContent("test", "Run project tests"), "build.md": createSlashCommandContent("build", "Build the project"), "deploy.md": createSlashCommandContent("deploy", "Deploy to production") } }; } return k(fileTree); } /** * High-order function to run tests with a temporary fixture * Automatically cleans up using TypeScript 'using' keyword */ async function withTempFixture(fileTree, callback) { try { var _usingCtx = (0, import_usingCtx.default)(); const fixture = _usingCtx.a(await k(fileTree)); return callback(fixture); } catch (_) { _usingCtx.e = _; } finally { await _usingCtx.d(); } } /** * Common test pattern helper for DRY - simplifies fixture-based tests */ async function testWithFixture(fixtureDef, testFn) { return withTempFixture(fixtureDef, testFn); } /** * Utility to create a complex project structure for testing */ async function createComplexProjectFixture() { return k({ "my-app": { "CLAUDE.md": DEFAULT_CLAUDE_MD, "CLAUDE.local.md": DEFAULT_CLAUDE_LOCAL_MD, ".claude": { commands: { "dev.md": createSlashCommandContent("dev", "Start development server"), "test.md": createSlashCommandContent("test", "Run tests"), "lint.md": createSlashCommandContent("lint", "Run linter"), production: { "deploy.md": createSlashCommandContent("deploy", "Deploy to production"), "rollback.md": createSlashCommandContent("rollback", "Rollback deployment") } } }, src: { components: { "Button.tsx": "export const Button = () => <button>Click me</button>;", "Input.tsx": "export const Input = () => <input />;" }, utils: { "helpers.ts": "export const helper = () => {};", "constants.ts": "export const API_URL = \"https://api.example.com\";" }, "index.ts": "export { Button } from \"./components/Button\";", "App.tsx": "export const App = () => <div>Hello</div>;" }, tests: { "App.test.tsx": "test(\"App renders\", () => {});" }, "package.json": JSON.stringify({ name: "my-app", version: "2.0.0", scripts: { dev: "vite", build: "vite build", test: "vitest" }, dependencies: { react: "^18.0.0", typescript: "^5.0.0" } }, null, 2), "README.md": "# My App\n\nAwesome application", ".gitignore": "node_modules\ndist\n.env" } }); } if (import.meta.vitest != null) { const { describe, test, expect } = import.meta.vitest; describe("test-fixture-helpers", () => { test("createClaudeProjectFixture creates project structure", async () => { try { var _usingCtx3 = (0, import_usingCtx.default)(); const fixture = _usingCtx3.a(await createClaudeProjectFixture({ projectName: "test-app", includeLocal: true, includeCommands: true })); expect(await fixture.exists("test-app/CLAUDE.md")).toBe(true); expect(await fixture.exists("test-app/CLAUDE.local.md")).toBe(true); expect(await fixture.exists("test-app/.claude/commands/test.md")).toBe(true); expect(await fixture.exists("test-app/src/index.ts")).toBe(true); } catch (_) { _usingCtx3.e = _; } finally { await _usingCtx3.d(); } }); test("withTempFixture provides automatic cleanup", async () => { let fixturePath; const result = await withTempFixture({ "test.txt": "Hello" }, async (fixture) => { fixturePath = fixture.path; expect(await fixture.exists("test.txt")).toBe(true); return "success"; }); expect(result).toBe("success"); if (fixturePath) { const { access } = await import("node:fs/promises"); await expect(access(fixturePath)).rejects.toThrow(); } }); test("createComplexProjectFixture creates realistic structure", async () => { try { var _usingCtx4 = (0, import_usingCtx.default)(); const fixture = _usingCtx4.a(await createComplexProjectFixture()); expect(await fixture.exists("my-app/CLAUDE.md")).toBe(true); expect(await fixture.exists("my-app/.claude/commands/production/deploy.md")).toBe(true); expect(await fixture.exists("my-app/src/components/Button.tsx")).toBe(true); expect(await fixture.exists("my-app/tests/App.test.tsx")).toBe(true); const claudeMd = await fixture.readFile("my-app/CLAUDE.md", "utf-8"); expect(claudeMd).toContain("CLAUDE.md"); } catch (_) { _usingCtx4.e = _; } finally { await _usingCtx4.d(); } }); }); } //#endregion export { DEFAULT_CLAUDE_MD, createClaudeProjectFixture, createComplexProjectFixture, testWithFixture, withTempFixture }; //# sourceMappingURL=test-fixture-helpers-jC6qse8O.js.map