Skip to content

Commit 70db77d

Browse files
committed
feat: parse junit report with message
1 parent 41662db commit 70db77d

File tree

5 files changed

+78
-1
lines changed

5 files changed

+78
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
![Tests failed](https://img.shields.io/badge/tests-1%20failed-critical)
2+
|Report|Passed|Failed|Skipped|Time|
3+
|:---|---:|---:|---:|---:|
4+
|fixtures/junit-with-message.xml||1 ❌||1ms|
5+
## ❌ <a id="user-content-r0" href="#r0">fixtures/junit-with-message.xml</a>
6+
**1** tests were completed in **1ms** with **0** passed, **1** failed and **0** skipped.
7+
|Test suite|Passed|Failed|Skipped|Time|
8+
|:---|---:|---:|---:|---:|
9+
|[Test](#r0s0)||1 ❌||1ms|
10+
### ❌ <a id="user-content-r0s0" href="#r0s0">Test</a>
11+
```
12+
Fails
13+
❌ Test
14+
error.cpp:01
15+
```

__tests__/__snapshots__/jest-junit.test.ts.snap

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,38 @@ TestRunResult {
2626
}
2727
`;
2828

29+
exports[`jest-junit tests parsing junit report with message succeeds 1`] = `
30+
TestRunResult {
31+
"path": "fixtures/junit-with-message.xml",
32+
"suites": [
33+
TestSuiteResult {
34+
"groups": [
35+
TestGroupResult {
36+
"name": "Fails",
37+
"tests": [
38+
TestCaseResult {
39+
"error": {
40+
"details": "error.cpp:01
41+
Expected: true
42+
Which is: false >",
43+
"line": undefined,
44+
"path": undefined,
45+
},
46+
"name": "Test",
47+
"result": "failed",
48+
"time": 0,
49+
},
50+
],
51+
},
52+
],
53+
"name": "Test",
54+
"totalTime": 1,
55+
},
56+
],
57+
"totalTime": 1,
58+
}
59+
`;
60+
2961
exports[`jest-junit tests report from #235 testing react components named <ComponentName /> 1`] = `
3062
TestRunResult {
3163
"path": "fixtures/external/jest/jest-react-component-test-results.xml",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites tests="1" failures="1" disabled="0" errors="0" time="0.001" name="Failure">
3+
<testsuite name="Test" tests="6" failures="1" disabled="0" errors="0" time="0.001">
4+
<testcase name="Test" status="run" time="0" classname="Fails">
5+
<failure message="error" type=""><![CDATA[error.cpp:01
6+
Expected: true
7+
Which is: false >]]></failure>
8+
</testcase>
9+
</testsuite>
10+
</testsuites>

__tests__/jest-junit.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,24 @@ describe('jest-junit tests', () => {
125125
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
126126
fs.writeFileSync(outputPath, report)
127127
})
128+
129+
it('parsing junit report with message succeeds', async () => {
130+
const fixturePath = path.join(__dirname, 'fixtures', 'junit-with-message.xml')
131+
const outputPath = path.join(__dirname, '__outputs__', 'junit-with-message.md')
132+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
133+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
134+
135+
const opts: ParseOptions = {
136+
parseErrors: true,
137+
trackedFiles: ['test.js']
138+
}
139+
140+
const parser = new JestJunitParser(opts)
141+
const result = await parser.parse(filePath, fileContent)
142+
expect(result).toMatchSnapshot()
143+
144+
const report = getReport([result])
145+
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
146+
fs.writeFileSync(outputPath, report)
147+
})
128148
})

src/parsers/jest-junit/jest-junit-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class JestJunitParser implements TestParser {
8585
return undefined
8686
}
8787

88-
const details = tc.failure[0]
88+
const details = typeof tc.failure[0] === 'string' ? tc.failure[0] : tc.failure[0]['_']
8989
let path
9090
let line
9191

0 commit comments

Comments
 (0)