From 6eff4c8db70d1e7fe161df514c6113356022c513 Mon Sep 17 00:00:00 2001 From: David Uebelacker Date: Mon, 22 May 2023 15:16:16 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=B2=20fixed=20"Error:=20TypeError:=20C?= =?UTF-8?q?annot=20read=20properties=20of=20undefined=20(reading=20'split'?= =?UTF-8?q?)"=20if=20failure=20element=20is=20empty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__snapshots__/java-junit.test.ts.snap | 54 +++++++++++++++++++ .../external/java/test-report-jest.xml | 25 +++++++++ __tests__/java-junit.test.ts | 22 ++++++++ src/utils/parse-utils.ts | 2 +- 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 __tests__/fixtures/external/java/test-report-jest.xml diff --git a/__tests__/__snapshots__/java-junit.test.ts.snap b/__tests__/__snapshots__/java-junit.test.ts.snap index 73c5f803..7c1a70d2 100644 --- a/__tests__/__snapshots__/java-junit.test.ts.snap +++ b/__tests__/__snapshots__/java-junit.test.ts.snap @@ -6878,3 +6878,57 @@ at java.lang.Thread.run(Thread.java:748) "totalTime": 2126531.0000000005, } `; + +exports[`java-junit tests report from jest in junit format 1`] = ` +TestRunResult { + "path": "fixtures/external/java/test-report-jest.xml", + "suites": Array [ + TestSuiteResult { + "groups": Array [ + TestGroupResult { + "name": "MaintenanceFilterComponent", + "tests": Array [ + TestCaseResult { + "error": Object { + "details": undefined, + "line": undefined, + "message": undefined, + "path": undefined, + }, + "name": "should create", + "result": "failed", + "time": 0, + }, + ], + }, + ], + "name": "maintenance/maintenance-filter/maintenance-filter.component.spec.ts", + "totalTime": 1204, + }, + TestSuiteResult { + "groups": Array [ + TestGroupResult { + "name": "AppComponent", + "tests": Array [ + TestCaseResult { + "error": undefined, + "name": "should create the app", + "result": "success", + "time": 0, + }, + TestCaseResult { + "error": undefined, + "name": "should forward to login page", + "result": "success", + "time": 0, + }, + ], + }, + ], + "name": "app.component.spec.ts", + "totalTime": 1244, + }, + ], + "totalTime": undefined, +} +`; diff --git a/__tests__/fixtures/external/java/test-report-jest.xml b/__tests__/fixtures/external/java/test-report-jest.xml new file mode 100644 index 00000000..cbd9f1de --- /dev/null +++ b/__tests__/fixtures/external/java/test-report-jest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/__tests__/java-junit.test.ts b/__tests__/java-junit.test.ts index e8111d41..d663fc96 100644 --- a/__tests__/java-junit.test.ts +++ b/__tests__/java-junit.test.ts @@ -73,6 +73,28 @@ describe('java-junit tests', () => { fs.writeFileSync(outputPath, report) }) + it('report from jest in junit format', async () => { + const fixturePath = path.join(__dirname, 'fixtures', 'external', 'java', 'test-report-jest.xml') + const trackedFilesPath = path.join(__dirname, 'fixtures', 'external', 'java', 'files.txt') + const outputPath = path.join(__dirname, '__outputs__', 'pulsar-test-results.md') + const filePath = normalizeFilePath(path.relative(__dirname, fixturePath)) + const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'}) + + const trackedFiles = fs.readFileSync(trackedFilesPath, {encoding: 'utf8'}).split(/\n\r?/g) + const opts: ParseOptions = { + parseErrors: true, + trackedFiles + } + + const parser = new JavaJunitParser(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) + }) + it('parses empty failures in test results', async () => { const fixturePath = path.join(__dirname, 'fixtures', 'external', 'java', 'empty_failures.xml') const filePath = normalizeFilePath(path.relative(__dirname, fixturePath)) diff --git a/src/utils/parse-utils.ts b/src/utils/parse-utils.ts index 44bc3890..59ad723d 100644 --- a/src/utils/parse-utils.ts +++ b/src/utils/parse-utils.ts @@ -19,6 +19,6 @@ export function parseIsoDate(str: string): Date { } export function getFirstNonEmptyLine(stackTrace: string): string | undefined { - const lines = stackTrace.split(/\r?\n/g) + const lines = stackTrace ? stackTrace.split(/\r?\n/g) : [] return lines.find(str => !/^\s*$/.test(str)) }