From 5e7ea9a99e3a2e4307f6134ae1f3ff5d3cf4342e Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Mon, 20 Mar 2017 16:50:02 +0000 Subject: [PATCH] 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. --- lib/reporters/mini.js | 8 ++++---- lib/reporters/verbose.js | 8 ++++---- test/reporters/mini.js | 22 ++++++++++++---------- test/reporters/verbose.js | 21 ++++++++++++--------- 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/lib/reporters/mini.js b/lib/reporters/mini.js index 38bfe468f..6bfd717a9 100644 --- a/lib/reporters/mini.js +++ b/lib/reporters/mini.js @@ -191,6 +191,10 @@ 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) { @@ -198,10 +202,6 @@ class MiniReporter { } } - 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')) { diff --git a/lib/reporters/verbose.js b/lib/reporters/verbose.js index d9b914fe4..a43dc81be 100644 --- a/lib/reporters/verbose.js +++ b/lib/reporters/verbose.js @@ -111,6 +111,10 @@ 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) { @@ -118,10 +122,6 @@ class VerboseReporter { } } - 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')) { diff --git a/test/reporters/mini.js b/test/reporters/mini.js index cd8b346bb..96c237adf 100644 --- a/test/reporters/mini.js +++ b/test/reporters/mini.js @@ -395,7 +395,6 @@ test('results with errors', t => { }; const output = reporter.finish(runStatus); - compareLineOutput(t, output, flatten([ '', ' ' + chalk.red('1 failed'), @@ -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, '', @@ -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(); }); @@ -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, '', @@ -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(); }); @@ -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, '', @@ -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(); }); diff --git a/test/reporters/verbose.js b/test/reporters/verbose.js index 216ca9e97..7bda0ed50 100644 --- a/test/reporters/verbose.js +++ b/test/reporters/verbose.js @@ -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, '', @@ -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(); }); @@ -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, '', @@ -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(); }); @@ -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, '', @@ -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(); });