agentic-qe
Version:
Agentic Quality Engineering Fleet System - AI-driven quality management platform
177 lines • 6.91 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSnapshotCommand = void 0;
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
function createSnapshotCommand() {
const command = new commander_1.Command('snapshot');
command
.description('Snapshot testing management and updates')
.option('-u, --update', 'Update snapshots', false)
.option('-p, --pattern <pattern>', 'Update only matching snapshots')
.option('--diff', 'Show snapshot differences', false)
.option('--clean', 'Remove obsolete snapshots', false)
.option('--list', 'List all snapshots', false)
.option('--coverage', 'Show snapshot coverage', false)
.action(async (options) => {
if (options.list) {
await listSnapshots();
return;
}
if (options.clean) {
await cleanSnapshots();
return;
}
if (options.diff) {
await showSnapshotDiff();
return;
}
if (options.coverage) {
await showSnapshotCoverage();
return;
}
if (options.update) {
await updateSnapshots(options.pattern);
return;
}
console.log(chalk_1.default.yellow('No action specified. Use --help for options.'));
});
return command;
}
exports.createSnapshotCommand = createSnapshotCommand;
async function updateSnapshots(pattern) {
console.log(chalk_1.default.bold('Updating snapshots...\n'));
if (pattern) {
console.log(chalk_1.default.gray(`Pattern: ${pattern}\n`));
}
const snapshots = getSnapshots(pattern);
for (const snapshot of snapshots) {
console.log(chalk_1.default.cyan(`Updating: ${snapshot.name}`));
// Simulate snapshot update
await new Promise(resolve => setTimeout(resolve, 200));
console.log(chalk_1.default.green(`✓ Updated: ${snapshot.file}`));
}
console.log(chalk_1.default.bold(`\n✓ Updated ${snapshots.length} snapshot(s)`));
}
async function listSnapshots() {
console.log(chalk_1.default.bold('Snapshots:\n'));
const snapshots = getSnapshots();
if (snapshots.length === 0) {
console.log(chalk_1.default.yellow('No snapshots found'));
return;
}
snapshots.forEach((snapshot, index) => {
console.log(chalk_1.default.bold(`${index + 1}. ${snapshot.name}`));
console.log(chalk_1.default.gray(` File: ${snapshot.file}`));
console.log(chalk_1.default.gray(` Size: ${formatBytes(snapshot.size)}`));
console.log(chalk_1.default.gray(` Created: ${snapshot.created.toISOString()}`));
console.log(chalk_1.default.gray(` Status: ${snapshot.used ? 'Active' : chalk_1.default.red('Obsolete')}\n`));
});
console.log(chalk_1.default.gray(`Total: ${snapshots.length} snapshot(s)`));
}
async function cleanSnapshots() {
console.log(chalk_1.default.bold('Cleaning obsolete snapshots...\n'));
const snapshots = getSnapshots();
const obsolete = snapshots.filter(s => !s.used);
if (obsolete.length === 0) {
console.log(chalk_1.default.green('No obsolete snapshots found'));
return;
}
for (const snapshot of obsolete) {
console.log(chalk_1.default.yellow(`Removing: ${snapshot.name}`));
// Simulate removal
await new Promise(resolve => setTimeout(resolve, 100));
console.log(chalk_1.default.green(`✓ Removed: ${snapshot.file}`));
}
console.log(chalk_1.default.bold(`\n✓ Cleaned ${obsolete.length} obsolete snapshot(s)`));
}
async function showSnapshotDiff() {
console.log(chalk_1.default.bold('Snapshot Diff:\n'));
const diffs = [
{
name: 'Component.test.ts',
snapshot: '__snapshots__/Component.test.ts.snap',
changes: [
{ line: 10, old: ' <div>Hello</div>', new: ' <div>Hello World</div>' },
{ line: 15, old: ' color: "red"', new: ' color: "blue"' }
]
}
];
for (const diff of diffs) {
console.log(chalk_1.default.cyan(`${diff.name} → ${diff.snapshot}`));
console.log(chalk_1.default.gray('─'.repeat(60)));
diff.changes.forEach(change => {
console.log(chalk_1.default.red(`- ${change.old}`));
console.log(chalk_1.default.green(`+ ${change.new}`));
console.log('');
});
}
console.log(chalk_1.default.bold('Run with --update to accept changes'));
}
async function showSnapshotCoverage() {
console.log(chalk_1.default.bold('Snapshot Coverage:\n'));
const stats = {
totalTests: 50,
testsWithSnapshots: 35,
totalSnapshots: 42,
activeSnapshots: 38,
obsoleteSnapshots: 4
};
const coverage = (stats.testsWithSnapshots / stats.totalTests) * 100;
console.log(`Total tests: ${stats.totalTests}`);
console.log(`Tests with snapshots: ${stats.testsWithSnapshots}`);
console.log(`Snapshot coverage: ${chalk_1.default.bold(coverage.toFixed(1) + '%')}`);
console.log('');
console.log(`Total snapshots: ${stats.totalSnapshots}`);
console.log(chalk_1.default.green(`Active: ${stats.activeSnapshots}`));
console.log(chalk_1.default.yellow(`Obsolete: ${stats.obsoleteSnapshots}`));
// Coverage bar
const barLength = 40;
const filledLength = Math.floor((coverage / 100) * barLength);
const bar = '█'.repeat(filledLength) + '░'.repeat(barLength - filledLength);
console.log(`\n${bar} ${coverage.toFixed(1)}%`);
}
function getSnapshots(pattern) {
const mockSnapshots = [
{
name: 'Auth Component',
file: '__snapshots__/Auth.test.ts.snap',
size: 1024,
created: new Date(),
used: true
},
{
name: 'Login Form',
file: '__snapshots__/LoginForm.test.ts.snap',
size: 2048,
created: new Date(),
used: true
},
{
name: 'Legacy Component',
file: '__snapshots__/Legacy.test.ts.snap',
size: 512,
created: new Date('2024-01-01'),
used: false
}
];
if (pattern) {
const regex = new RegExp(pattern.replace(/\*/g, '.*'));
return mockSnapshots.filter(s => regex.test(s.name));
}
return mockSnapshots;
}
function formatBytes(bytes) {
const units = ['B', 'KB', 'MB'];
let size = bytes;
let unitIndex = 0;
while (size >= 1024 && unitIndex < units.length - 1) {
size /= 1024;
unitIndex++;
}
return `${size.toFixed(2)} ${units[unitIndex]}`;
}
//# sourceMappingURL=snapshot.js.map