|
1 | 1 | const { |
2 | 2 | reporters: { Base }, |
3 | 3 | } = require('mocha') |
| 4 | +const figures = require('figures') |
4 | 5 | const ms = require('ms') |
5 | 6 | const event = require('../event') |
6 | 7 | const AssertionFailedError = require('../assert/error') |
@@ -163,33 +164,49 @@ class Cli extends Base { |
163 | 164 | const err = test.err |
164 | 165 |
|
165 | 166 | let log = '' |
| 167 | + let originalMessage = err.message |
166 | 168 |
|
167 | 169 | if (err instanceof AssertionFailedError) { |
168 | 170 | err.message = err.inspect() |
169 | 171 | } |
170 | 172 |
|
| 173 | + // multi-line error messages |
| 174 | + err.message = '\n ' + (err.message || '').replace(/^/gm, ' ').trim() |
| 175 | + |
171 | 176 | const steps = test.steps || (test.ctx && test.ctx.test.steps) |
172 | 177 |
|
173 | 178 | if (steps && steps.length) { |
174 | 179 | let scenarioTrace = '' |
175 | 180 | steps.reverse().forEach(step => { |
176 | | - const line = `- ${step.toCode()} ${step.line()}` |
177 | | - // if (step.status === 'failed') line = '' + line; |
| 181 | + const hasFailed = step.status === 'failed' |
| 182 | + let line = `${hasFailed ? output.styles.bold(figures.cross) : figures.tick} ${step.toCode()} ${step.line()}` |
| 183 | + if (hasFailed) line = output.styles.bold(line) |
178 | 184 | scenarioTrace += `\n${line}` |
179 | 185 | }) |
180 | | - log += `${output.styles.bold('Scenario Steps')}:${scenarioTrace}\n` |
| 186 | + log += `${output.styles.basic(figures.circle)} ${output.styles.section('Scenario Steps')}:${scenarioTrace}\n` |
181 | 187 | } |
182 | 188 |
|
183 | 189 | // display artifacts in debug mode |
184 | 190 | if (test?.artifacts && Object.keys(test.artifacts).length) { |
185 | | - log += `\n${output.styles.bold('Artifacts:')}` |
| 191 | + log += `\n${output.styles.basic(figures.circle)} ${output.styles.section('Artifacts:')}` |
186 | 192 | for (const artifact of Object.keys(test.artifacts)) { |
187 | 193 | log += `\n- ${artifact}: ${test.artifacts[artifact]}` |
188 | 194 | } |
189 | 195 | } |
190 | 196 |
|
| 197 | + // display metadata |
| 198 | + if (test.meta && Object.keys(test.meta).length) { |
| 199 | + log += `\n\n${output.styles.basic(figures.circle)} ${output.styles.section('Metadata:')}` |
| 200 | + for (const [key, value] of Object.entries(test.meta)) { |
| 201 | + log += `\n- ${key}: ${value}` |
| 202 | + } |
| 203 | + } |
| 204 | + |
191 | 205 | try { |
192 | | - let stack = err.stack ? err.stack.split('\n') : [] |
| 206 | + let stack = err.stack |
| 207 | + stack = stack.replace(originalMessage, '') |
| 208 | + stack = stack ? stack.split('\n') : [] |
| 209 | + |
193 | 210 | if (stack[0] && stack[0].includes(err.message)) { |
194 | 211 | stack.shift() |
195 | 212 | } |
|
0 commit comments