Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of ESLint reports in jest-junit format #134

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions __tests__/__outputs__/jest-junit-eslint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success)
<details><summary>Expand for details</summary>

|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|
|fixtures/jest-junit-eslint.xml|1 ✅|||0ms|
## ✅ <a id="user-content-r0" href="#r0">fixtures/jest-junit-eslint.xml</a>
**1** tests were completed in **0ms** with **1** passed, **0** failed and **0** skipped.
|Test suite|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|
|[test.jsx](#r0s0)|1 ✅|||0ms|
### ✅ <a id="user-content-r0s0" href="#r0s0">test.jsx</a>
```
test
✅ test.jsx
```
</details>
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 parsing ESLint report without timing information works - PR #134 1`] = `
TestRunResult {
"path": "fixtures/jest-junit-eslint.xml",
"suites": [
TestSuiteResult {
"groups": [
TestGroupResult {
"name": "test",
"tests": [
TestCaseResult {
"error": undefined,
"name": "test.jsx",
"result": "success",
"time": 0,
},
],
},
],
"name": "test.jsx",
"totalTime": 0,
},
],
"totalTime": undefined,
}
`;

exports[`jest-junit tests report from #235 testing react components named <ComponentName /> 1`] = `
TestRunResult {
"path": "fixtures/external/jest/jest-react-component-test-results.xml",
Expand Down
6 changes: 6 additions & 0 deletions __tests__/fixtures/jest-junit-eslint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite package="org.eslint" time="0" tests="1" errors="0" name="test.jsx">
<testcase time="0" name="test.jsx" classname="test" />
</testsuite>
</testsuites>
20 changes: 20 additions & 0 deletions __tests__/jest-junit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,24 @@ describe('jest-junit tests', () => {
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
fs.writeFileSync(outputPath, report)
})

it('parsing ESLint report without timing information works - PR #134', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit-eslint.xml')
const outputPath = path.join(__dirname, '__outputs__', 'jest-junit-eslint.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 changes: 1 addition & 1 deletion dist/index.js

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

2 changes: 1 addition & 1 deletion src/parsers/jest-junit/jest-junit-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class JestJunitParser implements TestParser {
return sr
})

const time = parseFloat(junit.testsuites.$.time) * 1000
const time = junit.testsuites.$ && parseFloat(junit.testsuites.$.time) * 1000
return new TestRunResult(path, suites, time)
}

Expand Down