| 25 | // Create an input stream specialized for testing an array of actions |
| 26 | class ActionStream extends stream.Stream { |
| 27 | run(data) { |
| 28 | const _iter = data[Symbol.iterator](); |
| 29 | const doAction = () => { |
| 30 | const next = _iter.next(); |
| 31 | if (next.done) { |
| 32 | // Close the repl. Note that it must have a clean prompt to do so. |
| 33 | setImmediate(() => { |
| 34 | this.emit('keypress', '', { ctrl: true, name: 'd' }); |
| 35 | }); |
| 36 | return; |
| 37 | } |
| 38 | const action = next.value; |
| 39 | |
| 40 | if (typeof action === 'object') { |
| 41 | this.emit('keypress', '', action); |
| 42 | } else { |
| 43 | this.emit('data', action); |
| 44 | } |
| 45 | setImmediate(doAction); |
| 46 | }; |
| 47 | doAction(); |
| 48 | } |
| 49 | resume() {} |
| 50 | pause() {} |
| 51 | } |