| 15 | // Create an input stream specialized for testing an array of actions |
| 16 | class ActionStream extends stream.Stream { |
| 17 | run(data) { |
| 18 | const _iter = data[Symbol.iterator](); |
| 19 | const doAction = () => { |
| 20 | const next = _iter.next(); |
| 21 | if (next.done) { |
| 22 | // Close the repl. Note that it must have a clean prompt to do so. |
| 23 | this.emit('keypress', '', { ctrl: true, name: 'd' }); |
| 24 | return; |
| 25 | } |
| 26 | const action = next.value; |
| 27 | |
| 28 | if (typeof action === 'object') { |
| 29 | this.emit('keypress', '', action); |
| 30 | } else { |
| 31 | this.emit('data', `${action}`); |
| 32 | } |
| 33 | setImmediate(doAction); |
| 34 | }; |
| 35 | doAction(); |
| 36 | } |
| 37 | resume() {} |
| 38 | pause() {} |
| 39 | } |