Add support for open-test-reporting format

Add a new parser for the open-test-reporting format developed by the
JUnit team (https://github.com/ota4j-team/open-test-reporting).

This format is a modern, framework-agnostic XML-based test reporting
standard that supports rich metadata including tags, attachments, and
infrastructure information.

Features:
- Auto-detection of both XML format variants:
  - Hierarchical format (h:execution) - tree-structured results
  - Event-based format (e:events) - streaming/real-time results
- ISO 8601 duration parsing (e.g., PT1.234S)
- Status mapping: SUCCESSFUL, SKIPPED, ABORTED, FAILED, ERRORED
- Error message extraction from failed tests
- Proper XML namespace handling

Files added:
- src/parsers/open-test-reporting/open-test-reporting-types.ts
- src/parsers/open-test-reporting/open-test-reporting-parser.ts
- __tests__/open-test-reporting.test.ts (20 tests)
- __tests__/fixtures/open-test-reporting/*.xml
This commit is contained in:
Piotr Mionskowski 2025-12-05 09:43:46 +01:00
parent ee446707ff
commit eedd088b6d
11 changed files with 1255 additions and 0 deletions

View file

@ -0,0 +1,24 @@
![Tests failed](https://img.shields.io/badge/tests-4%20passed%2C%201%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|
|[fixtures/open-test-reporting/events.xml](#user-content-r0)|4 ✅|1 ❌|1 ⚪|1s|
## ❌ <a id="user-content-r0" href="#user-content-r0">fixtures/open-test-reporting/events.xml</a>
**6** tests were completed in **1s** with **4** passed, **1** failed and **1** skipped.
|Test suite|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|
|[com.example.CalculatorTest](#user-content-r0s0)|2 ✅|1 ❌|1 ⚪|700ms|
|[com.example.StringUtilsTest](#user-content-r0s1)|2 ✅|||400ms|
### ❌ <a id="user-content-r0s0" href="#user-content-r0s0">com.example.CalculatorTest</a>
```
✅ testAddition
✅ testSubtraction
❌ testDivision
java.lang.ArithmeticException: Division by zero
⚪ testMultiplication
```
### ✅ <a id="user-content-r0s1" href="#user-content-r0s1">com.example.StringUtilsTest</a>
```
TrimTests
✅ testTrimLeft
✅ testTrimRight
```

View file

@ -0,0 +1,27 @@
![Tests failed](https://img.shields.io/badge/tests-5%20passed%2C%201%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|
|[fixtures/open-test-reporting/hierarchy.xml](#user-content-r0)|5 ✅|1 ❌|1 ⚪|4s|
## ❌ <a id="user-content-r0" href="#user-content-r0">fixtures/open-test-reporting/hierarchy.xml</a>
**7** tests were completed in **4s** with **5** passed, **1** failed and **1** skipped.
|Test suite|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|
|[com.example.EmptySuite](#user-content-r0s0)||||0ms|
|[com.example.PaymentServiceTest](#user-content-r0s1)|3 ✅|1 ❌||3s|
|[com.example.UserServiceTest](#user-content-r0s2)|2 ✅||1 ⚪|1s|
### ❌ <a id="user-content-r0s1" href="#user-content-r0s1">com.example.PaymentServiceTest</a>
```
ValidationTests
✅ testValidAmount
✅ testInvalidAmount
ProcessingTests
✅ testSuccessfulPayment
❌ testPaymentTimeout
org.opentest4j.AssertionFailedError: Payment should complete within 500ms but took 700ms
```
### ✅ <a id="user-content-r0s2" href="#user-content-r0s2">com.example.UserServiceTest</a>
```
✅ testUserCreation
✅ testUserDeletion
⚪ testUserUpdate
```

View file

@ -0,0 +1,157 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`open-test-reporting tests report generation result matches snapshot for events format 1`] = `
TestRunResult {
"path": "fixtures/open-test-reporting/events.xml",
"suites": [
TestSuiteResult {
"groups": [
TestGroupResult {
"name": "",
"tests": [
TestCaseResult {
"error": undefined,
"name": "testAddition",
"result": "success",
"time": 100,
},
TestCaseResult {
"error": undefined,
"name": "testSubtraction",
"result": "success",
"time": 150,
},
TestCaseResult {
"error": {
"details": "java.lang.ArithmeticException: Division by zero",
"message": "java.lang.ArithmeticException: Division by zero",
},
"name": "testDivision",
"result": "failed",
"time": 150,
},
TestCaseResult {
"error": undefined,
"name": "testMultiplication",
"result": "skipped",
"time": 10,
},
],
},
],
"name": "com.example.CalculatorTest",
"totalTime": 700,
},
TestSuiteResult {
"groups": [
TestGroupResult {
"name": "TrimTests",
"tests": [
TestCaseResult {
"error": undefined,
"name": "testTrimLeft",
"result": "success",
"time": 90,
},
TestCaseResult {
"error": undefined,
"name": "testTrimRight",
"result": "success",
"time": 90,
},
],
},
],
"name": "com.example.StringUtilsTest",
"totalTime": 400,
},
],
"totalTime": 1100,
}
`;
exports[`open-test-reporting tests report generation result matches snapshot for hierarchy format 1`] = `
TestRunResult {
"path": "fixtures/open-test-reporting/hierarchy.xml",
"suites": [
TestSuiteResult {
"groups": [
TestGroupResult {
"name": "",
"tests": [
TestCaseResult {
"error": undefined,
"name": "testUserCreation",
"result": "success",
"time": 123,
},
TestCaseResult {
"error": undefined,
"name": "testUserDeletion",
"result": "success",
"time": 234,
},
TestCaseResult {
"error": undefined,
"name": "testUserUpdate",
"result": "skipped",
"time": 45,
},
],
},
],
"name": "com.example.UserServiceTest",
"totalTime": 1234,
},
TestSuiteResult {
"groups": [
TestGroupResult {
"name": "ValidationTests",
"tests": [
TestCaseResult {
"error": undefined,
"name": "testValidAmount",
"result": "success",
"time": 200,
},
TestCaseResult {
"error": undefined,
"name": "testInvalidAmount",
"result": "success",
"time": 300,
},
],
},
TestGroupResult {
"name": "ProcessingTests",
"tests": [
TestCaseResult {
"error": undefined,
"name": "testSuccessfulPayment",
"result": "success",
"time": 500,
},
TestCaseResult {
"error": {
"details": "org.opentest4j.AssertionFailedError: Payment should complete within 500ms but took 700ms",
"message": "org.opentest4j.AssertionFailedError: Payment should complete within 500ms but took 700ms",
},
"name": "testPaymentTimeout",
"result": "failed",
"time": 700,
},
],
},
],
"name": "com.example.PaymentServiceTest",
"totalTime": 2500,
},
TestSuiteResult {
"groups": [],
"name": "com.example.EmptySuite",
"totalTime": 0,
},
],
"totalTime": 3734,
}
`;

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<h:execution xmlns:h="https://schemas.opentest4j.org/reporting/hierarchy/0.2.0"
xmlns="https://schemas.opentest4j.org/reporting/core/0.2.0">
</h:execution>

View file

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<e:events xmlns="https://schemas.opentest4j.org/reporting/core/0.2.0"
xmlns:e="https://schemas.opentest4j.org/reporting/events/0.2.0">
<infrastructure>
<hostName>build-agent-02</hostName>
<userName>runner</userName>
<operatingSystem>macOS</operatingSystem>
<cpuCores>8</cpuCores>
</infrastructure>
<!-- Suite: CalculatorTest starts -->
<e:started id="suite-1" name="com.example.CalculatorTest" time="2024-01-15T11:00:00.000Z"/>
<!-- Test: testAddition -->
<e:started id="test-1" name="testAddition" parentId="suite-1" time="2024-01-15T11:00:00.100Z"/>
<e:finished id="test-1" time="2024-01-15T11:00:00.200Z">
<result status="SUCCESSFUL"/>
</e:finished>
<!-- Test: testSubtraction -->
<e:started id="test-2" name="testSubtraction" parentId="suite-1" time="2024-01-15T11:00:00.250Z"/>
<e:finished id="test-2" time="2024-01-15T11:00:00.400Z">
<result status="SUCCESSFUL"/>
</e:finished>
<!-- Test: testDivision (fails) -->
<e:started id="test-3" name="testDivision" parentId="suite-1" time="2024-01-15T11:00:00.450Z"/>
<e:finished id="test-3" time="2024-01-15T11:00:00.600Z">
<result status="FAILED">
<reason>java.lang.ArithmeticException: Division by zero</reason>
</result>
</e:finished>
<!-- Test: testMultiplication (skipped) -->
<e:started id="test-4" name="testMultiplication" parentId="suite-1" time="2024-01-15T11:00:00.650Z"/>
<e:finished id="test-4" time="2024-01-15T11:00:00.660Z">
<result status="SKIPPED">
<reason>Test disabled</reason>
</result>
</e:finished>
<!-- Suite: CalculatorTest finishes -->
<e:finished id="suite-1" time="2024-01-15T11:00:00.700Z">
<result status="FAILED"/>
</e:finished>
<!-- Suite: StringUtilsTest starts -->
<e:started id="suite-2" name="com.example.StringUtilsTest" time="2024-01-15T11:00:01.000Z"/>
<!-- Group: TrimTests -->
<e:started id="group-1" name="TrimTests" parentId="suite-2" time="2024-01-15T11:00:01.100Z"/>
<e:started id="test-5" name="testTrimLeft" parentId="group-1" time="2024-01-15T11:00:01.110Z"/>
<e:finished id="test-5" time="2024-01-15T11:00:01.200Z">
<result status="SUCCESSFUL"/>
</e:finished>
<e:started id="test-6" name="testTrimRight" parentId="group-1" time="2024-01-15T11:00:01.210Z"/>
<e:finished id="test-6" time="2024-01-15T11:00:01.300Z">
<result status="SUCCESSFUL"/>
</e:finished>
<e:finished id="group-1" time="2024-01-15T11:00:01.310Z">
<result status="SUCCESSFUL"/>
</e:finished>
<!-- Suite: StringUtilsTest finishes -->
<e:finished id="suite-2" time="2024-01-15T11:00:01.400Z">
<result status="SUCCESSFUL"/>
</e:finished>
</e:events>

View file

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<h:execution xmlns:h="https://schemas.opentest4j.org/reporting/hierarchy/0.2.0"
xmlns="https://schemas.opentest4j.org/reporting/core/0.2.0">
<infrastructure>
<hostName>build-agent-01</hostName>
<userName>ci</userName>
<operatingSystem>Linux</operatingSystem>
<cpuCores>4</cpuCores>
</infrastructure>
<!-- Suite: UserServiceTest -->
<h:root duration="PT1.234S" name="com.example.UserServiceTest" start="2024-01-15T10:30:00.000Z">
<result status="SUCCESSFUL"/>
<h:child duration="PT0.123S" name="testUserCreation" start="2024-01-15T10:30:00.100Z">
<result status="SUCCESSFUL"/>
</h:child>
<h:child duration="PT0.234S" name="testUserDeletion" start="2024-01-15T10:30:00.300Z">
<result status="SUCCESSFUL"/>
</h:child>
<h:child duration="PT0.045S" name="testUserUpdate" start="2024-01-15T10:30:00.600Z">
<result status="SKIPPED">
<reason>Skipped: Database not available</reason>
</result>
</h:child>
</h:root>
<!-- Suite: PaymentServiceTest with nested groups -->
<h:root duration="PT2.5S" name="com.example.PaymentServiceTest" start="2024-01-15T10:30:02.000Z">
<result status="FAILED"/>
<!-- Group: ValidationTests -->
<h:child duration="PT0.8S" name="ValidationTests" start="2024-01-15T10:30:02.100Z">
<result status="SUCCESSFUL"/>
<h:child duration="PT0.2S" name="testValidAmount" start="2024-01-15T10:30:02.110Z">
<result status="SUCCESSFUL"/>
</h:child>
<h:child duration="PT0.3S" name="testInvalidAmount" start="2024-01-15T10:30:02.320Z">
<result status="SUCCESSFUL"/>
</h:child>
</h:child>
<!-- Group: ProcessingTests -->
<h:child duration="PT1.2S" name="ProcessingTests" start="2024-01-15T10:30:03.000Z">
<result status="FAILED"/>
<h:child duration="PT0.5S" name="testSuccessfulPayment" start="2024-01-15T10:30:03.100Z">
<result status="SUCCESSFUL"/>
</h:child>
<h:child duration="PT0.7S" name="testPaymentTimeout" start="2024-01-15T10:30:03.700Z">
<result status="FAILED">
<reason>org.opentest4j.AssertionFailedError: Payment should complete within 500ms but took 700ms</reason>
</result>
</h:child>
</h:child>
</h:root>
<!-- Suite: EmptySuite (edge case) -->
<h:root duration="PT0S" name="com.example.EmptySuite" start="2024-01-15T10:30:05.000Z">
<result status="SUCCESSFUL"/>
</h:root>
</h:execution>

View file

@ -0,0 +1,344 @@
import * as fs from 'fs'
import * as path from 'path'
import {OpenTestReportingParser} from '../src/parsers/open-test-reporting/open-test-reporting-parser'
import {ParseOptions} from '../src/test-parser'
import {getReport} from '../src/report/get-report'
import {normalizeFilePath} from '../src/utils/path-utils'
describe('open-test-reporting tests', () => {
const defaultOpts: ParseOptions = {
parseErrors: true,
trackedFiles: []
}
describe('hierarchy format', () => {
it('parses hierarchy format correctly', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'hierarchy.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
// 3 suites: UserServiceTest, PaymentServiceTest, EmptySuite
expect(result.suites.length).toBe(3)
// UserServiceTest: 3 tests (2 passed, 1 skipped)
const userSuite = result.suites.find(s => s.name === 'com.example.UserServiceTest')
expect(userSuite).toBeDefined()
expect(userSuite!.tests).toBe(3)
expect(userSuite!.passed).toBe(2)
expect(userSuite!.skipped).toBe(1)
expect(userSuite!.failed).toBe(0)
// PaymentServiceTest: 4 tests (3 passed, 1 failed) with nested groups
const paymentSuite = result.suites.find(s => s.name === 'com.example.PaymentServiceTest')
expect(paymentSuite).toBeDefined()
expect(paymentSuite!.tests).toBe(4)
expect(paymentSuite!.passed).toBe(3)
expect(paymentSuite!.failed).toBe(1)
// Check groups exist
expect(paymentSuite!.groups.length).toBe(2)
const validationGroup = paymentSuite!.groups.find(g => g.name === 'ValidationTests')
const processingGroup = paymentSuite!.groups.find(g => g.name === 'ProcessingTests')
expect(validationGroup).toBeDefined()
expect(processingGroup).toBeDefined()
expect(validationGroup!.tests.length).toBe(2)
expect(processingGroup!.tests.length).toBe(2)
// EmptySuite: 0 tests
const emptySuite = result.suites.find(s => s.name === 'com.example.EmptySuite')
expect(emptySuite).toBeDefined()
expect(emptySuite!.tests).toBe(0)
})
it('parses duration correctly', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'hierarchy.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
// UserServiceTest has duration PT1.234S = 1234ms
const userSuite = result.suites.find(s => s.name === 'com.example.UserServiceTest')
expect(userSuite!.time).toBeCloseTo(1234, 0)
// Check individual test times
const group = userSuite!.groups[0]
const creationTest = group.tests.find(t => t.name === 'testUserCreation')
expect(creationTest!.time).toBeCloseTo(123, 0) // PT0.123S
})
it('extracts error message from failed tests', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'hierarchy.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
const paymentSuite = result.suites.find(s => s.name === 'com.example.PaymentServiceTest')
const processingGroup = paymentSuite!.groups.find(g => g.name === 'ProcessingTests')
const timeoutTest = processingGroup!.tests.find(t => t.name === 'testPaymentTimeout')
expect(timeoutTest!.result).toBe('failed')
expect(timeoutTest!.error).toBeDefined()
expect(timeoutTest!.error!.message).toContain('AssertionFailedError')
})
it('handles empty hierarchy file', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'empty.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
expect(result.tests).toBe(0)
expect(result.suites.length).toBe(0)
expect(result.result).toBe('success')
})
})
describe('events format', () => {
it('parses events format correctly', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'events.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
// 2 suites: CalculatorTest, StringUtilsTest
expect(result.suites.length).toBe(2)
// CalculatorTest: 4 tests
const calcSuite = result.suites.find(s => s.name === 'com.example.CalculatorTest')
expect(calcSuite).toBeDefined()
expect(calcSuite!.tests).toBe(4)
expect(calcSuite!.passed).toBe(2)
expect(calcSuite!.failed).toBe(1)
expect(calcSuite!.skipped).toBe(1)
// StringUtilsTest: 2 tests in TrimTests group
const stringSuite = result.suites.find(s => s.name === 'com.example.StringUtilsTest')
expect(stringSuite).toBeDefined()
expect(stringSuite!.tests).toBe(2)
expect(stringSuite!.passed).toBe(2)
// Check TrimTests group
const trimGroup = stringSuite!.groups.find(g => g.name === 'TrimTests')
expect(trimGroup).toBeDefined()
expect(trimGroup!.tests.length).toBe(2)
})
it('calculates duration from timestamps', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'events.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
const calcSuite = result.suites.find(s => s.name === 'com.example.CalculatorTest')
// testAddition: 11:00:00.100 to 11:00:00.200 = 100ms
const addTest = calcSuite!.groups[0].tests.find(t => t.name === 'testAddition')
expect(addTest!.time).toBe(100)
})
it('extracts error message from failed events', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'events.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
const calcSuite = result.suites.find(s => s.name === 'com.example.CalculatorTest')
const divTest = calcSuite!.groups[0].tests.find(t => t.name === 'testDivision')
expect(divTest!.result).toBe('failed')
expect(divTest!.error).toBeDefined()
expect(divTest!.error!.message).toContain('ArithmeticException')
})
})
describe('format auto-detection', () => {
it('auto-detects hierarchy format', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'hierarchy.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
// Should parse successfully with hierarchy format
expect(result.suites.length).toBe(3)
})
it('auto-detects events format', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'events.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
// Should parse successfully with events format
expect(result.suites.length).toBe(2)
})
it('throws error for invalid format', async () => {
const invalidXml = '<?xml version="1.0"?><unknown><root/></unknown>'
const parser = new OpenTestReportingParser(defaultOpts)
await expect(parser.parse('invalid.xml', invalidXml)).rejects.toThrow(
'Unknown open-test-reporting format'
)
})
it('throws error for invalid XML', async () => {
const invalidXml = 'not valid xml at all'
const parser = new OpenTestReportingParser(defaultOpts)
await expect(parser.parse('invalid.xml', invalidXml)).rejects.toThrow('Invalid XML')
})
})
describe('status mapping', () => {
it('maps SUCCESSFUL to success', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'hierarchy.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
const userSuite = result.suites.find(s => s.name === 'com.example.UserServiceTest')
const creationTest = userSuite!.groups[0].tests.find(t => t.name === 'testUserCreation')
expect(creationTest!.result).toBe('success')
})
it('maps SKIPPED to skipped', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'hierarchy.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
const userSuite = result.suites.find(s => s.name === 'com.example.UserServiceTest')
const updateTest = userSuite!.groups[0].tests.find(t => t.name === 'testUserUpdate')
expect(updateTest!.result).toBe('skipped')
})
it('maps FAILED to failed', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'hierarchy.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
const paymentSuite = result.suites.find(s => s.name === 'com.example.PaymentServiceTest')
const processingGroup = paymentSuite!.groups.find(g => g.name === 'ProcessingTests')
const timeoutTest = processingGroup!.tests.find(t => t.name === 'testPaymentTimeout')
expect(timeoutTest!.result).toBe('failed')
})
})
describe('report generation', () => {
it('generates report from hierarchy format', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'hierarchy.xml')
const outputPath = path.join(__dirname, '__outputs__', 'open-test-reporting-hierarchy.md')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
const report = getReport([result])
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
fs.writeFileSync(outputPath, report)
// Verify report contains expected content
expect(report).toContain('UserServiceTest')
expect(report).toContain('PaymentServiceTest')
expect(report).toContain('testPaymentTimeout')
})
it('generates report from events format', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'events.xml')
const outputPath = path.join(__dirname, '__outputs__', 'open-test-reporting-events.md')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
const report = getReport([result])
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
fs.writeFileSync(outputPath, report)
// Verify report contains expected content
expect(report).toContain('CalculatorTest')
expect(report).toContain('StringUtilsTest')
expect(report).toContain('testDivision')
})
it('result matches snapshot for hierarchy format', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'hierarchy.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
expect(result).toMatchSnapshot()
})
it('result matches snapshot for events format', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'events.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
expect(result).toMatchSnapshot()
})
})
describe('duration parsing', () => {
it('parses seconds only format (PT0.123S)', async () => {
// This is tested through hierarchy.xml which uses PT0.123S format
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'hierarchy.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
const userSuite = result.suites.find(s => s.name === 'com.example.UserServiceTest')
// PT0.123S = 123ms
const creationTest = userSuite!.groups[0].tests.find(t => t.name === 'testUserCreation')
expect(creationTest!.time).toBeCloseTo(123, 0)
})
it('handles missing duration', async () => {
// EmptySuite has PT0S duration
const fixturePath = path.join(__dirname, 'fixtures', 'open-test-reporting', 'hierarchy.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const parser = new OpenTestReportingParser(defaultOpts)
const result = await parser.parse(filePath, fileContent)
const emptySuite = result.suites.find(s => s.name === 'com.example.EmptySuite')
expect(emptySuite!.time).toBe(0)
})
})
})