Skip to content

Commit da68f29

Browse files
LasaleFaminesindresorhus
authored andcommitted
Simplify failure output - fixes #1072 (#1234)
1 parent 2c683b9 commit da68f29

File tree

4 files changed

+16
-26
lines changed

4 files changed

+16
-26
lines changed

lib/reporters/mini.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ class MiniReporter {
204204
}
205205

206206
if (test.error.stack) {
207-
status += '\n' + indentString(colors.errorStack(extractStack(test.error.stack)), 2);
207+
const extracted = extractStack(test.error.stack);
208+
if (extracted.includes('\n')) {
209+
status += '\n' + indentString(colors.errorStack(extracted), 2);
210+
}
208211
}
209212
});
210213
}

lib/reporters/verbose.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ class VerboseReporter {
123123
}
124124

125125
if (test.error.stack) {
126-
output += '\n' + indentString(colors.errorStack(extractStack(test.error.stack)), 2);
126+
const extracted = extractStack(test.error.stack);
127+
if (extracted.includes('\n')) {
128+
output += '\n' + indentString(colors.errorStack(extracted), 2);
129+
}
127130
}
128131
});
129132
}

test/reporters/mini.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,7 @@ test('results with errors', t => {
409409
indentString(codeExcerpt(err2Path, err2.source.line), 2).split('\n'),
410410
'',
411411
indentString(formatAssertError(err2), 2).split('\n'),
412-
/failure two/,
413-
'',
414-
stackLineRegex
412+
/failure two/
415413
]));
416414
t.end();
417415
});
@@ -470,9 +468,7 @@ test('results with errors and disabled code excerpts', t => {
470468
indentString(codeExcerpt(err2Path, err2.source.line), 2).split('\n'),
471469
'',
472470
indentString(formatAssertError(err2), 2).split('\n'),
473-
/failure two/,
474-
'',
475-
stackLineRegex
471+
/failure two/
476472
]));
477473
t.end();
478474
});
@@ -534,9 +530,7 @@ test('results with errors and broken code excerpts', t => {
534530
indentString(codeExcerpt(err2Path, err2.source.line), 2).split('\n'),
535531
'',
536532
indentString(formatAssertError(err2), 2).split('\n'),
537-
/failure two/,
538-
'',
539-
stackLineRegex
533+
/failure two/
540534
]));
541535
t.end();
542536
});
@@ -599,9 +593,7 @@ test('results with errors and disabled assert output', t => {
599593
indentString(codeExcerpt(err2Path, err2.source.line), 2).split('\n'),
600594
'',
601595
indentString(formatAssertError(err2), 2).split('\n'),
602-
/failure two/,
603-
'',
604-
stackLineRegex
596+
/failure two/
605597
]));
606598
t.end();
607599
});

test/reporters/verbose.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,7 @@ test('results with errors', t => {
416416
indentString(codeExcerpt(err2Path, error2.source.line), 2).split('\n'),
417417
'',
418418
indentString(formatAssertError(error2), 2).split('\n'),
419-
/error two message/,
420-
'',
421-
stackLineRegex
419+
/error two message/
422420
]));
423421
t.end();
424422
});
@@ -474,9 +472,7 @@ test('results with errors and disabled code excerpts', t => {
474472
indentString(codeExcerpt(err2Path, error2.source.line), 2).split('\n'),
475473
'',
476474
indentString(formatAssertError(error2), 2).split('\n'),
477-
/error two message/,
478-
'',
479-
stackLineRegex
475+
/error two message/
480476
]));
481477
t.end();
482478
});
@@ -535,9 +531,7 @@ test('results with errors and disabled code excerpts', t => {
535531
indentString(codeExcerpt(err2Path, error2.source.line), 2).split('\n'),
536532
'',
537533
indentString(formatAssertError(error2), 2).split('\n'),
538-
/error two message/,
539-
'',
540-
stackLineRegex
534+
/error two message/
541535
]));
542536
t.end();
543537
});
@@ -597,9 +591,7 @@ test('results with errors and disabled assert output', t => {
597591
indentString(codeExcerpt(err2Path, error2.source.line), 2).split('\n'),
598592
'',
599593
indentString(formatAssertError(error2), 2).split('\n'),
600-
/error two message/,
601-
'',
602-
stackLineRegex
594+
/error two message/
603595
]));
604596
t.end();
605597
});

0 commit comments

Comments
 (0)