Skip to content

Commit

Permalink
Merge pull request #46 from dorny/improve-readme
Browse files Browse the repository at this point in the history
Improve README and action.yml
  • Loading branch information
Michal Dorner authored and GitHub committed Jan 24, 2021
2 parents 8fdf2ae + 6e80010 commit 1a9ca69
Show file tree
Hide file tree
Showing 14 changed files with 364 additions and 85 deletions.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

The MIT License (MIT)

Copyright (c) 2020 Michal Dorner and contributors
Copyright (c) 2021 Michal Dorner and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,4 +19,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
189 changes: 180 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,183 @@
**WIP**
# Test Reporter

# Test Check Report
This [Github Action](https://github.com/features/actions) displays test results from popular testing frameworks directly in GitHub.
- [x] Parses test results in XML or JSON format and creates nice report (Github Check Run)
- [x] Annotates code where it failed based on message and stack trace captured during test execution
- [x] Sets output variable conclusion to `success` if all tests passed or `failure` if any test failed

Goal of this project is to create [Github Action](https://github.com/features/actions)
that could presents test results from popular testing frameworks as Github check run with code annotation in places where test failed.
**Supported languages / frameworks:**
- .NET / [xUnit](https://xunit.net/) / [NUnit](https://nunit.org/) / [MSTest](https://github.com/Microsoft/testfx-docs)
- Dart / [test](https://pub.dev/packages/test)
- Flutter / [test](https://pub.dev/packages/test)
- JavaScript / [JEST](https://jestjs.io/)

Support for following test reports are planned for initial release:
- [ ] dart-json: [`dart test --file-reporter=\"json:test-results.json`](https://pub.dev/packages/test)
- [ ] dotnet-trx: [`dotnet test --logger "trx;LogFileName=test-results.trx"`](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#examples)
- [ ] flutter-machine: [`flutter test --machine > test-results.json`](https://flutter.dev/docs/cookbook/testing/unit/introduction)
- [ ] jest-junit: [`jest --ci --reporters=jest-junit`](https://github.com/jest-community/jest-junit#readme)
For more information see [Supported formats](#supported-formats) section.

**Support is planned for:**
- Java / [JUnit 5](https://junit.org/junit5/)

Do you miss support for your favorite language or framework?
Please create [Issue](https://github.com/dorny/test-reporter/issues/new) or contribute with PR.

## Example

```yaml
jobs:
build-test:
name: 'Build & Test'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2 # checkout the repo
- run: npm ci # install packages
- run: npm test # run tests (configured to use jest-junit reporter)

- name: 'Test Report'
uses: dorny/test-reporter@v1
if: always() # run this step even if previous step failed
with:
name: 'JEST Tests' # Name of the check run which will be created
path: 'reports/jest-*.xml' # Path to test report
reporter: 'jest-junit' # Format of test report
```
## Usage
```yaml
- uses: dorny/test-reporter@v1
with:

# Name of the Check Run which will be created
name: ''

# Path to test report
# Supports wildcards via [fast-glob](https://github.com/mrmlnc/fast-glob)
# Path may match multiple result files of same format
path: ''

# Format of test report. Supported options:
# dart-json
# dotnet-trx
# flutter-machine
# jest-junit
reporter: ''

# Enables code annotations with error message and stack trace captured during test execution
annotations: 'true'

# Set action as failed if test report contain any failed test
fail-on-error: 'true'

# Relative path under $GITHUB_WORKSPACE where the repository was checked out.
working-directory: ''

# Personal access token used to interact with Github API
# Default: ${{ github.token }}
token: ''
```
## Supported formats
<details>
<summary>dart-json</summary>
Test run must be configured to use [JSON](https://github.com/dart-lang/test/blob/master/pkgs/test/doc/configuration.md#reporter) reporter.
You can configure it in `dart_test.yaml`:

```yml
file_reporters:
json: reports/test-results.json
```

Or with CLI arguments:

[`dart test --file-reporter="json:test-results.json"`](https://pub.dev/packages/test)

For more information see:
- [test package](https://pub.dev/packages/test)
- [test configuration](https://github.com/dart-lang/test/blob/master/pkgs/test/doc/configuration.md)
</details>

<details>
<summary>dotnet-trx</summary>

Test execution must be configured to produce *Visual Studio Test Results* files (TRX).
To get test results in TRX format you can execute your tests with CLI arguments:

`dotnet test --logger "trx;LogFileName=test-results.trx"`

Or you can configure TRX test output in `*.csproj` or `Directory.Build.props`:
```xml
<PropertyGroup>
<VSTestLogger>trx%3bLogFileName=$(MSBuildProjectName).trx</VSTestLogger>
<VSTestResultsDirectory>$(MSBuildThisFileDirectory)/reports</VSTestResultsDirectory>
</PropertyGroup>
```

Supported testing frameworks:
- [xUnit](https://xunit.net/)
- [NUnit](https://nunit.org/)
- [MSTest](https://github.com/Microsoft/testfx-docs)

For more information see [dotnet test](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#examples)
</details>

<details>
<summary>flutter-machine</summary>

Test run must be configured to use [JSON](https://github.com/dart-lang/test/blob/master/pkgs/test/doc/configuration.md#reporter) reporter.
You can configure it in `dart_test.yaml`:
```yml
file_reporters:
json: reports/test-results.json
```

Or with (undocumented) CLI argument:

`flutter test --machine > test-results.json`


According to documentation `dart_test.yaml` should be at the root of the package, next to the package's pubspec.
It works in dart projects but the file is ignored by flutter. With flutter it works when `dart_test.yaml` is placed inside your `test` folder.

For more information see:
- [test package](https://pub.dev/packages/test)
- [test configuration](https://github.com/dart-lang/test/blob/master/pkgs/test/doc/configuration.md)
- [flutter-cli](https://flutter.dev/docs/reference/flutter-cli)
- [unit testing introduction](https://flutter.dev/docs/cookbook/testing/unit/introduction)

</details>

<details>
<summary>jest-junit</summary>

[JEST](https://jestjs.io/) testing framework support requires usage of [jest-junit](https://github.com/jest-community/jest-junit) reporter.
It will create test results in junit XML format which can be then processed by this action.
You can use following example configuration in `package.json`:
```json
"scripts": {
"test": "jest --ci --reporters=default --reporters=jest-junit"
},
"devDependencies": {
"jest": "^26.5.3",
"jest-junit": "^12.0.0"
},
"jest-junit": {
"outputDirectory": "reports",
"outputName": "jest-junit.xml",
"ancestorSeparator": " › ",
"uniqueOutputName": "false",
"suiteNameTemplate": "{filepath}",
"classNameTemplate": "{classname}",
"titleTemplate": "{title}"
}
```

Configuration of `uniqueOutputName`, `suiteNameTemplate`, `classNameTemplate`, `titleTemplate` is important for proper visualization of test results.
</details>

## See also
- [paths-filter](https://github.com/dorny/paths-filter) - Conditionally run actions based on files modified by PR, feature branch or pushed commits

## License

The scripts and documentation in this project are released under the [MIT License](https://github.com/dorny/test-reporter/blob/master/LICENSE)
2 changes: 2 additions & 0 deletions __tests__/__outputs__/dart-json.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%201%20skipped%2C%204%20failed-critical)

### fixtures/dart-json.json

**6** tests were completed in **3.760s** with **1** passed, **1** skipped and **4** failed.
Expand Down
2 changes: 2 additions & 0 deletions __tests__/__outputs__/dotnet-trx.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Tests failed](https://img.shields.io/badge/tests-3%20passed%2C%201%20skipped%2C%203%20failed-critical)

### fixtures/dotnet-trx.trx

**7** tests were completed in **1.061s** with **3** passed, **1** skipped and **3** failed.
Expand Down
2 changes: 2 additions & 0 deletions __tests__/__outputs__/jest-junit.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%201%20skipped%2C%204%20failed-critical)

### fixtures/jest-junit.xml

**6** tests were completed in **1.360s** with **1** passed, **1** skipped and **4** failed.
Expand Down
4 changes: 3 additions & 1 deletion __tests__/__snapshots__/dart-json.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ dart:isolate _RawReceivePortImpl._handleMessage
"title": "[test\\\\second_test.dart] Timeout test",
},
],
"summary": "### fixtures/dart-json.json
"summary": "![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%201%20skipped%2C%204%20failed-critical)
### fixtures/dart-json.json
**6** tests were completed in **3.760s** with **1** passed, **1** skipped and **4** failed.
Expand Down
4 changes: 3 additions & 1 deletion __tests__/__snapshots__/dotnet-trx.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ Actual: 2",
"title": "[DotnetTests.XUnitTests.CalculatorTests] Failing_Test",
},
],
"summary": "### fixtures/dotnet-trx.trx
"summary": "![Tests failed](https://img.shields.io/badge/tests-3%20passed%2C%201%20skipped%2C%203%20failed-critical)
### fixtures/dotnet-trx.trx
**7** tests were completed in **1.061s** with **3** passed, **1** skipped and **3** failed.
Expand Down
4 changes: 3 additions & 1 deletion __tests__/__snapshots__/jest-junit.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ Received: false
"title": "[__tests__\\\\second.test.js] Timeout test",
},
],
"summary": "### fixtures/jest-junit.xml
"summary": "![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%201%20skipped%2C%204%20failed-critical)
### fixtures/jest-junit.xml
**6** tests were completed in **1.360s** with **1** passed, **1** skipped and **4** failed.
Expand Down
27 changes: 13 additions & 14 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
name: 'Test Check Reporter'
name: Test Reporter
description: |
Presents test results from popular testing frameworks as Github check run.
Supports:
- dotnet (trx logger)
- flutter (JSON output with '--machine' flag )
- jest (jest-junit reporter)
author: 'Michal Dorner <dorner.michal@gmail.com>'
Displays test results from popular testing frameworks directly in GitHub.
Supports .NET (xUnit, NUnit, MSTest), Dart, Flutter and JavaScript (JEST).
author: Michal Dorner <dorner.michal@gmail.com>
inputs:
annotations:
description: 'Annotate code where exceptions in tests were thrown'
description: Enables code annotations with error message and stack trace captured during test execution
required: true
default: 'true'
fail-on-error:
description: 'Set this action as failed if test report contains any failed test'
description: Set this action as failed if test report contain any failed test
required: true
default: 'true'
name:
description: 'Name of the check run'
description: Name of the check run
required: true
path:
description: 'Path to test report'
description: Path to test report
required: true
reporter:
description: |
Expand All @@ -31,11 +27,11 @@ inputs:
- jest-junit
required: true
token:
description: 'GitHub Access Token'
description: GitHub Access Token
required: false
default: ${{ github.token }}
working-directory:
description: 'Relative path under $GITHUB_WORKSPACE where the repository was checked out.'
description: Relative path under $GITHUB_WORKSPACE where the repository was checked out
required: false
outputs:
conclusion:
Expand All @@ -46,3 +42,6 @@ outputs:
runs:
using: 'node12'
main: 'dist/index.js'
branding:
color: blue
icon: file-text
Loading

0 comments on commit 1a9ca69

Please sign in to comment.