name: cli-snapshot-tester description: 为CLI输出设置快照测试,包含更新工作流和差异报告。 allowed-tools: 读取,写入,编辑,Bash,Glob,Grep
CLI快照测试器
为CLI输出设置快照测试。
生成的模式
import { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
export function runCliSnapshot(cmd: string, name: string): void {
const output = execSync(cmd, { encoding: 'utf-8' });
const snapshotPath = path.join('__snapshots__', `${name}.txt`);
if (process.env.UPDATE_SNAPSHOTS) {
fs.mkdirSync(path.dirname(snapshotPath), { recursive: true });
fs.writeFileSync(snapshotPath, output);
return;
}
const expected = fs.readFileSync(snapshotPath, 'utf-8');
expect(output).toBe(expected);
}
目标流程
- cli单元集成测试
- cli文档生成