| 24 | const delay = (ms) => new Promise(done => setTimeout(done, ms)); |
| 25 | |
| 26 | async function json(path, body) { |
| 27 | const response = await fetch(ORIGIN + path, { |
| 28 | method: body === undefined ? 'GET' : 'POST', |
| 29 | ...(body === undefined ? {} : { headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }), |
| 30 | signal: AbortSignal.timeout(30000), |
| 31 | }); |
| 32 | const text = await response.text(); |
| 33 | report.directRequests.push({ at: new Date().toISOString(), method: body === undefined ? 'GET' : 'POST', path, status: response.status }); |
| 34 | assert.ok(response.ok, `${path}: HTTP ${response.status}: ${text.slice(0, 300)}`); |
| 35 | return JSON.parse(text); |
| 36 | } |
| 37 | |
| 38 | const logs = (project, extra = '') => json(`/api/logs?lines=500&min_level=warn${project === undefined ? '' : `&project=${encodeURIComponent(project)}`}${extra}`); |
| 39 | |