(message: string, diffText: string|null, cutoff: number = SUMMARY_LENGTH_CUTOFF)
| 82 | const SUMMARY_LENGTH_CUTOFF = 3950; |
| 83 | |
| 84 | export function formatSummary(message: string, diffText: string|null, cutoff: number = SUMMARY_LENGTH_CUTOFF): string { |
| 85 | let summary = message; |
| 86 | if (diffText) { |
| 87 | summary += '\n\n' + diffText; |
| 88 | } |
| 89 | |
| 90 | const lines = summary.split('\n'); |
| 91 | let result = ''; |
| 92 | let currentLength = 13; // for <pre></pre> and some safety margin |
| 93 | |
| 94 | for (const line of lines) { |
| 95 | const sanitized = sanitize(line); |
| 96 | let highlighted = sanitized; |
| 97 | if (line.startsWith('+')) { |
| 98 | highlighted = `<span style="color: green;">${sanitized}</span>`; |
| 99 | } else if (line.startsWith('-')) { |
| 100 | highlighted = `<span style="color: red;">${sanitized}</span>`; |
| 101 | } |
| 102 | |
| 103 | if (currentLength + highlighted.length + 1 > cutoff) { |
| 104 | result += '\n... (truncated)'; |
| 105 | break; |
| 106 | } |
| 107 | if (result.length > 0) { |
| 108 | result += '\n'; |
| 109 | } |
| 110 | result += highlighted; |
| 111 | currentLength += highlighted.length + 1; |
| 112 | } |
| 113 | |
| 114 | return `<pre>${result}</pre>`; |
| 115 | } |
| 116 | |
| 117 | export function formatAsHtml(assertionDiff: any): string|null { |
| 118 | const diffText = formatDiffText(assertionDiff); |
no test coverage detected