(reportDir = defaultReportDir())
| 119 | } |
| 120 | |
| 121 | export function readReportEvents(reportDir = defaultReportDir()): StoredReportEvent[] { |
| 122 | if (!existsSync(reportDir)) return []; |
| 123 | const files = readdirSync(reportDir) |
| 124 | .filter((file) => file.startsWith('events-') && file.endsWith('.jsonl')) |
| 125 | .toSorted(); |
| 126 | const events: StoredReportEvent[] = []; |
| 127 | for (const file of files) { |
| 128 | const text = readFileSync(join(reportDir, file), 'utf8'); |
| 129 | for (const line of text.split('\n')) { |
| 130 | if (line.trim().length === 0) continue; |
| 131 | events.push(JSON.parse(line) as StoredReportEvent); |
| 132 | } |
| 133 | } |
| 134 | return events.toSorted((a, b) => { |
| 135 | const byTime = Date.parse(a.at ?? '') - Date.parse(b.at ?? ''); |
| 136 | if (byTime !== 0) return byTime; |
| 137 | if (a.pid !== b.pid) return a.pid - b.pid; |
| 138 | return a.ordinal - b.ordinal; |
| 139 | }); |
| 140 | } |
| 141 | |
| 142 | export function writeHtmlReport(options?: HtmlReportOptions): string { |
| 143 | const reportDir = options?.reportDir ?? defaultReportDir(); |
no test coverage detected