Skip to content

Commit fa9b502

Browse files
committed
Trim JUnit stack traces some
1 parent 6a1a1bd commit fa9b502

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

dist/index.js

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/grader/builder/surefire.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ export interface SurefireReport {
4040
}
4141
}
4242

43+
function trimJunit5StackTrace(stackTrace: string): string {
44+
if (!stackTrace) {
45+
return ''
46+
}
47+
const lines = stackTrace.split('\n')
48+
const idxOfJunitLine = lines.findIndex((line) =>
49+
line.includes('org.junit.jupiter.engine.execution.MethodInvocation.proceed')
50+
)
51+
return idxOfJunitLine === -1
52+
? stackTrace
53+
: lines.slice(0, idxOfJunitLine).join('\n')
54+
}
55+
4356
export function parseSurefireXml(filePath: string): SurefireReport {
4457
const xmlContent = readFileSync(filePath, 'utf-8')
4558
const parser = new XMLParser({
@@ -93,7 +106,7 @@ export function parseSurefireXml(filePath: string): SurefireReport {
93106
message: testCase.failure.message || '',
94107
type: testCase.failure.type || '',
95108
description: testCase.failure._text || '',
96-
stackTrace: testCase.failure._text || ''
109+
stackTrace: trimJunit5StackTrace(testCase.failure._text || '')
97110
}
98111
}
99112

@@ -103,7 +116,7 @@ export function parseSurefireXml(filePath: string): SurefireReport {
103116
message: testCase.error.message || '',
104117
type: testCase.error.type || '',
105118
description: testCase.error._text || '',
106-
stackTrace: testCase.error._text || ''
119+
stackTrace: trimJunit5StackTrace(testCase.error._text || '')
107120
}
108121
}
109122

0 commit comments

Comments
 (0)