@@ -4,41 +4,40 @@ import { Writable } from 'node:stream'
44import { normalize , relative } from 'pathe'
55import c from 'picocolors'
66import cliTruncate from 'cli-truncate'
7- import type { StackTraceParserOptions } from '@vitest/utils/source-map'
87import { inspect } from '@vitest/utils'
98import stripAnsi from 'strip-ansi'
109import type { ErrorWithDiff , ParsedStack } from '../types'
1110import {
1211 lineSplitRE ,
13- parseErrorStacktrace ,
1412 positionToOffset ,
1513} from '../utils/source-map'
1614import { F_POINTER } from '../utils/figures'
1715import { TypeCheckError } from '../typecheck/typechecker'
1816import { isPrimitive } from '../utils'
1917import type { Vitest } from './core'
2018import { divider } from './reporters/renderers/utils'
19+ import type { ErrorOptions } from './logger'
2120import { Logger } from './logger'
2221import type { WorkspaceProject } from './workspace'
2322
2423interface PrintErrorOptions {
2524 type ?: string
2625 logger : Logger
27- fullStack ?: boolean
2826 showCodeFrame ?: boolean
2927 printProperties ?: boolean
3028 screenshotPaths ?: string [ ]
29+ parseErrorStacktrace : ( error : ErrorWithDiff ) => ParsedStack [ ]
3130}
3231
33- interface PrintErrorResult {
32+ export interface PrintErrorResult {
3433 nearest ?: ParsedStack
3534}
3635
3736// use Logger with custom Console to capture entire error printing
3837export function capturePrintError (
3938 error : unknown ,
4039 ctx : Vitest ,
41- project : WorkspaceProject ,
40+ options : ErrorOptions ,
4241) {
4342 let output = ''
4443 const writable = new Writable ( {
@@ -47,9 +46,10 @@ export function capturePrintError(
4746 callback ( )
4847 } ,
4948 } )
50- const result = printError ( error , project , {
49+ const logger = new Logger ( ctx , writable , writable )
50+ const result = logger . printError ( error , {
5151 showCodeFrame : false ,
52- logger : new Logger ( ctx , writable , writable ) ,
52+ ... options ,
5353 } )
5454 return { nearest : result ?. nearest , output }
5555}
@@ -59,7 +59,7 @@ export function printError(
5959 project : WorkspaceProject | undefined ,
6060 options : PrintErrorOptions ,
6161) : PrintErrorResult | undefined {
62- const { showCodeFrame = true , fullStack = false , type, printProperties = true } = options
62+ const { showCodeFrame = true , type, printProperties = true } = options
6363 const logger = options . logger
6464 let e = error as ErrorWithDiff
6565
@@ -84,16 +84,7 @@ export function printError(
8484 return
8585 }
8686
87- const parserOptions : StackTraceParserOptions = {
88- // only browser stack traces require remapping
89- getSourceMap : file => project . getBrowserSourceMapModuleById ( file ) ,
90- frameFilter : project . config . onStackTrace ,
91- }
92-
93- if ( fullStack ) {
94- parserOptions . ignoreStackEntries = [ ]
95- }
96- const stacks = parseErrorStacktrace ( e , parserOptions )
87+ const stacks = options . parseErrorStacktrace ( e )
9788
9889 const nearest
9990 = error instanceof TypeCheckError
@@ -195,9 +186,9 @@ export function printError(
195186 if ( typeof e . cause === 'object' && e . cause && 'name' in e . cause ) {
196187 ( e . cause as any ) . name = `Caused by: ${ ( e . cause as any ) . name } `
197188 printError ( e . cause , project , {
198- fullStack,
199189 showCodeFrame : false ,
200190 logger : options . logger ,
191+ parseErrorStacktrace : options . parseErrorStacktrace ,
201192 } )
202193 }
203194
0 commit comments