mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 13:57:09 +01:00
Merge pull request #236 from wingyplus/fix-iss-235
This commit is contained in:
commit
d9ef69ec3d
6 changed files with 75 additions and 2 deletions
10
__tests__/__outputs__/jest-react-component-test-results.md
Normal file
10
__tests__/__outputs__/jest-react-component-test-results.md
Normal file
|
|
@ -0,0 +1,10 @@
|
|||

|
||||
## ✅ <a id="user-content-r0" href="#r0">fixtures/external/jest/jest-react-component-test-results.xml</a>
|
||||
**1** tests were completed in **1000ms** with **1** passed, **0** failed and **0** skipped.
|
||||
|Test suite|Passed|Failed|Skipped|Time|
|
||||
|:---|---:|---:|---:|---:|
|
||||
|[\<Component /\>](#r0s0)|1✅|||798ms|
|
||||
### ✅ <a id="user-content-r0s0" href="#r0s0">\<Component /\></a>
|
||||
```
|
||||
✅ <Component /> should render properly
|
||||
```
|
||||
|
|
@ -1,5 +1,31 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`jest-junit tests report from #235 testing react components named <ComponentName /> 1`] = `
|
||||
TestRunResult {
|
||||
"path": "fixtures/external/jest/jest-react-component-test-results.xml",
|
||||
"suites": [
|
||||
TestSuiteResult {
|
||||
"groups": [
|
||||
TestGroupResult {
|
||||
"name": "",
|
||||
"tests": [
|
||||
TestCaseResult {
|
||||
"error": undefined,
|
||||
"name": "<Component /> should render properly",
|
||||
"result": "success",
|
||||
"time": 704,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
"name": "\\<Component /\\>",
|
||||
"totalTime": 798,
|
||||
},
|
||||
],
|
||||
"totalTime": 1000,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`jest-junit tests report from ./reports/jest test results matches snapshot 1`] = `
|
||||
TestRunResult {
|
||||
"path": "fixtures/jest-junit.xml",
|
||||
|
|
|
|||
7
__tests__/fixtures/external/jest/jest-react-component-test-results.xml
vendored
Normal file
7
__tests__/fixtures/external/jest/jest-react-component-test-results.xml
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites name="React components test" tests="1" failures="0" errors="0" time="1.0">
|
||||
<testsuite name="<Component />" errors="0" failures="0" skipped="0" timestamp="2021-01-24T19:21:45" time="0.798" tests="1">
|
||||
<testcase classname="" name="<Component /> should render properly" time="0.704">
|
||||
</testcase>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
|
@ -82,4 +82,27 @@ describe('jest-junit tests', () => {
|
|||
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||
fs.writeFileSync(outputPath, report)
|
||||
})
|
||||
|
||||
it('report from #235 testing react components named <ComponentName />', async () => {
|
||||
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'jest', 'jest-react-component-test-results.xml')
|
||||
const trackedFilesPath = path.join(__dirname, 'fixtures', 'external', 'jest', 'files.txt')
|
||||
const outputPath = path.join(__dirname, '__outputs__', 'jest-react-component-test-results.md')
|
||||
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||
|
||||
const trackedFiles = fs.readFileSync(trackedFilesPath, {encoding: 'utf8'}).split(/\n\r?/g)
|
||||
const opts: ParseOptions = {
|
||||
parseErrors: true,
|
||||
trackedFiles
|
||||
//workDir: '/home/dorny/dorny/jest/'
|
||||
}
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
5
dist/index.js
generated
vendored
5
dist/index.js
generated
vendored
|
|
@ -1212,7 +1212,7 @@ class JestJunitParser {
|
|||
const suites = junit.testsuites.testsuite === undefined
|
||||
? []
|
||||
: junit.testsuites.testsuite.map(ts => {
|
||||
const name = ts.$.name.trim();
|
||||
const name = this.escapeCharacters(ts.$.name.trim());
|
||||
const time = parseFloat(ts.$.time) * 1000;
|
||||
const sr = new test_results_1.TestSuiteResult(name, this.getGroups(ts), time);
|
||||
return sr;
|
||||
|
|
@ -1281,6 +1281,9 @@ class JestJunitParser {
|
|||
var _a, _b;
|
||||
return ((_b = (_a = this.options.workDir) !== null && _a !== void 0 ? _a : this.assumedWorkDir) !== null && _b !== void 0 ? _b : (this.assumedWorkDir = (0, path_utils_1.getBasePath)(path, this.options.trackedFiles)));
|
||||
}
|
||||
escapeCharacters(s) {
|
||||
return s.replace(/([<>])/g, '\\$1');
|
||||
}
|
||||
}
|
||||
exports.JestJunitParser = JestJunitParser;
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ export class JestJunitParser implements TestParser {
|
|||
junit.testsuites.testsuite === undefined
|
||||
? []
|
||||
: junit.testsuites.testsuite.map(ts => {
|
||||
const name = ts.$.name.trim()
|
||||
const name = this.escapeCharacters(ts.$.name.trim())
|
||||
const time = parseFloat(ts.$.time) * 1000
|
||||
const sr = new TestSuiteResult(name, this.getGroups(ts), time)
|
||||
return sr
|
||||
|
|
@ -118,4 +118,8 @@ export class JestJunitParser implements TestParser {
|
|||
(this.assumedWorkDir = getBasePath(path, this.options.trackedFiles))
|
||||
)
|
||||
}
|
||||
|
||||
private escapeCharacters(s: string): string {
|
||||
return s.replace(/([<>])/g, '\\$1')
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue