From 2acf6c2ccdac711265d342c72997dafaa1e62d6b Mon Sep 17 00:00:00 2001 From: Oles Galatsan Date: Thu, 15 May 2025 15:40:14 +0300 Subject: [PATCH 1/2] Fix for empty TRX TestDefinitions --- dist/index.js | 3 ++- src/parsers/dotnet-trx/dotnet-trx-parser.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index b0f6516..31f2cf0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -937,7 +937,8 @@ class DotnetTrxParser { } } getTestClasses(trx) { - if (trx.TestRun.TestDefinitions === undefined || trx.TestRun.Results === undefined) { + if (trx.TestRun.TestDefinitions === undefined || trx.TestRun.Results === undefined || + !trx.TestRun.TestDefinitions.some(td => td.UnitTest && Array.isArray(td.UnitTest))) { return []; } const unitTests = {}; diff --git a/src/parsers/dotnet-trx/dotnet-trx-parser.ts b/src/parsers/dotnet-trx/dotnet-trx-parser.ts index a81d4a2..3b7acc4 100644 --- a/src/parsers/dotnet-trx/dotnet-trx-parser.ts +++ b/src/parsers/dotnet-trx/dotnet-trx-parser.ts @@ -62,7 +62,8 @@ export class DotnetTrxParser implements TestParser { } private getTestClasses(trx: TrxReport): TestClass[] { - if (trx.TestRun.TestDefinitions === undefined || trx.TestRun.Results === undefined) { + if (trx.TestRun.TestDefinitions === undefined || trx.TestRun.Results === undefined || + !trx.TestRun.TestDefinitions.some(td => td.UnitTest && Array.isArray(td.UnitTest))) { return [] } From 5b447747020a91b5bbb3c716d4297516d99e7d05 Mon Sep 17 00:00:00 2001 From: Oles Galatsan Date: Fri, 16 May 2025 10:25:02 +0300 Subject: [PATCH 2/2] Add integration test for empty TRX TestDefinitions --- __tests__/dotnet-trx.test.ts | 16 ++++++++++++++ .../dotnet-trx-empty-test-definitions.trx | 22 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 __tests__/fixtures/empty/dotnet-trx-empty-test-definitions.trx diff --git a/__tests__/dotnet-trx.test.ts b/__tests__/dotnet-trx.test.ts index d4d5dac..498abcb 100644 --- a/__tests__/dotnet-trx.test.ts +++ b/__tests__/dotnet-trx.test.ts @@ -23,6 +23,22 @@ describe('dotnet-trx tests', () => { expect(result.result).toBe('success') }) + it('produces empty test run result when TestDefinitions is empty', async () => { + const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'dotnet-trx-empty-test-definitions.trx') + const filePath = normalizeFilePath(path.relative(__dirname, fixturePath)) + const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'}) + + const opts: ParseOptions = { + parseErrors: true, + trackedFiles: [] + } + + const parser = new DotnetTrxParser(opts) + const result = await parser.parse(filePath, fileContent) + expect(result.tests).toBe(0) + expect(result.result).toBe('success') + }) + it('matches report snapshot', async () => { const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-trx.trx') const outputPath = path.join(__dirname, '__outputs__', 'dotnet-trx.md') diff --git a/__tests__/fixtures/empty/dotnet-trx-empty-test-definitions.trx b/__tests__/fixtures/empty/dotnet-trx-empty-test-definitions.trx new file mode 100644 index 0000000..7066144 --- /dev/null +++ b/__tests__/fixtures/empty/dotnet-trx-empty-test-definitions.trx @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + No test is available in (...). Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again. + + + +