Skip to content

Commit af7b2d5

Browse files
committed
Don't print empty error stacks
1 parent 2e7c76b commit af7b2d5

File tree

10 files changed

+27
-43
lines changed

10 files changed

+27
-43
lines changed

lib/reporters/beautify-stack.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,9 @@ module.exports = stack => {
6565
return [];
6666
}
6767

68-
return stackUtils.clean(stack).trim().split('\n');
68+
return stackUtils.clean(stack)
69+
.trim()
70+
.split('\n')
71+
.map(line => line.trim())
72+
.filter(line => line !== '');
6973
};

lib/reporters/mini.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,27 +324,29 @@ class MiniReporter {
324324
this.lineWriter.writeLine(evt.err.summary);
325325
}
326326

327-
if (evt.err.stack) {
328-
const {stack} = evt.err;
329-
if (stack.includes('\n')) {
330-
this.lineWriter.writeLine();
331-
this.lineWriter.writeLine(this.formatErrorStack(evt.err));
332-
}
327+
const formatted = this.formatErrorStack(evt.err);
328+
if (formatted.length > 0) {
329+
this.lineWriter.writeLine();
330+
this.lineWriter.writeLine(formatted.join('\n'));
333331
}
334332
}
335333

336334
formatErrorStack(error) {
335+
if (!error.stack) {
336+
return [];
337+
}
338+
337339
if (error.shouldBeautifyStack) {
338340
return beautifyStack(error.stack).map(line => {
339341
if (nodeInternals.some(internal => internal.test(line))) {
340342
return colors.errorStackInternal(`${figures.pointerSmall} ${line}`);
341343
}
342344

343345
return colors.errorStack(`${figures.pointerSmall} ${line}`);
344-
}).join('\n');
346+
});
345347
}
346348

347-
return error.stack;
349+
return [error.stack];
348350
}
349351

350352
writeLogs(evt) {

lib/reporters/verbose.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,27 +263,29 @@ class VerboseReporter {
263263
this.lineWriter.writeLine(evt.err.summary);
264264
}
265265

266-
if (evt.err.stack) {
267-
const {stack} = evt.err;
268-
if (stack.includes('\n')) {
269-
this.lineWriter.writeLine();
270-
this.lineWriter.writeLine(this.formatErrorStack(evt.err));
271-
}
266+
const formatted = this.formatErrorStack(evt.err);
267+
if (formatted.length > 0) {
268+
this.lineWriter.writeLine();
269+
this.lineWriter.writeLine(formatted.join('\n'));
272270
}
273271
}
274272

275273
formatErrorStack(error) {
274+
if (!error.stack) {
275+
return [];
276+
}
277+
276278
if (error.shouldBeautifyStack) {
277279
return beautifyStack(error.stack).map(line => {
278280
if (nodeInternals.some(internal => internal.test(line))) {
279281
return colors.errorStackInternal(`${figures.pointerSmall} ${line}`);
280282
}
281283

282284
return colors.errorStack(`${figures.pointerSmall} ${line}`);
283-
}).join('\n');
285+
});
284286
}
285287

286-
return error.stack;
288+
return [error.stack];
287289
}
288290

289291
writePendingTests(evt) {

test-tap/reporters/mini.regular.v12.log

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@
204204

205205
Error: Test was expected to fail, but succeeded, you should stop marking the test as failing
206206

207-
› 
208-
209207

210208

211209
test › logs
@@ -325,8 +323,6 @@
325323

326324
null
327325

328-
› 
329-
330326

331327

332328
traces-in-t-throws › throws

test-tap/reporters/mini.regular.v13.log

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@
204204

205205
Error: Test was expected to fail, but succeeded, you should stop marking the test as failing
206206

207-
› 
208-
209207

210208

211209
test › logs
@@ -325,8 +323,6 @@
325323

326324
null
327325

328-
› 
329-
330326

331327

332328
traces-in-t-throws › throws

test-tap/reporters/mini.regular.v14.log

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@
204204

205205
Error: Test was expected to fail, but succeeded, you should stop marking the test as failing
206206

207-
› 
208-
209207

210208

211209
test › logs
@@ -325,8 +323,6 @@
325323

326324
null
327325

328-
› 
329-
330326

331327

332328
traces-in-t-throws › throws

test-tap/reporters/verbose.regular.v12.log

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@
164164

165165
Error: Test was expected to fail, but succeeded, you should stop marking the test as failing
166166

167-
› 
168-
169167

170168

171169
test › logs
@@ -285,8 +283,6 @@
285283

286284
null
287285

288-
› 
289-
290286

291287

292288
traces-in-t-throws › throws

test-tap/reporters/verbose.regular.v13.log

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
output-in-hook › beforeEach hook for failing test
2525
ℹ beforeEach
2626
---tty-stream-chunk-separator
27-
✔ output-in-hook › passing test
27+
✔ output-in-hook › passing test (105ms)
2828
---tty-stream-chunk-separator
2929
✖ output-in-hook › failing test Test failed via `t.fail()`
3030
---tty-stream-chunk-separator
@@ -164,8 +164,6 @@
164164

165165
Error: Test was expected to fail, but succeeded, you should stop marking the test as failing
166166

167-
› 
168-
169167

170168

171169
test › logs
@@ -285,8 +283,6 @@
285283

286284
null
287285

288-
› 
289-
290286

291287

292288
traces-in-t-throws › throws

test-tap/reporters/verbose.regular.v14.log

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@
164164

165165
Error: Test was expected to fail, but succeeded, you should stop marking the test as failing
166166

167-
› 
168-
169167

170168

171169
test › logs
@@ -285,8 +283,6 @@
285283

286284
null
287285

288-
› 
289-
290286

291287

292288
traces-in-t-throws › throws

test-tap/reporters/verbose.watch.v12.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
---tty-stream-chunk-separator
1111

1212
---tty-stream-chunk-separator
13-
✔ test › passes
13+
✔ test › passes (198ms)
1414
---tty-stream-chunk-separator
1515

1616
1 test passed [17:19:12]

0 commit comments

Comments
 (0)