Skip to content

Commit

Permalink
Fix JUnit test-cases with error misclassified as passed test
Browse files Browse the repository at this point in the history
Previous implementation considered only test-cases with <failure> as failed. This fix makes processing of <error> and <failure> the same. It also handles situation when error or failure elements contains only text and no attributes.
  • Loading branch information
Michal Dorner committed May 24, 2021
1 parent 6969ae6 commit d01ef00
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
16 changes: 11 additions & 5 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.

16 changes: 11 additions & 5 deletions src/parsers/java-junit/java-junit-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,24 @@ export class JavaJunitParser implements TestParser {
}

private getTestCaseResult(test: TestCase): TestExecutionResult {
if (test.failure) return 'failed'
if (test.failure || test.error) return 'failed'
if (test.skipped) return 'skipped'
return 'success'
}

private getTestCaseError(tc: TestCase): TestCaseError | undefined {
if (!this.options.parseErrors || !tc.failure) {
if (!this.options.parseErrors) {
return undefined
}

const failure = tc.failure[0]
const details = failure._
// We process <error> and <failure> the same way
const failures = tc.failure ?? tc.error
if (!failures) {
return undefined
}

const failure = failures[0]
const details = typeof failure === 'object' ? failure._ : failure
let filePath
let line

Expand All @@ -132,7 +138,7 @@ export class JavaJunitParser implements TestParser {
path: filePath,
line,
details,
message: failure.message
message: typeof failure === 'object' ? failure.message : undefined
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/parsers/java-junit/java-junit-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export interface TestCase {
name: string
time: string
}
failure?: Failure[]
failure?: string | Failure[]
error?: string | Failure[]
skipped?: string[]
}

Expand Down

0 comments on commit d01ef00

Please sign in to comment.