(url)
| 257 | } |
| 258 | |
| 259 | function httpGetJson(url) { |
| 260 | return new Promise((resolve, reject) => { |
| 261 | const req = http.get(url, (response) => { |
| 262 | let body = '' |
| 263 | response.setEncoding('utf8') |
| 264 | response.on('data', (chunk) => { |
| 265 | body += chunk |
| 266 | }) |
| 267 | response.on('end', () => { |
| 268 | if (response.statusCode !== 200) { |
| 269 | reject(new Error(`HTTP ${response.statusCode}`)) |
| 270 | return |
| 271 | } |
| 272 | try { |
| 273 | resolve(JSON.parse(body)) |
| 274 | } catch (error) { |
| 275 | reject(error) |
| 276 | } |
| 277 | }) |
| 278 | }) |
| 279 | req.on('error', reject) |
| 280 | req.setTimeout(2000, () => { |
| 281 | req.destroy(new Error('timeout')) |
| 282 | }) |
| 283 | }) |
| 284 | } |
| 285 | |
| 286 | async function waitFor(fn, timeoutMs, label) { |
| 287 | const start = Date.now() |
no test coverage detected