Files
ruflo/tests/unit/cli/simple-commands/monitor.test.js
T
rUvandClaude 63d391e10b 🚀 Release: Claude Flow v2.0.0-alpha.62
## 🔒 Security Fixes
- CRITICAL: Removed vulnerable pkg dependency (GHSA-22r3-9w55-cj54)
- Replaced with secure @vercel/ncc alternative
- Security score improved from 55/100 to 75/100
- All npm audit vulnerabilities resolved (0 vulnerabilities)

## 🚀 Infrastructure Improvements
- Re-enabled ALL CI/CD security gates with strict enforcement
- Fixed Jest configuration and test infrastructure
- Fixed 18 TypeScript test files with import issues
- Created comprehensive test utilities

## 🛠️ Code Quality
- Fixed 145 ESLint errors (16% reduction)
- Fixed 15 critical TypeScript errors
- Added development tooling configs

## 📚 Documentation
- Created security audit report
- Created fix summary documentation
- Created functionality review
- Updated GitHub issue #362

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-18 13:35:41 +00:00

87 lines
2.8 KiB
JavaScript

import { jest, describe, test, beforeEach, afterEach, expect } from '@jest/globals';
describe('monitor.js - Real Metrics Implementation', () => {
let consoleSpy;
let processExitSpy;
beforeEach(() => {
// Setup console spies
consoleSpy = {
log: jest.spyOn(console, 'log').mockImplementation(),
clear: jest.spyOn(console, 'clear').mockImplementation(),
error: jest.spyOn(console, 'error').mockImplementation()
};
// Setup process spies
processExitSpy = jest.spyOn(process, 'exit').mockImplementation();
});
afterEach(() => {
// Restore all spies
Object.values(consoleSpy).forEach(spy => spy.mockRestore());
processExitSpy.mockRestore();
});
describe('Basic Functionality', () => {
test('should import without errors', async () => {
const monitor = await import('../../../../src/cli/simple-commands/monitor.js');
expect(monitor.monitorCommand).toBeDefined();
expect(monitor.showMonitorHelp).toBeDefined();
});
test('should collect and display metrics', async () => {
const { monitorCommand } = await import('../../../../src/cli/simple-commands/monitor.js');
await monitorCommand([], {});
// Check if metrics were displayed
const output = consoleSpy.log.mock.calls.join('\n');
expect(output).toContain('System Metrics');
});
test('should show help information', async () => {
const { showMonitorHelp } = await import('../../../../src/cli/simple-commands/monitor.js');
showMonitorHelp();
const output = consoleSpy.log.mock.calls.join('\n');
expect(output).toContain('Monitor commands:');
expect(output).toContain('--interval');
expect(output).toContain('--format');
});
});
describe('Output Formats', () => {
test('should output JSON format when specified', async () => {
const { monitorCommand } = await import('../../../../src/cli/simple-commands/monitor.js');
await monitorCommand(['--format', 'json'], {});
const calls = consoleSpy.log.mock.calls;
const jsonOutput = calls.find(call => {
try {
JSON.parse(call[0]);
return true;
} catch {
return false;
}
});
expect(jsonOutput).toBeDefined();
if (jsonOutput) {
const parsed = JSON.parse(jsonOutput[0]);
expect(parsed).toHaveProperty('timestamp');
expect(parsed).toHaveProperty('system');
}
});
test('should output pretty format by default', async () => {
const { monitorCommand } = await import('../../../../src/cli/simple-commands/monitor.js');
await monitorCommand([], {});
const output = consoleSpy.log.mock.calls.join('\n');
expect(output).toMatch(/System Metrics|System Resources|Performance/);
});
});
});