Skip to content

Commit

Permalink
Print error message before formatted assertion
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
novemberborn committed Mar 26, 2017
1 parent 2d68282 commit 5e7ea9a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
8 changes: 4 additions & 4 deletions lib/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,17 @@ class MiniReporter {
}
}

if (test.error.message) {
status += '\n' + indentString(test.error.message, 2) + '\n';
}

if (test.error.avaAssertionError) {
const formatted = formatAssertError.formatSerializedError(test.error);
if (formatted) {
status += '\n' + indentString(formatted, 2);
}
}

if (test.error.message) {
status += '\n' + indentString(test.error.message, 2) + '\n';
}

if (test.error.stack) {
const extracted = extractStack(test.error.stack);
if (extracted.includes('\n')) {
Expand Down
8 changes: 4 additions & 4 deletions lib/reporters/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ class VerboseReporter {
}
}

if (test.error.message) {
output += '\n' + indentString(test.error.message, 2) + '\n';
}

if (test.error.avaAssertionError) {
const formatted = formatAssertError.formatSerializedError(test.error);
if (formatted) {
output += '\n' + indentString(formatted, 2);
}
}

if (test.error.message) {
output += '\n' + indentString(test.error.message, 2) + '\n';
}

if (test.error.stack) {
const extracted = extractStack(test.error.stack);
if (extracted.includes('\n')) {
Expand Down
22 changes: 12 additions & 10 deletions test/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ test('results with errors', t => {
};

const output = reporter.finish(runStatus);

compareLineOutput(t, output, flatten([
'',
' ' + chalk.red('1 failed'),
Expand All @@ -405,9 +404,9 @@ test('results with errors', t => {
'',
indentString(codeExcerpt(err1.source), 2).split('\n'),
'',
indentString(formatSerializedError(err1), 2).split('\n'),
/failure one/,
'',
indentString(formatSerializedError(err1), 2).split('\n'),
stackLineRegex,
compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
'',
Expand All @@ -418,8 +417,9 @@ test('results with errors', t => {
'',
indentString(codeExcerpt(err2.source), 2).split('\n'),
'',
indentString(formatSerializedError(err2), 2).split('\n'),
/failure two/
/failure two/,
'',
indentString(formatSerializedError(err2), 2).split('\n')
]));
t.end();
});
Expand Down Expand Up @@ -466,9 +466,9 @@ test('results with errors and disabled code excerpts', t => {
'',
' ' + chalk.bold.white('failed one'),
'',
indentString(formatSerializedError(err1), 2).split('\n'),
/failure one/,
'',
indentString(formatSerializedError(err1), 2).split('\n'),
stackLineRegex,
compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
'',
Expand All @@ -479,8 +479,9 @@ test('results with errors and disabled code excerpts', t => {
'',
indentString(codeExcerpt(err2.source), 2).split('\n'),
'',
indentString(formatSerializedError(err2), 2).split('\n'),
/failure two/
/failure two/,
'',
indentString(formatSerializedError(err2), 2).split('\n')
]));
t.end();
});
Expand Down Expand Up @@ -530,9 +531,9 @@ test('results with errors and broken code excerpts', t => {
' ' + chalk.bold.white('failed one'),
' ' + chalk.grey(`${err1.source.file}:${err1.source.line}`),
'',
indentString(formatSerializedError(err1), 2).split('\n'),
/failure one/,
'',
indentString(formatSerializedError(err1), 2).split('\n'),
stackLineRegex,
compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
'',
Expand All @@ -543,8 +544,9 @@ test('results with errors and broken code excerpts', t => {
'',
indentString(codeExcerpt(err2.source), 2).split('\n'),
'',
indentString(formatSerializedError(err2), 2).split('\n'),
/failure two/
/failure two/,
'',
indentString(formatSerializedError(err2), 2).split('\n')
]));
t.end();
});
Expand Down
21 changes: 12 additions & 9 deletions test/reporters/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ test('results with errors', t => {
'',
indentString(codeExcerpt(error1.source), 2).split('\n'),
'',
indentString(formatSerializedError(error1), 2).split('\n'),
/error one message/,
'',
indentString(formatSerializedError(error1), 2).split('\n'),
stackLineRegex,
compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
'',
Expand All @@ -425,8 +425,9 @@ test('results with errors', t => {
'',
indentString(codeExcerpt(error2.source), 2).split('\n'),
'',
indentString(formatSerializedError(error2), 2).split('\n'),
/error two message/
/error two message/,
'',
indentString(formatSerializedError(error2), 2).split('\n')
]));
t.end();
});
Expand Down Expand Up @@ -470,9 +471,9 @@ test('results with errors and disabled code excerpts', t => {
'',
' ' + chalk.bold.white('fail one'),
'',
indentString(formatSerializedError(error1), 2).split('\n'),
/error one message/,
'',
indentString(formatSerializedError(error1), 2).split('\n'),
stackLineRegex,
compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
'',
Expand All @@ -483,8 +484,9 @@ test('results with errors and disabled code excerpts', t => {
'',
indentString(codeExcerpt(error2.source), 2).split('\n'),
'',
indentString(formatSerializedError(error2), 2).split('\n'),
/error two message/
/error two message/,
'',
indentString(formatSerializedError(error2), 2).split('\n')
]));
t.end();
});
Expand Down Expand Up @@ -531,9 +533,9 @@ test('results with errors and disabled code excerpts', t => {
' ' + chalk.bold.white('fail one'),
' ' + chalk.grey(`${error1.source.file}:${error1.source.line}`),
'',
indentString(formatSerializedError(error1), 2).split('\n'),
/error one message/,
'',
indentString(formatSerializedError(error1), 2).split('\n'),
stackLineRegex,
compareLineOutput.SKIP_UNTIL_EMPTY_LINE,
'',
Expand All @@ -544,8 +546,9 @@ test('results with errors and disabled code excerpts', t => {
'',
indentString(codeExcerpt(error2.source), 2).split('\n'),
'',
indentString(formatSerializedError(error2), 2).split('\n'),
/error two message/
/error two message/,
'',
indentString(formatSerializedError(error2), 2).split('\n')
]));
t.end();
});
Expand Down

0 comments on commit 5e7ea9a

Please sign in to comment.