copied files from phoenix-actions/test-reporting

This commit is contained in:
dharmendrasha 2022-12-28 15:40:43 +05:30
parent e9fa2f582c
commit 8409beeffb
4 changed files with 173 additions and 22 deletions

View file

@ -1,12 +1,11 @@
![Tests failed](https://img.shields.io/badge/tests-5%20passed%2C%205%20failed%2C%201%20skipped-critical) ![Tests failed](https://img.shields.io/badge/tests-5%20passed%2C%205%20failed%2C%201%20skipped-critical)
## ❌ <a id="user-content-r0" href="#r0">fixtures/dotnet-trx.trx</a> ## ❌ <a id="user-content-r0" href="#r0">fixtures/dotnet-trx.trx</a>
**11** tests were completed in **1s** with **5** passed, **5** failed and **1** skipped. **11** tests were completed in **1s** with **5** passed, **5** failed and **1** skipped.
|Test suite|Passed|Failed|Skipped|Time| |Test suite|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:| |:---|---:|---:|---:|---:|
|[DotnetTests.XUnitTests.CalculatorTests](#r0s0)|5✅|5❌|1⚪|118ms| |[DotnetTests.XUnitTests.CalculatorTests](#r0s0)|5✔️|5❌|1✖|118ms|
### ❌ <a id="user-content-r0s0" href="#r0s0">DotnetTests.XUnitTests.CalculatorTests</a> ### ❌ <a id="user-content-r0s0" href="#r0s0">DotnetTests.XUnitTests.CalculatorTests</a>
``` ```
✅ Custom Name
❌ Exception_In_TargetTest ❌ Exception_In_TargetTest
System.DivideByZeroException : Attempted to divide by zero. System.DivideByZeroException : Attempted to divide by zero.
❌ Exception_In_Test ❌ Exception_In_Test
@ -15,17 +14,12 @@
Assert.Equal() Failure Assert.Equal() Failure
Expected: 3 Expected: 3
Actual: 2 Actual: 2
✅ Is_Even_Number(i: 2)
❌ Is_Even_Number(i: 3) ❌ Is_Even_Number(i: 3)
Assert.True() Failure Assert.True() Failure
Expected: True Expected: True
Actual: False Actual: False
✅ Passing_Test
✅ Should be even number(i: 2)
❌ Should be even number(i: 3) ❌ Should be even number(i: 3)
Assert.True() Failure Assert.True() Failure
Expected: True Expected: True
Actual: False Actual: False
⚪ Skipped_Test
✅ Timeout_Test
``` ```

View file

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`dotnet-trx tests matches report snapshot 1`] = ` exports[`dotnet-trx tests matches report snapshot (only failed tests) 1`] = `
TestRunResult { TestRunResult {
"path": "fixtures/dotnet-trx.trx", "path": "fixtures/dotnet-trx.trx",
"suites": Array [ "suites": Array [
@ -18,8 +18,8 @@ TestRunResult {
TestCaseResult { TestCaseResult {
"error": Object { "error": Object {
"details": "System.DivideByZeroException : Attempted to divide by zero. "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.Unit.Calculator.Div(Int32 a, Int32 b) in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporting\\\\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", at DotnetTests.XUnitTests.CalculatorTests.Exception_In_TargetTest() in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporting\\\\reports\\\\dotnet\\\\DotnetTests.XUnitTests\\\\CalculatorTests.cs:line 33",
"line": 9, "line": 9,
"message": "System.DivideByZeroException : Attempted to divide by zero.", "message": "System.DivideByZeroException : Attempted to divide by zero.",
"path": "DotnetTests.Unit/Calculator.cs", "path": "DotnetTests.Unit/Calculator.cs",
@ -31,7 +31,7 @@ TestRunResult {
TestCaseResult { TestCaseResult {
"error": Object { "error": Object {
"details": "System.Exception : Test "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", at DotnetTests.XUnitTests.CalculatorTests.Exception_In_Test() in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporting\\\\reports\\\\dotnet\\\\DotnetTests.XUnitTests\\\\CalculatorTests.cs:line 39",
"line": 39, "line": 39,
"message": "System.Exception : Test", "message": "System.Exception : Test",
"path": "DotnetTests.XUnitTests/CalculatorTests.cs", "path": "DotnetTests.XUnitTests/CalculatorTests.cs",
@ -45,7 +45,7 @@ TestRunResult {
"details": "Assert.Equal() Failure "details": "Assert.Equal() Failure
Expected: 3 Expected: 3
Actual: 2 Actual: 2
at DotnetTests.XUnitTests.CalculatorTests.Failing_Test() in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporter\\\\reports\\\\dotnet\\\\DotnetTests.XUnitTests\\\\CalculatorTests.cs:line 27", at DotnetTests.XUnitTests.CalculatorTests.Failing_Test() in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporting\\\\reports\\\\dotnet\\\\DotnetTests.XUnitTests\\\\CalculatorTests.cs:line 27",
"line": 27, "line": 27,
"message": "Assert.Equal() Failure "message": "Assert.Equal() Failure
Expected: 3 Expected: 3
@ -67,7 +67,7 @@ Actual: 2",
"details": "Assert.True() Failure "details": "Assert.True() Failure
Expected: True Expected: True
Actual: False 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", at DotnetTests.XUnitTests.CalculatorTests.Is_Even_Number(Int32 i) in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporting\\\\reports\\\\dotnet\\\\DotnetTests.XUnitTests\\\\CalculatorTests.cs:line 59",
"line": 59, "line": 59,
"message": "Assert.True() Failure "message": "Assert.True() Failure
Expected: True Expected: True
@ -95,7 +95,136 @@ Actual: False",
"details": "Assert.True() Failure "details": "Assert.True() Failure
Expected: True Expected: True
Actual: False 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", at DotnetTests.XUnitTests.CalculatorTests.Theory_With_Custom_Name(Int32 i) in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporting\\\\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",
"suites": Array [
TestSuiteResult {
"groups": Array [
TestGroupResult {
"name": null,
"tests": Array [
TestCaseResult {
"error": undefined,
"name": "Custom Name",
"result": "success",
"time": 0.1371,
},
TestCaseResult {
"error": Object {
"details": "System.DivideByZeroException : Attempted to divide by zero.
at DotnetTests.Unit.Calculator.Div(Int32 a, Int32 b) in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporting\\\\reports\\\\dotnet\\\\DotnetTests.Unit\\\\Calculator.cs:line 9
at DotnetTests.XUnitTests.CalculatorTests.Exception_In_TargetTest() in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporting\\\\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": Object {
"details": "System.Exception : Test
at DotnetTests.XUnitTests.CalculatorTests.Exception_In_Test() in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporting\\\\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": Object {
"details": "Assert.Equal() Failure
Expected: 3
Actual: 2
at DotnetTests.XUnitTests.CalculatorTests.Failing_Test() in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporting\\\\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": Object {
"details": "Assert.True() Failure
Expected: True
Actual: False
at DotnetTests.XUnitTests.CalculatorTests.Is_Even_Number(Int32 i) in C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-reporting\\\\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": Object {
"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-reporting\\\\reports\\\\dotnet\\\\DotnetTests.XUnitTests\\\\CalculatorTests.cs:line 67",
"line": 67, "line": 67,
"message": "Assert.True() Failure "message": "Assert.True() Failure
Expected: True Expected: True
@ -1577,7 +1706,7 @@ TestRunResult {
}, },
TestCaseResult { TestCaseResult {
"error": undefined, "error": undefined,
"name": "Valid_email_addresses_aspnetcore_compatible(email: \\" @someDomain.com\\")", "name": "Valid_email_addresses_aspnetcore_compatible(email: \\" @someDomain.com\\")",
"result": "success", "result": "success",
"time": 0.0173, "time": 0.0173,
}, },

View file

@ -3,7 +3,7 @@ import * as path from 'path'
import {DotnetTrxParser} from '../src/parsers/dotnet-trx/dotnet-trx-parser' import {DotnetTrxParser} from '../src/parsers/dotnet-trx/dotnet-trx-parser'
import {ParseOptions} from '../src/test-parser' import {ParseOptions} from '../src/test-parser'
import {getReport} from '../src/report/get-report' import {getReport, ReportOptions} from '../src/report/get-report'
import {normalizeFilePath} from '../src/utils/path-utils' import {normalizeFilePath} from '../src/utils/path-utils'
describe('dotnet-trx tests', () => { describe('dotnet-trx tests', () => {
@ -44,6 +44,32 @@ describe('dotnet-trx tests', () => {
fs.writeFileSync(outputPath, report) 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']
}
const parser = new DotnetTrxParser(opts)
const result = await parser.parse(filePath, fileContent)
expect(result).toMatchSnapshot()
const reportOptions: ReportOptions = {
listSuites: 'all',
listTests: 'failed',
onlySummary: false,
baseUrl: ''
}
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 () => { it('report from FluentValidation test results matches snapshot', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'FluentValidation.Tests.trx') const fixturePath = path.join(__dirname, 'fixtures', 'external', 'FluentValidation.Tests.trx')
const outputPath = path.join(__dirname, '__outputs__', 'fluent-validation-test-results.md') const outputPath = path.join(__dirname, '__outputs__', 'fluent-validation-test-results.md')

View file

@ -1,7 +1,6 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import {TestExecutionResult, TestRunResult, TestSuiteResult} from '../test-results' import {TestExecutionResult, TestRunResult, TestSuiteResult} from '../test-results'
import {Align, formatTime, Icon, link, table} from '../utils/markdown-utils' import {Align, formatTime, Icon, link, table} from '../utils/markdown-utils'
import {DEFAULT_LOCALE} from '../utils/node-utils'
import {getFirstNonEmptyLine} from '../utils/parse-utils' import {getFirstNonEmptyLine} from '../utils/parse-utils'
import {slug} from '../utils/slugger' import {slug} from '../utils/slugger'
@ -80,9 +79,9 @@ function trimReport(lines: string[]): string {
} }
function applySort(results: TestRunResult[]): void { function applySort(results: TestRunResult[]): void {
results.sort((a, b) => a.path.localeCompare(b.path, DEFAULT_LOCALE)) results.sort((a, b) => a.path.localeCompare(b.path))
for (const res of results) { for (const res of results) {
res.suites.sort((a, b) => a.name.localeCompare(b.name, DEFAULT_LOCALE)) res.suites.sort((a, b) => a.name.localeCompare(b.name))
} }
} }
@ -232,6 +231,9 @@ function getTestsReport(ts: TestSuiteResult, runIndex: number, suiteIndex: numbe
} }
const space = grp.name ? ' ' : '' const space = grp.name ? ' ' : ''
for (const tc of grp.tests) { for (const tc of grp.tests) {
if (options.listTests === 'failed' && tc.result !== 'failed') {
continue
}
const result = getResultIcon(tc.result) const result = getResultIcon(tc.result)
sections.push(`${space}${result} ${tc.name}`) sections.push(`${space}${result} ${tc.name}`)
if (tc.error) { if (tc.error) {