(emitter, matcher, timeout = 5000)
| 157 | } |
| 158 | |
| 159 | function waitForText (emitter, matcher, timeout = 5000) { |
| 160 | return new Promise((resolve, reject) => { |
| 161 | let output = '' |
| 162 | const timer = setTimeout(() => { |
| 163 | cleanup() |
| 164 | reject(new Error(`Timed out waiting for text. Received: ${output}`)) |
| 165 | }, timeout) |
| 166 | |
| 167 | const onData = (chunk) => { |
| 168 | output += chunk.toString() |
| 169 | if (matcher(output, chunk)) { |
| 170 | cleanup() |
| 171 | resolve(output) |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | const onClose = () => { |
| 176 | cleanup() |
| 177 | reject(new Error(`Stream closed before matcher succeeded. Received: ${output}`)) |
| 178 | } |
| 179 | |
| 180 | const cleanup = () => { |
| 181 | clearTimeout(timer) |
| 182 | emitter.off('data', onData) |
| 183 | emitter.off('close', onClose) |
| 184 | emitter.off('end', onClose) |
| 185 | } |
| 186 | |
| 187 | emitter.on('data', onData) |
| 188 | emitter.on('close', onClose) |
| 189 | emitter.on('end', onClose) |
| 190 | }) |
| 191 | } |
| 192 | |
| 193 | describe('session-ftp transport flows', () => { |
| 194 | let ftpServer |
no test coverage detected