Skip to content

Commit

Permalink
Merge pull request #1222 from mikepenz/fix/1189
Browse files Browse the repository at this point in the history
Introduce flag to `fail_on_parse_error`
  • Loading branch information
mikepenz authored Nov 2, 2024
2 parents 53f82ad + 151ecba commit c39e623
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {parseFile, Transformer} from '../src/testParser'
import {readTransformers} from '../src/utils'

/**
* Copyright 2022 Mike Penz
* Copyright 2024 Mike Penz
*/
jest.setTimeout(30000)

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ inputs:
description: 'Fail the build in case a test failure occurred.'
required: false
default: 'false'
fail_on_parse_error:
description: 'Fail the build if the test report file can not be parsed.'
required: false
default: 'false'
require_tests:
description: 'Fail if no test are found.'
required: false
Expand Down
11 changes: 7 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export async function run(): Promise<void> {
const checkAnnotations = core.getInput('check_annotations') === 'true'
const commit = core.getInput('commit')
const failOnFailure = core.getInput('fail_on_failure') === 'true'
const failOnParseError = core.getInput('fail_on_parse_error') === 'true'
const requireTests = core.getInput('require_tests') === 'true'
const requirePassedTests = core.getInput('require_passed_tests') === 'true'
const includePassed = core.getInput('include_passed') === 'true'
Expand Down Expand Up @@ -84,7 +85,8 @@ export async function run(): Promise<void> {
transformers,
followSymlink,
annotationsLimit,
truncateStackTraces
truncateStackTraces,
failOnParseError
)
mergedResult.totalCount += testResult.totalCount
mergedResult.skipped += testResult.skipped
Expand Down
10 changes: 7 additions & 3 deletions src/testParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ export async function parseFile(
transformer: Transformer[] = [],
followSymlink = false,
annotationsLimit = -1,
truncateStackTraces = true
truncateStackTraces = true,
failOnParseError = false
): Promise<InternalTestResult> {
core.debug(`Parsing file ${file}`)

Expand All @@ -178,6 +179,7 @@ export async function parseFile(
report = JSON.parse(parser.xml2json(data, {compact: true}))
} catch (error) {
core.error(`⚠️ Failed to parse file (${file}) with error ${error}`)
if (failOnParseError) throw Error(`⚠️ Failed to parse file (${file}) with error ${error}`)
return {
name: '',
totalCount: 0,
Expand Down Expand Up @@ -549,7 +551,8 @@ export async function parseTestReports(
transformer: Transformer[] = [],
followSymlink = false,
annotationsLimit = -1,
truncateStackTraces = true
truncateStackTraces = true,
failOnParseError = false
): Promise<TestResult> {
core.debug(`Process test report for: ${reportPaths} (${checkName})`)
const globber = await glob.create(reportPaths, {followSymbolicLinks: followSymlink})
Expand Down Expand Up @@ -577,7 +580,8 @@ export async function parseTestReports(
transformer,
followSymlink,
annotationsLimit,
truncateStackTraces
truncateStackTraces,
failOnParseError
)
if (c === 0) continue
totalCount += c
Expand Down

0 comments on commit c39e623

Please sign in to comment.