UNPKG

ctrlshiftleft

Version:

AI-powered toolkit for embedding QA and security testing into development workflows

139 lines (120 loc) 4.44 kB
#!/usr/bin/env node /** * NPM Import Test Script * * This script verifies that the ctrl.shift.left package can be correctly imported * and that the main API functions and classes are available. */ const path = require('path'); const fs = require('fs'); const { execSync } = require('child_process'); // ANSI color codes for pretty output const COLORS = { reset: '\x1b[0m', bright: '\x1b[1m', green: '\x1b[32m', yellow: '\x1b[33m', red: '\x1b[31m', cyan: '\x1b[36m' }; // Print a colored message function log(message, type = 'info') { switch (type) { case 'success': console.log(`${COLORS.green}✓ ${message}${COLORS.reset}`); break; case 'error': console.log(`${COLORS.red}✗ ERROR: ${message}${COLORS.reset}`); break; case 'warning': console.log(`${COLORS.yellow}⚠ WARNING: ${message}${COLORS.reset}`); break; case 'step': console.log(`\n${COLORS.cyan}${COLORS.bright}${message}${COLORS.reset}`); break; default: console.log(message); } } // Main test function async function main() { log('Testing ctrl.shift.left NPM Import', 'step'); // Create a temporary test directory const tempDir = path.join(__dirname, '..', 'npm-test-dir'); if (fs.existsSync(tempDir)) { fs.rmSync(tempDir, { recursive: true, force: true }); } fs.mkdirSync(tempDir); try { // Create a package.json log('Creating test package.json', 'step'); const packageJson = { name: 'ctrlshiftleft-test', version: '1.0.0', description: 'Test project for ctrlshiftleft', main: 'test.js', type: 'commonjs' }; fs.writeFileSync( path.join(tempDir, 'package.json'), JSON.stringify(packageJson, null, 2) ); // Create a test file log('Creating test script', 'step'); const testScript = ` const ctrlShiftLeft = require('ctrlshiftleft'); // Test API import console.log('\\nAPI Functions Available:'); console.log('- generateTests:', typeof ctrlShiftLeft.generateTests === 'function'); console.log('- runTests:', typeof ctrlShiftLeft.runTests === 'function'); console.log('- generateChecklist:', typeof ctrlShiftLeft.generateChecklist === 'function'); console.log('- analyzeSecurityWithAI:', typeof ctrlShiftLeft.analyzeSecurityWithAI === 'function'); console.log('- isAISecurityAvailable:', typeof ctrlShiftLeft.isAISecurityAvailable === 'function'); // Test class import console.log('\\nAPI Classes Available:'); console.log('- TestGenerator:', typeof ctrlShiftLeft.TestGenerator === 'function'); console.log('- ChecklistGenerator:', typeof ctrlShiftLeft.ChecklistGenerator === 'function'); console.log('- EnhancedWatcher:', typeof ctrlShiftLeft.EnhancedWatcher === 'function'); // Test EnhancedWatcher instantiation with OpenAI dependency handling console.log('\\nTesting EnhancedWatcher...'); try { // Configure with AI disabled to avoid OpenAI API key requirement const watcher = new ctrlShiftLeft.EnhancedWatcher({ useAIAnalysis: false }); console.log('- EnhancedWatcher instantiated successfully'); console.log('- isAIAvailable:', typeof watcher.isAIAvailable === 'function'); console.log('- watch:', typeof watcher.watch === 'function'); console.log('- stop:', typeof watcher.stop === 'function'); } catch (error) { console.log('- EnhancedWatcher instantiation threw error (possibly due to missing OpenAI API key)'); console.log('- Class exists but requires proper configuration'); } console.log('\\nImport Test Completed Successfully!'); process.exit(0); `; fs.writeFileSync(path.join(tempDir, 'test.js'), testScript); // Link the local package log('Linking local package', 'step'); process.chdir(tempDir); log('Installing local ctrlshiftleft package...'); execSync('npm link ctrlshiftleft', { stdio: 'inherit' }); // Run the test log('Running import test', 'step'); execSync('node test.js', { stdio: 'inherit' }); // Clean up process.chdir(path.join(__dirname, '..')); fs.rmSync(tempDir, { recursive: true, force: true }); log('Import test completed successfully!', 'success'); } catch (error) { log(`Import test failed: ${error.message}`, 'error'); console.error(error); process.exit(1); } } // Run the main function main().catch(error => { log(`Unexpected error: ${error.message}`, 'error'); console.error(error); process.exit(1); });