diff --git a/__tests__/fixtures/external/pytest/pytest-single-case.xml b/__tests__/fixtures/external/pytest/pytest-single-case.xml new file mode 100644 index 0000000..a091c1d --- /dev/null +++ b/__tests__/fixtures/external/pytest/pytest-single-case.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/__tests__/pytest-junit.test.ts b/__tests__/pytest-junit.test.ts new file mode 100644 index 0000000..f9bd7b1 --- /dev/null +++ b/__tests__/pytest-junit.test.ts @@ -0,0 +1,24 @@ +import * as fs from 'fs' +import * as path from 'path' + +import { JestJunitParser } from '../src/parsers/jest-junit/jest-junit-parser' +import { ParseOptions } from '../src/test-parser' +import { normalizeFilePath } from '../src/utils/path-utils' + +describe('pytest-junit tests', () => { + it('test with one successful test', async () => { + const fixturePath = path.join(__dirname, 'fixtures', 'external', 'pytest', 'pytest-single-case.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(1) + expect(result.result).toBe('success') + }) +}) diff --git a/src/parsers/jest-junit/jest-junit-parser.ts b/src/parsers/jest-junit/jest-junit-parser.ts index cbfe0ae..fc2fae1 100644 --- a/src/parsers/jest-junit/jest-junit-parser.ts +++ b/src/parsers/jest-junit/jest-junit-parser.ts @@ -33,7 +33,7 @@ export class JestJunitParser implements TestParser { } private getTestRunResult(path: string, junit: JunitReport): TestRunResult { - const suites = + const suites: TestSuiteResult[] = junit.testsuites.testsuite === undefined ? [] : junit.testsuites.testsuite.map(ts => { @@ -43,7 +43,11 @@ export class JestJunitParser implements TestParser { return sr }) - const time = parseFloat(junit.testsuites.$.time) * 1000 + const time = + junit.testsuites.$ === undefined + ? suites.reduce((sum, suite) => sum + suite.time, 0) + : parseFloat(junit.testsuites.$.time) * 1000 + return new TestRunResult(path, suites, time) } diff --git a/src/parsers/jest-junit/jest-junit-types.ts b/src/parsers/jest-junit/jest-junit-types.ts index 3ca03b9..c89c582 100644 --- a/src/parsers/jest-junit/jest-junit-types.ts +++ b/src/parsers/jest-junit/jest-junit-types.ts @@ -3,7 +3,7 @@ export interface JunitReport { } export interface TestSuites { - $: { + $?: { time: string } testsuite?: TestSuite[]