()
| 99 | } |
| 100 | |
| 101 | export function assertConsoleLogsCleared() { |
| 102 | const logs = clearLogs(); |
| 103 | const warnings = clearWarnings(); |
| 104 | const errors = clearErrors(); |
| 105 | |
| 106 | if (logs.length > 0 || errors.length > 0 || warnings.length > 0) { |
| 107 | let message = `${chalk.dim('asserConsoleLogsCleared')}(${chalk.red( |
| 108 | 'expected', |
| 109 | )})\n`; |
| 110 | |
| 111 | if (logs.length > 0) { |
| 112 | message += `\nconsole.log was called without assertConsoleLogDev:\n${diff( |
| 113 | '', |
| 114 | logs.join('\n'), |
| 115 | { |
| 116 | omitAnnotationLines: true, |
| 117 | }, |
| 118 | )}\n`; |
| 119 | } |
| 120 | |
| 121 | if (warnings.length > 0) { |
| 122 | message += `\nconsole.warn was called without assertConsoleWarnDev:\n${diff( |
| 123 | '', |
| 124 | warnings.map(normalizeComponentStack).join('\n'), |
| 125 | { |
| 126 | omitAnnotationLines: true, |
| 127 | }, |
| 128 | )}\n`; |
| 129 | } |
| 130 | if (errors.length > 0) { |
| 131 | message += `\nconsole.error was called without assertConsoleErrorDev:\n${diff( |
| 132 | '', |
| 133 | errors.map(normalizeComponentStack).join('\n'), |
| 134 | { |
| 135 | omitAnnotationLines: true, |
| 136 | }, |
| 137 | )}\n`; |
| 138 | } |
| 139 | |
| 140 | message += `\nYou must call one of the assertConsoleDev helpers between each act call.`; |
| 141 | |
| 142 | const error = Error(message); |
| 143 | Error.captureStackTrace(error, assertConsoleLogsCleared); |
| 144 | throw error; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | function normalizeCodeLocInfo(str) { |
| 149 | if (typeof str !== 'string') { |
no test coverage detected