UNPKG

agentsqripts

Version:

Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems

94 lines (80 loc) 2.98 kB
/** * @file Unit tests for CLI help formatter utility * @description Tests help message generation and formatting for CLI tools */ const { createHelpFunction } = require('./helpFormatter'); const qtests = require('qtests'); /** * qtests test suite for help formatter */ function getTestSuite() { const { stubMethod, mockConsole, testHelpers, createAssertions } = require('qtests'); const assert = createAssertions(); return { 'createHelpFunction returns valid help function': async () => { await testHelpers.withSavedEnv(async () => { // Test basic help function creation const showHelp = createHelpFunction({ command: 'test-command.js', description: 'Test command description', options: [ { flag: '--test-flag', description: 'Test flag description' } ] }); assert.truthy(typeof showHelp === 'function', 'createHelpFunction should return a function'); }); }, 'help function produces formatted output': async () => { await testHelpers.withSavedEnv(async () => { // Use qtests console mocking for help output await testHelpers.withMockConsole('log', async (consoleSpy) => { const showHelp = createHelpFunction({ command: 'test-command.js', description: 'Test command description', options: [ { flag: '--output-format <fmt>', description: 'Output format: json, summary (default: summary)' }, { flag: '--help', description: 'Show this help message' } ], examples: [ 'node test-command.js .', 'node test-command.js --output-format json src/' ] }); // Execute help function showHelp(); // Verify help output contains expected content const helpOutput = consoleSpy.mock.calls.map(call => call[0]).join('\n'); assert.truthy(helpOutput.includes('test-command.js'), 'Help should include command name'); assert.truthy(helpOutput.includes('Test command description'), 'Help should include description'); }); }); } }; } module.exports = { getTestSuite }; // Auto-execute when run directly (for qtests-runner compatibility) if (require.main === module) { (async () => { const testSuite = getTestSuite(); let passed = 0; let failed = 0; for (const [testName, testFn] of Object.entries(testSuite)) { try { await testFn(); console.log(`✓ ${testName}`); passed++; } catch (error) { console.log(`✗ ${testName}`); console.error(`Error: ${error.message}`); failed++; } } if (failed > 0) { console.log(`\nSummary: ${passed} passed, ${failed} failed`); process.exit(1); } else { console.log(`\nSummary: ${passed} passed`); process.exit(0); } })(); }