Update interfaces to accept multiple reports to parse

This commit is contained in:
Michal Dorner 2021-01-16 21:19:40 +01:00
parent 656ede0390
commit 659bb4fff3
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
8 changed files with 36 additions and 22 deletions

View file

@ -4,8 +4,12 @@ import * as path from 'path'
import {parseDartJson} from '../src/parsers/dart-json/dart-json-parser' import {parseDartJson} from '../src/parsers/dart-json/dart-json-parser'
import {ParseOptions} from '../src/parsers/parser-types' import {ParseOptions} from '../src/parsers/parser-types'
const xmlFixture = fs.readFileSync(path.join(__dirname, 'fixtures', 'dart-json.json'), {encoding: 'utf8'}) const fixturePath = path.join(__dirname, 'fixtures', 'dart-json.json')
const outputPath = __dirname + '/__outputs__/dart-json.md' const outputPath = path.join(__dirname, '__outputs__', 'dart-json.md')
const xmlFixture = {
path: fixturePath,
content: fs.readFileSync(fixturePath, {encoding: 'utf8'})
}
describe('dart-json tests', () => { describe('dart-json tests', () => {
it('matches report snapshot', async () => { it('matches report snapshot', async () => {
@ -16,7 +20,7 @@ describe('dart-json tests', () => {
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dart/' 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.mkdirSync(path.dirname(outputPath), {recursive: true})
fs.writeFileSync(outputPath, result?.output?.summary ?? '') fs.writeFileSync(outputPath, result?.output?.summary ?? '')

View file

@ -4,8 +4,12 @@ import * as path from 'path'
import {parseDotnetTrx} from '../src/parsers/dotnet-trx/dotnet-trx-parser' import {parseDotnetTrx} from '../src/parsers/dotnet-trx/dotnet-trx-parser'
import {ParseOptions} from '../src/parsers/parser-types' import {ParseOptions} from '../src/parsers/parser-types'
const xmlFixture = fs.readFileSync(path.join(__dirname, 'fixtures', 'dotnet-trx.trx'), {encoding: 'utf8'}) const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-trx.trx')
const outputPath = __dirname + '/__outputs__/dotnet-trx.md' const outputPath = path.join(__dirname, '__outputs__', 'dotnet-trx.md')
const xmlFixture = {
path: fixturePath,
content: fs.readFileSync(fixturePath, {encoding: 'utf8'})
}
describe('dotnet-trx tests', () => { describe('dotnet-trx tests', () => {
it('matches report snapshot', async () => { it('matches report snapshot', async () => {
@ -16,7 +20,7 @@ describe('dotnet-trx tests', () => {
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dotnet/' 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.mkdirSync(path.dirname(outputPath), {recursive: true})
fs.writeFileSync(outputPath, result?.output?.summary ?? '') fs.writeFileSync(outputPath, result?.output?.summary ?? '')

View file

@ -4,8 +4,12 @@ import * as path from 'path'
import {parseJestJunit} from '../src/parsers/jest-junit/jest-junit-parser' import {parseJestJunit} from '../src/parsers/jest-junit/jest-junit-parser'
import {ParseOptions} from '../src/parsers/parser-types' import {ParseOptions} from '../src/parsers/parser-types'
const xmlFixture = fs.readFileSync(path.join(__dirname, 'fixtures', 'jest-junit.xml'), {encoding: 'utf8'}) const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
const outputPath = __dirname + '/__outputs__/jest-junit.md' const outputPath = path.join(__dirname, '__outputs__', 'jest-junit.md')
const xmlFixture = {
path: fixturePath,
content: fs.readFileSync(fixturePath, {encoding: 'utf8'})
}
describe('jest-junit tests', () => { describe('jest-junit tests', () => {
it('matches report snapshot', async () => { it('matches report snapshot', async () => {
@ -16,7 +20,7 @@ describe('jest-junit tests', () => {
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/jest/' 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.mkdirSync(path.dirname(outputPath), {recursive: true})
fs.writeFileSync(outputPath, result?.output?.summary ?? '') fs.writeFileSync(outputPath, result?.output?.summary ?? '')

View file

@ -5,7 +5,7 @@ import glob from 'fast-glob'
import {parseDartJson} from './parsers/dart-json/dart-json-parser' import {parseDartJson} from './parsers/dart-json/dart-json-parser'
import {parseDotnetTrx} from './parsers/dotnet-trx/dotnet-trx-parser' import {parseDotnetTrx} from './parsers/dotnet-trx/dotnet-trx-parser'
import {parseJestJunit} from './parsers/jest-junit/jest-junit-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 {normalizeDirPath} from './utils/file-utils'
import {listFiles} from './utils/git' import {listFiles} from './utils/git'
import {getCheckRunSha} from './utils/github-utils' import {getCheckRunSha} from './utils/github-utils'
@ -54,7 +54,7 @@ async function main(): Promise<void> {
return return
} }
const result = await parser(files[0].content, opts) const result = await parser(files, opts)
const conclusion = result.success ? 'success' : 'failure' const conclusion = result.success ? 'success' : 'failure'
await octokit.checks.create({ 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}) const paths = await glob(pattern, {dot: true})
return Promise.all( return Promise.all(
paths.map(async path => { paths.map(async path => {

View file

@ -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 getReport from '../../report/get-report'
import {normalizeFilePath} from '../../utils/file-utils' import {normalizeFilePath} from '../../utils/file-utils'
@ -68,8 +68,8 @@ class TestCase {
} }
} }
export async function parseDartJson(content: string, options: ParseOptions): Promise<TestResult> { export async function parseDartJson(files: FileContent[], options: ParseOptions): Promise<TestResult> {
const testRun = getTestRun(content) const testRun = getTestRun(files[0].content)
const icon = testRun.success ? Icon.success : Icon.fail const icon = testRun.success ? Icon.success : Icon.fail
return { return {

View file

@ -1,6 +1,6 @@
import {ErrorInfo, Outcome, TestMethod, TrxReport} from './dotnet-trx-types' 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 {parseStringPromise} from 'xml2js'
import {normalizeFilePath} from '../../utils/file-utils' import {normalizeFilePath} from '../../utils/file-utils'
@ -41,8 +41,8 @@ class Test {
} }
} }
export async function parseDotnetTrx(content: string, options: ParseOptions): Promise<TestResult> { export async function parseDotnetTrx(files: FileContent[], options: ParseOptions): Promise<TestResult> {
const trx = (await parseStringPromise(content, { const trx = (await parseStringPromise(files[0].content, {
attrValueProcessors: [parseAttribute] attrValueProcessors: [parseAttribute]
})) as TrxReport })) as TrxReport

View file

@ -1,4 +1,4 @@
import {Annotation, ParseOptions, TestResult} from '../parser-types' import {Annotation, FileContent, ParseOptions, TestResult} from '../parser-types'
import {parseStringPromise} from 'xml2js' import {parseStringPromise} from 'xml2js'
import {JunitReport, TestCase, TestSuite} from './jest-junit-types' import {JunitReport, TestCase, TestSuite} from './jest-junit-types'
@ -15,8 +15,8 @@ import {
} from '../../report/test-results' } from '../../report/test-results'
import getReport from '../../report/get-report' import getReport from '../../report/get-report'
export async function parseJestJunit(content: string, options: ParseOptions): Promise<TestResult> { export async function parseJestJunit(files: FileContent[], options: ParseOptions): Promise<TestResult> {
const junit = (await parseStringPromise(content, { const junit = (await parseStringPromise(files[0].content, {
attrValueProcessors: [parseAttribute] attrValueProcessors: [parseAttribute]
})) as JunitReport })) as JunitReport
const testsuites = junit.testsuites const testsuites = junit.testsuites

View file

@ -13,7 +13,9 @@ export type Annotation = {
raw_details?: string 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 { export interface ParseOptions {
name: string name: string