@@ -40,17 +40,36 @@ export interface SurefireReport {
40
40
}
41
41
}
42
42
43
- function trimJunit5StackTrace ( stackTrace : string ) : string {
43
+ function trimJunitStackTrace ( stackTrace : string ) : string {
44
44
if ( ! stackTrace ) {
45
45
return ''
46
46
}
47
47
const lines = stackTrace . split ( '\n' )
48
- const idxOfJunitLine = lines . findIndex ( ( line ) =>
49
- line . includes ( 'org.junit.jupiter.engine.execution.MethodInvocation.proceed' )
48
+ const idxOfJunitLine = lines . findIndex (
49
+ ( line ) =>
50
+ line . includes (
51
+ 'org.junit.jupiter.engine.execution.MethodInvocation.proceed'
52
+ ) || line . includes ( 'org.junit.runners.BlockJUnit4ClassRunner' )
50
53
)
51
- return idxOfJunitLine === - 1
52
- ? stackTrace
53
- : lines . slice ( 0 , idxOfJunitLine ) . join ( '\n' )
54
+ if ( idxOfJunitLine === - 1 ) {
55
+ return stackTrace
56
+ }
57
+
58
+ let idxOfLastReflectionLineFromBottom = - 1
59
+ for ( let i = idxOfJunitLine - 1 ; i >= 0 ; i -- ) {
60
+ if (
61
+ ! lines [ i ] . includes ( 'jdk.internal.reflect' ) &&
62
+ ! lines [ i ] . includes ( 'java.lang.reflect' ) &&
63
+ ! lines [ i ] . includes ( 'org.junit.platform.commons.util.ReflectionUtils' )
64
+ ) {
65
+ idxOfLastReflectionLineFromBottom = i + 1
66
+ break
67
+ }
68
+ }
69
+ if ( idxOfLastReflectionLineFromBottom === - 1 ) {
70
+ return lines . slice ( 0 , idxOfJunitLine ) . join ( '\n' )
71
+ }
72
+ return lines . slice ( 0 , idxOfLastReflectionLineFromBottom ) . join ( '\n' )
54
73
}
55
74
56
75
export function parseSurefireXml ( filePath : string ) : SurefireReport {
@@ -106,7 +125,7 @@ export function parseSurefireXml(filePath: string): SurefireReport {
106
125
message : testCase . failure . message || '' ,
107
126
type : testCase . failure . type || '' ,
108
127
description : testCase . failure . _text || '' ,
109
- stackTrace : trimJunit5StackTrace ( testCase . failure . _text || '' )
128
+ stackTrace : trimJunitStackTrace ( testCase . failure . _text || '' )
110
129
}
111
130
}
112
131
@@ -116,7 +135,7 @@ export function parseSurefireXml(filePath: string): SurefireReport {
116
135
message : testCase . error . message || '' ,
117
136
type : testCase . error . type || '' ,
118
137
description : testCase . error . _text || '' ,
119
- stackTrace : trimJunit5StackTrace ( testCase . error . _text || '' )
138
+ stackTrace : trimJunitStackTrace ( testCase . error . _text || '' )
120
139
}
121
140
}
122
141
0 commit comments