mirror of
https://github.com/dorny/test-reporter.git
synced 2026-02-01 02:45:22 -08:00
Add sample files from PHPUnit results in JUnit XML format
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -99,4 +99,188 @@ describe('phpunit-junit tests', () => {
|
||||
expect(test.error!.details).toContain('Failed asserting that string matches format description')
|
||||
}
|
||||
})
|
||||
|
||||
it('parses junit-basic.xml with nested suites and failure', async () => {
|
||||
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'phpunit', 'junit-basic.xml')
|
||||
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||
|
||||
const opts: ParseOptions = {
|
||||
parseErrors: true,
|
||||
trackedFiles: []
|
||||
}
|
||||
|
||||
const parser = new PhpunitJunitParser(opts)
|
||||
const result = await parser.parse(filePath, fileContent)
|
||||
|
||||
// Verify test counts
|
||||
expect(result.tests).toBe(9)
|
||||
expect(result.passed).toBe(8)
|
||||
expect(result.failed).toBe(1)
|
||||
expect(result.result).toBe('failed')
|
||||
|
||||
// Verify suites - should have Tests.Registration, Tests.Authentication.Login, and Tests.Authentication
|
||||
expect(result.suites.length).toBe(3)
|
||||
|
||||
const suiteNames = result.suites.map(s => s.name)
|
||||
expect(suiteNames).toContain('Tests.Registration')
|
||||
expect(suiteNames).toContain('Tests.Authentication.Login')
|
||||
expect(suiteNames).toContain('Tests.Authentication')
|
||||
|
||||
// Verify the Registration suite has 3 tests
|
||||
const registrationSuite = result.suites.find(s => s.name === 'Tests.Registration')
|
||||
expect(registrationSuite).toBeDefined()
|
||||
const registrationTests = registrationSuite!.groups.flatMap(g => g.tests)
|
||||
expect(registrationTests.length).toBe(3)
|
||||
|
||||
// Verify the Authentication suite has 3 direct tests (not counting nested suite)
|
||||
const authSuite = result.suites.find(s => s.name === 'Tests.Authentication')
|
||||
expect(authSuite).toBeDefined()
|
||||
const authTests = authSuite!.groups.flatMap(g => g.tests)
|
||||
expect(authTests.length).toBe(3)
|
||||
|
||||
// Verify the Login nested suite has 3 tests
|
||||
const loginSuite = result.suites.find(s => s.name === 'Tests.Authentication.Login')
|
||||
expect(loginSuite).toBeDefined()
|
||||
const loginTests = loginSuite!.groups.flatMap(g => g.tests)
|
||||
expect(loginTests.length).toBe(3)
|
||||
|
||||
// Verify failure is captured
|
||||
const failedTest = authTests.find(t => t.name === 'testCase9')
|
||||
expect(failedTest).toBeDefined()
|
||||
expect(failedTest!.result).toBe('failed')
|
||||
expect(failedTest!.error).toBeDefined()
|
||||
expect(failedTest!.error!.message).toBe('AssertionError: Assertion error message')
|
||||
})
|
||||
|
||||
it('parses phpcheckstyle-phpunit.xml with deeply nested suites', async () => {
|
||||
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'phpunit', 'phpcheckstyle-phpunit.xml')
|
||||
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||
|
||||
const opts: ParseOptions = {
|
||||
parseErrors: true,
|
||||
trackedFiles: []
|
||||
}
|
||||
|
||||
const parser = new PhpunitJunitParser(opts)
|
||||
const result = await parser.parse(filePath, fileContent)
|
||||
|
||||
// Verify test counts from the XML: tests="30", failures="2"
|
||||
expect(result.tests).toBe(30)
|
||||
expect(result.passed).toBe(28)
|
||||
expect(result.failed).toBe(2)
|
||||
expect(result.result).toBe('failed')
|
||||
|
||||
// Verify the number of test suites extracted (leaf suites with testcases)
|
||||
// CommentsTest, DeprecationTest, GoodTest, IndentationTest, MetricsTest,
|
||||
// NamingTest, OptimizationTest, OtherTest, PHPTagsTest, ProhibitedTest,
|
||||
// StrictCompareTest, UnusedTest = 12 suites
|
||||
expect(result.suites.length).toBe(12)
|
||||
|
||||
const suiteNames = result.suites.map(s => s.name)
|
||||
expect(suiteNames).toContain('CommentsTest')
|
||||
expect(suiteNames).toContain('GoodTest')
|
||||
expect(suiteNames).toContain('IndentationTest')
|
||||
expect(suiteNames).toContain('OtherTest')
|
||||
})
|
||||
|
||||
it('extracts test data from phpcheckstyle-phpunit.xml', async () => {
|
||||
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'phpunit', 'phpcheckstyle-phpunit.xml')
|
||||
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||
|
||||
const opts: ParseOptions = {
|
||||
parseErrors: true,
|
||||
trackedFiles: []
|
||||
}
|
||||
|
||||
const parser = new PhpunitJunitParser(opts)
|
||||
const result = await parser.parse(filePath, fileContent)
|
||||
|
||||
// Find the CommentsTest suite
|
||||
const commentsSuite = result.suites.find(s => s.name === 'CommentsTest')
|
||||
expect(commentsSuite).toBeDefined()
|
||||
|
||||
// Verify tests are extracted correctly
|
||||
const tests = commentsSuite!.groups.flatMap(g => g.tests)
|
||||
expect(tests.length).toBe(3)
|
||||
|
||||
const testGoodDoc = tests.find(t => t.name === 'testGoodDoc')
|
||||
expect(testGoodDoc).toBeDefined()
|
||||
expect(testGoodDoc!.result).toBe('success')
|
||||
})
|
||||
|
||||
it('captures failure details from phpcheckstyle-phpunit.xml', async () => {
|
||||
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'phpunit', 'phpcheckstyle-phpunit.xml')
|
||||
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||
|
||||
const opts: ParseOptions = {
|
||||
parseErrors: true,
|
||||
trackedFiles: []
|
||||
}
|
||||
|
||||
const parser = new PhpunitJunitParser(opts)
|
||||
const result = await parser.parse(filePath, fileContent)
|
||||
|
||||
// Find the OtherTest suite which has failures
|
||||
const otherSuite = result.suites.find(s => s.name === 'OtherTest')
|
||||
expect(otherSuite).toBeDefined()
|
||||
|
||||
const failedTests = otherSuite!.groups.flatMap(g => g.tests).filter(t => t.result === 'failed')
|
||||
expect(failedTests.length).toBe(2)
|
||||
|
||||
// Verify failure details
|
||||
const testOther = failedTests.find(t => t.name === 'testOther')
|
||||
expect(testOther).toBeDefined()
|
||||
expect(testOther!.error).toBeDefined()
|
||||
expect(testOther!.error!.details).toContain('We expect 20 warnings')
|
||||
expect(testOther!.error!.details).toContain('Failed asserting that 19 matches expected 20')
|
||||
|
||||
const testException = failedTests.find(t => t.name === 'testException')
|
||||
expect(testException).toBeDefined()
|
||||
expect(testException!.error).toBeDefined()
|
||||
expect(testException!.error!.details).toContain('We expect 1 error')
|
||||
})
|
||||
|
||||
it('report from junit-basic.xml matches snapshot', async () => {
|
||||
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'phpunit', 'junit-basic.xml')
|
||||
const outputPath = path.join(__dirname, '__outputs__', 'phpunit-junit-basic-results.md')
|
||||
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||
|
||||
const opts: ParseOptions = {
|
||||
parseErrors: true,
|
||||
trackedFiles: []
|
||||
}
|
||||
|
||||
const parser = new PhpunitJunitParser(opts)
|
||||
const result = await parser.parse(filePath, fileContent)
|
||||
expect(result).toMatchSnapshot()
|
||||
|
||||
const report = getReport([result])
|
||||
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||
fs.writeFileSync(outputPath, report)
|
||||
})
|
||||
|
||||
it('report from phpcheckstyle-phpunit.xml matches snapshot', async () => {
|
||||
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'phpunit', 'phpcheckstyle-phpunit.xml')
|
||||
const outputPath = path.join(__dirname, '__outputs__', 'phpunit-phpcheckstyle-results.md')
|
||||
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||
|
||||
const opts: ParseOptions = {
|
||||
parseErrors: true,
|
||||
trackedFiles: []
|
||||
}
|
||||
|
||||
const parser = new PhpunitJunitParser(opts)
|
||||
const result = await parser.parse(filePath, fileContent)
|
||||
expect(result).toMatchSnapshot()
|
||||
|
||||
const report = getReport([result])
|
||||
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||
fs.writeFileSync(outputPath, report)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user