mirror of
https://github.com/dorny/test-reporter.git
synced 2026-02-04 05:27:55 +01:00
Add annotations support to dotnet-trx
This commit is contained in:
parent
6f32e41222
commit
c4b64b0cf4
2 changed files with 77 additions and 6 deletions
|
|
@ -2,7 +2,36 @@
|
||||||
|
|
||||||
exports[`dotnet-trx tests matches report snapshot 1`] = `
|
exports[`dotnet-trx tests matches report snapshot 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"annotations": Array [],
|
"annotations": Array [
|
||||||
|
Object {
|
||||||
|
"annotation_level": "failure",
|
||||||
|
"end_line": 9,
|
||||||
|
"message": "System.DivideByZeroException : Attempted to divide by zero.",
|
||||||
|
"path": "DotnetTests.Unit/Calculator.cs",
|
||||||
|
"start_line": 9,
|
||||||
|
"title": "[DotnetTests.XUnitTests.CalculatorTests] Exception_In_TargetTest",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"annotation_level": "failure",
|
||||||
|
"end_line": 39,
|
||||||
|
"message": "System.Exception : Test",
|
||||||
|
"path": "DotnetTests.XUnitTests/CalculatorTests.cs",
|
||||||
|
"start_line": 39,
|
||||||
|
"title": "[DotnetTests.XUnitTests.CalculatorTests] Exception_In_Test",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"annotation_level": "failure",
|
||||||
|
"end_line": 27,
|
||||||
|
"message": "Assert.Equal() Failure
|
||||||
|
|
||||||
|
Expected: 3
|
||||||
|
|
||||||
|
Actual: 2",
|
||||||
|
"path": "DotnetTests.XUnitTests/CalculatorTests.cs",
|
||||||
|
"start_line": 27,
|
||||||
|
"title": "[DotnetTests.XUnitTests.CalculatorTests] Failing_Test",
|
||||||
|
},
|
||||||
|
],
|
||||||
"summary": "**7** tests were completed in **1.061s** with **3** passed, **1** skipped and **3** failed.
|
"summary": "**7** tests were completed in **1.061s** with **3** passed, **1** skipped and **3** failed.
|
||||||
| Result | Suite | Tests | Time | Passed ✔️ | Failed ❌ | Skipped ✖️ |
|
| Result | Suite | Tests | Time | Passed ✔️ | Failed ❌ | Skipped ✖️ |
|
||||||
| :---: | :--- | ---: | ---: | ---: | ---: | ---: |
|
| :---: | :--- | ---: | ---: | ---: | ---: | ---: |
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {ErrorInfo, Outcome, TestMethod, TrxReport} from './dotnet-trx-types'
|
||||||
import {Annotation, ParseOptions, TestResult} from '../parser-types'
|
import {Annotation, ParseOptions, TestResult} from '../parser-types'
|
||||||
import {parseStringPromise} from 'xml2js'
|
import {parseStringPromise} from 'xml2js'
|
||||||
|
|
||||||
|
import {normalizeFilePath} from '../../utils/file-utils'
|
||||||
import {parseAttribute} from '../../utils/xml-utils'
|
import {parseAttribute} from '../../utils/xml-utils'
|
||||||
import {Icon} from '../../utils/markdown-utils'
|
import {Icon} from '../../utils/markdown-utils'
|
||||||
|
|
||||||
|
|
@ -55,9 +56,7 @@ export async function parseDotnetTrx(content: string, options: ParseOptions): Pr
|
||||||
output: {
|
output: {
|
||||||
title: `${options.name.trim()} ${icon}`,
|
title: `${options.name.trim()} ${icon}`,
|
||||||
summary: getReport(testRun),
|
summary: getReport(testRun),
|
||||||
annotations: options.annotations
|
annotations: options.annotations ? getAnnotations(testClasses, options.workDir, options.trackedFiles) : undefined
|
||||||
? getAnnotations(/*testClasses, options.workDir, options.trackedFiles*/)
|
|
||||||
: undefined
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -110,6 +109,49 @@ function getTestClasses(trx: TrxReport): TestClass[] {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAnnotations(/*testClasses: TestClass[], workDir: string, trackedFiles: string[]*/): Annotation[] {
|
function getAnnotations(testClasses: TestClass[], workDir: string, trackedFiles: string[]): Annotation[] {
|
||||||
return []
|
const annotations: Annotation[] = []
|
||||||
|
for (const tc of testClasses) {
|
||||||
|
for (const t of tc.tests) {
|
||||||
|
if (t.error) {
|
||||||
|
const src = exceptionThrowSource(t.error.StackTrace[0], workDir, trackedFiles)
|
||||||
|
if (src === null) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
annotations.push({
|
||||||
|
annotation_level: 'failure',
|
||||||
|
start_line: src.line,
|
||||||
|
end_line: src.line,
|
||||||
|
path: src.file,
|
||||||
|
message: t.error.Message[0],
|
||||||
|
title: `[${tc.name}] ${t.name}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return annotations
|
||||||
|
}
|
||||||
|
|
||||||
|
export function exceptionThrowSource(
|
||||||
|
ex: string,
|
||||||
|
workDir: string,
|
||||||
|
trackedFiles: string[]
|
||||||
|
): {file: string; line: number} | null {
|
||||||
|
const lines = ex.split(/\r*\n/)
|
||||||
|
const re = / in (.+):line (\d+)$/
|
||||||
|
|
||||||
|
for (const str of lines) {
|
||||||
|
const match = str.match(re)
|
||||||
|
if (match !== null) {
|
||||||
|
const [_, fileStr, lineStr] = match
|
||||||
|
const filePath = normalizeFilePath(fileStr)
|
||||||
|
const file = filePath.startsWith(workDir) ? filePath.substr(workDir.length) : filePath
|
||||||
|
if (trackedFiles.includes(file)) {
|
||||||
|
const line = parseInt(lineStr)
|
||||||
|
return {file, line}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue