diff --git a/__tests__/dotnet-trx.test.ts b/__tests__/dotnet-trx.test.ts index d4d5dac7..498abcb3 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 00000000..70661441 --- /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. + + + + diff --git a/dist/index.js b/dist/index.js index b0f65166..31f2cf0a 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 a81d4a23..3b7acc49 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 [] }