-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
omit
input, deprecate others (#15)
* add omit input, deprecate others * naming * docs + additional dist checking * quickstart
- Loading branch information
Showing
13 changed files
with
398 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,56 @@ | ||
# go-test-action | ||
|
||
GitHub Action for running `go test ...` and getting rich summary and annotations as output. | ||
- [go-test-action](#go-test-action) | ||
- [Quick start](#quick-start) | ||
- [Inputs](#inputs) | ||
- [Screenshots](#screenshots) | ||
- [Examples](#examples) | ||
- [Basic](#basic) | ||
- [Using existing test file](#using-existing-test-file) | ||
- [Omitting elements](#omitting-elements) | ||
|
||
GitHub Action for running `go test ./...` and getting rich summary and annotations as output. | ||
|
||
Powered by [Job Summaries](https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/), this Action will generate a convenient interactive viewer for tests based on Go's [test2json](https://pkg.go.dev/cmd/test2json) output. If there are any errors during `go test`, the Action will report back the same exit code, which will fail the job. | ||
|
||
## Quick start | ||
|
||
```yaml | ||
- name: Test | ||
uses: robherley/go-test-action@v0 | ||
``` | ||
## Inputs | ||
| Input | Default | Description | | ||
| - | - | - | | ||
| moduleDirectory | `.` | relative path to the directory containing the `go.mod` of the module you wish to test | | ||
| testArguments | `./...` | arguments to pass to `go test`, `-json` will be prepended automatically | | ||
| fromJSONFile | null | parse an exisiting [test2json](https://pkg.go.dev/cmd/test2json) file, instead of executing go test | | ||
| omitUntestedPackages | `false` | omit any go packages that don't have any tests from the summary output | | ||
| omitSuccessfulPackages | `false` | omit any go packages that didn't contain failed tests | | ||
| omitPie | `false` | omit the pie chart from the summary output | ||
```yaml | ||
- uses: robherley/go-test-action@v0 | ||
with: | ||
# Relative path to the directory containing the go.mod of the module you wish to test. | ||
# Optional. Default is '.' | ||
moduleDirectory: | ||
|
||
# Arguments to pass to go test, -json will be prepended automatically. | ||
# Optional. Default is './...' | ||
testArguments: | ||
|
||
# Parse an exisiting [test2json](https://pkg.go.dev/cmd/test2json) file, instead of executing go test. | ||
# Will always exit(0) on successful test file parse. | ||
# Optional. No default | ||
fromJSONFile: | ||
|
||
# Whitespace separated list of renderable items to omit. | ||
# Valid options to omit are: | ||
# untested: packages that have no tests | ||
# successful: packages that are successful | ||
# pie: mermaid.js pie chart | ||
# pkg-tests: per-package test list | ||
# pkg-output: per-package test output | ||
# stderr: standard error output of `go test` subprocess | ||
# Optional. No default | ||
omit: | ||
``` | ||
## Demo | ||
## Screenshots | ||
Tests are organized per package, with a brief summary of individual test results: | ||
|
@@ -25,7 +60,9 @@ Expand for per-test (with subtest) results and to view raw test output: | |
![summary expanded](docs/img/expanded.png) | ||
## Example workflow | ||
## Examples | ||
### Basic | ||
```yaml | ||
name: Go | ||
|
@@ -48,6 +85,36 @@ jobs: | |
run: go build -v ./... | ||
|
||
- name: Test | ||
uses: robherley/[email protected] | ||
uses: robherley/go-test-action@v0 | ||
``` | ||
### Using existing test file | ||
```yaml | ||
- name: Test | ||
uses: robherley/go-test-action@v0 | ||
with: | ||
fromJSONFile: /path/to/test2json.json | ||
``` | ||
### Omitting elements | ||
See [Inputs](#inputs) above for valid options | ||
```yaml | ||
- name: Test | ||
uses: robherley/go-test-action@v0 | ||
with: | ||
omit: | | ||
pie | ||
stderr | ||
``` | ||
or | ||
```yaml | ||
- name: Test | ||
uses: robherley/go-test-action@v0 | ||
with: | ||
omit: 'pie' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import * as core from '@actions/core' | ||
import { OmitOption, getInputs } from '../src/inputs' | ||
|
||
jest.mock('@actions/core') | ||
|
||
const mockGetInput = core.getInput as jest.MockedFunction<typeof core.getInput> | ||
const mockGetBooleanInput = core.getBooleanInput as jest.MockedFunction< | ||
typeof core.getBooleanInput | ||
> | ||
|
||
const mockInput = (name: string, value: string) => { | ||
mockGetInput.mockImplementation((n: string) => (n === name ? value : '')) | ||
} | ||
|
||
describe('renderer', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
it('uses default values', () => { | ||
mockGetInput.mockReturnValue('') | ||
const inputs = getInputs() | ||
|
||
expect(inputs).toEqual({ | ||
moduleDirectory: '.', | ||
testArguments: ['./...'], | ||
fromJSONFile: null, | ||
omit: new Set(), | ||
}) | ||
}) | ||
|
||
it('parses moduleDirectory', () => { | ||
mockInput('moduleDirectory', 'foo') | ||
const inputs = getInputs() | ||
|
||
expect(inputs.moduleDirectory).toEqual('foo') | ||
}) | ||
|
||
it('parses testArguments', () => { | ||
mockInput('testArguments', 'foo bar') | ||
const inputs = getInputs() | ||
|
||
expect(inputs.testArguments).toEqual(['foo', 'bar']) | ||
}) | ||
|
||
it('parses fromJSONFile', () => { | ||
mockInput('fromJSONFile', 'foo.json') | ||
const inputs = getInputs() | ||
|
||
expect(inputs.fromJSONFile).toEqual('foo.json') | ||
}) | ||
|
||
it('parses omit', () => { | ||
mockInput( | ||
'omit', | ||
[...Object.values(OmitOption), 'foo', 'bar', 'baz'].join('\n') | ||
) | ||
const inputs = getInputs() | ||
|
||
expect(inputs.omit).toEqual(new Set(Object.values(OmitOption))) | ||
}) | ||
|
||
it('supports deprecated inputs', () => { | ||
mockGetInput.mockImplementation((name: string) => { | ||
switch (name) { | ||
case 'omitUntestedPackages': | ||
case 'omitSuccessfulPackages': | ||
case 'omitPie': | ||
return 'true' | ||
default: | ||
return '' | ||
} | ||
}) | ||
|
||
mockGetBooleanInput.mockReturnValue(true) | ||
|
||
const inputs = getInputs() | ||
expect(inputs.omit).toEqual( | ||
new Set([OmitOption.Untested, OmitOption.Successful, OmitOption.Pie]) | ||
) | ||
expect(core.warning).toHaveBeenCalled() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.