mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-16 14:27:10 +01:00
Add support for loading test results from artifacts
This commit is contained in:
parent
71f2f95ef0
commit
3510d9ac27
19 changed files with 11665 additions and 338 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import {ParseOptions, TestParser} from '../../test-parser'
|
||||
|
||||
import {normalizeFilePath} from '../../utils/file-utils'
|
||||
import {getBasePath, normalizeFilePath} from '../../utils/path-utils'
|
||||
|
||||
import {
|
||||
ReportEvent,
|
||||
|
|
@ -72,6 +72,8 @@ class TestCase {
|
|||
}
|
||||
|
||||
export class DartJsonParser implements TestParser {
|
||||
assumedWorkDir: string | undefined
|
||||
|
||||
constructor(readonly options: ParseOptions, readonly sdk: 'dart' | 'flutter') {}
|
||||
|
||||
async parse(path: string, content: string): Promise<TestRunResult> {
|
||||
|
|
@ -207,14 +209,24 @@ export class DartJsonParser implements TestParser {
|
|||
}
|
||||
|
||||
private getRelativePath(path: string): string {
|
||||
const {workDir} = this.options
|
||||
const prefix = 'file://'
|
||||
if (path.startsWith(prefix)) {
|
||||
path = path.substr(prefix.length)
|
||||
}
|
||||
if (path.startsWith(workDir)) {
|
||||
|
||||
path = normalizeFilePath(path)
|
||||
const workDir = this.getWorkDir(path)
|
||||
if (workDir !== undefined && path.startsWith(workDir)) {
|
||||
path = path.substr(workDir.length)
|
||||
}
|
||||
return normalizeFilePath(path)
|
||||
return path
|
||||
}
|
||||
|
||||
private getWorkDir(path: string): string | undefined {
|
||||
return (
|
||||
this.options.workDir ??
|
||||
this.assumedWorkDir ??
|
||||
(this.assumedWorkDir = getBasePath(path, this.options.trackedFiles))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import {parseStringPromise} from 'xml2js'
|
|||
import {ErrorInfo, Outcome, TestMethod, TrxReport} from './dotnet-trx-types'
|
||||
import {ParseOptions, TestParser} from '../../test-parser'
|
||||
|
||||
import {normalizeFilePath} from '../../utils/file-utils'
|
||||
import {getBasePath, normalizeFilePath} from '../../utils/path-utils'
|
||||
import {parseIsoDate, parseNetDuration} from '../../utils/parse-utils'
|
||||
|
||||
import {
|
||||
|
|
@ -41,6 +41,8 @@ class Test {
|
|||
}
|
||||
|
||||
export class DotnetTrxParser implements TestParser {
|
||||
assumedWorkDir: string | undefined
|
||||
|
||||
constructor(readonly options: ParseOptions) {}
|
||||
|
||||
async parse(path: string, content: string): Promise<TestRunResult> {
|
||||
|
|
@ -137,19 +139,30 @@ export class DotnetTrxParser implements TestParser {
|
|||
private exceptionThrowSource(stackTrace: string): {path: string; line: number} | undefined {
|
||||
const lines = stackTrace.split(/\r*\n/)
|
||||
const re = / in (.+):line (\d+)$/
|
||||
const {workDir, trackedFiles} = this.options
|
||||
const {trackedFiles} = this.options
|
||||
|
||||
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 {path: file, line}
|
||||
const workDir = this.getWorkDir(filePath)
|
||||
if (workDir) {
|
||||
const file = filePath.substr(workDir.length)
|
||||
if (trackedFiles.includes(file)) {
|
||||
const line = parseInt(lineStr)
|
||||
return {path: file, line}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private getWorkDir(path: string): string | undefined {
|
||||
return (
|
||||
this.options.workDir ??
|
||||
this.assumedWorkDir ??
|
||||
(this.assumedWorkDir = getBasePath(path, this.options.trackedFiles))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import {ParseOptions, TestParser} from '../../test-parser'
|
|||
import {parseStringPromise} from 'xml2js'
|
||||
|
||||
import {JunitReport, TestCase, TestSuite} from './jest-junit-types'
|
||||
import {normalizeFilePath} from '../../utils/file-utils'
|
||||
import {getBasePath, normalizeFilePath} from '../../utils/path-utils'
|
||||
|
||||
import {
|
||||
TestExecutionResult,
|
||||
|
|
@ -14,6 +14,8 @@ import {
|
|||
} from '../../test-results'
|
||||
|
||||
export class JestJunitParser implements TestParser {
|
||||
assumedWorkDir: string | undefined
|
||||
|
||||
constructor(readonly options: ParseOptions) {}
|
||||
|
||||
async parse(path: string, content: string): Promise<TestRunResult> {
|
||||
|
|
@ -96,13 +98,20 @@ export class JestJunitParser implements TestParser {
|
|||
const lines = stackTrace.split(/\r?\n/)
|
||||
const re = /\((.*):(\d+):\d+\)$/
|
||||
|
||||
const {workDir, trackedFiles} = this.options
|
||||
const {trackedFiles} = this.options
|
||||
for (const str of lines) {
|
||||
const match = str.match(re)
|
||||
if (match !== null) {
|
||||
const [_, fileStr, lineStr] = match
|
||||
const filePath = normalizeFilePath(fileStr)
|
||||
const path = filePath.startsWith(workDir) ? filePath.substr(workDir.length) : filePath
|
||||
if (filePath.startsWith('internal/') || filePath.includes('/node_modules/')) {
|
||||
continue
|
||||
}
|
||||
const workDir = this.getWorkDir(filePath)
|
||||
if (!workDir) {
|
||||
continue
|
||||
}
|
||||
const path = filePath.substr(workDir.length)
|
||||
if (trackedFiles.includes(path)) {
|
||||
const line = parseInt(lineStr)
|
||||
|
||||
|
|
@ -111,4 +120,12 @@ export class JestJunitParser implements TestParser {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private getWorkDir(path: string): string | undefined {
|
||||
return (
|
||||
this.options.workDir ??
|
||||
this.assumedWorkDir ??
|
||||
(this.assumedWorkDir = getBasePath(path, this.options.trackedFiles))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue