Skip to content

Commit 5e7ea9a

Browse files
committed
Print error message before formatted assertion
The formatted labels sometimes assume the context of the error message. And, since formatted values can be quite long, it's odd to see the message only at the very end.
1 parent 2d68282 commit 5e7ea9a

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

lib/reporters/mini.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,17 @@ class MiniReporter {
191191
}
192192
}
193193

194+
if (test.error.message) {
195+
status += '\n' + indentString(test.error.message, 2) + '\n';
196+
}
197+
194198
if (test.error.avaAssertionError) {
195199
const formatted = formatAssertError.formatSerializedError(test.error);
196200
if (formatted) {
197201
status += '\n' + indentString(formatted, 2);
198202
}
199203
}
200204

201-
if (test.error.message) {
202-
status += '\n' + indentString(test.error.message, 2) + '\n';
203-
}
204-
205205
if (test.error.stack) {
206206
const extracted = extractStack(test.error.stack);
207207
if (extracted.includes('\n')) {

lib/reporters/verbose.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,17 @@ class VerboseReporter {
111111
}
112112
}
113113

114+
if (test.error.message) {
115+
output += '\n' + indentString(test.error.message, 2) + '\n';
116+
}
117+
114118
if (test.error.avaAssertionError) {
115119
const formatted = formatAssertError.formatSerializedError(test.error);
116120
if (formatted) {
117121
output += '\n' + indentString(formatted, 2);
118122
}
119123
}
120124

121-
if (test.error.message) {
122-
output += '\n' + indentString(test.error.message, 2) + '\n';
123-
}
124-
125125
if (test.error.stack) {
126126
const extracted = extractStack(test.error.stack);
127127
if (extracted.includes('\n')) {

test/reporters/mini.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ test('results with errors', t => {
395395
};
396396

397397
const output = reporter.finish(runStatus);
398-
399398
compareLineOutput(t, output, flatten([
400399
'',
401400
' ' + chalk.red('1 failed'),
@@ -405,9 +404,9 @@ test('results with errors', t => {
405404
'',
406405
indentString(codeExcerpt(err1.source), 2).split('\n'),
407406
'',
408-
indentString(formatSerializedError(err1), 2).split('\n'),
409407
/failure one/,
410408
'',
409+
indentString(formatSerializedError(err1), 2).split('\n'),
411410
stackLineRegex,
412411
compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
413412
'',
@@ -418,8 +417,9 @@ test('results with errors', t => {
418417
'',
419418
indentString(codeExcerpt(err2.source), 2).split('\n'),
420419
'',
421-
indentString(formatSerializedError(err2), 2).split('\n'),
422-
/failure two/
420+
/failure two/,
421+
'',
422+
indentString(formatSerializedError(err2), 2).split('\n')
423423
]));
424424
t.end();
425425
});
@@ -466,9 +466,9 @@ test('results with errors and disabled code excerpts', t => {
466466
'',
467467
' ' + chalk.bold.white('failed one'),
468468
'',
469-
indentString(formatSerializedError(err1), 2).split('\n'),
470469
/failure one/,
471470
'',
471+
indentString(formatSerializedError(err1), 2).split('\n'),
472472
stackLineRegex,
473473
compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
474474
'',
@@ -479,8 +479,9 @@ test('results with errors and disabled code excerpts', t => {
479479
'',
480480
indentString(codeExcerpt(err2.source), 2).split('\n'),
481481
'',
482-
indentString(formatSerializedError(err2), 2).split('\n'),
483-
/failure two/
482+
/failure two/,
483+
'',
484+
indentString(formatSerializedError(err2), 2).split('\n')
484485
]));
485486
t.end();
486487
});
@@ -530,9 +531,9 @@ test('results with errors and broken code excerpts', t => {
530531
' ' + chalk.bold.white('failed one'),
531532
' ' + chalk.grey(`${err1.source.file}:${err1.source.line}`),
532533
'',
533-
indentString(formatSerializedError(err1), 2).split('\n'),
534534
/failure one/,
535535
'',
536+
indentString(formatSerializedError(err1), 2).split('\n'),
536537
stackLineRegex,
537538
compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
538539
'',
@@ -543,8 +544,9 @@ test('results with errors and broken code excerpts', t => {
543544
'',
544545
indentString(codeExcerpt(err2.source), 2).split('\n'),
545546
'',
546-
indentString(formatSerializedError(err2), 2).split('\n'),
547-
/failure two/
547+
/failure two/,
548+
'',
549+
indentString(formatSerializedError(err2), 2).split('\n')
548550
]));
549551
t.end();
550552
});

test/reporters/verbose.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,9 @@ test('results with errors', t => {
412412
'',
413413
indentString(codeExcerpt(error1.source), 2).split('\n'),
414414
'',
415-
indentString(formatSerializedError(error1), 2).split('\n'),
416415
/error one message/,
417416
'',
417+
indentString(formatSerializedError(error1), 2).split('\n'),
418418
stackLineRegex,
419419
compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
420420
'',
@@ -425,8 +425,9 @@ test('results with errors', t => {
425425
'',
426426
indentString(codeExcerpt(error2.source), 2).split('\n'),
427427
'',
428-
indentString(formatSerializedError(error2), 2).split('\n'),
429-
/error two message/
428+
/error two message/,
429+
'',
430+
indentString(formatSerializedError(error2), 2).split('\n')
430431
]));
431432
t.end();
432433
});
@@ -470,9 +471,9 @@ test('results with errors and disabled code excerpts', t => {
470471
'',
471472
' ' + chalk.bold.white('fail one'),
472473
'',
473-
indentString(formatSerializedError(error1), 2).split('\n'),
474474
/error one message/,
475475
'',
476+
indentString(formatSerializedError(error1), 2).split('\n'),
476477
stackLineRegex,
477478
compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
478479
'',
@@ -483,8 +484,9 @@ test('results with errors and disabled code excerpts', t => {
483484
'',
484485
indentString(codeExcerpt(error2.source), 2).split('\n'),
485486
'',
486-
indentString(formatSerializedError(error2), 2).split('\n'),
487-
/error two message/
487+
/error two message/,
488+
'',
489+
indentString(formatSerializedError(error2), 2).split('\n')
488490
]));
489491
t.end();
490492
});
@@ -531,9 +533,9 @@ test('results with errors and disabled code excerpts', t => {
531533
' ' + chalk.bold.white('fail one'),
532534
' ' + chalk.grey(`${error1.source.file}:${error1.source.line}`),
533535
'',
534-
indentString(formatSerializedError(error1), 2).split('\n'),
535536
/error one message/,
536537
'',
538+
indentString(formatSerializedError(error1), 2).split('\n'),
537539
stackLineRegex,
538540
compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
539541
'',
@@ -544,8 +546,9 @@ test('results with errors and disabled code excerpts', t => {
544546
'',
545547
indentString(codeExcerpt(error2.source), 2).split('\n'),
546548
'',
547-
indentString(formatSerializedError(error2), 2).split('\n'),
548-
/error two message/
549+
/error two message/,
550+
'',
551+
indentString(formatSerializedError(error2), 2).split('\n')
549552
]));
550553
t.end();
551554
});

0 commit comments

Comments
 (0)