From 45526f79fd28e77106b6b721ae8204fb5b947201 Mon Sep 17 00:00:00 2001 From: Philipp Jardas Date: Fri, 6 Aug 2021 14:05:34 +0200 Subject: [PATCH 1/2] 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 `` element. --- __tests__/__outputs__/jest-junit-eslint.md | 11 ++++++++ .../__snapshots__/jest-junit.test.ts.snap | 26 +++++++++++++++++++ __tests__/fixtures/jest-junit-eslint.xml | 6 +++++ __tests__/jest-junit.test.ts | 20 ++++++++++++++ dist/index.js | 2 +- src/parsers/jest-junit/jest-junit-parser.ts | 2 +- 6 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 __tests__/__outputs__/jest-junit-eslint.md create mode 100644 __tests__/fixtures/jest-junit-eslint.xml diff --git a/__tests__/__outputs__/jest-junit-eslint.md b/__tests__/__outputs__/jest-junit-eslint.md new file mode 100644 index 00000000..4a8f0301 --- /dev/null +++ b/__tests__/__outputs__/jest-junit-eslint.md @@ -0,0 +1,11 @@ +![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success) +## ✅ fixtures/jest-junit-eslint.xml +**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| +### ✅ test.jsx +``` +test + ✅ test.jsx +``` \ No newline at end of file diff --git a/__tests__/__snapshots__/jest-junit.test.ts.snap b/__tests__/__snapshots__/jest-junit.test.ts.snap index f29b5c82..fd1e839f 100644 --- a/__tests__/__snapshots__/jest-junit.test.ts.snap +++ b/__tests__/__snapshots__/jest-junit.test.ts.snap @@ -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 1`] = ` TestRunResult { "path": "fixtures/external/jest/jest-react-component-test-results.xml", diff --git a/__tests__/fixtures/jest-junit-eslint.xml b/__tests__/fixtures/jest-junit-eslint.xml new file mode 100644 index 00000000..ceac3c65 --- /dev/null +++ b/__tests__/fixtures/jest-junit-eslint.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/__tests__/jest-junit.test.ts b/__tests__/jest-junit.test.ts index d42405cf..751893af 100644 --- a/__tests__/jest-junit.test.ts +++ b/__tests__/jest-junit.test.ts @@ -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) + }) }) diff --git a/dist/index.js b/dist/index.js index 89beb386..fa45c864 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1320,7 +1320,7 @@ class JestJunitParser { const sr = new test_results_1.TestSuiteResult(name, this.getGroups(ts), time); 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); } getGroups(suite) { diff --git a/src/parsers/jest-junit/jest-junit-parser.ts b/src/parsers/jest-junit/jest-junit-parser.ts index 64198f4a..be009a92 100644 --- a/src/parsers/jest-junit/jest-junit-parser.ts +++ b/src/parsers/jest-junit/jest-junit-parser.ts @@ -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) } From 7befe80c6c58c691d43619d251fb46b2afbf731c Mon Sep 17 00:00:00 2001 From: Jozef Izso Date: Wed, 26 Jun 2024 13:45:39 +0200 Subject: [PATCH 2/2] Update format of the `jest-junit-eslint.md` output file --- __tests__/__outputs__/jest-junit-eslint.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/__tests__/__outputs__/jest-junit-eslint.md b/__tests__/__outputs__/jest-junit-eslint.md index 4a8f0301..32608c37 100644 --- a/__tests__/__outputs__/jest-junit-eslint.md +++ b/__tests__/__outputs__/jest-junit-eslint.md @@ -1,11 +1,17 @@ ![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success) +
Expand for details + +|Report|Passed|Failed|Skipped|Time| +|:---|---:|---:|---:|---:| +|fixtures/jest-junit-eslint.xml|1 ✅|||0ms| ## ✅ fixtures/jest-junit-eslint.xml **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| +|[test.jsx](#r0s0)|1 ✅|||0ms| ### ✅ test.jsx ``` test ✅ test.jsx -``` \ No newline at end of file +``` +
\ No newline at end of file