(actual, expected)
| 123 | } |
| 124 | |
| 125 | function getStackedDiff(actual, expected) { |
| 126 | const isStringComparison = typeof actual === 'string' && typeof expected === 'string'; |
| 127 | |
| 128 | let message = `\n${colors.green}+${colors.white} ${actual}\n${colors.red}- ${colors.white}${expected}`; |
| 129 | const stringsLen = actual.length + expected.length; |
| 130 | const maxTerminalLength = process.stderr.isTTY ? process.stderr.columns : 80; |
| 131 | const showIndicator = isStringComparison && (stringsLen <= maxTerminalLength); |
| 132 | |
| 133 | if (showIndicator) { |
| 134 | let indicatorIdx = -1; |
| 135 | |
| 136 | for (let i = 0; i < actual.length; i++) { |
| 137 | if (actual[i] !== expected[i]) { |
| 138 | // Skip the indicator for the first 2 characters because the diff is immediately apparent |
| 139 | // It is 3 instead of 2 to account for the quotes |
| 140 | if (i >= 3) { |
| 141 | indicatorIdx = i; |
| 142 | } |
| 143 | break; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | if (indicatorIdx !== -1) { |
| 148 | message += `\n${StringPrototypeRepeat(' ', indicatorIdx + 2)}^`; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | return { message }; |
| 153 | } |
| 154 | |
| 155 | function getSimpleDiff(originalActual, actual, originalExpected, expected) { |
| 156 | let stringsLen = actual.length + expected.length; |
no outgoing calls
no test coverage detected
searching dependent graphs…