Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle empty failure tags #213

Merged
merged 2 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __tests__/fixtures/external/java/empty_failures.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='utf-8'?>
<testsuites name="my_package.test_foo" tests="3" failures="1" errors="0" time="6.79"><testsuite name="my_package.test_foo.launch_tests" tests="3" failures="1" errors="0" skipped="0" time="6.79"><testcase classname="my_package.TestFoo" name="test_normal_case" time="2.172" /><testcase classname="my_package.TestFoo" name="test_other_case" time="4.558"><failure message="Traceback (most recent call last):&#10; File &quot;/home/redacted/test_foo.py&quot;, line 183, in test_other_case&#10; self.assertFalse(True)&#10;AssertionError: True is not false&#10;" /></testcase><testcase classname="my_package.TestFoo" name="test_yet_another_case" time="0.06" /></testsuite></testsuites>
18 changes: 18 additions & 0 deletions __tests__/java-junit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,22 @@ describe('java-junit tests', () => {
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
fs.writeFileSync(outputPath, report)
})

it('parses empty failures in test results', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'java', 'empty_failures.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})

const trackedFiles: string[] = []
const opts: ParseOptions = {
parseErrors: true,
trackedFiles
}

const parser = new JavaJunitParser(opts)
const result = await parser.parse(filePath, fileContent)

expect(result.result === 'failed')
expect(result.failed === 1)
})
})
10 changes: 6 additions & 4 deletions dist/index.js

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

10 changes: 6 additions & 4 deletions src/parsers/java-junit/java-junit-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ export class JavaJunitParser implements TestParser {
let filePath
let line

const src = this.exceptionThrowSource(details)
if (src) {
filePath = src.filePath
line = src.line
if (details != null) {
const src = this.exceptionThrowSource(details)
if (src) {
filePath = src.filePath
line = src.line
}
}

return {
Expand Down