Skip to content

Commit

Permalink
Don't print empty error stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed Apr 25, 2020
1 parent 2e7c76b commit af7b2d5
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 43 deletions.
6 changes: 5 additions & 1 deletion lib/reporters/beautify-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,9 @@ module.exports = stack => {
return [];
}

return stackUtils.clean(stack).trim().split('\n');
return stackUtils.clean(stack)
.trim()
.split('\n')
.map(line => line.trim())
.filter(line => line !== '');
};
18 changes: 10 additions & 8 deletions lib/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,27 +324,29 @@ class MiniReporter {
this.lineWriter.writeLine(evt.err.summary);
}

if (evt.err.stack) {
const {stack} = evt.err;
if (stack.includes('\n')) {
this.lineWriter.writeLine();
this.lineWriter.writeLine(this.formatErrorStack(evt.err));
}
const formatted = this.formatErrorStack(evt.err);
if (formatted.length > 0) {
this.lineWriter.writeLine();
this.lineWriter.writeLine(formatted.join('\n'));
}
}

formatErrorStack(error) {
if (!error.stack) {
return [];
}

if (error.shouldBeautifyStack) {
return beautifyStack(error.stack).map(line => {
if (nodeInternals.some(internal => internal.test(line))) {
return colors.errorStackInternal(`${figures.pointerSmall} ${line}`);
}

return colors.errorStack(`${figures.pointerSmall} ${line}`);
}).join('\n');
});
}

return error.stack;
return [error.stack];
}

writeLogs(evt) {
Expand Down
18 changes: 10 additions & 8 deletions lib/reporters/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,27 +263,29 @@ class VerboseReporter {
this.lineWriter.writeLine(evt.err.summary);
}

if (evt.err.stack) {
const {stack} = evt.err;
if (stack.includes('\n')) {
this.lineWriter.writeLine();
this.lineWriter.writeLine(this.formatErrorStack(evt.err));
}
const formatted = this.formatErrorStack(evt.err);
if (formatted.length > 0) {
this.lineWriter.writeLine();
this.lineWriter.writeLine(formatted.join('\n'));
}
}

formatErrorStack(error) {
if (!error.stack) {
return [];
}

if (error.shouldBeautifyStack) {
return beautifyStack(error.stack).map(line => {
if (nodeInternals.some(internal => internal.test(line))) {
return colors.errorStackInternal(`${figures.pointerSmall} ${line}`);
}

return colors.errorStack(`${figures.pointerSmall} ${line}`);
}).join('\n');
});
}

return error.stack;
return [error.stack];
}

writePendingTests(evt) {
Expand Down
4 changes: 0 additions & 4 deletions test-tap/reporters/mini.regular.v12.log
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@

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

› 



test › logs
Expand Down Expand Up @@ -325,8 +323,6 @@

null

› 



traces-in-t-throws › throws
Expand Down
4 changes: 0 additions & 4 deletions test-tap/reporters/mini.regular.v13.log
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@

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

› 



test › logs
Expand Down Expand Up @@ -325,8 +323,6 @@

null

› 



traces-in-t-throws › throws
Expand Down
4 changes: 0 additions & 4 deletions test-tap/reporters/mini.regular.v14.log
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@

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

› 



test › logs
Expand Down Expand Up @@ -325,8 +323,6 @@

null

› 



traces-in-t-throws › throws
Expand Down
4 changes: 0 additions & 4 deletions test-tap/reporters/verbose.regular.v12.log
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@

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

› 



test › logs
Expand Down Expand Up @@ -285,8 +283,6 @@

null

› 



traces-in-t-throws › throws
Expand Down
6 changes: 1 addition & 5 deletions test-tap/reporters/verbose.regular.v13.log
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
output-in-hook › beforeEach hook for failing test
ℹ beforeEach
---tty-stream-chunk-separator
✔ output-in-hook › passing test
✔ output-in-hook › passing test (105ms)
---tty-stream-chunk-separator
✖ output-in-hook › failing test Test failed via `t.fail()`
---tty-stream-chunk-separator
Expand Down Expand Up @@ -164,8 +164,6 @@

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

› 



test › logs
Expand Down Expand Up @@ -285,8 +283,6 @@

null

› 



traces-in-t-throws › throws
Expand Down
4 changes: 0 additions & 4 deletions test-tap/reporters/verbose.regular.v14.log
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@

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

› 



test › logs
Expand Down Expand Up @@ -285,8 +283,6 @@

null

› 



traces-in-t-throws › throws
Expand Down
2 changes: 1 addition & 1 deletion test-tap/reporters/verbose.watch.v12.log
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
---tty-stream-chunk-separator

---tty-stream-chunk-separator
✔ test › passes
✔ test › passes (198ms)
---tty-stream-chunk-separator

1 test passed [17:19:12]
Expand Down

0 comments on commit af7b2d5

Please sign in to comment.