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 nested testsuite elements for JUnit. #193

Merged
merged 3 commits into from
Nov 13, 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
5 changes: 5 additions & 0 deletions __tests__/fixtures/empty/jest-junit-empty-testsuite.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="jest tests" tests="0" failures="0" errors="0" time="11.299">
<testsuite name="__tests__\main.test.js" errors="0" failures="0" skipped="0" timestamp="2020-10-27T21:39:41" time="0.486" tests="0">
</testsuite>
</testsuites>
18 changes: 17 additions & 1 deletion __tests__/jest-junit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {getReport} from '../src/report/get-report'
import {normalizeFilePath} from '../src/utils/path-utils'

describe('jest-junit tests', () => {
it('produces empty test run result when there are no test cases', async () => {
it('produces empty test run result when there are no test cases in the testsuites element', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'jest-junit.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
Expand All @@ -23,6 +23,22 @@ describe('jest-junit tests', () => {
expect(result.result).toBe('success')
})

it('produces empty test run result when there are no test cases in a nested testsuite element', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'jest-junit-empty-testsuite.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})

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

const parser = new JestJunitParser(opts)
const result = await parser.parse(filePath, fileContent)
expect(result.tests).toBe(0)
expect(result.result).toBe('success')
})

it('report from ./reports/jest test results matches snapshot', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
const outputPath = path.join(__dirname, '__outputs__', 'jest-junit.md')
Expand Down
3 changes: 3 additions & 0 deletions dist/index.js

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

4 changes: 4 additions & 0 deletions src/parsers/jest-junit/jest-junit-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export class JestJunitParser implements TestParser {
}

private getGroups(suite: TestSuite): TestGroupResult[] {
if (!suite.testcase) {
return []
}

const groups: {describe: string; tests: TestCase[]}[] = []
for (const tc of suite.testcase) {
let grp = groups.find(g => g.describe === tc.$.classname)
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/jest-junit/jest-junit-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface TestSuite {
time: string
timestamp?: Date
}
testcase: TestCase[]
testcase?: TestCase[]
}

export interface TestCase {
Expand Down