mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-17 14:57:09 +01:00
oop
This commit is contained in:
parent
45ad0f6ed6
commit
26b8b7c891
2 changed files with 816 additions and 13 deletions
26
src/main.ts
26
src/main.ts
|
|
@ -9,10 +9,15 @@ import {TestRunResult} from './test-results'
|
|||
import {getAnnotations} from './report/get-annotations'
|
||||
import {getReport} from './report/get-report'
|
||||
|
||||
import {DartJsonParser} from './parsers/dart-json/dart-json-parser'
|
||||
import {DotnetTrxParser} from './parsers/dotnet-trx/dotnet-trx-parser'
|
||||
import {JavaJunitParser} from './parsers/java-junit/java-junit-parser'
|
||||
import {JestJunitParser} from './parsers/jest-junit/jest-junit-parser'
|
||||
import {MochaJsonParser} from './parsers/mocha-json/mocha-json-parser'
|
||||
|
||||
import {normalizeDirPath, normalizeFilePath} from './utils/path-utils'
|
||||
import {getCheckRunContext} from './utils/github-utils'
|
||||
import {Icon} from './utils/markdown-utils'
|
||||
import {IncomingWebhook} from '@slack/webhook'
|
||||
import fs from 'fs'
|
||||
import bent from 'bent'
|
||||
|
|
@ -169,6 +174,7 @@ class TestReporter {
|
|||
const results: TestRunResult[] = []
|
||||
for (const {file, content} of files) {
|
||||
try {
|
||||
core.info(`Processing test results from ${file}`)
|
||||
const tr = await parser.parse(file, content)
|
||||
results.push(tr)
|
||||
} catch (error) {
|
||||
|
|
@ -197,13 +203,9 @@ class TestReporter {
|
|||
core.info('Creating annotations')
|
||||
const annotations = getAnnotations(results, this.maxAnnotations)
|
||||
|
||||
const isFailed = this.failOnError && results.some(tr => tr.result === 'failed')
|
||||
const isFailed = results.some(tr => tr.result === 'failed')
|
||||
const conclusion = isFailed ? 'failure' : 'success'
|
||||
|
||||
const passed = results.reduce((sum, tr) => sum + tr.passed, 0)
|
||||
const failed = results.reduce((sum, tr) => sum + tr.failed, 0)
|
||||
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0)
|
||||
const shortSummary = `${passed} passed, ${failed} failed and ${skipped} skipped `
|
||||
const icon = isFailed ? Icon.fail : Icon.success
|
||||
|
||||
core.info(`Updating check run conclusion (${conclusion}) and output`)
|
||||
const resp = await this.octokit.rest.checks.update({
|
||||
|
|
@ -211,7 +213,7 @@ class TestReporter {
|
|||
conclusion,
|
||||
status: 'completed',
|
||||
output: {
|
||||
title: shortSummary,
|
||||
title: `${name} ${icon}`,
|
||||
summary,
|
||||
annotations
|
||||
},
|
||||
|
|
@ -263,8 +265,18 @@ class TestReporter {
|
|||
|
||||
getParser(reporter: string, options: ParseOptions): TestParser {
|
||||
switch (reporter) {
|
||||
case 'dart-json':
|
||||
return new DartJsonParser(options, 'dart')
|
||||
case 'dotnet-trx':
|
||||
return new DotnetTrxParser(options)
|
||||
case 'flutter-json':
|
||||
return new DartJsonParser(options, 'flutter')
|
||||
case 'java-junit':
|
||||
return new JavaJunitParser(options)
|
||||
case 'jest-junit':
|
||||
return new JestJunitParser(options)
|
||||
case 'mocha-json':
|
||||
return new MochaJsonParser(options)
|
||||
default:
|
||||
throw new Error(`Input variable 'reporter' is set to invalid value '${reporter}'`)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue