@@ -4,41 +4,40 @@ import { Writable } from 'node:stream'
4
4
import { normalize , relative } from 'pathe'
5
5
import c from 'picocolors'
6
6
import cliTruncate from 'cli-truncate'
7
- import type { StackTraceParserOptions } from '@vitest/utils/source-map'
8
7
import { inspect } from '@vitest/utils'
9
8
import stripAnsi from 'strip-ansi'
10
9
import type { ErrorWithDiff , ParsedStack } from '../types'
11
10
import {
12
11
lineSplitRE ,
13
- parseErrorStacktrace ,
14
12
positionToOffset ,
15
13
} from '../utils/source-map'
16
14
import { F_POINTER } from '../utils/figures'
17
15
import { TypeCheckError } from '../typecheck/typechecker'
18
16
import { isPrimitive } from '../utils'
19
17
import type { Vitest } from './core'
20
18
import { divider } from './reporters/renderers/utils'
19
+ import type { ErrorOptions } from './logger'
21
20
import { Logger } from './logger'
22
21
import type { WorkspaceProject } from './workspace'
23
22
24
23
interface PrintErrorOptions {
25
24
type ?: string
26
25
logger : Logger
27
- fullStack ?: boolean
28
26
showCodeFrame ?: boolean
29
27
printProperties ?: boolean
30
28
screenshotPaths ?: string [ ]
29
+ parseErrorStacktrace : ( error : ErrorWithDiff ) => ParsedStack [ ]
31
30
}
32
31
33
- interface PrintErrorResult {
32
+ export interface PrintErrorResult {
34
33
nearest ?: ParsedStack
35
34
}
36
35
37
36
// use Logger with custom Console to capture entire error printing
38
37
export function capturePrintError (
39
38
error : unknown ,
40
39
ctx : Vitest ,
41
- project : WorkspaceProject ,
40
+ options : ErrorOptions ,
42
41
) {
43
42
let output = ''
44
43
const writable = new Writable ( {
@@ -47,9 +46,10 @@ export function capturePrintError(
47
46
callback ( )
48
47
} ,
49
48
} )
50
- const result = printError ( error , project , {
49
+ const logger = new Logger ( ctx , writable , writable )
50
+ const result = logger . printError ( error , {
51
51
showCodeFrame : false ,
52
- logger : new Logger ( ctx , writable , writable ) ,
52
+ ... options ,
53
53
} )
54
54
return { nearest : result ?. nearest , output }
55
55
}
@@ -59,7 +59,7 @@ export function printError(
59
59
project : WorkspaceProject | undefined ,
60
60
options : PrintErrorOptions ,
61
61
) : PrintErrorResult | undefined {
62
- const { showCodeFrame = true , fullStack = false , type, printProperties = true } = options
62
+ const { showCodeFrame = true , type, printProperties = true } = options
63
63
const logger = options . logger
64
64
let e = error as ErrorWithDiff
65
65
@@ -84,16 +84,7 @@ export function printError(
84
84
return
85
85
}
86
86
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 )
97
88
98
89
const nearest
99
90
= error instanceof TypeCheckError
@@ -195,9 +186,9 @@ export function printError(
195
186
if ( typeof e . cause === 'object' && e . cause && 'name' in e . cause ) {
196
187
( e . cause as any ) . name = `Caused by: ${ ( e . cause as any ) . name } `
197
188
printError ( e . cause , project , {
198
- fullStack,
199
189
showCodeFrame : false ,
200
190
logger : options . logger ,
191
+ parseErrorStacktrace : options . parseErrorStacktrace ,
201
192
} )
202
193
}
203
194
0 commit comments