From 70db77d88c30cc30674e126944fd6716ba0137d8 Mon Sep 17 00:00:00 2001 From: Connor Monaghan Date: Tue, 11 Mar 2025 18:11:28 +1000 Subject: [PATCH 1/2] feat: parse junit report with message --- __tests__/__outputs__/junit-with-message.md | 15 +++++++++ .../__snapshots__/jest-junit.test.ts.snap | 32 +++++++++++++++++++ __tests__/fixtures/junit-with-message.xml | 10 ++++++ __tests__/jest-junit.test.ts | 20 ++++++++++++ src/parsers/jest-junit/jest-junit-parser.ts | 2 +- 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 __tests__/__outputs__/junit-with-message.md create mode 100644 __tests__/fixtures/junit-with-message.xml diff --git a/__tests__/__outputs__/junit-with-message.md b/__tests__/__outputs__/junit-with-message.md new file mode 100644 index 00000000..948309aa --- /dev/null +++ b/__tests__/__outputs__/junit-with-message.md @@ -0,0 +1,15 @@ +![Tests failed](https://img.shields.io/badge/tests-1%20failed-critical) +|Report|Passed|Failed|Skipped|Time| +|:---|---:|---:|---:|---:| +|fixtures/junit-with-message.xml||1 ❌||1ms| +## ❌ fixtures/junit-with-message.xml +**1** tests were completed in **1ms** with **0** passed, **1** failed and **0** skipped. +|Test suite|Passed|Failed|Skipped|Time| +|:---|---:|---:|---:|---:| +|[Test](#r0s0)||1 ❌||1ms| +### ❌ Test +``` +Fails + ❌ Test + error.cpp:01 +``` \ 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 fd1e839f..eb20dfe1 100644 --- a/__tests__/__snapshots__/jest-junit.test.ts.snap +++ b/__tests__/__snapshots__/jest-junit.test.ts.snap @@ -26,6 +26,38 @@ TestRunResult { } `; +exports[`jest-junit tests parsing junit report with message succeeds 1`] = ` +TestRunResult { + "path": "fixtures/junit-with-message.xml", + "suites": [ + TestSuiteResult { + "groups": [ + TestGroupResult { + "name": "Fails", + "tests": [ + TestCaseResult { + "error": { + "details": "error.cpp:01 + Expected: true + Which is: false >", + "line": undefined, + "path": undefined, + }, + "name": "Test", + "result": "failed", + "time": 0, + }, + ], + }, + ], + "name": "Test", + "totalTime": 1, + }, + ], + "totalTime": 1, +} +`; + 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/junit-with-message.xml b/__tests__/fixtures/junit-with-message.xml new file mode 100644 index 00000000..2e3d584c --- /dev/null +++ b/__tests__/fixtures/junit-with-message.xml @@ -0,0 +1,10 @@ + + + + + ]]> + + + diff --git a/__tests__/jest-junit.test.ts b/__tests__/jest-junit.test.ts index 751893af..d52c0475 100644 --- a/__tests__/jest-junit.test.ts +++ b/__tests__/jest-junit.test.ts @@ -125,4 +125,24 @@ describe('jest-junit tests', () => { fs.mkdirSync(path.dirname(outputPath), {recursive: true}) fs.writeFileSync(outputPath, report) }) + + it('parsing junit report with message succeeds', async () => { + const fixturePath = path.join(__dirname, 'fixtures', 'junit-with-message.xml') + const outputPath = path.join(__dirname, '__outputs__', 'junit-with-message.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/src/parsers/jest-junit/jest-junit-parser.ts b/src/parsers/jest-junit/jest-junit-parser.ts index be009a92..6631d000 100644 --- a/src/parsers/jest-junit/jest-junit-parser.ts +++ b/src/parsers/jest-junit/jest-junit-parser.ts @@ -85,7 +85,7 @@ export class JestJunitParser implements TestParser { return undefined } - const details = tc.failure[0] + const details = typeof tc.failure[0] === 'string' ? tc.failure[0] : tc.failure[0]['_'] let path let line From 10d304d4fbfa8829fbe4e645416dbeeaf8bea32a Mon Sep 17 00:00:00 2001 From: Jozef Izso Date: Wed, 12 Mar 2025 13:14:18 +0100 Subject: [PATCH 2/2] build: recompile production code --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index fa45c864..fd169b7b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1358,7 +1358,7 @@ class JestJunitParser { if (!this.options.parseErrors || !tc.failure) { return undefined; } - const details = tc.failure[0]; + const details = typeof tc.failure[0] === 'string' ? tc.failure[0] : tc.failure[0]['_']; let path; let line; const src = (0, node_utils_1.getExceptionSource)(details, this.options.trackedFiles, file => this.getRelativePath(file));