()
| 8 | */ |
| 9 | window.runExample = async function (emulatorUrl) { |
| 10 | const foo = async () => { |
| 11 | const { Nodebox } = window; |
| 12 | |
| 13 | const emulator = new Nodebox({ |
| 14 | runtimeUrl: emulatorUrl, |
| 15 | iframe: document.getElementById('frame'), |
| 16 | }); |
| 17 | |
| 18 | await emulator.connect(); |
| 19 | await emulator.fs.init({ |
| 20 | 'foo.js': `process.stdout.write('Hello world'); |
| 21 | process.exit();`, |
| 22 | |
| 23 | 'index.js': `const { exec } = require('node:child_process'); |
| 24 | |
| 25 | exec("./foo", { encoding: "utf8", timeout: 5_000 }, (err, stdout, stderr) => { |
| 26 | console.log("Exec output: " + stdout) |
| 27 | });`, |
| 28 | }); |
| 29 | |
| 30 | const shellProcess = emulator.shell.create(); |
| 31 | |
| 32 | return new Promise(async (resolve) => { |
| 33 | shellProcess.stdout.on('data', (data) => { |
| 34 | return resolve(data); |
| 35 | }); |
| 36 | |
| 37 | await shellProcess.runCommand('node', ['index.js']); |
| 38 | }); |
| 39 | }; |
| 40 | |
| 41 | console.log(await foo()); |
| 42 | }; |
no test coverage detected