()
| 125 | } |
| 126 | |
| 127 | function client() { |
| 128 | if (current === test.requests.length) return next(); |
| 129 | const port = server.address().port; |
| 130 | const conn = net.createConnection(port, '127.0.0.1', connected); |
| 131 | |
| 132 | function connected() { |
| 133 | const ctx = test.requests[current]; |
| 134 | console.error(' > CLIENT SENDING REQUEST', ctx); |
| 135 | conn.setEncoding('utf8'); |
| 136 | conn.write(ctx.data); |
| 137 | |
| 138 | function onclose() { |
| 139 | console.error(' > CLIENT CLOSE'); |
| 140 | if (!ctx.expectClose) throw new Error('unexpected close'); |
| 141 | client(); |
| 142 | } |
| 143 | conn.on('close', onclose); |
| 144 | |
| 145 | function ondata(s) { |
| 146 | console.error(' > CLIENT ONDATA %j %j', s.length, s.toString()); |
| 147 | current++; |
| 148 | if (ctx.expectClose) return; |
| 149 | conn.removeListener('close', onclose); |
| 150 | conn.removeListener('data', ondata); |
| 151 | connected(); |
| 152 | } |
| 153 | conn.on('data', ondata); |
| 154 | } |
| 155 | } |
| 156 | } |
no test coverage detected