in src/reporters/reporter-util.ts [166:185]
export function serializeError(
error: Error | any,
highlightCode = true
): TestError {
if (!(error instanceof Error) || !error.stack) {
return { message: `thrown: ${inspect(error)}` };
}
const testErr: TestError = { message: error.message };
const { message, stack, location } = prepareError(error);
testErr.message = message;
if (stack) {
testErr.stack = stack;
}
if (location && highlightCode) {
testErr.location = location;
testErr.source = highLightSource(testErr.location);
}
return testErr;
}