mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 22:07:09 +01:00
Merge pull request #193 from rvdlaarschot/mocha-empty-test-suite
Gracefully handle empty nested testsuite elements for JUnit.
This commit is contained in:
commit
074fe2cd27
5 changed files with 30 additions and 2 deletions
5
__tests__/fixtures/empty/jest-junit-empty-testsuite.xml
Normal file
5
__tests__/fixtures/empty/jest-junit-empty-testsuite.xml
Normal file
|
|
@ -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>
|
||||
|
|
@ -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'})
|
||||
|
|
@ -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')
|
||||
|
|
|
|||
3
dist/index.js
generated
vendored
3
dist/index.js
generated
vendored
|
|
@ -1163,6 +1163,9 @@ class JestJunitParser {
|
|||
return new test_results_1.TestRunResult(path, suites, time);
|
||||
}
|
||||
getGroups(suite) {
|
||||
if (!suite.testcase) {
|
||||
return [];
|
||||
}
|
||||
const groups = [];
|
||||
for (const tc of suite.testcase) {
|
||||
let grp = groups.find(g => g.describe === tc.$.classname);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ export interface TestSuite {
|
|||
time: string
|
||||
timestamp?: Date
|
||||
}
|
||||
testcase: TestCase[]
|
||||
testcase?: TestCase[]
|
||||
}
|
||||
|
||||
export interface TestCase {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue