()
| 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 | 'index.mjs': `import timers from "timers/promises"; |
| 21 | |
| 22 | async function run() { |
| 23 | console.log("Start timers"); |
| 24 | console.log(await timers.setTimeout(1500, "test timeout")); |
| 25 | console.log(await timers.setImmediate("immediate")); |
| 26 | |
| 27 | const interval = 100; |
| 28 | for await (const startTime of timers.setInterval(interval, Date.now())) { |
| 29 | const now = Date.now(); |
| 30 | console.log(now); |
| 31 | if (now - startTime > 1000) { |
| 32 | break; |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | run().catch(console.error); |
| 38 | `, |
| 39 | }); |
| 40 | |
| 41 | const shellProcess = emulator.shell.create(); |
| 42 | |
| 43 | return new Promise(async (resolve) => { |
| 44 | shellProcess.stdout.on('data', (data) => { |
| 45 | return resolve(data); |
| 46 | }); |
| 47 | |
| 48 | await shellProcess.runCommand('node', ['index.mjs']); |
| 49 | }); |
| 50 | }; |
| 51 | |
| 52 | console.log(await foo()); |
| 53 | }; |
no test coverage detected