mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 22:07:09 +01:00
Update interfaces to accept multiple reports to parse
This commit is contained in:
parent
656ede0390
commit
659bb4fff3
8 changed files with 36 additions and 22 deletions
|
|
@ -4,8 +4,12 @@ import * as path from 'path'
|
|||
import {parseDartJson} from '../src/parsers/dart-json/dart-json-parser'
|
||||
import {ParseOptions} from '../src/parsers/parser-types'
|
||||
|
||||
const xmlFixture = fs.readFileSync(path.join(__dirname, 'fixtures', 'dart-json.json'), {encoding: 'utf8'})
|
||||
const outputPath = __dirname + '/__outputs__/dart-json.md'
|
||||
const fixturePath = path.join(__dirname, 'fixtures', 'dart-json.json')
|
||||
const outputPath = path.join(__dirname, '__outputs__', 'dart-json.md')
|
||||
const xmlFixture = {
|
||||
path: fixturePath,
|
||||
content: fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||
}
|
||||
|
||||
describe('dart-json tests', () => {
|
||||
it('matches report snapshot', async () => {
|
||||
|
|
@ -16,7 +20,7 @@ describe('dart-json tests', () => {
|
|||
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dart/'
|
||||
}
|
||||
|
||||
const result = await parseDartJson(xmlFixture, opts)
|
||||
const result = await parseDartJson([xmlFixture], opts)
|
||||
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||
fs.writeFileSync(outputPath, result?.output?.summary ?? '')
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,12 @@ import * as path from 'path'
|
|||
import {parseDotnetTrx} from '../src/parsers/dotnet-trx/dotnet-trx-parser'
|
||||
import {ParseOptions} from '../src/parsers/parser-types'
|
||||
|
||||
const xmlFixture = fs.readFileSync(path.join(__dirname, 'fixtures', 'dotnet-trx.trx'), {encoding: 'utf8'})
|
||||
const outputPath = __dirname + '/__outputs__/dotnet-trx.md'
|
||||
const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-trx.trx')
|
||||
const outputPath = path.join(__dirname, '__outputs__', 'dotnet-trx.md')
|
||||
const xmlFixture = {
|
||||
path: fixturePath,
|
||||
content: fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||
}
|
||||
|
||||
describe('dotnet-trx tests', () => {
|
||||
it('matches report snapshot', async () => {
|
||||
|
|
@ -16,7 +20,7 @@ describe('dotnet-trx tests', () => {
|
|||
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dotnet/'
|
||||
}
|
||||
|
||||
const result = await parseDotnetTrx(xmlFixture, opts)
|
||||
const result = await parseDotnetTrx([xmlFixture], opts)
|
||||
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||
fs.writeFileSync(outputPath, result?.output?.summary ?? '')
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,12 @@ import * as path from 'path'
|
|||
import {parseJestJunit} from '../src/parsers/jest-junit/jest-junit-parser'
|
||||
import {ParseOptions} from '../src/parsers/parser-types'
|
||||
|
||||
const xmlFixture = fs.readFileSync(path.join(__dirname, 'fixtures', 'jest-junit.xml'), {encoding: 'utf8'})
|
||||
const outputPath = __dirname + '/__outputs__/jest-junit.md'
|
||||
const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
|
||||
const outputPath = path.join(__dirname, '__outputs__', 'jest-junit.md')
|
||||
const xmlFixture = {
|
||||
path: fixturePath,
|
||||
content: fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||
}
|
||||
|
||||
describe('jest-junit tests', () => {
|
||||
it('matches report snapshot', async () => {
|
||||
|
|
@ -16,7 +20,7 @@ describe('jest-junit tests', () => {
|
|||
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/jest/'
|
||||
}
|
||||
|
||||
const result = await parseJestJunit(xmlFixture, opts)
|
||||
const result = await parseJestJunit([xmlFixture], opts)
|
||||
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||
fs.writeFileSync(outputPath, result?.output?.summary ?? '')
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import glob from 'fast-glob'
|
|||
import {parseDartJson} from './parsers/dart-json/dart-json-parser'
|
||||
import {parseDotnetTrx} from './parsers/dotnet-trx/dotnet-trx-parser'
|
||||
import {parseJestJunit} from './parsers/jest-junit/jest-junit-parser'
|
||||
import {ParseOptions, ParseTestResult} from './parsers/parser-types'
|
||||
import {FileContent, ParseOptions, ParseTestResult} from './parsers/parser-types'
|
||||
import {normalizeDirPath} from './utils/file-utils'
|
||||
import {listFiles} from './utils/git'
|
||||
import {getCheckRunSha} from './utils/github-utils'
|
||||
|
|
@ -54,7 +54,7 @@ async function main(): Promise<void> {
|
|||
return
|
||||
}
|
||||
|
||||
const result = await parser(files[0].content, opts)
|
||||
const result = await parser(files, opts)
|
||||
const conclusion = result.success ? 'success' : 'failure'
|
||||
|
||||
await octokit.checks.create({
|
||||
|
|
@ -87,7 +87,7 @@ function getParser(reporter: string): ParseTestResult {
|
|||
}
|
||||
}
|
||||
|
||||
export async function getFiles(pattern: string): Promise<{path: string; content: string}[]> {
|
||||
export async function getFiles(pattern: string): Promise<FileContent[]> {
|
||||
const paths = await glob(pattern, {dot: true})
|
||||
return Promise.all(
|
||||
paths.map(async path => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {Annotation, ParseOptions, TestResult} from '../parser-types'
|
||||
import {Annotation, FileContent, ParseOptions, TestResult} from '../parser-types'
|
||||
|
||||
import getReport from '../../report/get-report'
|
||||
import {normalizeFilePath} from '../../utils/file-utils'
|
||||
|
|
@ -68,8 +68,8 @@ class TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
export async function parseDartJson(content: string, options: ParseOptions): Promise<TestResult> {
|
||||
const testRun = getTestRun(content)
|
||||
export async function parseDartJson(files: FileContent[], options: ParseOptions): Promise<TestResult> {
|
||||
const testRun = getTestRun(files[0].content)
|
||||
const icon = testRun.success ? Icon.success : Icon.fail
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import {ErrorInfo, Outcome, TestMethod, TrxReport} from './dotnet-trx-types'
|
||||
|
||||
import {Annotation, ParseOptions, TestResult} from '../parser-types'
|
||||
import {Annotation, FileContent, ParseOptions, TestResult} from '../parser-types'
|
||||
import {parseStringPromise} from 'xml2js'
|
||||
|
||||
import {normalizeFilePath} from '../../utils/file-utils'
|
||||
|
|
@ -41,8 +41,8 @@ class Test {
|
|||
}
|
||||
}
|
||||
|
||||
export async function parseDotnetTrx(content: string, options: ParseOptions): Promise<TestResult> {
|
||||
const trx = (await parseStringPromise(content, {
|
||||
export async function parseDotnetTrx(files: FileContent[], options: ParseOptions): Promise<TestResult> {
|
||||
const trx = (await parseStringPromise(files[0].content, {
|
||||
attrValueProcessors: [parseAttribute]
|
||||
})) as TrxReport
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {Annotation, ParseOptions, TestResult} from '../parser-types'
|
||||
import {Annotation, FileContent, ParseOptions, TestResult} from '../parser-types'
|
||||
import {parseStringPromise} from 'xml2js'
|
||||
|
||||
import {JunitReport, TestCase, TestSuite} from './jest-junit-types'
|
||||
|
|
@ -15,8 +15,8 @@ import {
|
|||
} from '../../report/test-results'
|
||||
import getReport from '../../report/get-report'
|
||||
|
||||
export async function parseJestJunit(content: string, options: ParseOptions): Promise<TestResult> {
|
||||
const junit = (await parseStringPromise(content, {
|
||||
export async function parseJestJunit(files: FileContent[], options: ParseOptions): Promise<TestResult> {
|
||||
const junit = (await parseStringPromise(files[0].content, {
|
||||
attrValueProcessors: [parseAttribute]
|
||||
})) as JunitReport
|
||||
const testsuites = junit.testsuites
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@ export type Annotation = {
|
|||
raw_details?: string
|
||||
}
|
||||
|
||||
export type ParseTestResult = (content: string, options: ParseOptions) => Promise<TestResult>
|
||||
export type ParseTestResult = (files: FileContent[], options: ParseOptions) => Promise<TestResult>
|
||||
|
||||
export type FileContent = {path: string; content: string}
|
||||
|
||||
export interface ParseOptions {
|
||||
name: string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue