Skip to content

Commit

Permalink
Add test for java-junit
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Marcus authored and Jozef Izso committed May 17, 2025
1 parent 0841c81 commit 0840d7c
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion __tests__/java-junit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path'

import {JavaJunitParser} from '../src/parsers/java-junit/java-junit-parser'
import {ParseOptions} from '../src/test-parser'
import {getReport} from '../src/report/get-report'
import {ReportOptions, getReport} from '../src/report/get-report'
import {normalizeFilePath} from '../src/utils/path-utils'

describe('java-junit tests', () => {
Expand Down Expand Up @@ -90,4 +90,47 @@ describe('java-junit tests', () => {
expect(result.result === 'failed')
expect(result.failed === 1)
})

it('report includes the default report title', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'java-junit.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})

const opts: ParseOptions = {
parseErrors: true,
trackedFiles: []
}

const parser = new JavaJunitParser(opts)
const result = await parser.parse(filePath, fileContent)
const report = getReport([result])
// Report should have the title as the first line
expect(report).toMatch(/^# Test Results\n/)
})

it('report includes a custom report title', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'java-junit.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})

const opts: ParseOptions = {
parseErrors: true,
trackedFiles: []
}

const parser = new JavaJunitParser(opts)
const result = await parser.parse(filePath, fileContent)
const reportOpts: ReportOptions = {
listSuites: 'all',
listTests: 'all',
baseUrl: '',
onlySummary: false,
useActionsSummary: true,
badgeTitle: 'tests',
reportTitle: 'My Custom Title'
}
const report = getReport([result], reportOpts)
// Report should have the title as the first line
expect(report).toMatch(/^# My Custom Title\n/)
})
})

0 comments on commit 0840d7c

Please sign in to comment.