Merge pull request #559 from cmonaghan1/feat/support-junit-report-with-message

feat: parse junit report with message
This commit is contained in:
Jozef Izso 2025-03-12 13:16:52 +01:00 committed by GitHub
commit 27dd4e035f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 79 additions and 2 deletions

View file

@ -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
```

View file

@ -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",

View file

@ -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>

View file

@ -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
dist/index.js generated vendored
View file

@ -1358,7 +1358,7 @@ class JestJunitParser {
if (!this.options.parseErrors || !tc.failure) {
return undefined;
}
const details = tc.failure[0];
const details = typeof tc.failure[0] === 'string' ? tc.failure[0] : tc.failure[0]['_'];
let path;
let line;
const src = (0, node_utils_1.getExceptionSource)(details, this.options.trackedFiles, file => this.getRelativePath(file));

View file

@ -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