From da68f2941b76c0400bc806bde39dc41d690a1818 Mon Sep 17 00:00:00 2001 From: Alessio Occhipinti Date: Tue, 14 Feb 2017 10:42:05 +0100 Subject: [PATCH] Simplify failure output - fixes #1072 (#1234) --- lib/reporters/mini.js | 5 ++++- lib/reporters/verbose.js | 5 ++++- test/reporters/mini.js | 16 ++++------------ test/reporters/verbose.js | 16 ++++------------ 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/lib/reporters/mini.js b/lib/reporters/mini.js index 8cc0513fa..40b9bd328 100644 --- a/lib/reporters/mini.js +++ b/lib/reporters/mini.js @@ -204,7 +204,10 @@ class MiniReporter { } if (test.error.stack) { - status += '\n' + indentString(colors.errorStack(extractStack(test.error.stack)), 2); + const extracted = extractStack(test.error.stack); + if (extracted.includes('\n')) { + status += '\n' + indentString(colors.errorStack(extracted), 2); + } } }); } diff --git a/lib/reporters/verbose.js b/lib/reporters/verbose.js index 7e494d459..a76d2c647 100644 --- a/lib/reporters/verbose.js +++ b/lib/reporters/verbose.js @@ -123,7 +123,10 @@ class VerboseReporter { } if (test.error.stack) { - output += '\n' + indentString(colors.errorStack(extractStack(test.error.stack)), 2); + const extracted = extractStack(test.error.stack); + if (extracted.includes('\n')) { + output += '\n' + indentString(colors.errorStack(extracted), 2); + } } }); } diff --git a/test/reporters/mini.js b/test/reporters/mini.js index af12d4108..f53c60ad3 100644 --- a/test/reporters/mini.js +++ b/test/reporters/mini.js @@ -409,9 +409,7 @@ test('results with errors', t => { indentString(codeExcerpt(err2Path, err2.source.line), 2).split('\n'), '', indentString(formatAssertError(err2), 2).split('\n'), - /failure two/, - '', - stackLineRegex + /failure two/ ])); t.end(); }); @@ -470,9 +468,7 @@ test('results with errors and disabled code excerpts', t => { indentString(codeExcerpt(err2Path, err2.source.line), 2).split('\n'), '', indentString(formatAssertError(err2), 2).split('\n'), - /failure two/, - '', - stackLineRegex + /failure two/ ])); t.end(); }); @@ -534,9 +530,7 @@ test('results with errors and broken code excerpts', t => { indentString(codeExcerpt(err2Path, err2.source.line), 2).split('\n'), '', indentString(formatAssertError(err2), 2).split('\n'), - /failure two/, - '', - stackLineRegex + /failure two/ ])); t.end(); }); @@ -599,9 +593,7 @@ test('results with errors and disabled assert output', t => { indentString(codeExcerpt(err2Path, err2.source.line), 2).split('\n'), '', indentString(formatAssertError(err2), 2).split('\n'), - /failure two/, - '', - stackLineRegex + /failure two/ ])); t.end(); }); diff --git a/test/reporters/verbose.js b/test/reporters/verbose.js index cbbfddd28..2e00ee42a 100644 --- a/test/reporters/verbose.js +++ b/test/reporters/verbose.js @@ -416,9 +416,7 @@ test('results with errors', t => { indentString(codeExcerpt(err2Path, error2.source.line), 2).split('\n'), '', indentString(formatAssertError(error2), 2).split('\n'), - /error two message/, - '', - stackLineRegex + /error two message/ ])); t.end(); }); @@ -474,9 +472,7 @@ test('results with errors and disabled code excerpts', t => { indentString(codeExcerpt(err2Path, error2.source.line), 2).split('\n'), '', indentString(formatAssertError(error2), 2).split('\n'), - /error two message/, - '', - stackLineRegex + /error two message/ ])); t.end(); }); @@ -535,9 +531,7 @@ test('results with errors and disabled code excerpts', t => { indentString(codeExcerpt(err2Path, error2.source.line), 2).split('\n'), '', indentString(formatAssertError(error2), 2).split('\n'), - /error two message/, - '', - stackLineRegex + /error two message/ ])); t.end(); }); @@ -597,9 +591,7 @@ test('results with errors and disabled assert output', t => { indentString(codeExcerpt(err2Path, error2.source.line), 2).split('\n'), '', indentString(formatAssertError(error2), 2).split('\n'), - /error two message/, - '', - stackLineRegex + /error two message/ ])); t.end(); });