UNPKG

claudes-office

Version:

CLI tool to initialize Claude's office in your project

102 lines (86 loc) 3.48 kB
#!/usr/bin/env node const fs = require('fs-extra'); const path = require('path'); const os = require('os'); const { spawn } = require('child_process'); const chalk = require('chalk'); async function runTest() { try { // Create a temporary test directory const testDir = path.join(os.tmpdir(), `claudes-office-test-${Date.now()}`); await fs.ensureDir(testDir); console.log(chalk.blue(`Created test directory: ${testDir}`)); // Create a dummy package.json in the test directory await fs.writeJson(path.join(testDir, 'package.json'), { name: 'test-project', version: '1.0.0' }); // Run the CLI command in the test directory with no-interactive flag // to avoid the need for interactive responses console.log(chalk.blue('Running the CLI command...')); const cliPath = path.join(__dirname, 'bin', 'claudes-office'); // Create a mock stdin to simulate user input process.env.NODE_OPTIONS = "--trace-warnings"; const childProcess = spawn('node', [cliPath, 'init', '--force'], { cwd: testDir, stdio: ['pipe', 'inherit', 'inherit'] // Use pipe for stdin to simulate input }); // Simulating user input automated responses to prompts // This is based on the prompts in lib/index.js // Define the sequence of inputs to simulate (with delays) const responses = [ { input: 'n\n', delay: 1000 }, // No custom name { input: ' \n', delay: 1000 }, // Select frontend project type (space to select, enter to continue) { input: ' \n', delay: 1000 }, // Select React { input: '\n', delay: 1000 }, // Skip backend selection { input: '\n', delay: 1000 }, // Skip additional technologies { input: 'y\n', delay: 1000 } // Yes to DevOps roles ]; // Schedule the input sequence let currentTimeout = 0; responses.forEach(response => { currentTimeout += response.delay; setTimeout(() => { console.log(chalk.yellow(`Sending simulated input: ${response.input.replace(/\n/g, '\\n')}`)); childProcess.stdin.write(response.input); }, currentTimeout); }); await new Promise((resolve, reject) => { childProcess.on('close', code => { if (code === 0) { resolve(); } else { reject(new Error(`Process exited with code ${code}`)); } }); }); // Check if the files were created correctly const filesCreated = [ 'CLAUDE.md', 'Initialize_Project.md', 'claudes-office' ]; let allFilesExist = true; for (const file of filesCreated) { const exists = await fs.pathExists(path.join(testDir, file)); if (exists) { console.log(chalk.green(`✓ ${file} was created successfully`)); } else { console.log(chalk.red(`✗ ${file} was not created`)); allFilesExist = false; } } if (allFilesExist) { console.log(chalk.green('\nTest passed! All files were created successfully.')); } else { console.log(chalk.red('\nTest failed! Some files were not created.')); } // Clean up console.log(chalk.blue('\nCleaning up test directory...')); await fs.remove(testDir); console.log(chalk.blue('Test directory removed.')); } catch (error) { console.error(chalk.red('Test failed with error:'), error); } } // Run the test runTest();