mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-17 06:47:09 +01:00
feat: support pytest JUnit XML format
This commit is contained in:
parent
e9fa2f582c
commit
98f7746baa
4 changed files with 38 additions and 3 deletions
7
__tests__/fixtures/external/pytest/pytest-single-case.xml
vendored
Normal file
7
__tests__/fixtures/external/pytest/pytest-single-case.xml
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="pytest" errors="0" failures="0" skipped="0" tests="1" time="0.178"
|
||||||
|
timestamp="2023-03-08T11:47:09.377238" hostname="0e634555ad5c">
|
||||||
|
<testcase classname="product_changes.tests.first_test.MyTestCase" name="test_something" time="0.133"/>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
24
__tests__/pytest-junit.test.ts
Normal file
24
__tests__/pytest-junit.test.ts
Normal file
|
|
@ -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')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -33,7 +33,7 @@ export class JestJunitParser implements TestParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private getTestRunResult(path: string, junit: JunitReport): TestRunResult {
|
private getTestRunResult(path: string, junit: JunitReport): TestRunResult {
|
||||||
const suites =
|
const suites: TestSuiteResult[] =
|
||||||
junit.testsuites.testsuite === undefined
|
junit.testsuites.testsuite === undefined
|
||||||
? []
|
? []
|
||||||
: junit.testsuites.testsuite.map(ts => {
|
: junit.testsuites.testsuite.map(ts => {
|
||||||
|
|
@ -43,7 +43,11 @@ export class JestJunitParser implements TestParser {
|
||||||
return sr
|
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)
|
return new TestRunResult(path, suites, time)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ export interface JunitReport {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TestSuites {
|
export interface TestSuites {
|
||||||
$: {
|
$?: {
|
||||||
time: string
|
time: string
|
||||||
}
|
}
|
||||||
testsuite?: TestSuite[]
|
testsuite?: TestSuite[]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue