( errorOrStack: Error | string, config: StackTraceConfig, options: StackTraceOptions, testPath?: string, )
| 405 | } |
| 406 | |
| 407 | function formatErrorStack( |
| 408 | errorOrStack: Error | string, |
| 409 | config: StackTraceConfig, |
| 410 | options: StackTraceOptions, |
| 411 | testPath?: string, |
| 412 | ): string { |
| 413 | // The stack of new Error('message') contains both the message and the stack, |
| 414 | // thus we need to sanitize and clean it for proper display using separateMessageFromStack. |
| 415 | const sourceStack = |
| 416 | typeof errorOrStack === 'string' ? errorOrStack : errorOrStack.stack || ''; |
| 417 | let {message, stack} = separateMessageFromStack(sourceStack); |
| 418 | stack = options.noStackTrace |
| 419 | ? '' |
| 420 | : `${STACK_TRACE_COLOR( |
| 421 | formatStackTrace(stack, config, options, testPath), |
| 422 | )}\n`; |
| 423 | |
| 424 | message = checkForCommonEnvironmentErrors(message); |
| 425 | message = indentAllLines(message); |
| 426 | |
| 427 | let cause = ''; |
| 428 | if (isErrorOrStackWithCause(errorOrStack)) { |
| 429 | const nestedCause = formatErrorStack( |
| 430 | errorOrStack.cause, |
| 431 | config, |
| 432 | options, |
| 433 | testPath, |
| 434 | ); |
| 435 | cause = `\n${MESSAGE_INDENT}Cause:\n${nestedCause}`; |
| 436 | } |
| 437 | |
| 438 | return `${message}\n${stack}${cause}`; |
| 439 | } |
| 440 | |
| 441 | function failureDetailsToErrorOrStack( |
| 442 | failureDetails: unknown, |
no test coverage detected