mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-16 14:27:10 +01:00
refactor: extract parsing java StackTraceElement to allow improving
This commit is contained in:
parent
b41f730922
commit
e5edb614dd
3 changed files with 66 additions and 4 deletions
|
|
@ -3,6 +3,7 @@ import {ParseOptions, TestParser} from '../../test-parser'
|
|||
import {parseStringPromise} from 'xml2js'
|
||||
|
||||
import {JunitReport, SingleSuiteReport, TestCase, TestSuite} from './java-junit-types'
|
||||
import {parseStackTraceElement} from './java-stack-trace-element-parser'
|
||||
import {normalizeFilePath} from '../../utils/path-utils'
|
||||
|
||||
import {
|
||||
|
|
@ -144,12 +145,11 @@ export class JavaJunitParser implements TestParser {
|
|||
|
||||
private exceptionThrowSource(stackTrace: string): {filePath: string; line: number} | undefined {
|
||||
const lines = stackTrace.split(/\r?\n/)
|
||||
const re = /^at (.*)\((.*):(\d+)\)$/
|
||||
|
||||
for (const str of lines) {
|
||||
const match = str.match(re)
|
||||
if (match !== null) {
|
||||
const [_, tracePath, fileName, lineStr] = match
|
||||
const stackTraceElement = parseStackTraceElement(str)
|
||||
if (stackTraceElement) {
|
||||
const {tracePath, fileName, lineStr} = stackTraceElement
|
||||
const filePath = this.getFilePath(tracePath, fileName)
|
||||
if (filePath !== undefined) {
|
||||
const line = parseInt(lineStr)
|
||||
|
|
|
|||
22
src/parsers/java-junit/java-stack-trace-element-parser.ts
Normal file
22
src/parsers/java-junit/java-stack-trace-element-parser.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
export interface StackTraceElement {
|
||||
tracePath: string
|
||||
fileName: string
|
||||
lineStr: string
|
||||
}
|
||||
|
||||
// simple format:
|
||||
// at <FULLY_QUALIFIED_METHOD_NAME>(<FILE_NAME>:<LINE_NUMBER>)
|
||||
const re = /^at (.*)\((.*):(\d+)\)$/
|
||||
|
||||
export function parseStackTraceElement(stackTraceLine: string): StackTraceElement | undefined {
|
||||
const match = stackTraceLine.match(re)
|
||||
if (match !== null) {
|
||||
const [_, tracePath, fileName, lineStr] = match
|
||||
return {
|
||||
tracePath,
|
||||
fileName,
|
||||
lineStr
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue