Skip to content

Commit 95058ab

Browse files
authored
Merge pull request dorny#134 from phjardas/fix-jest-junit-missing-time
2 parents 9557e57 + 7befe80 commit 95058ab

File tree

6 files changed

+71
-2
lines changed

6 files changed

+71
-2
lines changed
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success)
2+
<details><summary>Expand for details</summary>
3+
4+
|Report|Passed|Failed|Skipped|Time|
5+
|:---|---:|---:|---:|---:|
6+
|fixtures/jest-junit-eslint.xml|1 ✅|||0ms|
7+
## ✅ <a id="user-content-r0" href="#r0">fixtures/jest-junit-eslint.xml</a>
8+
**1** tests were completed in **0ms** with **1** passed, **0** failed and **0** skipped.
9+
|Test suite|Passed|Failed|Skipped|Time|
10+
|:---|---:|---:|---:|---:|
11+
|[test.jsx](#r0s0)|1 ✅|||0ms|
12+
### ✅ <a id="user-content-r0s0" href="#r0s0">test.jsx</a>
13+
```
14+
test
15+
✅ test.jsx
16+
```
17+
</details>

__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 parsing ESLint report without timing information works - PR #134 1`] = `
4+
TestRunResult {
5+
"path": "fixtures/jest-junit-eslint.xml",
6+
"suites": [
7+
TestSuiteResult {
8+
"groups": [
9+
TestGroupResult {
10+
"name": "test",
11+
"tests": [
12+
TestCaseResult {
13+
"error": undefined,
14+
"name": "test.jsx",
15+
"result": "success",
16+
"time": 0,
17+
},
18+
],
19+
},
20+
],
21+
"name": "test.jsx",
22+
"totalTime": 0,
23+
},
24+
],
25+
"totalTime": undefined,
26+
}
27+
`;
28+
329
exports[`jest-junit tests report from #235 testing react components named <ComponentName /> 1`] = `
430
TestRunResult {
531
"path": "fixtures/external/jest/jest-react-component-test-results.xml",
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<testsuites>
3+
<testsuite package="org.eslint" time="0" tests="1" errors="0" name="test.jsx">
4+
<testcase time="0" name="test.jsx" classname="test" />
5+
</testsuite>
6+
</testsuites>

__tests__/jest-junit.test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,24 @@ describe('jest-junit tests', () => {
105105
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
106106
fs.writeFileSync(outputPath, report)
107107
})
108+
109+
it('parsing ESLint report without timing information works - PR #134', async () => {
110+
const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit-eslint.xml')
111+
const outputPath = path.join(__dirname, '__outputs__', 'jest-junit-eslint.md')
112+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
113+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
114+
115+
const opts: ParseOptions = {
116+
parseErrors: true,
117+
trackedFiles: ['test.js']
118+
}
119+
120+
const parser = new JestJunitParser(opts)
121+
const result = await parser.parse(filePath, fileContent)
122+
expect(result).toMatchSnapshot()
123+
124+
const report = getReport([result])
125+
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
126+
fs.writeFileSync(outputPath, report)
127+
})
108128
})

dist/index.js

+1-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

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class JestJunitParser implements TestParser {
4343
return sr
4444
})
4545

46-
const time = parseFloat(junit.testsuites.$.time) * 1000
46+
const time = junit.testsuites.$ && parseFloat(junit.testsuites.$.time) * 1000
4747
return new TestRunResult(path, suites, time)
4848
}
4949

0 commit comments

Comments
 (0)