(fileName, text)
| 284 | } |
| 285 | |
| 286 | function parseUploadedFile(fileName, text) { |
| 287 | const trimmed = text.trim(); |
| 288 | if (!trimmed) { |
| 289 | throw new Error("The uploaded file is empty."); |
| 290 | } |
| 291 | |
| 292 | if (looksLikeNdjson(trimmed)) { |
| 293 | return normalizeNdjsonRun(fileName, trimmed); |
| 294 | } |
| 295 | |
| 296 | if (trimmed.startsWith("{")) { |
| 297 | let parsed; |
| 298 | try { |
| 299 | parsed = JSON.parse(trimmed); |
| 300 | } catch (error) { |
| 301 | throw new Error("That JSON file could not be parsed."); |
| 302 | } |
| 303 | if (parsed && parsed.metrics) { |
| 304 | return normalizeSummaryRun(fileName, parsed); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | if (looksLikeCsv(trimmed)) { |
| 309 | return normalizeCsvRun(fileName, trimmed); |
| 310 | } |
| 311 | |
| 312 | throw new Error("Unsupported file. Use a k6 summary JSON, raw NDJSON export, or the minute-bucket CSV output."); |
| 313 | } |
| 314 | |
| 315 | function normalizeSummaryRun(fileName, payload) { |
| 316 | const metrics = payload.metrics || {}; |
no test coverage detected