mirror of
https://github.com/dorny/test-reporter.git
synced 2026-02-03 19:55:22 -08:00
Add list-suites and list-tests options to limit report size
This commit is contained in:
33
src/main.ts
33
src/main.ts
@@ -5,10 +5,12 @@ 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 {getReport} from './report/get-report'
|
||||
import {FileContent, ParseOptions, ParseTestResult} from './parsers/parser-types'
|
||||
import {normalizeDirPath} from './utils/file-utils'
|
||||
import {listFiles} from './utils/git'
|
||||
import {enforceCheckRunLimits, getCheckRunSha} from './utils/github-utils'
|
||||
import {Icon} from './utils/markdown-utils'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
@@ -19,13 +21,25 @@ async function run(): Promise<void> {
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const maxAnnotations = parseInt(core.getInput('max-annotations', {required: true}))
|
||||
const failOnError = core.getInput('fail-on-error', {required: true}) === 'true'
|
||||
const name = core.getInput('name', {required: true})
|
||||
const path = core.getInput('path', {required: true})
|
||||
const reporter = core.getInput('reporter', {required: true})
|
||||
const token = core.getInput('token', {required: true})
|
||||
const listSuites = core.getInput('list-suites', {required: true})
|
||||
const listTests = core.getInput('list-tests', {required: true})
|
||||
const maxAnnotations = parseInt(core.getInput('max-annotations', {required: true}))
|
||||
const failOnError = core.getInput('fail-on-error', {required: true}) === 'true'
|
||||
const workDirInput = core.getInput('working-directory', {required: false})
|
||||
const token = core.getInput('token', {required: true})
|
||||
|
||||
if (listSuites !== 'all' && listSuites !== 'only-failed') {
|
||||
core.setFailed(`Input parameter 'list-suites' has invalid value`)
|
||||
return
|
||||
}
|
||||
|
||||
if (listTests !== 'all' && listTests !== 'only-failed' && listTests !== 'none') {
|
||||
core.setFailed(`Input parameter 'list-tests' has invalid value`)
|
||||
return
|
||||
}
|
||||
|
||||
if (isNaN(maxAnnotations) || maxAnnotations < 0 || maxAnnotations > 50) {
|
||||
core.setFailed(`Input parameter 'max-annotations' has invalid value`)
|
||||
@@ -46,7 +60,6 @@ async function main(): Promise<void> {
|
||||
const trackedFiles = annotations ? await listFiles() : []
|
||||
|
||||
const opts: ParseOptions = {
|
||||
name,
|
||||
trackedFiles,
|
||||
workDir,
|
||||
annotations
|
||||
@@ -62,9 +75,11 @@ async function main(): Promise<void> {
|
||||
|
||||
core.info(`Using test report parser '${reporter}'`)
|
||||
const result = await parser(files, opts)
|
||||
const conclusion = result.success ? 'success' : 'failure'
|
||||
|
||||
enforceCheckRunLimits(result, maxAnnotations)
|
||||
const isFailed = result.testRuns.some(tr => tr.result === 'failed')
|
||||
const conclusion = isFailed ? 'failure' : 'success'
|
||||
const icon = isFailed ? Icon.fail : Icon.success
|
||||
|
||||
core.info(`Creating check run '${name}' with conclusion '${conclusion}'`)
|
||||
await octokit.checks.create({
|
||||
@@ -72,12 +87,16 @@ async function main(): Promise<void> {
|
||||
name,
|
||||
conclusion,
|
||||
status: 'completed',
|
||||
output: result.output,
|
||||
output: {
|
||||
title: `${name} ${icon}`,
|
||||
summary: getReport(result.testRuns, {listSuites, listTests}),
|
||||
annotations: result.annotations
|
||||
},
|
||||
...github.context.repo
|
||||
})
|
||||
|
||||
core.setOutput('conclusion', conclusion)
|
||||
if (failOnError && !result.success) {
|
||||
if (failOnError && isFailed) {
|
||||
core.setFailed(`Failed test has been found and 'fail-on-error' option is set to ${failOnError}`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user