Skip to content

Commit

Permalink
Update interfaces to accept multiple reports to parse
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Dorner committed Jan 16, 2021
1 parent 656ede0 commit 659bb4f
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 22 deletions.
10 changes: 7 additions & 3 deletions __tests__/dart-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 ?? '')

Expand Down
10 changes: 7 additions & 3 deletions __tests__/dotnet-trx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 ?? '')

Expand Down
10 changes: 7 additions & 3 deletions __tests__/jest-junit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 ?? '')

Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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 => {
Expand Down
6 changes: 3 additions & 3 deletions src/parsers/dart-json/dart-json-parser.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/parsers/dotnet-trx/dotnet-trx-parser.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/parsers/jest-junit/jest-junit-parser.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/parsers/parser-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 659bb4f

Please sign in to comment.