MCPcopy
hub / github.com/jestjs/jest / formatErrorStack

Function formatErrorStack

packages/jest-message-util/src/index.ts:407–439  ·  view source on GitHub ↗
(
  errorOrStack: Error | string,
  config: StackTraceConfig,
  options: StackTraceOptions,
  testPath?: string,
)

Source from the content-addressed store, hash-verified

405}
406
407function 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
441function failureDetailsToErrorOrStack(
442 failureDetails: unknown,

Callers 1

formatResultsErrorsFunction · 0.85

Calls 5

separateMessageFromStackFunction · 0.85
formatStackTraceFunction · 0.85
indentAllLinesFunction · 0.85
isErrorOrStackWithCauseFunction · 0.70

Tested by

no test coverage detected