Skip to content

Commit d9ef69e

Browse files
authored
Merge pull request #236 from wingyplus/fix-iss-235
2 parents 57cb273 + 7aa575a commit d9ef69e

File tree

6 files changed

+75
-2
lines changed

6 files changed

+75
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success)
2+
## ✅ <a id="user-content-r0" href="#r0">fixtures/external/jest/jest-react-component-test-results.xml</a>
3+
**1** tests were completed in **1000ms** with **1** passed, **0** failed and **0** skipped.
4+
|Test suite|Passed|Failed|Skipped|Time|
5+
|:---|---:|---:|---:|---:|
6+
|[\<Component /\>](#r0s0)|1✅|||798ms|
7+
### ✅ <a id="user-content-r0s0" href="#r0s0">\<Component /\></a>
8+
```
9+
✅ <Component /> should render properly
10+
```

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

+26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`jest-junit tests report from #235 testing react components named <ComponentName /> 1`] = `
4+
TestRunResult {
5+
"path": "fixtures/external/jest/jest-react-component-test-results.xml",
6+
"suites": [
7+
TestSuiteResult {
8+
"groups": [
9+
TestGroupResult {
10+
"name": "",
11+
"tests": [
12+
TestCaseResult {
13+
"error": undefined,
14+
"name": "<Component /> should render properly",
15+
"result": "success",
16+
"time": 704,
17+
},
18+
],
19+
},
20+
],
21+
"name": "\\<Component /\\>",
22+
"totalTime": 798,
23+
},
24+
],
25+
"totalTime": 1000,
26+
}
27+
`;
28+
329
exports[`jest-junit tests report from ./reports/jest test results matches snapshot 1`] = `
430
TestRunResult {
531
"path": "fixtures/jest-junit.xml",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites name="React components test" tests="1" failures="0" errors="0" time="1.0">
3+
<testsuite name="&lt;Component /&gt;" errors="0" failures="0" skipped="0" timestamp="2021-01-24T19:21:45" time="0.798" tests="1">
4+
<testcase classname="" name="&lt;Component /&gt; should render properly" time="0.704">
5+
</testcase>
6+
</testsuite>
7+
</testsuites>

__tests__/jest-junit.test.ts

+23
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,27 @@ describe('jest-junit tests', () => {
8282
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
8383
fs.writeFileSync(outputPath, report)
8484
})
85+
86+
it('report from #235 testing react components named <ComponentName />', async () => {
87+
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'jest', 'jest-react-component-test-results.xml')
88+
const trackedFilesPath = path.join(__dirname, 'fixtures', 'external', 'jest', 'files.txt')
89+
const outputPath = path.join(__dirname, '__outputs__', 'jest-react-component-test-results.md')
90+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
91+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
92+
93+
const trackedFiles = fs.readFileSync(trackedFilesPath, {encoding: 'utf8'}).split(/\n\r?/g)
94+
const opts: ParseOptions = {
95+
parseErrors: true,
96+
trackedFiles
97+
//workDir: '/home/dorny/dorny/jest/'
98+
}
99+
100+
const parser = new JestJunitParser(opts)
101+
const result = await parser.parse(filePath, fileContent)
102+
expect(result).toMatchSnapshot()
103+
104+
const report = getReport([result])
105+
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
106+
fs.writeFileSync(outputPath, report)
107+
})
85108
})

dist/index.js

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class JestJunitParser implements TestParser {
3737
junit.testsuites.testsuite === undefined
3838
? []
3939
: junit.testsuites.testsuite.map(ts => {
40-
const name = ts.$.name.trim()
40+
const name = this.escapeCharacters(ts.$.name.trim())
4141
const time = parseFloat(ts.$.time) * 1000
4242
const sr = new TestSuiteResult(name, this.getGroups(ts), time)
4343
return sr
@@ -118,4 +118,8 @@ export class JestJunitParser implements TestParser {
118118
(this.assumedWorkDir = getBasePath(path, this.options.trackedFiles))
119119
)
120120
}
121+
122+
private escapeCharacters(s: string): string {
123+
return s.replace(/([<>])/g, '\\$1')
124+
}
121125
}

0 commit comments

Comments
 (0)