diff --git a/__tests__/__outputs__/dotnet-trx-only-failed.md b/__tests__/__outputs__/dotnet-trx-only-failed.md
new file mode 100644
index 0000000..826fb24
--- /dev/null
+++ b/__tests__/__outputs__/dotnet-trx-only-failed.md
@@ -0,0 +1,28 @@
+
+|Report|Passed|Failed|Skipped|Time|
+|:---|---:|---:|---:|---:|
+|[fixtures/dotnet-trx.trx](#user-content-r0)|5 ✅|5 ❌|1 ⚪|1s|
+## ❌ fixtures/dotnet-trx.trx
+**11** tests were completed in **1s** with **5** passed, **5** failed and **1** skipped.
+|Test suite|Passed|Failed|Skipped|Time|
+|:---|---:|---:|---:|---:|
+|[DotnetTests.XUnitTests.CalculatorTests](#user-content-r0s0)|5 ✅|5 ❌|1 ⚪|118ms|
+### ❌ DotnetTests.XUnitTests.CalculatorTests
+```
+❌ Exception_In_TargetTest
+ System.DivideByZeroException : Attempted to divide by zero.
+❌ Exception_In_Test
+ System.Exception : Test
+❌ Failing_Test
+ Assert.Equal() Failure
+ Expected: 3
+ Actual: 2
+❌ Is_Even_Number(i: 3)
+ Assert.True() Failure
+ Expected: True
+ Actual: False
+❌ Should be even number(i: 3)
+ Assert.True() Failure
+ Expected: True
+ Actual: False
+```
\ No newline at end of file
diff --git a/__tests__/__snapshots__/dotnet-trx.test.ts.snap b/__tests__/__snapshots__/dotnet-trx.test.ts.snap
index 1ca07eb..04d535b 100644
--- a/__tests__/__snapshots__/dotnet-trx.test.ts.snap
+++ b/__tests__/__snapshots__/dotnet-trx.test.ts.snap
@@ -1,5 +1,134 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`dotnet-trx tests matches report snapshot (only failed tests) 1`] = `
+TestRunResult {
+ "path": "fixtures/dotnet-trx.trx",
+ "suites": [
+ TestSuiteResult {
+ "groups": [
+ TestGroupResult {
+ "name": null,
+ "tests": [
+ TestCaseResult {
+ "error": undefined,
+ "name": "Custom Name",
+ "result": "success",
+ "time": 0.1371,
+ },
+ TestCaseResult {
+ "error": {
+ "details": "System.DivideByZeroException : Attempted to divide by zero.
+ at DotnetTests.Unit.Calculator.Div(Int32 a, Int32 b) in C:\\Users\\Michal\\Workspace\\dorny\\test-reporter\\reports\\dotnet\\DotnetTests.Unit\\Calculator.cs:line 9
+ at DotnetTests.XUnitTests.CalculatorTests.Exception_In_TargetTest() in C:\\Users\\Michal\\Workspace\\dorny\\test-reporter\\reports\\dotnet\\DotnetTests.XUnitTests\\CalculatorTests.cs:line 33",
+ "line": 9,
+ "message": "System.DivideByZeroException : Attempted to divide by zero.",
+ "path": "DotnetTests.Unit/Calculator.cs",
+ },
+ "name": "Exception_In_TargetTest",
+ "result": "failed",
+ "time": 0.8377,
+ },
+ TestCaseResult {
+ "error": {
+ "details": "System.Exception : Test
+ at DotnetTests.XUnitTests.CalculatorTests.Exception_In_Test() in C:\\Users\\Michal\\Workspace\\dorny\\test-reporter\\reports\\dotnet\\DotnetTests.XUnitTests\\CalculatorTests.cs:line 39",
+ "line": 39,
+ "message": "System.Exception : Test",
+ "path": "DotnetTests.XUnitTests/CalculatorTests.cs",
+ },
+ "name": "Exception_In_Test",
+ "result": "failed",
+ "time": 2.5175,
+ },
+ TestCaseResult {
+ "error": {
+ "details": "Assert.Equal() Failure
+Expected: 3
+Actual: 2
+ at DotnetTests.XUnitTests.CalculatorTests.Failing_Test() in C:\\Users\\Michal\\Workspace\\dorny\\test-reporter\\reports\\dotnet\\DotnetTests.XUnitTests\\CalculatorTests.cs:line 27",
+ "line": 27,
+ "message": "Assert.Equal() Failure
+Expected: 3
+Actual: 2",
+ "path": "DotnetTests.XUnitTests/CalculatorTests.cs",
+ },
+ "name": "Failing_Test",
+ "result": "failed",
+ "time": 3.8697,
+ },
+ TestCaseResult {
+ "error": undefined,
+ "name": "Is_Even_Number(i: 2)",
+ "result": "success",
+ "time": 0.0078,
+ },
+ TestCaseResult {
+ "error": {
+ "details": "Assert.True() Failure
+Expected: True
+Actual: False
+ at DotnetTests.XUnitTests.CalculatorTests.Is_Even_Number(Int32 i) in C:\\Users\\Michal\\Workspace\\dorny\\test-reporter\\reports\\dotnet\\DotnetTests.XUnitTests\\CalculatorTests.cs:line 59",
+ "line": 59,
+ "message": "Assert.True() Failure
+Expected: True
+Actual: False",
+ "path": "DotnetTests.XUnitTests/CalculatorTests.cs",
+ },
+ "name": "Is_Even_Number(i: 3)",
+ "result": "failed",
+ "time": 0.41409999999999997,
+ },
+ TestCaseResult {
+ "error": undefined,
+ "name": "Passing_Test",
+ "result": "success",
+ "time": 0.1365,
+ },
+ TestCaseResult {
+ "error": undefined,
+ "name": "Should be even number(i: 2)",
+ "result": "success",
+ "time": 0.0097,
+ },
+ TestCaseResult {
+ "error": {
+ "details": "Assert.True() Failure
+Expected: True
+Actual: False
+ at DotnetTests.XUnitTests.CalculatorTests.Theory_With_Custom_Name(Int32 i) in C:\\Users\\Michal\\Workspace\\dorny\\test-reporter\\reports\\dotnet\\DotnetTests.XUnitTests\\CalculatorTests.cs:line 67",
+ "line": 67,
+ "message": "Assert.True() Failure
+Expected: True
+Actual: False",
+ "path": "DotnetTests.XUnitTests/CalculatorTests.cs",
+ },
+ "name": "Should be even number(i: 3)",
+ "result": "failed",
+ "time": 0.6537000000000001,
+ },
+ TestCaseResult {
+ "error": undefined,
+ "name": "Skipped_Test",
+ "result": "skipped",
+ "time": 1,
+ },
+ TestCaseResult {
+ "error": undefined,
+ "name": "Timeout_Test",
+ "result": "success",
+ "time": 108.42580000000001,
+ },
+ ],
+ },
+ ],
+ "name": "DotnetTests.XUnitTests.CalculatorTests",
+ "totalTime": undefined,
+ },
+ ],
+ "totalTime": 1116,
+}
+`;
+
exports[`dotnet-trx tests matches report snapshot 1`] = `
TestRunResult {
"path": "fixtures/dotnet-trx.trx",
diff --git a/__tests__/dotnet-trx.test.ts b/__tests__/dotnet-trx.test.ts
index e7f83ee..ede52b0 100644
--- a/__tests__/dotnet-trx.test.ts
+++ b/__tests__/dotnet-trx.test.ts
@@ -3,7 +3,7 @@ import * as path from 'path'
import {DotnetTrxParser} from '../src/parsers/dotnet-trx/dotnet-trx-parser'
import {ParseOptions} from '../src/test-parser'
-import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report'
+import {DEFAULT_OPTIONS, getReport, ReportOptions} from '../src/report/get-report'
import {normalizeFilePath} from '../src/utils/path-utils'
describe('dotnet-trx tests', () => {
@@ -60,6 +60,32 @@ describe('dotnet-trx tests', () => {
fs.writeFileSync(outputPath, report)
})
+ it('matches report snapshot (only failed tests)', async () => {
+ const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-trx.trx')
+ const outputPath = path.join(__dirname, '__outputs__', 'dotnet-trx-only-failed.md')
+ const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
+ const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
+
+ const opts: ParseOptions = {
+ parseErrors: true,
+ trackedFiles: ['DotnetTests.Unit/Calculator.cs', 'DotnetTests.XUnitTests/CalculatorTests.cs']
+ //workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dotnet/'
+ }
+
+ const parser = new DotnetTrxParser(opts)
+ const result = await parser.parse(filePath, fileContent)
+ expect(result).toMatchSnapshot()
+
+ const reportOptions: ReportOptions = {
+ ...DEFAULT_OPTIONS,
+ listSuites: 'all',
+ listTests: 'failed'
+ }
+ const report = getReport([result], reportOptions)
+ fs.mkdirSync(path.dirname(outputPath), {recursive: true})
+ fs.writeFileSync(outputPath, report)
+ })
+
it('report from FluentValidation test results matches snapshot', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'FluentValidation.Tests.trx')
const outputPath = path.join(__dirname, '__outputs__', 'fluent-validation-test-results.md')
diff --git a/dist/index.js b/dist/index.js
index 6596a6f..a4a5b4d 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -2115,6 +2115,9 @@ function getTestsReport(ts, runIndex, suiteIndex, options) {
}
const space = grp.name ? ' ' : '';
for (const tc of grp.tests) {
+ if (options.listTests === 'failed' && tc.result !== 'failed') {
+ continue;
+ }
const result = getResultIcon(tc.result);
sections.push(`${space}${result} ${tc.name}`);
if (tc.error) {
diff --git a/src/report/get-report.ts b/src/report/get-report.ts
index 24465e3..5ea44fe 100644
--- a/src/report/get-report.ts
+++ b/src/report/get-report.ts
@@ -263,6 +263,9 @@ function getTestsReport(ts: TestSuiteResult, runIndex: number, suiteIndex: numbe
}
const space = grp.name ? ' ' : ''
for (const tc of grp.tests) {
+ if (options.listTests === 'failed' && tc.result !== 'failed') {
+ continue
+ }
const result = getResultIcon(tc.result)
sections.push(`${space}${result} ${tc.name}`)
if (tc.error) {