mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 22:07:09 +01:00
Fix parsing of ESLint reports in jest-junit format
The [ESLint junit formatter](https://www.npmjs.com/package/eslint-junit) does not include a total time attribute for the root `<testsuites>` element.
This commit is contained in:
parent
9557e57e83
commit
45526f79fd
6 changed files with 65 additions and 2 deletions
11
__tests__/__outputs__/jest-junit-eslint.md
Normal file
11
__tests__/__outputs__/jest-junit-eslint.md
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|

|
||||||
|
## ✅ <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
|
||||||
|
```
|
||||||
|
|
@ -1,5 +1,31 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// 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`] = `
|
exports[`jest-junit tests report from #235 testing react components named <ComponentName /> 1`] = `
|
||||||
TestRunResult {
|
TestRunResult {
|
||||||
"path": "fixtures/external/jest/jest-react-component-test-results.xml",
|
"path": "fixtures/external/jest/jest-react-component-test-results.xml",
|
||||||
|
|
|
||||||
6
__tests__/fixtures/jest-junit-eslint.xml
Normal file
6
__tests__/fixtures/jest-junit-eslint.xml
Normal file
|
|
@ -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>
|
||||||
|
|
@ -105,4 +105,24 @@ describe('jest-junit tests', () => {
|
||||||
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||||
fs.writeFileSync(outputPath, report)
|
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
dist/index.js
generated
vendored
2
dist/index.js
generated
vendored
|
|
@ -1320,7 +1320,7 @@ class JestJunitParser {
|
||||||
const sr = new test_results_1.TestSuiteResult(name, this.getGroups(ts), time);
|
const sr = new test_results_1.TestSuiteResult(name, this.getGroups(ts), time);
|
||||||
return sr;
|
return sr;
|
||||||
});
|
});
|
||||||
const time = parseFloat(junit.testsuites.$.time) * 1000;
|
const time = junit.testsuites.$ && parseFloat(junit.testsuites.$.time) * 1000;
|
||||||
return new test_results_1.TestRunResult(path, suites, time);
|
return new test_results_1.TestRunResult(path, suites, time);
|
||||||
}
|
}
|
||||||
getGroups(suite) {
|
getGroups(suite) {
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ export class JestJunitParser implements TestParser {
|
||||||
return sr
|
return sr
|
||||||
})
|
})
|
||||||
|
|
||||||
const time = parseFloat(junit.testsuites.$.time) * 1000
|
const time = junit.testsuites.$ && parseFloat(junit.testsuites.$.time) * 1000
|
||||||
return new TestRunResult(path, suites, time)
|
return new TestRunResult(path, suites, time)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue