()
| 2 | import { replManager } from '../dist/repl-manager.js'; |
| 3 | |
| 4 | async function testNodeREPL() { |
| 5 | try { |
| 6 | console.log('Creating a Node.js REPL session...'); |
| 7 | const pid = await replManager.createSession('node', 5000); |
| 8 | console.log(`Created Node.js REPL session with PID ${pid}`); |
| 9 | |
| 10 | console.log('Executing a simple Node.js command...'); |
| 11 | const result = await replManager.executeCode(pid, 'console.log("Hello from Node.js!")', { |
| 12 | waitForPrompt: true, |
| 13 | timeout: 5000 |
| 14 | }); |
| 15 | console.log(`Result: ${JSON.stringify(result)}`); |
| 16 | |
| 17 | console.log('Executing a multi-line Node.js code block...'); |
| 18 | const nodeCode = ` |
| 19 | function greet(name) { |
| 20 | return \`Hello, \${name}!\`; |
| 21 | } |
| 22 | |
| 23 | console.log(greet("World")); |
| 24 | `; |
| 25 | |
| 26 | const result2 = await replManager.executeCode(pid, nodeCode, { |
| 27 | multiline: true, |
| 28 | timeout: 10000, |
| 29 | waitForPrompt: true |
| 30 | }); |
| 31 | console.log(`Multi-line result: ${JSON.stringify(result2)}`); |
| 32 | |
| 33 | console.log('Terminating the session...'); |
| 34 | const terminated = await replManager.terminateSession(pid); |
| 35 | console.log(`Session terminated: ${terminated}`); |
| 36 | |
| 37 | console.log('Test completed successfully'); |
| 38 | } catch (error) { |
| 39 | console.error(`Test failed with error: ${error.message}`); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | testNodeREPL(); |
no test coverage detected