@@ -8,13 +8,19 @@ interface JUnitTestCase {
8
8
classname : string ;
9
9
name : string ;
10
10
time : string ;
11
- failure ?: string ;
12
- error ?: string ;
11
+ hasFailure : boolean ;
12
+ failureTrace : string | undefined ,
13
+ failureMessage : string | undefined ,
14
+ failureType : string | undefined ,
15
+ hasError : boolean ,
16
+ errorTrace : string | undefined ,
17
+ errorMessage : string | undefined ,
18
+ errorType : string | undefined ,
13
19
skipped ?: boolean ;
14
20
}
15
21
16
22
async function parseJUnitReport ( filePath : string ) : Promise < JUnitTestCase [ ] > {
17
- console . log ( 'Reading JUnit report file:' , filePath ) ;
23
+ console . log ( 'Reading JUnit report file:' , filePath ) ;
18
24
const xml = await fs . readFile ( filePath , 'utf-8' ) ;
19
25
const result = await xml2js . parseStringPromise ( xml ) ;
20
26
const testCases : JUnitTestCase [ ] = [ ] ;
@@ -23,16 +29,31 @@ async function parseJUnitReport(filePath: string): Promise<JUnitTestCase[]> {
23
29
if ( suite . testcase ) {
24
30
suite . testcase . forEach ( ( testCase : any ) => {
25
31
const { classname, name, time } = testCase . $ ;
26
- const failure = testCase . failure ? testCase . failure [ 0 ] : undefined ;
27
- const error = testCase . error ? testCase . error [ 0 ] : undefined ;
32
+
33
+ const hasFailure = testCase . failure !== undefined ;
34
+ const failureTrace = hasFailure ? ( testCase . failure [ 0 ] ?. _ || '' ) : undefined ;
35
+ const failureMessage = hasFailure ? ( testCase . failure [ 0 ] ?. $ ?. message || '' ) : undefined ;
36
+ const failureType = hasFailure ? ( testCase . failure [ 0 ] ?. $ ?. type || '' ) : undefined ;
37
+
38
+ const hasError = testCase . error !== undefined ;
39
+ const errorTrace = hasError ? ( testCase . error [ 0 ] ?. _ || '' ) : undefined ;
40
+ const errorMessage = hasError ? ( testCase . error [ 0 ] ?. $ ?. message || '' ) : undefined ;
41
+ const errorType = hasError ? ( testCase . error [ 0 ] ?. $ ?. type || '' ) : undefined ;
42
+
28
43
const skipped = testCase . skipped !== undefined ;
29
44
testCases . push ( {
30
45
suite : suiteName ,
31
46
classname,
32
47
name,
33
48
time,
34
- failure : failure ? ( typeof failure === 'string' ? failure : failure . _ ) : undefined ,
35
- error : error ? ( typeof error === 'string' ? error : error . _ ) : undefined ,
49
+ hasFailure,
50
+ failureTrace,
51
+ failureMessage,
52
+ failureType,
53
+ hasError,
54
+ errorTrace,
55
+ errorMessage,
56
+ errorType,
36
57
skipped,
37
58
} ) ;
38
59
} ) ;
@@ -64,17 +85,17 @@ async function parseJUnitReport(filePath: string): Promise<JUnitTestCase[]> {
64
85
function convertToCTRFTest ( testCase : JUnitTestCase , useSuiteName : boolean ) : CtrfTest {
65
86
let status : CtrfTest [ 'status' ] = 'other' ;
66
87
67
- if ( testCase . failure ) {
88
+ if ( testCase . hasFailure ) {
68
89
status = 'failed' ;
69
- } else if ( testCase . error ) {
90
+ } else if ( testCase . hasError ) {
70
91
status = 'failed' ;
71
92
} else if ( testCase . skipped ) {
72
93
status = 'skipped' ;
73
94
} else {
74
95
status = 'passed' ;
75
96
}
76
97
77
- const durationMs = Math . round ( parseFloat ( testCase . time ) * 1000 ) ;
98
+ const durationMs = Math . round ( parseFloat ( testCase . time || '0' ) * 1000 ) ;
78
99
79
100
const testName = useSuiteName
80
101
? `${ testCase . suite } : ${ testCase . name } `
@@ -84,9 +105,9 @@ function convertToCTRFTest(testCase: JUnitTestCase, useSuiteName: boolean): Ctrf
84
105
name : testName ,
85
106
status,
86
107
duration : durationMs ,
87
- message : testCase . failure || testCase . error ? ( testCase . failure || testCase . error ) : undefined ,
88
- trace : testCase . failure || testCase . error ? ( testCase . failure || testCase . error ) : undefined ,
89
- suite : testCase . suite || ''
108
+ message : testCase . failureMessage || testCase . errorMessage || undefined ,
109
+ trace : testCase . failureTrace || testCase . errorTrace || undefined ,
110
+ suite : testCase . suite || '' ,
90
111
} ;
91
112
}
92
113
@@ -110,8 +131,8 @@ function createCTRFReport(
110
131
skipped,
111
132
pending,
112
133
other,
113
- start : 0 ,
114
- stop : 0 ,
134
+ start : 0 ,
135
+ stop : 0 ,
115
136
} ;
116
137
117
138
const tool : Tool = {
@@ -150,6 +171,6 @@ export async function convertJUnitToCTRF(
150
171
const outputDir = path . dirname ( finalOutputPath ) ;
151
172
await fs . ensureDir ( outputDir ) ;
152
173
153
- console . log ( 'Writing CTRF report to:' , finalOutputPath ) ;
174
+ console . log ( 'Writing CTRF report to:' , finalOutputPath ) ;
154
175
await fs . outputJson ( finalOutputPath , ctrfReport , { spaces : 2 } ) ;
155
176
}
0 commit comments