Skip to content

Commit

Permalink
Merge pull request #559 from cmonaghan1/feat/support-junit-report-wit…
Browse files Browse the repository at this point in the history
…h-message

feat: parse junit report with message
  • Loading branch information
Jozef Izso authored and GitHub committed Mar 12, 2025
2 parents 41662db + 10d304d commit 27dd4e0
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 2 deletions.
15 changes: 15 additions & 0 deletions __tests__/__outputs__/junit-with-message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
![Tests failed](https://img.shields.io/badge/tests-1%20failed-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|
|fixtures/junit-with-message.xml||1 ❌||1ms|
## ❌ <a id="user-content-r0" href="#r0">fixtures/junit-with-message.xml</a>
**1** tests were completed in **1ms** with **0** passed, **1** failed and **0** skipped.
|Test suite|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|
|[Test](#r0s0)||1 ❌||1ms|
### ❌ <a id="user-content-r0s0" href="#r0s0">Test</a>
```
Fails
❌ Test
error.cpp:01
```
32 changes: 32 additions & 0 deletions __tests__/__snapshots__/jest-junit.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@ TestRunResult {
}
`;

exports[`jest-junit tests parsing junit report with message succeeds 1`] = `
TestRunResult {
"path": "fixtures/junit-with-message.xml",
"suites": [
TestSuiteResult {
"groups": [
TestGroupResult {
"name": "Fails",
"tests": [
TestCaseResult {
"error": {
"details": "error.cpp:01
Expected: true
Which is: false >",
"line": undefined,
"path": undefined,
},
"name": "Test",
"result": "failed",
"time": 0,
},
],
},
],
"name": "Test",
"totalTime": 1,
},
],
"totalTime": 1,
}
`;

exports[`jest-junit tests report from #235 testing react components named <ComponentName /> 1`] = `
TestRunResult {
"path": "fixtures/external/jest/jest-react-component-test-results.xml",
Expand Down
10 changes: 10 additions & 0 deletions __tests__/fixtures/junit-with-message.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="1" disabled="0" errors="0" time="0.001" name="Failure">
<testsuite name="Test" tests="6" failures="1" disabled="0" errors="0" time="0.001">
<testcase name="Test" status="run" time="0" classname="Fails">
<failure message="error" type=""><![CDATA[error.cpp:01
Expected: true
Which is: false >]]></failure>
</testcase>
</testsuite>
</testsuites>
20 changes: 20 additions & 0 deletions __tests__/jest-junit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,24 @@ describe('jest-junit tests', () => {
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
fs.writeFileSync(outputPath, report)
})

it('parsing junit report with message succeeds', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'junit-with-message.xml')
const outputPath = path.join(__dirname, '__outputs__', 'junit-with-message.md')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})

const opts: ParseOptions = {
parseErrors: true,
trackedFiles: ['test.js']
}

const parser = new JestJunitParser(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)
})
})
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/parsers/jest-junit/jest-junit-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class JestJunitParser implements TestParser {
return undefined
}

const details = tc.failure[0]
const details = typeof tc.failure[0] === 'string' ? tc.failure[0] : tc.failure[0]['_']
let path
let line

Expand Down

0 comments on commit 27dd4e0

Please sign in to comment.