Skip to content

Commit d1bf678

Browse files
authored
Merge pull request #582 from OlesGalatsan/bugfix/empty-trx-test-definitions
Fix for empty TRX TestDefinitions
2 parents ef77935 + 5b44774 commit d1bf678

4 files changed

Lines changed: 42 additions & 2 deletions

File tree

__tests__/dotnet-trx.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ describe('dotnet-trx tests', () => {
2323
expect(result.result).toBe('success')
2424
})
2525

26+
it('produces empty test run result when TestDefinitions is empty', async () => {
27+
const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'dotnet-trx-empty-test-definitions.trx')
28+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
29+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
30+
31+
const opts: ParseOptions = {
32+
parseErrors: true,
33+
trackedFiles: []
34+
}
35+
36+
const parser = new DotnetTrxParser(opts)
37+
const result = await parser.parse(filePath, fileContent)
38+
expect(result.tests).toBe(0)
39+
expect(result.result).toBe('success')
40+
})
41+
2642
it('matches report snapshot', async () => {
2743
const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-trx.trx')
2844
const outputPath = path.join(__dirname, '__outputs__', 'dotnet-trx.md')
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<TestRun id="80e4c095-f726-4ab2-9441-416daa162672" name="..." runUser="..." xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
3+
<Times creation="2021-02-26T10:36:33.7131022+02:00" queuing="2021-02-26T10:36:33.7131029+02:00" start="2021-02-26T10:36:33.3278956+02:00" finish="2021-02-26T10:36:33.7139830+02:00" />
4+
<TestSettings name="default" id="863a1d8b-ee3b-45f9-86ee-1869bc4e889f">
5+
<Deployment runDeploymentRoot="..." />
6+
</TestSettings>
7+
<Results />
8+
<TestDefinitions />
9+
<TestEntries />
10+
<TestLists>
11+
<TestList name="Results Not in a List" id="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
12+
<TestList name="All Loaded Results" id="19431567-8539-422a-85d7-44ee4e166bda" />
13+
</TestLists>
14+
<ResultSummary outcome="Completed">
15+
<Counters total="0" executed="0" passed="0" failed="0" error="0" timeout="0" aborted="0" inconclusive="0" passedButRunAborted="0" notRunnable="0" notExecuted="0" disconnected="0" warning="0" completed="0" inProgress="0" pending="0" />
16+
<RunInfos>
17+
<RunInfo computerName="..." outcome="Warning" timestamp="2021-02-26T10:36:33.6676104+02:00">
18+
<Text>No test is available in (...). Make sure that test discoverer &amp; executors are registered and platform &amp; framework version settings are appropriate and try again.</Text>
19+
</RunInfo>
20+
</RunInfos>
21+
</ResultSummary>
22+
</TestRun>

dist/index.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/parsers/dotnet-trx/dotnet-trx-parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ export class DotnetTrxParser implements TestParser {
6262
}
6363

6464
private getTestClasses(trx: TrxReport): TestClass[] {
65-
if (trx.TestRun.TestDefinitions === undefined || trx.TestRun.Results === undefined) {
65+
if (trx.TestRun.TestDefinitions === undefined || trx.TestRun.Results === undefined ||
66+
!trx.TestRun.TestDefinitions.some(td => td.UnitTest && Array.isArray(td.UnitTest))) {
6667
return []
6768
}
6869

0 commit comments

Comments
 (0)