Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/reporters/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const colors = {
get stack() {
return chalk.red;
},
get cause() {
return chalk.cyan;
},
get information() {
return chalk.magenta;
},
Expand Down
11 changes: 11 additions & 0 deletions lib/reporters/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,17 @@ export default class Reporter {
}
}

const hasCause = error.cause instanceof Object && (error.cause.message || error.cause.stack);
if (hasCause) {
const {cause} = error;
this.lineWriter.writeLine(colors.cause('Cause:'));
this.lineWriter.writeLine(colors.cause(cause.message ?? ''));
if (cause.stack) {
this.lineWriter.writeLine(colors.cause(cause.stack));
}
this.lineWriter.writeLine();
}

let summary = '';
let printStack = true;
if (error.type === 'native') {
Expand Down
3 changes: 2 additions & 1 deletion lib/serialize-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ export default function serializeError(error, {testFile = null} = {}) {
};
}

const {message, name, stack} = error;
const {message, name, stack, cause} = error;
const base = {
message,
name,
originalError: error, // Note that the main process receives a structured clone.
stack,
cause,
};

if (!isAvaAssertionError(error)) {
Expand Down
Loading