@@ -3,13 +3,12 @@ import { hostname } from 'node:os'
33import { dirname , relative , resolve } from 'pathe'
44
55import type { Task } from '@vitest/runner'
6- import type { ErrorWithDiff } from '@vitest/utils'
76import { getSuites } from '@vitest/runner/utils'
7+ import stripAnsi from 'strip-ansi'
88import type { Vitest } from '../../node'
99import type { Reporter } from '../../types/reporter'
10- import { parseErrorStacktrace } from '../../utils/source-map'
11- import { F_POINTER } from '../../utils/figures'
1210import { getOutputFile } from '../../utils/config-helpers'
11+ import { captuerPrintError } from '../error'
1312import { IndentedLogger } from './renderers/indented-logger'
1413
1514export interface JUnitOptions {
@@ -140,31 +139,6 @@ export class JUnitReporter implements Reporter {
140139 await this . logger . log ( `</${ name } >` )
141140 }
142141
143- async writeErrorDetails ( task : Task , error : ErrorWithDiff ) : Promise < void > {
144- const errorName = error . name ?? error . nameStr ?? 'Unknown Error'
145- const errorDetails = `${ errorName } : ${ error . message } `
146-
147- // Be sure to escape any XML in the error Details
148- await this . baseLog ( escapeXML ( errorDetails ) )
149-
150- const project = this . ctx . getProjectByTaskId ( task . id )
151- const stack = parseErrorStacktrace ( error , {
152- getSourceMap : file => project . getBrowserSourceMapModuleById ( file ) ,
153- frameFilter : this . ctx . config . onStackTrace ,
154- } )
155-
156- // TODO: This is same as printStack but without colors. Find a way to reuse code.
157- for ( const frame of stack ) {
158- const path = relative ( this . ctx . config . root , frame . file )
159-
160- await this . baseLog ( escapeXML ( ` ${ F_POINTER } ${ [ frame . method , `${ path } :${ frame . line } :${ frame . column } ` ] . filter ( Boolean ) . join ( ' ' ) } ` ) )
161-
162- // reached at test file, skip the follow stack
163- if ( frame . file in this . ctx . state . filesMap )
164- break
165- }
166- }
167-
168142 async writeLogs ( task : Task , type : 'err' | 'out' ) : Promise < void > {
169143 if ( task . logs == null || task . logs . length === 0 )
170144 return
@@ -205,7 +179,12 @@ export class JUnitReporter implements Reporter {
205179 if ( ! error )
206180 return
207181
208- await this . writeErrorDetails ( task , error )
182+ const result = await captuerPrintError (
183+ error ,
184+ this . ctx ,
185+ this . ctx . getProjectByTaskId ( task . id ) ,
186+ )
187+ await this . baseLog ( escapeXML ( stripAnsi ( result . output . trim ( ) ) ) )
209188 } )
210189 }
211190 }
0 commit comments