Skip to content

Commit

Permalink
Add tests for results with React component names
Browse files Browse the repository at this point in the history
  • Loading branch information
jozefizso committed Dec 18, 2023
1 parent 28aa0a4 commit 7c05f9c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
10 changes: 10 additions & 0 deletions __tests__/__outputs__/jest-react-component-test-results.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success)
## ✅ <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
```
26 changes: 26 additions & 0 deletions __tests__/__snapshots__/jest-junit.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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="&lt;Component /&gt;" errors="0" failures="0" skipped="0" timestamp="2021-01-24T19:21:45" time="0.798" tests="1">
<testcase classname="" name="&lt;Component /&gt; should render properly" time="0.704">
</testcase>
</testsuite>
</testsuites>
23 changes: 23 additions & 0 deletions __tests__/jest-junit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 4 additions & 1 deletion dist/index.js

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

0 comments on commit 7c05f9c

Please sign in to comment.