Skip to content

Commit

Permalink
Merge pull request #43 from dorny/dotnet-trx
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Dorner authored and GitHub committed Jan 14, 2021
2 parents 6482e39 + 760c090 commit dfddea6
Show file tree
Hide file tree
Showing 12 changed files with 492 additions and 16 deletions.
53 changes: 53 additions & 0 deletions __tests__/__snapshots__/dotnet-trx.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`dotnet-trx tests matches report snapshot 1`] = `
Object {
"annotations": Array [
Object {
"annotation_level": "failure",
"end_line": 9,
"message": "System.DivideByZeroException : Attempted to divide by zero.",
"path": "DotnetTests.Unit/Calculator.cs",
"start_line": 9,
"title": "[DotnetTests.XUnitTests.CalculatorTests] Exception_In_TargetTest",
},
Object {
"annotation_level": "failure",
"end_line": 39,
"message": "System.Exception : Test",
"path": "DotnetTests.XUnitTests/CalculatorTests.cs",
"start_line": 39,
"title": "[DotnetTests.XUnitTests.CalculatorTests] Exception_In_Test",
},
Object {
"annotation_level": "failure",
"end_line": 27,
"message": "Assert.Equal() Failure
Expected: 3
Actual: 2",
"path": "DotnetTests.XUnitTests/CalculatorTests.cs",
"start_line": 27,
"title": "[DotnetTests.XUnitTests.CalculatorTests] Failing_Test",
},
],
"summary": "**7** tests were completed in **1.061s** with **3** passed, **1** skipped and **3** failed.
| Result | Suite | Tests | Time | Passed ✔️ | Failed| Skipped ✖️ |
| :---: | :--- | ---: | ---: | ---: | ---: | ---: |
|| [DotnetTests.XUnitTests.CalculatorTests](#ts-0-DotnetTests-XUnitTests-CalculatorTests) | 7 | 109.5761ms | 3 | 3 | 1 |
# Test Suites
## <a id=\\"user-content-ts-0-DotnetTests-XUnitTests-CalculatorTests\\" href=\\"#ts-0-DotnetTests-XUnitTests-CalculatorTests\\">DotnetTests.XUnitTests.CalculatorTests</a>
| Result | Test | Time |
| :---: | :--- | ---: |
|| Exception_In_TargetTest | 0.4975ms |
|| Exception_In_Test | 2.2728ms |
|| Failing_Test | 3.2953ms |
| ✔️ | Passing_Test | 0.1254ms |
| ✔️ | Passing_Test_With_Name | 0.103ms |
| ✖️ | Skipped_Test | 1ms |
| ✔️ | Timeout_Test | 102.2821ms |
",
"title": "Dotnet TRX tests ❌",
}
`;
26 changes: 26 additions & 0 deletions __tests__/dotnet-trx.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as fs from 'fs'
import * as path from 'path'

import {parseDotnetTrx} from '../src/parsers/dotnet-trx/dotnet-trx-parser'
import {ParseOptions} from '../src/parsers/parser-types'

const xmlFixture = fs.readFileSync(path.join(__dirname, 'fixtures', 'dotnet-trx.trx'), {encoding: 'utf8'})
const outputPath = __dirname + '/__outputs__/dotnet-trx.md'

describe('dotnet-trx tests', () => {
it('matches report snapshot', async () => {
const opts: ParseOptions = {
name: 'Dotnet TRX tests',
annotations: true,
trackedFiles: ['DotnetTests.Unit/Calculator.cs', 'DotnetTests.XUnitTests/CalculatorTests.cs'],
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dotnet/'
}

const result = await parseDotnetTrx(xmlFixture, opts)
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
fs.writeFileSync(outputPath, result?.output?.summary ?? '')

expect(result.success).toBeFalsy()
expect(result?.output).toMatchSnapshot()
})
})
172 changes: 166 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import {parseJestJunit} from './parsers/jest-junit/jest-junit-parser'
import {parseDartJson} from './parsers/dart-json/dart-json-parser'
import {parseDotnetTrx} from './parsers/dotnet-trx/dotnet-trx-parser'
import {parseJestJunit} from './parsers/jest-junit/jest-junit-parser'
import {ParseOptions, ParseTestResult} from './parsers/parser-types'
import {getFileContent, normalizeDirPath} from './utils/file-utils'
import {listFiles} from './utils/git'
Expand All @@ -28,7 +29,7 @@ async function main(): Promise<void> {
process.chdir(workDirInput)
}

const workDir = normalizeDirPath(workDirInput || process.cwd(), true)
const workDir = normalizeDirPath(process.cwd(), true)
const octokit = github.getOctokit(token)
const sha = getCheckRunSha()

Expand Down Expand Up @@ -67,7 +68,7 @@ function getParser(reporter: string): ParseTestResult {
case 'dart-json':
return parseDartJson
case 'dotnet-trx':
throw new Error('Not implemented yet!')
return parseDotnetTrx
case 'flutter-machine':
return parseDartJson
case 'jest-junit':
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/dart-json/dart-json-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Annotation, ParseOptions, TestResult} from '../parser-types'

import getReport from '../../report/get-report'
import {normalizeFilePath} from '../../utils/file-utils'
import {Icon} from '../../utils/markdown-utils'
import {Icon, fixEol} from '../../utils/markdown-utils'

import {
ReportEvent,
Expand Down Expand Up @@ -176,7 +176,7 @@ function getAnnotation(
start_line: src.line,
end_line: src.line,
path: src.file,
message: `${test.error?.error}\n\n${test.error?.stackTrace}`,
message: `${fixEol(test.error?.error)}\n\n${fixEol(test.error?.stackTrace)}`,
title: `[${testSuite.suite.path}] ${test.testStart.test.name}`
}
}
Expand Down
Loading

0 comments on commit dfddea6

Please sign in to comment.