MCPcopy Create free account
hub / github.com/wonderwhy-er/DesktopCommanderMCP / testNodeREPL

Function testNodeREPL

test/test-node-repl.js:36–151  ·  view source on GitHub ↗

* Test Node.js REPL interaction directly

()

Source from the content-addressed store, hash-verified

34 * Test Node.js REPL interaction directly
35 */
36async function testNodeREPL() {
37 console.log(`${colors.blue}Direct Node.js REPL test...${colors.reset}`);
38
39 // Create output directory if it doesn't exist
40 const OUTPUT_DIR = path.join(__dirname, 'test_output');
41 try {
42 await fs.mkdir(OUTPUT_DIR, { recursive: true });
43 } catch (error) {
44 console.warn(`${colors.yellow}Warning: Could not create output directory: ${error.message}${colors.reset}`);
45 }
46
47 // File for debugging output
48 const debugFile = path.join(OUTPUT_DIR, 'node_repl_debug.txt');
49 let debugLog = '';
50
51 // Log both to console and to file
52 function log(message) {
53 console.log(message);
54 debugLog += message + '\n';
55 }
56
57 // Start Node.js REPL
58 log(`${colors.blue}Starting Node.js REPL...${colors.reset}`);
59
60 // Use the -i flag to ensure interactive mode
61 const node = spawn('node', ['-i']);
62
63 // Track all output
64 let outputBuffer = '';
65
66 // Set up output listeners
67 node.stdout.on('data', (data) => {
68 const text = data.toString();
69 outputBuffer += text;
70 log(`${colors.green}[STDOUT] ${text.trim()}${colors.reset}`);
71 });
72
73 node.stderr.on('data', (data) => {
74 const text = data.toString();
75 outputBuffer += text;
76 log(`${colors.red}[STDERR] ${text.trim()}${colors.reset}`);
77 });
78
79 // Set up exit handler
80 node.on('exit', (code) => {
81 log(`${colors.blue}Node.js process exited with code ${code}${colors.reset}`);
82
83 // Write debug log to file after exit
84 fs.writeFile(debugFile, debugLog).catch(err => {
85 console.error(`Failed to write debug log: ${err.message}`);
86 });
87 });
88
89 // Wait for Node.js to initialize
90 log(`${colors.blue}Waiting for Node.js startup...${colors.reset}`);
91 await sleep(2000);
92
93 // Log initial state

Callers 1

test-node-repl.jsFile · 0.70

Calls 5

logMethod · 0.80
onMethod · 0.80
logFunction · 0.70
sleepFunction · 0.70
writeMethod · 0.65

Tested by

no test coverage detected