remove auto conversion of XML attributes based on value

This commit is contained in:
Michal Dorner 2021-01-24 21:05:34 +01:00
parent 1a9ca69197
commit 40b5f476c7
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
6 changed files with 44 additions and 55 deletions

View file

@ -5,8 +5,8 @@ import {Annotation, FileContent, ParseOptions, TestResult} from '../parser-types
import {parseStringPromise} from 'xml2js'
import {normalizeFilePath} from '../../utils/file-utils'
import {parseAttribute} from '../../utils/xml-utils'
import {Icon, fixEol} from '../../utils/markdown-utils'
import {parseIsoDate, parseNetDuration} from '../../utils/parse-utils'
import {
TestExecutionResult,
@ -70,9 +70,7 @@ export async function parseDotnetTrx(files: FileContent[], options: ParseOptions
async function getTrxReport(file: FileContent): Promise<TrxReport> {
core.info(`Parsing content of '${file.path}'`)
try {
return (await parseStringPromise(file.content, {
attrValueProcessors: [parseAttribute]
})) as TrxReport
return (await parseStringPromise(file.content)) as TrxReport
} catch (e) {
throw new Error(`Invalid XML at ${file.path}\n\n${e}`)
}
@ -80,7 +78,7 @@ async function getTrxReport(file: FileContent): Promise<TrxReport> {
function getTestRunResult(path: string, trx: TrxReport, testClasses: TestClass[]): TestRunResult {
const times = trx.TestRun.Times[0].$
const totalTime = times.finish.getTime() - times.start.getTime()
const totalTime = parseIsoDate(times.finish).getTime() - parseIsoDate(times.start).getTime()
const suites = testClasses.map(tc => {
const tests = tc.tests.map(t => new TestCaseResult(t.name, t.result, t.duration))
@ -113,7 +111,8 @@ function getTestClasses(trx: TrxReport): TestClass[] {
}
const output = r.unitTestResult.Output
const error = output?.length > 0 && output[0].ErrorInfo?.length > 0 ? output[0].ErrorInfo[0] : undefined
const test = new Test(r.testMethod.$.name, r.unitTestResult.$.outcome, r.unitTestResult.$.duration, error)
const duration = parseNetDuration(r.unitTestResult.$.duration)
const test = new Test(r.testMethod.$.name, r.unitTestResult.$.outcome, duration, error)
tc.tests.push(test)
}

View file

@ -10,10 +10,10 @@ export interface TestRun {
export interface Times {
$: {
creation: Date
queuing: Date
start: Date
finish: Date
creation: string
queuing: string
start: string
finish: string
}
}
@ -43,7 +43,7 @@ export interface UnitTestResult {
$: {
testId: string
testName: string
duration: number
duration: string
outcome: Outcome
}
Output: Output[]

View file

@ -5,7 +5,6 @@ import {parseStringPromise} from 'xml2js'
import {JunitReport, TestCase, TestSuite} from './jest-junit-types'
import {fixEol, Icon} from '../../utils/markdown-utils'
import {normalizeFilePath} from '../../utils/file-utils'
import {parseAttribute} from '../../utils/xml-utils'
import {
TestExecutionResult,
@ -43,9 +42,7 @@ export async function parseJestJunit(files: FileContent[], options: ParseOptions
async function getJunitReport(file: FileContent): Promise<JunitReport> {
core.info(`Parsing content of '${file.path}'`)
try {
return (await parseStringPromise(file.content, {
attrValueProcessors: [parseAttribute]
})) as JunitReport
return (await parseStringPromise(file.content)) as JunitReport
} catch (e) {
throw new Error(`Invalid XML at ${file.path}\n\n${e}`)
}
@ -54,12 +51,12 @@ async function getJunitReport(file: FileContent): Promise<JunitReport> {
function getTestRunResult(path: string, junit: JunitReport): TestRunResult {
const suites = junit.testsuites.testsuite.map(ts => {
const name = ts.$.name.trim()
const time = ts.$.time * 1000
const time = parseFloat(ts.$.time) * 1000
const sr = new TestSuiteResult(name, getGroups(ts), time)
return sr
})
const time = junit.testsuites.$.time * 1000
const time = parseFloat(junit.testsuites.$.time) * 1000
return new TestRunResult(path, suites, time)
}
@ -78,7 +75,7 @@ function getGroups(suite: TestSuite): TestGroupResult[] {
const tests = grp.tests.map(tc => {
const name = tc.$.name.trim()
const result = getTestCaseResult(tc)
const time = tc.$.time * 1000
const time = parseFloat(tc.$.time) * 1000
return new TestCaseResult(name, result, time)
})
return new TestGroupResult(grp.describe, tests)

View file

@ -5,10 +5,10 @@ export interface JunitReport {
export interface TestSuites {
$: {
name: string
tests: number
failures: number // assertion failed
errors: number // unhandled exception during test execution
time: number
tests: string
failures: string // assertion failed
errors: string // unhandled exception during test execution
time: string
}
testsuite: TestSuite[]
}
@ -16,11 +16,11 @@ export interface TestSuites {
export interface TestSuite {
$: {
name: string
tests: number
errors: number
failures: number
skipped: number
time: number
tests: string
errors: string
failures: string
skipped: string
time: string
timestamp?: Date
}
testcase: TestCase[]
@ -31,7 +31,7 @@ export interface TestCase {
classname: string
file?: string
name: string
time: number
time: string
}
failure?: string[]
skipped?: string[]